├── .ci ├── all_check.py ├── build.sh ├── build_clash_dev.sh ├── build_docs.sh ├── build_sdist.sh ├── cabal.project.local ├── cabal.project.local.append-HEAD ├── docker │ ├── Dockerfile │ └── build-and-publish-docker-image.sh ├── effective_cpus.sh ├── get_build_dist.sh ├── gitlab │ ├── benchmark.yml │ ├── common.yml │ ├── publish.yml │ └── test.yml ├── kloonbot.sh ├── publish_sdist.sh ├── report_status.sh ├── retry.sh ├── setup-gitlab-runner.sh ├── setup.sh ├── stack-8.10.yaml ├── stack-9.0.yaml ├── stack-9.10.yaml ├── stack-9.2.yaml ├── stack-9.4.yaml ├── stack-9.6.yaml └── stack-9.8.yaml ├── .github ├── PULL_REQUEST_TEMPLATE.md └── workflows │ ├── ci.yml │ └── kloonbot.yml ├── .gitignore ├── .gitlab-ci.yml ├── .mergify.yml ├── .readthedocs.yml ├── .vscode ├── README.md ├── extensions.json └── settings.json ├── ARCHITECTURE.md ├── AUTHORS.md ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── Clash.hs ├── HACKING.rst ├── LICENSE ├── README.md ├── RELEASING.md ├── STYLE.rst ├── benchmark ├── benchmark-concurrency.hs ├── benchmark-normalization.hs ├── clash-benchmark.cabal ├── common │ └── BenchmarkCommon.hs ├── profiling │ ├── README.profiling.md │ ├── prepare │ │ ├── clash-profiling-prepare.cabal │ │ ├── instances │ │ │ └── SerialiseInstances.hs │ │ ├── profile-netlist-prepare.hs │ │ └── profile-normalization-prepare.hs │ └── run │ │ ├── clash-profiling.cabal │ │ ├── profile-netlist-run.hs │ │ └── profile-normalization-run.hs └── tests │ ├── BundleMapRepeat.hs │ ├── ManyEntitiesEqual.hs │ ├── ManyEntitiesVaried.hs │ └── PipelinesViaFolds.hs ├── cabal.project ├── changelog ├── 2024-02-11T11_14_33+01_00_drop_support_for_ghc86_ghc88 ├── 2024-02-22T13_45_10+01_00_remove_verilator_shims ├── 2024-03-04T11_17_07+01_00_fix_2508 ├── 2024-03-09T15_02_17+01_00_fix_2482 ├── 2024-03-10T17_55_54+01_00_add_counter_instances ├── 2024-03-11T21_22_11+01_00_make_counter_functions_public ├── 2024-04-08T06_51_45+00_00_smap_with_bounds ├── 2024-05-07T22_51_59+10_00_add_vec_complete_pragma ├── 2024-06-18T11_16_48+02_00_add_time_types ├── 2024-07-05T14_06_50+02_00_require_positive_period ├── 2024-07-07T22_14_16+02_00_remove_multiple_hidden ├── 2024-08-20T14_53_00+10_00_add_ramop_autoreg_instance ├── 2024-10-29T14_54_54+01_00_fix2831 ├── 2024-11-02T17_43_16+08_00_distributive_representative_vec ├── 2024-11-16T11_59_31+01_00_avoid_using_unsafecoerce ├── 2024-11-25T20_38_27+08_00_reset_strategy ├── 2024-12-14T13_35_37+01_00_fix_ddr_prims ├── 2025-01-16T14_20_35+01_00_ddroutclock ├── 2025-01-22T16_23_00+01_00_improve_ddr ├── 2025-02-10T20_01_41+01_00_reorder_hedgehog_type_args ├── 2025-02-13T09_00_14+01_00_add_resize_functions ├── 2025-02-15T11_08_19+01_00_drop_default_class ├── 2025-03-04T15_40_21+01_00_account_for_simonly ├── 2025-03-06T11_10_03+01_00_add_nfdatax_simonly ├── 2025-03-19T08_52_01+01_00_new_partial_signal_operators ├── 2025-03-30T20_42_00+02_00_add_clash_class_num_convert ├── 2025-04-02T09_08_44+02_00_add_ghc967_support ├── 2025-04-05T17_48_30+02_00_ignore_ticks ├── 2025-04-18T15_27_46+02_00_less_knownnat ├── 2025-04-27T14_45_08+02_00_windows_910 ├── 2025-04-28T14_17_05+02_00_fix2542 ├── 2025-05-09T17_51_26+02_00_bitpack_char ├── README.md ├── blame-pr.py └── comment-gh.py ├── clash-cosim ├── .gitignore ├── LICENSE ├── README.md ├── Setup.hs ├── clash-cosim.cabal ├── src │ ├── Clash │ │ ├── CoSim.hs │ │ └── CoSim │ │ │ ├── CoSimInstances.hs │ │ │ ├── CodeGeneration.hs │ │ │ ├── DSLParser.hs │ │ │ ├── Paths_clash_cosim.hs │ │ │ ├── Simulator.hs │ │ │ └── Types.hs │ ├── cbits │ │ ├── Makefile │ │ ├── comm │ │ │ ├── cosim_comm.c │ │ │ └── cosim_comm.h │ │ ├── control │ │ │ ├── cosim_control_vpi.c │ │ │ └── cosim_control_vpi.h │ │ ├── cosim_clash.c │ │ ├── cosim_vpi.c │ │ ├── include │ │ │ ├── vpi_compatibility.h │ │ │ └── vpi_user.h │ │ ├── process │ │ │ ├── cosim_commands.c │ │ │ ├── cosim_commands.h │ │ │ ├── cosim_process.c │ │ │ └── cosim_process.h │ │ ├── traversing │ │ │ ├── cosim_traversing.c │ │ │ ├── cosim_traversing.h │ │ │ ├── cosim_traversing_vpi.c │ │ │ └── cosim_traversing_vpi.h │ │ └── types │ │ │ ├── cosim_types.c │ │ │ ├── cosim_types.h │ │ │ ├── cosim_types_vpi.c │ │ │ └── cosim_types_vpi.h │ └── prims │ │ └── verilog │ │ └── README.md └── tests │ ├── CoSimTest.hs │ └── test.hs ├── clash-dev ├── clash-dev.ps1 ├── clash-ffi ├── .gitignore ├── LICENSE ├── README.md ├── cbits │ └── entry_vpi.c ├── clash-ffi.cabal ├── example │ ├── LICENSE │ ├── Setup.hs │ ├── Simulate.hs │ ├── cabal.project │ ├── clash-ffi-example.cabal │ ├── run-iverilog.sh │ └── run-vsim.sh ├── include │ └── vpi_user.h ├── src │ └── Clash │ │ └── FFI │ │ ├── VPI │ │ ├── Callback.hs │ │ ├── Callback │ │ │ └── Reason.hs │ │ ├── Control.hs │ │ ├── Error.hs │ │ ├── Error │ │ │ ├── Level.hs │ │ │ └── State.hs │ │ ├── IO.hs │ │ ├── Info.hs │ │ ├── Iterator.hs │ │ ├── Module.hs │ │ ├── Net.hs │ │ ├── Object.hs │ │ ├── Object │ │ │ ├── Property.hs │ │ │ ├── Time.hs │ │ │ ├── Type.hs │ │ │ ├── Value.hs │ │ │ └── Value │ │ │ │ ├── Delay.hs │ │ │ │ ├── Format.hs │ │ │ │ ├── Parse.hs │ │ │ │ ├── Scalar.hs │ │ │ │ └── Vector.hs │ │ ├── Parameter.hs │ │ ├── Port.hs │ │ ├── Port │ │ │ └── Direction.hs │ │ └── Reg.hs │ │ └── View.hs └── tests │ ├── Clash │ └── FFI │ │ ├── Test.hs │ │ └── Test │ │ └── Instances.hs │ ├── Main.hs │ └── cbits │ ├── Pipe.c │ ├── Pipe.h │ ├── Print.c │ ├── Print.h │ ├── Test.c │ ├── Test.h │ └── VPI.c ├── clash-ghc ├── CHANGELOG.md ├── LICENSE ├── LICENSE_GHC ├── README.md ├── Setup.hs ├── cbits │ ├── PosixSource.h │ └── hschooks.c ├── clash-ghc.cabal ├── src-bin-8.10 │ └── Clash │ │ ├── GHCi │ │ ├── Leak.hs │ │ ├── UI.hs │ │ ├── UI │ │ │ ├── Info.hs │ │ │ ├── Monad.hs │ │ │ └── Tags.hs │ │ └── Util.hs │ │ └── Main.hs ├── src-bin-9.0 │ └── Clash │ │ ├── GHCi │ │ ├── Leak.hs │ │ ├── UI.hs │ │ ├── UI │ │ │ ├── Info.hs │ │ │ ├── Monad.hs │ │ │ └── Tags.hs │ │ └── Util.hs │ │ └── Main.hs ├── src-bin-9.10 │ └── Clash │ │ ├── GHCi │ │ ├── Leak.hs │ │ ├── UI.hs │ │ ├── UI │ │ │ ├── Exception.hs │ │ │ ├── Info.hs │ │ │ └── Monad.hs │ │ └── Util.hs │ │ └── Main.hs ├── src-bin-9.2 │ └── Clash │ │ ├── GHCi │ │ ├── Leak.hs │ │ ├── UI.hs │ │ ├── UI │ │ │ ├── Info.hs │ │ │ ├── Monad.hs │ │ │ └── Tags.hs │ │ └── Util.hs │ │ └── Main.hs ├── src-bin-9.4 │ └── Clash │ │ ├── GHCi │ │ ├── Leak.hs │ │ ├── UI.hs │ │ ├── UI │ │ │ ├── Info.hs │ │ │ ├── Monad.hs │ │ │ └── Tags.hs │ │ └── Util.hs │ │ └── Main.hs ├── src-bin-9.6 │ └── Clash │ │ ├── GHCi │ │ ├── Leak.hs │ │ ├── UI.hs │ │ ├── UI │ │ │ ├── Info.hs │ │ │ ├── Monad.hs │ │ │ └── Tags.hs │ │ └── Util.hs │ │ └── Main.hs ├── src-bin-9.8 │ └── Clash │ │ ├── GHCi │ │ ├── Leak.hs │ │ ├── UI.hs │ │ ├── UI │ │ │ ├── Exception.hs │ │ │ ├── Info.hs │ │ │ └── Monad.hs │ │ └── Util.hs │ │ └── Main.hs ├── src-bin-common │ └── Clash │ │ └── GHCi │ │ └── Common.hs └── src-ghc │ ├── Batch.hs │ ├── Clash │ └── GHC │ │ ├── ClashFlags.hs │ │ ├── Evaluator.hs │ │ ├── Evaluator.hs-boot │ │ ├── Evaluator │ │ └── Primitive.hs │ │ ├── GHC2Core.hs │ │ ├── GenerateBindings.hs │ │ ├── LoadInterfaceFiles.hs │ │ ├── LoadModules.hs │ │ ├── NetlistTypes.hs │ │ ├── PartialEval.hs │ │ ├── PartialEval │ │ ├── Eval.hs │ │ ├── Primitive.hs │ │ └── Quote.hs │ │ └── Util.hs │ ├── Data │ └── Text │ │ └── Extra.hs │ └── Interactive.hs ├── clash-lib-hedgehog ├── LICENSE ├── clash-lib-hedgehog.cabal └── src │ └── Clash │ └── Hedgehog │ ├── Core │ ├── DataCon.hs │ ├── Literal.hs │ ├── Monad.hs │ ├── Name.hs │ ├── Term.hs │ ├── TyCon.hs │ ├── Type.hs │ └── Var.hs │ ├── Internal │ └── Bias.hs │ └── Unique.hs ├── clash-lib ├── CHANGELOG.md ├── LICENSE ├── README.md ├── Setup.hs ├── clash-lib.cabal ├── data-files │ └── tcl │ │ └── clashConnector.tcl ├── prims │ ├── common │ │ ├── Clash_Annotations_BitRepresentation_Deriving.primitives.yaml │ │ ├── Clash_Class_BitPack.primitives.yaml │ │ ├── Clash_Explicit_Signal.primitives.yaml │ │ ├── Clash_Explicit_Testbench.primitives.yaml │ │ ├── Clash_GHC_GHC2Core.primitives.yaml │ │ ├── Clash_Intel_ClockGen.primitives.yaml │ │ ├── Clash_Magic.primitives.yaml │ │ ├── Clash_Normalize_Primitives.primitives.yaml │ │ ├── Clash_Promoted_Nat.primitives.yaml │ │ ├── Clash_Promoted_Nat_Unsafe.primitives.yaml │ │ ├── Clash_Promoted_Symbol.primitives.yaml │ │ ├── Clash_Signal_BiSignal.primitives.yaml │ │ ├── Clash_Signal_Bundle.primitives.yaml │ │ ├── Clash_Signal_Internal.primitives.yaml │ │ ├── Clash_Signal_Trace.primitives.yaml │ │ ├── Clash_Sized_Internal_BitVector.primitives.yaml │ │ ├── Clash_Sized_Internal_Signed.primitives.yaml │ │ ├── Clash_Sized_Internal_Unsigned.primitives.yaml │ │ ├── Clash_Sized_RTree.primitives.yaml │ │ ├── Clash_Sized_Vector.primitives.yaml │ │ ├── Clash_XException.primitives.yaml │ │ ├── Clash_Xilinx_ClockGen.primitives.yaml │ │ ├── Control_Exception_Base.primitives.yaml │ │ ├── Debug_Trace.primitives.yaml │ │ ├── GHC_Base.primitives.yaml │ │ ├── GHC_CString.primitives.yaml │ │ ├── GHC_Classes.primitives.yaml │ │ ├── GHC_Err.primitives.yaml │ │ ├── GHC_IO_Exception.primitives.yaml │ │ ├── GHC_Integer_Type.primitives.yaml │ │ ├── GHC_Internal_Debug_Trace.primitives.yaml │ │ ├── GHC_Internal_Err.primitives.yaml │ │ ├── GHC_Internal_TypeNats.primitives.yaml │ │ ├── GHC_Magic.primitives.yaml │ │ ├── GHC_Natural.primitives.yaml │ │ ├── GHC_Num_Integer.primitives.yaml │ │ ├── GHC_Num_Natural.primitives.yaml │ │ ├── GHC_Prim.primitives.yaml │ │ ├── GHC_Prim_Panic.primitives.yaml │ │ ├── GHC_Real.primitives.yaml │ │ ├── GHC_TypeNats.primitives.yaml │ │ ├── GHC_Typelits.primitives.yaml │ │ ├── GHC_Types.primitives.yaml │ │ └── Unsafe_Coerce.primitives.yaml │ ├── commonverilog │ │ ├── Clash_Class_BitPack.primitives.yaml │ │ ├── Clash_Class_Exp.primitives.yaml │ │ ├── Clash_Explicit_SimIO.primitives.yaml │ │ ├── Clash_Explicit_Testbench.primitives.yaml │ │ ├── Clash_Intel_DDR.primitives.yaml │ │ ├── Clash_Magic.primitives.yaml │ │ ├── Clash_Promoted_Nat.primitives.yaml │ │ ├── Clash_Signal_Internal.primitives.yaml │ │ ├── Clash_Sized_Internal_BitVector.primitives.yaml │ │ ├── Clash_Sized_Internal_Index.primitives.yaml │ │ ├── Clash_Sized_Internal_Signed.primitives.yaml │ │ ├── Clash_Sized_Internal_Unsigned.primitives.yaml │ │ ├── Clash_Sized_Vector.primitives.yaml │ │ ├── GHC_Base.primitives.yaml │ │ ├── GHC_Classes.primitives.yaml │ │ ├── GHC_Int.primitives.yaml │ │ ├── GHC_Integer_Logarithms.primitives.yaml │ │ ├── GHC_Integer_Type.primitives.yaml │ │ ├── GHC_Natural.primitives.yaml │ │ ├── GHC_Num_Integer.primitives.yaml │ │ ├── GHC_Num_Natural.primitives.yaml │ │ ├── GHC_Prim.primitives.yaml │ │ └── GHC_Word.primitives.yaml │ ├── systemverilog │ │ ├── Clash_Explicit_BlockRam.primitives.yaml │ │ ├── Clash_Explicit_BlockRam_Blob.primitives.yaml │ │ ├── Clash_Explicit_BlockRam_File.primitives.yaml │ │ ├── Clash_Explicit_DDR.primitives.yaml │ │ ├── Clash_Explicit_RAM.primitives.yaml │ │ ├── Clash_Explicit_ROM.primitives.yaml │ │ ├── Clash_Explicit_ROM_Blob.primitives.yaml │ │ ├── Clash_Explicit_ROM_File.primitives.yaml │ │ ├── Clash_Explicit_Testbench.primitives.yaml │ │ ├── Clash_Intel_DDR.primitives.yaml │ │ ├── Clash_Prelude_ROM.primitives.yaml │ │ ├── Clash_Prelude_ROM_Blob.primitives.yaml │ │ ├── Clash_Prelude_ROM_File.primitives.yaml │ │ ├── Clash_Signal_BiSignal.primitives.yaml │ │ ├── Clash_Signal_Internal.primitives.yaml │ │ ├── Clash_Sized_Internal_BitVector.primitives.yaml │ │ ├── Clash_Sized_Internal_Signed.primitives.yaml │ │ ├── Clash_Sized_Internal_Unsigned.primitives.yaml │ │ ├── Clash_Sized_RTree.primitives.yaml │ │ ├── Clash_Sized_Vector.primitives.yaml │ │ ├── Clash_Xilinx_DDR.primitives.yaml │ │ ├── GHC_Base.primitives.yaml │ │ ├── GHC_Classes.primitives.yaml │ │ ├── GHC_Integer_Type.primitives.yaml │ │ ├── GHC_Num_Integer.primitives.yaml │ │ └── GHC_Prim.primitives.yaml │ ├── verilog │ │ ├── Clash_Explicit_BlockRam.primitives.yaml │ │ ├── Clash_Explicit_BlockRam_Blob.primitives.yaml │ │ ├── Clash_Explicit_BlockRam_File.primitives.yaml │ │ ├── Clash_Explicit_DDR.primitives.yaml │ │ ├── Clash_Explicit_RAM.primitives.yaml │ │ ├── Clash_Explicit_ROM.primitives.yaml │ │ ├── Clash_Explicit_ROM_Blob.primitives.yaml │ │ ├── Clash_Explicit_ROM_File.primitives.yaml │ │ ├── Clash_Explicit_Testbench.primitives.yaml │ │ ├── Clash_Intel_DDR.primitives.yaml │ │ ├── Clash_Prelude_ROM.primitives.yaml │ │ ├── Clash_Prelude_ROM_Blob.primitives.yaml │ │ ├── Clash_Prelude_ROM_File.primitives.yaml │ │ ├── Clash_Signal_BiSignal.primitives.yaml │ │ ├── Clash_Signal_Internal.primitives.yaml │ │ ├── Clash_Sized_Internal_BitVector.primitives.yaml │ │ ├── Clash_Sized_Internal_Signed.primitives.yaml │ │ ├── Clash_Sized_Internal_Unsigned.primitives.yaml │ │ ├── Clash_Sized_RTree.primitives.yaml │ │ ├── Clash_Sized_Vector.primitives.yaml │ │ ├── Clash_Xilinx_DDR.primitives.yaml │ │ ├── GHC_Base.primitives.yaml │ │ ├── GHC_Classes.primitives.yaml │ │ ├── GHC_Integer_Type.primitives.yaml │ │ ├── GHC_Num_Integer.primitives.yaml │ │ └── GHC_Prim.primitives.yaml │ └── vhdl │ │ ├── Clash_Class_BitPack.primitives.yaml │ │ ├── Clash_Class_Exp.primitives.yaml │ │ ├── Clash_Explicit_BlockRam.primitives.yaml │ │ ├── Clash_Explicit_BlockRam_Blob.primitives.yaml │ │ ├── Clash_Explicit_BlockRam_File.primitives.yaml │ │ ├── Clash_Explicit_DDR.primitives.yaml │ │ ├── Clash_Explicit_RAM.primitives.yaml │ │ ├── Clash_Explicit_ROM.primitives.yaml │ │ ├── Clash_Explicit_ROM_Blob.primitives.yaml │ │ ├── Clash_Explicit_ROM_File.primitives.yaml │ │ ├── Clash_Explicit_SimIO.primitives.yaml │ │ ├── Clash_Explicit_Testbench.primitives.yaml │ │ ├── Clash_Intel_DDR.primitives.yaml │ │ ├── Clash_Magic.primitives.yaml │ │ ├── Clash_Prelude_ROM.primitives.yaml │ │ ├── Clash_Prelude_ROM_Blob.primitives.yaml │ │ ├── Clash_Prelude_ROM_File.primitives.yaml │ │ ├── Clash_Promoted_Nat.primitives.yaml │ │ ├── Clash_Signal_BiSignal.primitives.yaml │ │ ├── Clash_Signal_Internal.primitives.yaml │ │ ├── Clash_Sized_Internal_BitVector.primitives.yaml │ │ ├── Clash_Sized_Internal_Index.primitives.yaml │ │ ├── Clash_Sized_Internal_Signed.primitives.yaml │ │ ├── Clash_Sized_Internal_Unsigned.primitives.yaml │ │ ├── Clash_Sized_RTree.primitives.yaml │ │ ├── Clash_Sized_Vector.primitives.yaml │ │ ├── Clash_Xilinx_DDR.primitives.yaml │ │ ├── GHC_Base.primitives.yaml │ │ ├── GHC_Classes.primitives.yaml │ │ ├── GHC_Int.primitives.yaml │ │ ├── GHC_Integer_Logarithms.primitives.yaml │ │ ├── GHC_Integer_Type.primitives.yaml │ │ ├── GHC_Natural.primitives.yaml │ │ ├── GHC_Num_Integer.primitives.yaml │ │ ├── GHC_Num_Natural.primitives.yaml │ │ ├── GHC_Prim.primitives.yaml │ │ └── GHC_Word.primitives.yaml ├── src │ ├── Clash │ │ ├── Annotations │ │ │ ├── BitRepresentation │ │ │ │ └── ClashLib.hs │ │ │ └── TopEntity │ │ │ │ └── Extra.hs │ │ ├── Backend.hs │ │ ├── Backend │ │ │ ├── SystemVerilog.hs │ │ │ ├── VHDL.hs │ │ │ ├── Verilog.hs │ │ │ └── Verilog │ │ │ │ └── Time.hs │ │ ├── Core │ │ │ ├── DataCon.hs │ │ │ ├── EqSolver.hs │ │ │ ├── Evaluator │ │ │ │ └── Types.hs │ │ │ ├── FreeVars.hs │ │ │ ├── HasFreeVars.hs │ │ │ ├── HasType.hs │ │ │ ├── Literal.hs │ │ │ ├── Name.hs │ │ │ ├── PartialEval.hs │ │ │ ├── PartialEval │ │ │ │ ├── AsTerm.hs │ │ │ │ ├── Monad.hs │ │ │ │ └── NormalForm.hs │ │ │ ├── Pretty.hs │ │ │ ├── Subst.hs │ │ │ ├── Subst.hs-boot │ │ │ ├── Term.hs │ │ │ ├── Term.hs-boot │ │ │ ├── TermInfo.hs │ │ │ ├── TermLiteral.hs │ │ │ ├── TermLiteral │ │ │ │ └── TH.hs │ │ │ ├── TyCon.hs │ │ │ ├── TyCon.hs-boot │ │ │ ├── Type.hs │ │ │ ├── Type.hs-boot │ │ │ ├── TysPrim.hs │ │ │ ├── Util.hs │ │ │ ├── Var.hs │ │ │ └── VarEnv.hs │ │ ├── Data │ │ │ └── UniqMap.hs │ │ ├── DataFiles.hs │ │ ├── Debug.hs │ │ ├── Driver.hs │ │ ├── Driver │ │ │ ├── Bool.hs │ │ │ ├── BrokenGhcs.hs │ │ │ ├── Manifest.hs │ │ │ └── Types.hs │ │ ├── Edalize │ │ │ └── Edam.hs │ │ ├── Netlist.hs │ │ ├── Netlist.hs-boot │ │ ├── Netlist │ │ │ ├── BlackBox.hs │ │ │ ├── BlackBox.hs-boot │ │ │ ├── BlackBox │ │ │ │ ├── Parser.hs │ │ │ │ ├── Types.hs │ │ │ │ ├── Util.hs │ │ │ │ └── Util.hs-boot │ │ │ ├── Expr.hs │ │ │ ├── Id.hs │ │ │ ├── Id.hs-boot │ │ │ ├── Id │ │ │ │ ├── Common.hs │ │ │ │ ├── Internal.hs │ │ │ │ ├── SystemVerilog.hs │ │ │ │ ├── VHDL.hs │ │ │ │ └── Verilog.hs │ │ │ ├── Types.hs │ │ │ ├── Types.hs-boot │ │ │ └── Util.hs │ │ ├── Normalize.hs │ │ ├── Normalize │ │ │ ├── PrimitiveReductions.hs │ │ │ ├── Primitives.hs │ │ │ ├── Primitives.hs-boot │ │ │ ├── Strategy.hs │ │ │ ├── Strategy.hs-boot │ │ │ ├── Transformations.hs │ │ │ ├── Transformations │ │ │ │ ├── ANF.hs │ │ │ │ ├── Case.hs │ │ │ │ ├── Cast.hs │ │ │ │ ├── DEC.hs │ │ │ │ ├── EtaExpand.hs │ │ │ │ ├── Inline.hs │ │ │ │ ├── Letrec.hs │ │ │ │ ├── MultiPrim.hs │ │ │ │ ├── Reduce.hs │ │ │ │ ├── SeparateArgs.hs │ │ │ │ ├── Specialize.hs │ │ │ │ └── XOptimize.hs │ │ │ ├── Types.hs │ │ │ └── Util.hs │ │ ├── Pretty.hs │ │ ├── Primitives │ │ │ ├── Annotations │ │ │ │ └── SynthesisAttributes.hs │ │ │ ├── DSL.hs │ │ │ ├── GHC │ │ │ │ ├── Int.hs │ │ │ │ ├── Literal.hs │ │ │ │ └── Word.hs │ │ │ ├── Intel │ │ │ │ └── ClockGen.hs │ │ │ ├── Magic.hs │ │ │ ├── Sized │ │ │ │ ├── Signed.hs │ │ │ │ ├── ToInteger.hs │ │ │ │ └── Vector.hs │ │ │ ├── Types.hs │ │ │ ├── Util.hs │ │ │ ├── Verification.hs │ │ │ └── Xilinx │ │ │ │ └── ClockGen.hs │ │ ├── Rewrite │ │ │ ├── Combinators.hs │ │ │ ├── Types.hs │ │ │ ├── Util.hs │ │ │ └── WorkFree.hs │ │ ├── Unique.hs │ │ ├── Util.hs │ │ ├── Util │ │ │ ├── Eq.hs │ │ │ ├── Graph.hs │ │ │ ├── Interpolate.hs │ │ │ └── Supply.hs │ │ └── Verification │ │ │ └── Pretty.hs │ ├── ClashDebug.h │ ├── Data │ │ ├── Aeson │ │ │ └── Extra.hs │ │ ├── IntMap │ │ │ └── Extra.hs │ │ ├── List │ │ │ └── Extra.hs │ │ ├── Map │ │ │ └── Ordered │ │ │ │ └── Extra.hs │ │ ├── Monoid │ │ │ └── Extra.hs │ │ ├── Primitive │ │ │ └── ByteArray │ │ │ │ └── Extra.hs │ │ ├── Set │ │ │ └── Ordered │ │ │ │ └── Extra.hs │ │ └── Text │ │ │ ├── Extra.hs │ │ │ └── Prettyprint │ │ │ └── Doc │ │ │ └── Extra.hs │ └── GHC │ │ ├── BasicTypes │ │ └── Extra.hs │ │ └── SrcLoc │ │ └── Extra.hs ├── tests │ ├── Clash │ │ └── Tests │ │ │ ├── Core │ │ │ ├── FreeVars.hs │ │ │ ├── Subst.hs │ │ │ ├── TermLiteral.hs │ │ │ └── TermLiteral │ │ │ │ └── Types.hs │ │ │ ├── Driver │ │ │ └── Manifest.hs │ │ │ ├── Netlist │ │ │ └── Id.hs │ │ │ ├── Normalize │ │ │ └── Transformations.hs │ │ │ └── Util │ │ │ └── Interpolate.hs │ ├── Test │ │ └── Clash │ │ │ └── Rewrite.hs │ ├── doctests.hs │ └── unittests.hs └── tools │ ├── static-files.hs │ └── v16-upgrade-primitives.hs ├── clash-prelude-hedgehog ├── CHANGELOG.md ├── LICENSE ├── clash-prelude-hedgehog.cabal └── src │ └── Clash │ └── Hedgehog │ ├── Annotations │ └── SynthesisAttributes.hs │ ├── Signal.hs │ └── Sized │ ├── BitVector.hs │ ├── Index.hs │ ├── RTree.hs │ ├── Signed.hs │ ├── Unsigned.hs │ └── Vector.hs ├── clash-prelude ├── AUTHORS.md ├── CHANGELOG.md ├── HACKING.MD ├── LICENSE ├── README.md ├── benchmarks │ ├── BenchBitVector.hs │ ├── BenchCommon.hs │ ├── BenchFixed.hs │ ├── BenchRAM.hs │ ├── BenchSigned.hs │ ├── BenchUnsigned.hs │ ├── BenchVector.hs │ └── benchmark-main.hs ├── clash-prelude.cabal ├── doc │ ├── csSort.graffle │ ├── csSort.svg │ ├── firstDF.graffle │ ├── firstDF.svg │ ├── fold.graffle │ ├── fold.svg │ ├── foldl.graffle │ ├── foldl.svg │ ├── foldl1.graffle │ ├── foldl1.svg │ ├── foldr.graffle │ ├── foldr.svg │ ├── foldr1.graffle │ ├── foldr1.svg │ ├── generate.graffle │ ├── generate.svg │ ├── idDF.graffle │ ├── idDF.svg │ ├── ifoldl.graffle │ ├── ifoldl.svg │ ├── ifoldr.graffle │ ├── ifoldr.svg │ ├── imap.graffle │ ├── imap.svg │ ├── iterate.graffle │ ├── iterate.svg │ ├── izipWith.graffle │ ├── izipWith.svg │ ├── linuwial-wrap-types.css │ ├── lockStep.graffle │ ├── lockStep.svg │ ├── loopDF.graffle │ ├── loopDF.svg │ ├── loopDF_sync.graffle │ ├── loopDF_sync.svg │ ├── map.graffle │ ├── map.svg │ ├── mapAccumL.graffle │ ├── mapAccumL.svg │ ├── mapAccumR.graffle │ ├── mapAccumR.svg │ ├── parDF.graffle │ ├── parDF.svg │ ├── scanl.graffle │ ├── scanl.svg │ ├── scanlPar.graffle │ ├── scanlPar.svg │ ├── scanr.graffle │ ├── scanr.svg │ ├── secondDF.graffle │ ├── secondDF.svg │ ├── seqDF.graffle │ ├── seqDF.svg │ ├── sscanl.graffle │ ├── sscanl.svg │ ├── sscanr.graffle │ ├── sscanr.svg │ ├── stepLock.graffle │ ├── stepLock.svg │ ├── swapDF.graffle │ ├── swapDF.svg │ ├── zipWith.graffle │ ├── zipWith.svg │ ├── zipWith3.graffle │ └── zipWith3.svg ├── src │ ├── Clash │ │ ├── Annotations │ │ │ ├── BitRepresentation.hs │ │ │ ├── BitRepresentation │ │ │ │ ├── Deriving.hs │ │ │ │ ├── Internal.hs │ │ │ │ └── Util.hs │ │ │ ├── Primitive.hs │ │ │ ├── SynthesisAttributes.hs │ │ │ ├── TH.hs │ │ │ └── TopEntity.hs │ │ ├── CPP.hs │ │ ├── Class │ │ │ ├── AutoReg.hs │ │ │ ├── AutoReg │ │ │ │ ├── Instances.hs │ │ │ │ └── Internal.hs │ │ │ ├── BitPack.hs │ │ │ ├── BitPack │ │ │ │ ├── BitIndex.hs │ │ │ │ ├── BitReduction.hs │ │ │ │ ├── Internal.hs │ │ │ │ └── Internal │ │ │ │ │ └── TH.hs │ │ │ ├── Counter.hs │ │ │ ├── Counter │ │ │ │ ├── Internal.hs │ │ │ │ └── TH.hs │ │ │ ├── Exp.hs │ │ │ ├── HasDomain.hs │ │ │ ├── HasDomain │ │ │ │ ├── CodeGen.hs │ │ │ │ ├── Common.hs │ │ │ │ ├── HasSingleDomain.hs │ │ │ │ └── HasSpecificDomain.hs │ │ │ ├── Num.hs │ │ │ ├── NumConvert.hs │ │ │ ├── NumConvert │ │ │ │ └── Internal │ │ │ │ │ ├── MaybeNumConvert.hs │ │ │ │ │ └── NumConvert.hs │ │ │ ├── Parity.hs │ │ │ └── Resize.hs │ │ ├── Clocks.hs │ │ ├── Clocks │ │ │ └── Internal.hs │ │ ├── Examples.hs │ │ ├── Examples │ │ │ └── Internal.hs │ │ ├── Explicit │ │ │ ├── BlockRam.hs │ │ │ ├── BlockRam │ │ │ │ ├── Blob.hs │ │ │ │ ├── File.hs │ │ │ │ ├── Internal.hs │ │ │ │ └── Model.hs │ │ │ ├── DDR.hs │ │ │ ├── Mealy.hs │ │ │ ├── Moore.hs │ │ │ ├── Prelude.hs │ │ │ ├── Prelude │ │ │ │ └── Safe.hs │ │ │ ├── RAM.hs │ │ │ ├── ROM.hs │ │ │ ├── ROM │ │ │ │ ├── Blob.hs │ │ │ │ └── File.hs │ │ │ ├── Reset.hs │ │ │ ├── Signal.hs │ │ │ ├── Signal │ │ │ │ └── Delayed.hs │ │ │ ├── SimIO.hs │ │ │ ├── Synchronizer.hs │ │ │ ├── Testbench.hs │ │ │ └── Verification.hs │ │ ├── HaskellPrelude.hs │ │ ├── Hidden.hs │ │ ├── Intel │ │ │ ├── ClockGen.hs │ │ │ └── DDR.hs │ │ ├── Magic.hs │ │ ├── NamedTypes.hs │ │ ├── Num │ │ │ ├── Erroring.hs │ │ │ ├── Overflowing.hs │ │ │ ├── Saturating.hs │ │ │ ├── Wrapping.hs │ │ │ └── Zeroing.hs │ │ ├── Prelude.hs │ │ ├── Prelude │ │ │ ├── BlockRam.hs │ │ │ ├── BlockRam │ │ │ │ ├── Blob.hs │ │ │ │ └── File.hs │ │ │ ├── DataFlow.hs │ │ │ ├── Mealy.hs │ │ │ ├── Moore.hs │ │ │ ├── RAM.hs │ │ │ ├── ROM.hs │ │ │ ├── ROM │ │ │ │ ├── Blob.hs │ │ │ │ └── File.hs │ │ │ ├── Safe.hs │ │ │ └── Testbench.hs │ │ ├── Promoted │ │ │ ├── Nat.hs │ │ │ ├── Nat │ │ │ │ ├── Literals.hs │ │ │ │ ├── TH.hs │ │ │ │ └── Unsafe.hs │ │ │ └── Symbol.hs │ │ ├── Signal.hs │ │ ├── Signal │ │ │ ├── BiSignal.hs │ │ │ ├── Bundle.hs │ │ │ ├── Bundle │ │ │ │ └── Internal.hs │ │ │ ├── Delayed.hs │ │ │ ├── Delayed │ │ │ │ ├── Bundle.hs │ │ │ │ └── Internal.hs │ │ │ ├── Internal.hs │ │ │ ├── Internal │ │ │ │ └── Ambiguous.hs │ │ │ └── Trace.hs │ │ ├── Sized │ │ │ ├── BitVector.hs │ │ │ ├── Fixed.hs │ │ │ ├── Index.hs │ │ │ ├── Internal.hs │ │ │ ├── Internal │ │ │ │ ├── BitVector.hs │ │ │ │ ├── BitVector.hs-boot │ │ │ │ ├── Index.hs │ │ │ │ ├── Index.hs-boot │ │ │ │ ├── Mod.hs │ │ │ │ ├── Signed.hs │ │ │ │ └── Unsigned.hs │ │ │ ├── RTree.hs │ │ │ ├── Signed.hs │ │ │ ├── Unsigned.hs │ │ │ ├── Vector.hs │ │ │ ├── Vector.hs-boot │ │ │ └── Vector │ │ │ │ ├── ToTuple.hs │ │ │ │ └── ToTuple │ │ │ │ └── TH.hs │ │ ├── Tutorial.hs │ │ ├── Verification.hs │ │ ├── Verification │ │ │ ├── DSL.hs │ │ │ └── Internal.hs │ │ ├── XException.hs │ │ ├── XException.hs-boot │ │ ├── XException │ │ │ ├── Internal.hs │ │ │ ├── MaybeX.hs │ │ │ └── TH.hs │ │ └── Xilinx │ │ │ ├── ClockGen.hs │ │ │ └── DDR.hs │ └── Language │ │ └── Haskell │ │ └── TH │ │ └── Compat.hs └── tests │ ├── Clash │ └── Tests │ │ ├── AsyncFIFOSynchronizer.hs │ │ ├── AutoReg.hs │ │ ├── BitPack.hs │ │ ├── BitVector.hs │ │ ├── BlockRam.hs │ │ ├── BlockRam │ │ └── Blob.hs │ │ ├── Clocks.hs │ │ ├── Counter.hs │ │ ├── DerivingDataRepr.hs │ │ ├── DerivingDataReprTypes.hs │ │ ├── Fixed.hs │ │ ├── FixedExhaustive.hs │ │ ├── Laws │ │ ├── Enum.hs │ │ └── SaturatingNum.hs │ │ ├── MaybeNumConvert.hs │ │ ├── MaybeX.hs │ │ ├── NFDataX.hs │ │ ├── NumConvert.hs │ │ ├── NumNewtypes.hs │ │ ├── Ram.hs │ │ ├── Reset.hs │ │ ├── Resize.hs │ │ ├── Signal.hs │ │ ├── Signed.hs │ │ ├── SizedNum.hs │ │ ├── TopEntityGeneration.hs │ │ ├── Unsigned.hs │ │ ├── Vector.hs │ │ └── XException.hs │ ├── Hedgehog │ └── Extra.hs │ ├── Test │ ├── QuickCheck │ │ └── Extra.hs │ └── Tasty │ │ ├── HUnit │ │ └── Extra.hs │ │ └── Hedgehog │ │ └── Extra.hs │ ├── doctests.hs │ └── unittests.hs ├── clash-term ├── LICENSE ├── Main.hs ├── README.md ├── Setup.hs ├── clash-term.cabal └── theme.ini ├── default.nix ├── docs ├── CHANGELOG.md ├── README.md ├── build-docs.sh ├── changelog.rst ├── conf.py ├── developing-hardware │ ├── flags.rst │ ├── index.rst │ ├── language.rst │ └── prelude.rst ├── general │ ├── LICENSE │ ├── faqs.rst │ ├── index.rst │ ├── intro.rst │ ├── license.rst │ └── relnotes.rst ├── getting-started │ ├── first-circuit.rst │ ├── index.rst │ └── installing.rst ├── hacking-on-clash │ ├── hacking.rst │ ├── index.rst │ └── style.rst ├── index.rst ├── refs.rst └── requirements.txt ├── examples ├── ALU.hs ├── Blinker.hs ├── BlockRamTest.hs ├── CHIP8.hs ├── Calculator.hs ├── CalculatorTypes.hs ├── CochleaPlus.hs ├── FIR.hs ├── Fifo.hs ├── MAC.hs ├── MatrixVect.hs ├── Queens.hs ├── Reducer.hs ├── Sprockell.hs ├── Windows.hs ├── crc32 │ ├── CRC32.hs │ └── CRC32Table.hs └── i2c │ ├── I2C.hs │ ├── I2C │ ├── BitMaster.hs │ ├── BitMaster │ │ ├── BusCtrl.hs │ │ └── StateMachine.hs │ ├── ByteMaster.hs │ ├── ByteMaster │ │ └── ShiftRegister.hs │ └── Types.hs │ ├── I2Ctest.hs │ └── I2Ctest │ ├── I2CConfig.hs │ └── I2CSlave.hs ├── flake.lock ├── flake.nix ├── hie.yaml ├── nix ├── README.md ├── devshell.nix ├── overlay-ghc910.nix ├── overlay-ghc96.nix ├── overlay-ghc98.nix └── overlay.nix ├── repld ├── shell.nix ├── stack.yaml └── tests ├── LICENSE ├── Main.hs ├── Setup.hs ├── clash-testsuite.cabal ├── data-files └── tcl │ └── clash_namespace.tcl ├── shouldfail ├── BlackBox │ ├── T1945.hs │ └── WrongReference.hs ├── GADTs │ └── T1311.hs ├── InvalidPrimitive │ ├── InvalidPrimitive.hs │ └── InvalidPrimitive.primitives.yaml ├── LiftRecursiveGroup.hs ├── Poly.hs ├── Poly2.hs ├── PrimitiveGuards │ ├── DontTranslate.hs │ └── HasBlackBox.hs ├── RecursiveBoxed.hs ├── RecursiveDatatype.hs ├── RecursivePoly.hs ├── Signal │ └── MAC.hs ├── SynthesisAttributes │ ├── ProductInArgs.hs │ └── ProductInResult.hs ├── Testbench │ └── UnsafeOutputVerifier.hs ├── TopEntity │ ├── T1033.hs │ └── T1063.hs ├── Verification │ ├── NonTemporal.hs │ ├── NonTemporalPSL.hs │ ├── NonTemporalSVA.hs │ ├── SymbiYosys.hs │ └── Temporal.hs └── ZeroWidth │ ├── FailGracefully1.hs │ ├── FailGracefully2.hs │ └── FailGracefully3.hs ├── shouldwork ├── AutoReg │ ├── AutoReg.hs │ ├── T1507.hs │ └── T1632.hs ├── Basic │ ├── AES.hs │ ├── BangData.hs │ ├── ByteSwap32.hs │ ├── CaseOfErr.hs │ ├── CharTest.hs │ ├── ClassOps.hs │ ├── CountTrailingZeros.hs │ ├── DeepseqX.hs │ ├── DivMod.hs │ ├── DivZero.hs │ ├── IrrefError.hs │ ├── LambdaDrop.hs │ ├── LotOfStates.hs │ ├── NORX.hs │ ├── NameInlining.hs │ ├── NameInstance.hs │ ├── NameOverlap.hs │ ├── NestedPrimitives.hs │ ├── NestedPrimitives2.hs │ ├── Parameters.hs │ ├── PatError.hs │ ├── RecordSumOfProducts.hs │ ├── Replace.hs │ ├── SetName.hs │ ├── Shift.hs │ ├── SimOnly.hs │ ├── SimpleConstructor.hs │ ├── SimulationMagic2736.hs │ ├── SomeNatVal.hs │ ├── T1012.hs │ ├── T1240.hs │ ├── T1242.hs │ ├── T1254.hs │ ├── T1292.hs │ ├── T1297.hs │ ├── T1304.hs │ ├── T1305.hs │ ├── T1316.hs │ ├── T1322.hs │ ├── T1340.hs │ ├── T1354A.hs │ ├── T1354B.hs │ ├── T1402.hs │ ├── T1402b.hs │ ├── T1556.hs │ ├── T1591.hs │ ├── TagToEnum.hs │ ├── TestIndex.hs │ ├── Time.hs │ ├── Trace.hs │ ├── TwoFunctions.hs │ ├── TyEqConstraints.hs │ ├── XToError.hs │ └── precompiled │ │ └── SimulationMagic2736a.hs ├── BitVector │ ├── AppendZero.hs │ ├── Box.hs │ ├── BoxGrow.hs │ ├── CLZ.hs │ ├── ExtendingNumZero.hs │ ├── GenericBitPack.hs │ ├── GenericBitPackTypes.hs │ ├── RePack.hs │ ├── ReduceOne.hs │ ├── ReduceZero.hs │ └── UnpackUndefined.hs ├── BlackBox │ ├── BlackBoxFunction.hs │ ├── BlackBoxFunctionHO.hs │ ├── DSL.hs │ ├── ExternalPrimitive.hs │ ├── ExternalPrimitive.primitives │ ├── ExternalPrimitive.primitives.yaml │ ├── LITrendering.hs │ ├── MultiResult.hs │ ├── T1524.hs │ ├── T1786.hs │ ├── T2117.hs │ ├── T919.hs │ ├── TemplateFunction.hs │ └── ZeroWidth.hs ├── BoxedFunctions │ └── DeadRecursiveBoxed.hs ├── CSignal │ ├── CBlockRamTest.hs │ └── MAC.hs ├── CoSim │ ├── Multiply.hs │ └── Register.hs ├── CustomReprs │ ├── Deriving │ │ └── BitPackDerivation.hs │ ├── Indexed │ │ ├── Indexed.hs │ │ └── Type.hs │ ├── Rotate │ │ └── Rotate.hs │ ├── RotateC │ │ ├── ReprCompact.hs │ │ ├── ReprCompactScrambled.hs │ │ ├── ReprLastBitConstructor.hs │ │ ├── ReprStrangeMasks.hs │ │ ├── ReprWide.hs │ │ ├── RotateC.hs │ │ └── RotateCScrambled.hs │ ├── RotateCNested │ │ └── RotateCNested.hs │ ├── T694.hs │ └── ZeroWidth │ │ └── ZeroWidth.hs ├── DDR │ ├── DDRin.hs │ ├── DDRout.hs │ ├── IntelDDR.hs │ ├── VendorDDR.hs │ └── XilinxDDR.hs ├── DSignal │ ├── DelayI.hs │ ├── DelayN.hs │ └── DelayedFold.hs ├── Feedback │ ├── Fib.hs │ └── MutuallyRecursive.hs ├── Fixed │ ├── Mixer.hs │ ├── SFixedTest.hs │ ├── SatWrap.hs │ └── ZeroInt.hs ├── FixedNumber │ └── FixedS.hs ├── Floating │ ├── FloatConstFolding.hs │ ├── FloatPack.hs │ └── T1803.hs ├── GADTs │ ├── Constrained.hs │ ├── Head.hs │ ├── HeadM.hs │ ├── MonomorphicTopEntity.hs │ ├── Record.hs │ ├── T1310.hs │ ├── T1536.hs │ ├── Tail.hs │ ├── TailM.hs │ └── TailOfTail.hs ├── HOPrim │ ├── HOIdx.hs │ ├── HOImap.hs │ ├── Map.hs │ ├── Map2.hs │ ├── TestMap.hs │ ├── Transpose.hs │ └── VecFun.hs ├── Issues │ ├── T1171.hs │ ├── T1187.hs │ ├── T1187 │ │ ├── Keypad.hs │ │ ├── SerialTx.hs │ │ └── Utils.hs │ ├── T1388.hs │ ├── T1439.hs │ ├── T1477.hs │ ├── T1506A.hs │ ├── T1506B.hs │ ├── T1568.hs │ ├── T1606A.hs │ ├── T1606B.hs │ ├── T1615.hs │ ├── T1663.hs │ ├── T1669_DEC.hs │ ├── T1715.hs │ ├── T1721.hs │ ├── T1742.hs │ ├── T1756.hs │ ├── T1881.hs │ ├── T1921.hs │ ├── T1933.hs │ ├── T1996.hs │ ├── T2040.hs │ ├── T2046.hs │ ├── T2046B.hs │ ├── T2046BType.hs │ ├── T2046C.hs │ ├── T2097.hs │ ├── T2154.hs │ ├── T2220_toEnumOOB.hs │ ├── T2272.hs │ ├── T2325.hs │ ├── T2325f.hs │ ├── T2325g.hs │ ├── T2325h.hs │ ├── T2325j.hs │ ├── T2334.hs │ ├── T2342A.hs │ ├── T2342B.hs │ ├── T2360.hs │ ├── T2502.hs │ ├── T2508.hs │ ├── T2510.hs │ ├── T2542.hs │ ├── T2593.hs │ ├── T2623CaseConFVs.hs │ ├── T2628.hs │ ├── T2831.hs │ ├── T2839.hs │ ├── T2845.hs │ ├── T2904.hs │ ├── T359.hs │ ├── T431.hs │ ├── T508.hs │ └── T779.hs ├── LoadModules │ ├── T1796.hs │ └── precompiled │ │ └── T1796a.hs ├── Naming │ ├── NameHint.hs │ ├── T1041.hs │ ├── T967a.hs │ ├── T967b.hs │ └── T967c.hs ├── Netlist │ ├── Identity.hs │ ├── NoDeDup.hs │ ├── T1766.hs │ └── T1935.hs ├── Numbers │ ├── BitInteger.hs │ ├── BitReverse.hs │ ├── Bits.hs │ ├── BitsTB.hs │ ├── Bounds.hs │ ├── ConstantFoldingUtil.hs │ ├── DivideByZero.hs │ ├── Exp.hs │ ├── ExpWithClashCF.hs │ ├── ExpWithGhcCF.hs │ ├── HalfAsBlackboxArg.hs │ ├── Integral.hs │ ├── IntegralTB.hs │ ├── NaturalToInteger.hs │ ├── Naturals.hs │ ├── NegativeLits.hs │ ├── NumConstantFoldingTB_1.hs │ ├── NumConstantFoldingTB_2.hs │ ├── NumConstantFolding_1.hs │ ├── NumConstantFolding_2.hs │ ├── NumConstantFolding_Common.hs │ ├── Resize.hs │ ├── Resize2.hs │ ├── Resize3.hs │ ├── SatMult.hs │ ├── ShiftRotate.hs │ ├── ShiftRotateBase.hs │ ├── ShiftRotateNegative.hs │ ├── SignedProjection.hs │ ├── SignedProjectionTB.hs │ ├── SignedZero.hs │ ├── Signum.hs │ ├── Strict.hs │ ├── T1019.hs │ ├── T1351.hs │ ├── T2149.hs │ ├── UndefinedConstantFolding.hs │ ├── UndefinedConstantFoldingTB.hs │ └── UnsignedZero.hs ├── PartialEvaluation │ ├── CaseOfCase.hs │ ├── EtaExpansion.hs │ ├── KnownCase.hs │ ├── LazyEvaluation.hs │ └── MutualRecursion.hs ├── Polymorphism │ ├── ExistentialBoxed.hs │ ├── FunctionInstances.hs │ ├── GADTExistential.hs │ └── LocalPoly.hs ├── PrimitiveGuards │ ├── MultipleGuards.hs │ └── WarnAlways.hs ├── PrimitiveReductions │ ├── Lambda.hs │ └── ReplaceInt.hs ├── RTree │ ├── TFold.hs │ ├── TRepeat.hs │ ├── TRepeat2.hs │ └── TZip.hs ├── Shadowing │ └── T990.hs ├── Signal │ ├── AlwaysHigh.hs │ ├── AndEnable.hs │ ├── BangPatterns.hs │ ├── BiSignal │ │ ├── Counter.hs │ │ ├── CounterHalfTuple.hs │ │ ├── CounterHalfTupleRev.hs │ │ └── T2472.hs │ ├── BlockRam │ │ └── Blob.hs │ ├── BlockRam0.hs │ ├── BlockRam1.hs │ ├── BlockRamFile.hs │ ├── BlockRamLazy.hs │ ├── BlockRamTest.hs │ ├── Compression.hs │ ├── DelayedReset.hs │ ├── DualBlockRam.hs │ ├── DualBlockRamDefinitions.hs │ ├── DualBlockRamTypes.hs │ ├── DynamicClocks.hs │ ├── NoCPR.hs │ ├── Oversample.hs │ ├── ROM │ │ ├── Async.hs │ │ ├── AsyncBlob.hs │ │ ├── Blob.hs │ │ └── BlobVec.hs │ ├── Ram.hs │ ├── Ram │ │ ├── RMulti.hs │ │ ├── RMultiTop.hs │ │ ├── RWMulti.hs │ │ └── RWMultiTop.hs │ ├── RegisterAE.hs │ ├── RegisterAR.hs │ ├── RegisterSE.hs │ ├── RegisterSR.hs │ ├── ResetGen.hs │ ├── ResetLow.hs │ ├── ResetSynchronizer.hs │ ├── Rom.hs │ ├── RomFile.hs │ ├── RomNegative.hs │ ├── SigP.hs │ ├── T1007.hs │ ├── T1102A.hs │ ├── T1102B.hs │ ├── T2069.hs │ └── memory.list ├── SimIO │ ├── Test00.hs │ ├── goldenInput00.txt │ └── goldenOutput00.txt ├── SynthesisAttributes │ ├── Annotate.hs │ ├── InstDeclAnnotations.hs │ ├── MultipleAnnotations.hs │ ├── Product.hs │ ├── Simple.hs │ └── T1771.hs ├── Testbench │ ├── SyncTB.hs │ └── TB.hs ├── TopEntity │ ├── Multiple.hs │ ├── PortGeneration.hs │ ├── PortNames.hs │ ├── PortNamesWithRTree.hs │ ├── PortNamesWithSingletonVector.hs │ ├── PortNamesWithUnit.hs │ ├── PortNamesWithVector.hs │ ├── PortProducts.hs │ ├── PortProductsSum.hs │ ├── T1033.hs │ ├── T1072.hs │ ├── T1074.hs │ ├── T1139.hs │ ├── T1182A.hs │ ├── T1182B.hs │ ├── T701.hs │ └── TopEntHOArg.hs ├── Types │ ├── NatExp.hs │ └── TypeFamilyReduction.hs ├── Unit │ ├── Imap.hs │ ├── MapConstUnit.hs │ ├── ZipWithTripleWithUnitMiddle.hs │ ├── ZipWithTupleWithUnitLeft.hs │ ├── ZipWithTupleWithUnitRight.hs │ ├── ZipWithUnitSP.hs │ ├── ZipWithUnitSP2.hs │ └── ZipWithUnitVector.hs ├── Vector │ ├── Concat.hs │ ├── DFold.hs │ ├── DFold2.hs │ ├── DTFold.hs │ ├── EnumTypes.hs │ ├── FindIndex.hs │ ├── FirOddSize.hs │ ├── Fold.hs │ ├── FoldlFuns.hs │ ├── Foldr.hs │ ├── FoldrEmpty.hs │ ├── HOClock.hs │ ├── HOCon.hs │ ├── HOPrim.hs │ ├── IndexInt.hs │ ├── IndexInt2.hs │ ├── Indices.hs │ ├── Iterate.hs │ ├── IterateCF.hs │ ├── Minimum.hs │ ├── MovingAvg.hs │ ├── PatHOCon.hs │ ├── Scatter.hs │ ├── Split.hs │ ├── T1360.hs │ ├── T452.hs │ ├── T478.hs │ ├── T895.hs │ ├── ToList.hs │ ├── Unconcat.hs │ ├── VACC.hs │ ├── VEmpty.hs │ ├── VFold.hs │ ├── VIndex.hs │ ├── VIndicesI.hs │ ├── VMapAccum.hs │ ├── VMerge.hs │ ├── VReplace.hs │ ├── VReverse.hs │ ├── VRotate.hs │ ├── VScan.hs │ ├── VSelect.hs │ ├── VZip.hs │ ├── VecConst.hs │ └── VecOfSum.hs ├── Verification │ └── SymbiYosys.hs ├── XOptimization │ ├── Conjunction.hs │ ├── Disjunction.hs │ ├── ManyDefined.hs │ ├── OneDefinedDataPat.hs │ ├── OneDefinedDefaultPat.hs │ └── OneDefinedLitPat.hs └── Xilinx │ └── ClockWizard.hs └── src └── Test └── Tasty ├── Clash.hs ├── Clash ├── CollectSimResults.hs ├── CoreTest.hs └── NetlistTest.hs ├── Common.hs ├── Ghdl.hs ├── Iverilog.hs ├── Modelsim.hs ├── Program.hs ├── SymbiYosys.hs ├── Verilator.hs └── Vivado.hs /.ci/all_check.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | """ 3 | Makes sure: 4 | * All jobs are listed in the 'all' job 5 | * Only existing tests are listed 6 | """ 7 | 8 | import sys 9 | import yaml 10 | 11 | CI_PATH = ".github/workflows/ci.yml" 12 | ALL_TEST = "all" 13 | 14 | def main(): 15 | ci_yml_fp = open(CI_PATH, "r") 16 | ci_yml_parsed = yaml.load(ci_yml_fp, Loader=yaml.FullLoader) 17 | 18 | all_jobs = set(ci_yml_parsed['jobs'].keys()) - {ALL_TEST} 19 | all_needs = set(ci_yml_parsed["jobs"][ALL_TEST]["needs"]) 20 | 21 | if all_jobs - all_needs: 22 | sys.exit(f"Not all jobs mentioned in {ALL_TEST}.needs: {all_jobs - all_needs}") 23 | 24 | if all_needs - all_jobs: 25 | sys.exit(f"Non-existing jobs found in {ALL_TEST}.needs: {all_needs - all_jobs}") 26 | 27 | 28 | if __name__ == '__main__': 29 | main() 30 | -------------------------------------------------------------------------------- /.ci/build_clash_dev.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -xeou pipefail 3 | 4 | # Check that clash-dev works 5 | echo "" > clash-dev.result 6 | echo 'main >> writeFile "clash-dev.result" "success"' | ./clash-dev 7 | if [[ "$(cat clash-dev.result)" != "success" ]]; then 8 | echo "clash-dev test failed" 9 | exit 1 10 | fi 11 | -------------------------------------------------------------------------------- /.ci/build_sdist.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -x -euf -o pipefail 3 | 4 | cd $(dirname $0)/.. 5 | 6 | # Enable documentation building for all dependencies 7 | sed -i 's/documentation: False/documentation: True/g' cabal.project.local 8 | 9 | # Build source distribution 10 | cabal sdist $1 |& tee sdist.log 11 | 12 | # Build documentation 13 | cabal v2-haddock $1 \ 14 | --haddock-for-hackage \ 15 | --haddock-hyperlinked-source \ 16 | --enable-documentation |& tee haddock.log 17 | 18 | # Extract location of sdist tarball 19 | SDIST=$(grep "Wrote tarball sdist to" -A 1 sdist.log | tail -n 1) 20 | 21 | # Extract location of documentation tarball 22 | DDIST=$(grep "Documentation tarball created:" -A 1 haddock.log | tail -n 1) 23 | 24 | # Copy 25 | cd - 26 | cp $SDIST $(basename $SDIST) # Example: clash-prelude-0.9999.tar.gz 27 | cp $DDIST $(basename $DDIST) # Example: clash-prelude-0.9999-docs.tar.gz 28 | -------------------------------------------------------------------------------- /.ci/cabal.project.local.append-HEAD: -------------------------------------------------------------------------------- 1 | 2 | repository head.hackage.ghc.haskell.org 3 | url: https://ghc.gitlab.haskell.org/head.hackage/ 4 | secure: True 5 | key-threshold: 3 6 | root-keys: 7 | f76d08be13e9a61a377a85e2fb63f4c5435d40f8feb3e12eb05905edb8cdea89 8 | 26021a13b401500c8eb2761ca95c61f2d625bfef951b939a8124ed12ecf07329 9 | 7541f32a4ccca4f97aea3b22f5e593ba2c0267546016b992dfadcd2fe944e55d 10 | 11 | allow-newer: *:base, *:Cabal, doctest:ghc, attoparsec:ghc-prim, *:template-haskell 12 | 13 | source-repository-package 14 | type: git 15 | location: https://github.com/haskell-hint/hint.git 16 | tag: fc4651a7c327c531645c8d4d2d03d9ed7d324f9f 17 | source-repository-package 18 | type: git 19 | location: https://github.com/utdemir/haskell-hedgehog.git 20 | tag: c98aa9e33bf6871098d6f4ac94eeaac10383d696 21 | subdir: hedgehog 22 | -------------------------------------------------------------------------------- /.ci/gitlab/publish.yml: -------------------------------------------------------------------------------- 1 | hackage-sdist: 2 | extends: .common-local 3 | needs: [] 4 | stage: pack 5 | script: 6 | - .ci/build_sdist.sh clash-prelude 7 | - .ci/build_sdist.sh clash-prelude-hedgehog 8 | - .ci/build_sdist.sh clash-lib 9 | - .ci/build_sdist.sh clash-lib-hedgehog 10 | - .ci/build_sdist.sh clash-ghc 11 | artifacts: 12 | paths: 13 | - clash-*.tar.gz # clash-{prelude,lib,ghc}-$version{-docs,}.tar.gz 14 | expire_in: 1 week 15 | 16 | .hackage: 17 | extends: .common 18 | interruptible: false 19 | stage: publish 20 | cache: 21 | key: hackage-$CI_JOB_IMAGE 22 | script: 23 | - .ci/publish_sdist.sh clash-prelude 24 | - .ci/publish_sdist.sh clash-prelude-hedgehog 25 | - .ci/publish_sdist.sh clash-lib 26 | - .ci/publish_sdist.sh clash-lib-hedgehog 27 | - .ci/publish_sdist.sh clash-ghc 28 | -------------------------------------------------------------------------------- /.ci/publish_sdist.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -eu -o pipefail 3 | 4 | PASSWORD=$(echo $HACKAGE_PASSWORD | base64 --decode --ignore-garbage) 5 | 6 | SDIST=$(find . -type f -regex "\./$1-[0-9\.]+\.tar\.gz") 7 | DDIST=$(find . -type f -regex "\./$1-[0-9\.]+-docs\.tar\.gz") 8 | 9 | set +u 10 | 11 | if [[ "$HACKAGE_RELEASE" == "yes" ]]; then 12 | # Release tag set, upload as release. 13 | cabal upload --publish --username=${HACKAGE_USERNAME} --password=${PASSWORD} ${SDIST} 14 | cabal upload --publish --documentation --token=${HACKAGE_TOKEN} ${DDIST} 15 | elif [[ "$HACKAGE_RELEASE" == "no" ]]; then 16 | # Upload as release candidate 17 | cabal upload --username=${HACKAGE_USERNAME} --password=${PASSWORD} ${SDIST} 18 | cabal upload --documentation --token=${HACKAGE_TOKEN} ${DDIST} 19 | else 20 | echo "Unrecognized \$HACKAGE_RELEASE: $HACKAGE_RELEASE" 21 | exit 1; 22 | fi 23 | -------------------------------------------------------------------------------- /.ci/report_status.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | commit_status=${1} 3 | username="clash-lang" 4 | repo="clash-compiler" 5 | 6 | curl --url "https://api.github.com/repos/${username}/${repo}/statuses/${CI_COMMIT_SHA}" \ 7 | --header 'Content-Type: application/json' \ 8 | --header "authorization: Bearer ${GITHUB_STATUS_TOKEN}" \ 9 | --data "{ \"state\": \"${commit_status}\", \"target_url\": \"${CI_PIPELINE_URL}\", \"description\": \"All Gitlab pipelines\", \"context\": \"ci/gitlab/gitlab.com\" }" 10 | 11 | if [ "$CI_PIPELINE_SOURCE" = schedule -a "$commit_status" = failure ]; then 12 | # Send a Slack message to #monitor 13 | curl --url "https://slack.com/api/chat.postMessage" --request POST \ 14 | --header "Authorization: Bearer ${SLACK_BOT_TOKEN}" \ 15 | --data "channel=CQR9YG4CT" \ 16 | --data "text=Nightly for \`${CI_COMMIT_BRANCH}\` <${CI_PIPELINE_URL}|*failed*>!" 17 | fi 18 | -------------------------------------------------------------------------------- /.ci/retry.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | n=0 3 | until [ "$n" -ge 5 ] 4 | do 5 | $@ && exit 0 6 | n=$((n+1)) 7 | sleep ${n} 8 | done 9 | 10 | exit 1 11 | -------------------------------------------------------------------------------- /.ci/stack-9.0.yaml: -------------------------------------------------------------------------------- 1 | resolver: lts-19.33 2 | 3 | ghc-options: 4 | "$locals": -Wall -Wcompat 5 | 6 | packages: 7 | - clash-prelude 8 | - clash-prelude-hedgehog 9 | - clash-lib 10 | - clash-lib-hedgehog 11 | - clash-ghc 12 | - tests 13 | 14 | extra-deps: 15 | - prettyprinter-interp-0.2.0.0@sha256:45299b61bd6c27d594c1a72b5a8dd5734e791a59828725e4f4e420f3cc37232b,2016 16 | - infinite-list-0.1@sha256:4de250517ce75e128c766fbc1f23b5a778ea964e695e47f8e83e0f3b293091bf,2383 17 | - tasty-1.5@sha256:c62c96da1e9d65bf61ce583e9f7085eed1daeb62a45f3106ca252bf9ef87025b,2763 18 | - attoparsec-aeson-2.1.0.0@sha256:fa83aba43bfa58490de8f274d19b9d58b6403a207b12cac5f93922102b084c52,1154 19 | - tasty-flaky-0.1.2.0@sha256:2f91ab9f55ae0c472474087f98bb54076aca18f8b058343479d24597a3aa181b,1858 20 | -------------------------------------------------------------------------------- /.ci/stack-9.10.yaml: -------------------------------------------------------------------------------- 1 | resolver: nightly-2025-04-17 2 | 3 | ghc-options: 4 | "$locals": -Wall -Wcompat 5 | 6 | packages: 7 | - clash-prelude 8 | - clash-prelude-hedgehog 9 | - clash-lib 10 | - clash-lib-hedgehog 11 | - clash-ghc 12 | - tests 13 | 14 | extra-deps: 15 | - tasty-flaky-0.1.2.0@sha256:2f91ab9f55ae0c472474087f98bb54076aca18f8b058343479d24597a3aa181b,1858 16 | -------------------------------------------------------------------------------- /.ci/stack-9.2.yaml: -------------------------------------------------------------------------------- 1 | resolver: lts-20.26 2 | 3 | ghc-options: 4 | "$locals": -Wall -Wcompat 5 | 6 | packages: 7 | - clash-prelude 8 | - clash-prelude-hedgehog 9 | - clash-lib 10 | - clash-lib-hedgehog 11 | - clash-ghc 12 | - tests 13 | 14 | extra-deps: 15 | - prettyprinter-interp-0.2.0.0@sha256:7072e659fb902cbcab790c9cca2b0739f9f4b81b666a63f2140139950f05025d,2086 16 | - infinite-list-0.1@sha256:4de250517ce75e128c766fbc1f23b5a778ea964e695e47f8e83e0f3b293091bf,2383 17 | - tasty-1.5@sha256:c62c96da1e9d65bf61ce583e9f7085eed1daeb62a45f3106ca252bf9ef87025b,2763 18 | - attoparsec-aeson-2.1.0.0@sha256:fa83aba43bfa58490de8f274d19b9d58b6403a207b12cac5f93922102b084c52,1154 19 | - tasty-flaky-0.1.2.0@sha256:2f91ab9f55ae0c472474087f98bb54076aca18f8b058343479d24597a3aa181b,1858 20 | -------------------------------------------------------------------------------- /.ci/stack-9.4.yaml: -------------------------------------------------------------------------------- 1 | resolver: lts-21.21 2 | 3 | ghc-options: 4 | "$locals": -Wall -Wcompat 5 | 6 | packages: 7 | - clash-prelude 8 | - clash-prelude-hedgehog 9 | - clash-lib 10 | - clash-lib-hedgehog 11 | - clash-ghc 12 | - tests 13 | 14 | extra-deps: 15 | - prettyprinter-interp-0.2.0.0@sha256:7072e659fb902cbcab790c9cca2b0739f9f4b81b666a63f2140139950f05025d,2086 16 | - git: https://github.com/christiaanb/hint.git 17 | commit: 7803c34c8ae1d83c0f7c13fe6b30fcb3abd0ac51 18 | - tasty-1.5@sha256:c62c96da1e9d65bf61ce583e9f7085eed1daeb62a45f3106ca252bf9ef87025b,2763 19 | - tasty-flaky-0.1.2.0@sha256:2f91ab9f55ae0c472474087f98bb54076aca18f8b058343479d24597a3aa181b,1858 20 | -------------------------------------------------------------------------------- /.ci/stack-9.6.yaml: -------------------------------------------------------------------------------- 1 | resolver: lts-22.43 2 | 3 | ghc-options: 4 | "$locals": -Wall -Wcompat 5 | 6 | packages: 7 | - clash-prelude 8 | - clash-prelude-hedgehog 9 | - clash-lib 10 | - clash-lib-hedgehog 11 | - clash-ghc 12 | - tests 13 | 14 | extra-deps: 15 | - hedgehog-fakedata-0.0.1.5@sha256:955223750b74b0097ce426c07409c4629d22fb6cbd3b6bd0e9aeedf991241bad,1424 16 | - tasty-1.5.3@sha256:9d56ea9dbc274fc853fc531373b2c91bfe360e21460c2c6a5838897d86e3f6d0,2923 17 | - tasty-flaky-0.1.2.0@sha256:2f91ab9f55ae0c472474087f98bb54076aca18f8b058343479d24597a3aa181b,1858 18 | -------------------------------------------------------------------------------- /.ci/stack-9.8.yaml: -------------------------------------------------------------------------------- 1 | resolver: lts-23.18 2 | 3 | ghc-options: 4 | "$locals": -Wall -Wcompat 5 | 6 | packages: 7 | - clash-prelude 8 | - clash-prelude-hedgehog 9 | - clash-lib 10 | - clash-lib-hedgehog 11 | - clash-ghc 12 | - tests 13 | 14 | extra-deps: 15 | - fakedata-1.0.5@sha256:c44c037382a296f3a92991479fdc9522c31935322a67641b8bf107872a425d21,24593 16 | - hedgehog-fakedata-0.0.1.5@sha256:955223750b74b0097ce426c07409c4629d22fb6cbd3b6bd0e9aeedf991241bad,1424 17 | - string-random-0.1.4.4@sha256:5ea686e58354e89a9f236f795b9b161c8730a61b56194281639b97742d53ba48,2144 18 | - tasty-flaky-0.1.2.0@sha256:2f91ab9f55ae0c472474087f98bb54076aca18f8b058343479d24597a3aa181b,1858 19 | -------------------------------------------------------------------------------- /.github/workflows/kloonbot.yml: -------------------------------------------------------------------------------- 1 | name: Kloonbot 2 | 3 | on: issue_comment 4 | 5 | jobs: 6 | kloonbot: 7 | name: Clone branch to local branch 8 | runs-on: ubuntu-latest 9 | if: ${{ github.event.issue.pull_request }} 10 | 11 | env: 12 | KBOT_AUTHOR_ASSOC: ${{ github.event.comment.author_association }} 13 | KBOT_COMMENT: ${{ github.event.comment.body }} 14 | KBOT_PULL_REQUEST_URL: ${{ github.event.issue.pull_request.url }} 15 | 16 | steps: 17 | - name: Checkout 18 | uses: actions/checkout@v2 19 | 20 | - run: | 21 | ./.ci/kloonbot.sh 22 | -------------------------------------------------------------------------------- /.mergify.yml: -------------------------------------------------------------------------------- 1 | pull_request_rules: 2 | # For more information: https://doc.mergify.io/actions.html#copy 3 | # We used to use the 'backport' action, but: 4 | # https://github.com/Mergifyio/mergify-engine/issues/789 5 | - name: backport patches to 1.8 6 | conditions: 7 | - base=master 8 | - label=backport 1.8 9 | - merged 10 | actions: 11 | copy: 12 | ignore_conflicts: true 13 | merge_conflict_style: diff3 14 | branches: 15 | - "1.8" 16 | -------------------------------------------------------------------------------- /.readthedocs.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | formats: all 3 | 4 | build: 5 | image: latest 6 | 7 | python: 8 | version: 3.7 9 | install: 10 | - requirements: docs/requirements.txt 11 | 12 | sphinx: 13 | builder: html 14 | configuration: docs/conf.py 15 | fail_on_warning: true 16 | 17 | -------------------------------------------------------------------------------- /.vscode/README.md: -------------------------------------------------------------------------------- 1 | Please do not add opiniated settings, unless they're recommended by the 2 | style guide. 3 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": ["haskell.haskell"] 3 | } 4 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "cSpell.words": [ 3 | "NOINLINE", 4 | "WHNF", 5 | "fmap", 6 | "frontends", 7 | "inlines", 8 | "scrutinee", 9 | "subterms" 10 | ], 11 | "files.exclude": { 12 | "**/*.dyn_hi": true, 13 | "**/*.dyn_o": true, 14 | "**/*.hi": true, 15 | "**/*.o": true, 16 | "**/*.o-boot": true, 17 | "**/*.hi-boot": true, 18 | "**/dist-newstyle": true, 19 | "**/.stack-work": true, 20 | "**/.ghc.environment.*": true, 21 | ".clash-test-tmp": true 22 | }, 23 | "files.insertFinalNewline": true, 24 | "files.trimFinalNewlines": true, 25 | "files.trimTrailingWhitespace": true, 26 | "editor.rulers": [ 27 | 80, 28 | 90 29 | ], 30 | "editor.tabSize": 2 31 | } 32 | -------------------------------------------------------------------------------- /AUTHORS.md: -------------------------------------------------------------------------------- 1 | See [GitHub contributors statistics](https://github.com/clash-lang/clash-compiler/graphs/contributors) and [clash-lang.org/publications](https://clash-lang.org/publications/). 2 | -------------------------------------------------------------------------------- /benchmark/profiling/README.profiling.md: -------------------------------------------------------------------------------- 1 | You can use this to profile just the normalization process. 2 | 3 | Add the following lines to your cabal.project.local: 4 | ``` 5 | packages: ./benchmark/profiling/*/*.cabal 6 | 7 | package clash-profiling 8 | profiling: True 9 | ``` 10 | 11 | And run using: 12 | ``` 13 | $ cabal v2-run clash-profile-normalization-prepare -- [INPUT_FILES] 14 | $ cabal v2-run clash-profile-normalization-run -- [INPUT_FILES] +RTS -p 15 | ``` 16 | -------------------------------------------------------------------------------- /benchmark/tests/BundleMapRepeat.hs: -------------------------------------------------------------------------------- 1 | -- source: https://github.com/clash-lang/clash-compiler/issues/236 2 | 3 | module BundleMapRepeat where 4 | 5 | import Clash.Prelude 6 | 7 | topEntity :: Signal System (Unsigned 16) -> Signal System (Vec 17 (Unsigned 16)) 8 | topEntity x = bundle . map ($ x) $ repeat id 9 | -------------------------------------------------------------------------------- /changelog/2024-02-11T11_14_33+01_00_drop_support_for_ghc86_ghc88: -------------------------------------------------------------------------------- 1 | REMOVED: Clash no longer supports GHC 8.6 and GHC 8.8 2 | -------------------------------------------------------------------------------- /changelog/2024-02-22T13_45_10+01_00_remove_verilator_shims: -------------------------------------------------------------------------------- 1 | REMOVED: Newer Verilators (> v5) can deal with delay statements, hence removing the need for Clash specific workarounds. If you relied on Clash-generated Verilator shims, consider using `verilator --build --binary` instead. 2 | -------------------------------------------------------------------------------- /changelog/2024-03-04T11_17_07+01_00_fix_2508: -------------------------------------------------------------------------------- 1 | FIXED: Clash now generates more intuitive names for specialized binders. See [#2508](https://github.com/clash-lang/clash-compiler/issues/2508). 2 | -------------------------------------------------------------------------------- /changelog/2024-03-09T15_02_17+01_00_fix_2482: -------------------------------------------------------------------------------- 1 | FIXED: `foldl` on `Vec` is now strict. See [this GitHub discussion](https://github.com/hasura/graphql-engine/pull/2933#discussion_r328821960) and [this blog post](https://well-typed.com/blog/90/) for more information. [#2482](https://github.com/clash-lang/clash-compiler/issues/2482) 2 | -------------------------------------------------------------------------------- /changelog/2024-03-10T17_55_54+01_00_add_counter_instances: -------------------------------------------------------------------------------- 1 | ADDED: `Counter` instances for `Bool`, `Bit`, `Int`, `Int8`, `Int16`, `Int32`, `Int64`, `Word`, `Word8`, `Word16`, `Word32`, `Word64`, `Identity` and `Maybe`. 2 | -------------------------------------------------------------------------------- /changelog/2024-03-11T21_22_11+01_00_make_counter_functions_public: -------------------------------------------------------------------------------- 1 | CHANGED: functions defined on `Clash.Class.Counter` are now public 2 | -------------------------------------------------------------------------------- /changelog/2024-04-08T06_51_45+00_00_smap_with_bounds: -------------------------------------------------------------------------------- 1 | CHANGED: `dfold` now offers a proof witness for the upper bound of the vector size to the folding function. Note that this change may require additional type annotations, as solutions working in the past may complain with an untouchable type error now. 2 | ADDED: `smapWithBounds` extending `smap` via offering a proof witness for the upper bound of the vector size to the mapping function. 3 | -------------------------------------------------------------------------------- /changelog/2024-05-07T22_51_59+10_00_add_vec_complete_pragma: -------------------------------------------------------------------------------- 1 | ADDED: The Vec type now has a [COMPLETE pragma](https://ghc.gitlab.haskell.org/ghc/doc/users_guide/exts/pragmas.html#complete-pragma) to avoid incomplete pattern matches when using the `(:>)` pattern. 2 | -------------------------------------------------------------------------------- /changelog/2024-06-18T11_16_48+02_00_add_time_types: -------------------------------------------------------------------------------- 1 | ADDED: Introduced various new types to `Clash.Signal` to more easily represent time and its relation to your clock domain. New types: `Seconds`, `Milliseconds`, `Microseconds`, `Nanoseconds`, `Picoseconds`, `DomainToHz`, `HzToPeriod`, `PeriodToHz`, `PeriodToCycles`, `ClockDivider`. 2 | -------------------------------------------------------------------------------- /changelog/2024-07-05T14_06_50+02_00_require_positive_period: -------------------------------------------------------------------------------- 1 | CHANGED: You can now only create an `SDomainConfiguration` when the `period` of the domain is at least `1`. 2 | Pattern matching on an `SDomainConfiguration` bring the `1 <= period` into scope. 3 | This in turns enables the following code to typecheck: 4 | ``` 5 | import Clash.Prelude 6 | import Data.Proxy 7 | 8 | f :: 9 | forall dom . 10 | KnownDomain dom => 11 | Proxy dom -> 12 | SNat (PeriodToCycles dom (Milliseconds 1)) 13 | f Proxy = case knownDomain @dom of 14 | SDomainConfiguration {} -> SNat 15 | ``` 16 | where the `DivRU` in 17 | ``` 18 | type PeriodToCycles (dom :: Domain) (period :: Nat) = period `DivRU` DomainPeriod dom 19 | ``` 20 | requires that the `DomainPeriod dom` is at least `1`. 21 | -------------------------------------------------------------------------------- /changelog/2024-07-07T22_14_16+02_00_remove_multiple_hidden: -------------------------------------------------------------------------------- 1 | REMOVED: Experimental feature "multiple hidden domains" 2 | -------------------------------------------------------------------------------- /changelog/2024-08-20T14_53_00+10_00_add_ramop_autoreg_instance: -------------------------------------------------------------------------------- 1 | ADDED: RamOp now has an AutoReg instance. 2 | -------------------------------------------------------------------------------- /changelog/2024-10-29T14_54_54+01_00_fix2831: -------------------------------------------------------------------------------- 1 | FIXED: Clash errors out when `Clash.Sized.Vector.splitAt` is compile-time evaluated in an illegal context 2 | -------------------------------------------------------------------------------- /changelog/2024-11-02T17_43_16+08_00_distributive_representative_vec: -------------------------------------------------------------------------------- 1 | ADDED: `Distributive` and `Representable` instances for `Vec` 2 | -------------------------------------------------------------------------------- /changelog/2024-11-16T11_59_31+01_00_avoid_using_unsafecoerce: -------------------------------------------------------------------------------- 1 | CHANGED: `select` and `selectI` now use `<=` constraints instead of `CmpNat`. 2 | -------------------------------------------------------------------------------- /changelog/2024-11-25T20_38_27+08_00_reset_strategy: -------------------------------------------------------------------------------- 1 | CHANGED: `ResetStrategy` now contains the reset function, to avoid dummy arguments on `NoClearOnReset` 2 | -------------------------------------------------------------------------------- /changelog/2025-01-16T14_20_35+01_00_ddroutclock: -------------------------------------------------------------------------------- 1 | NEW: The function `Clash.Explicit.DDR.ddrForwardClock`, which uses a DDR output primitive to forward a clock signal to a DDR-capable output pin. 2 | -------------------------------------------------------------------------------- /changelog/2025-01-22T16_23_00+01_00_improve_ddr: -------------------------------------------------------------------------------- 1 | CHANGED: `Clash.Explicit.DDR`, `Clash.Intel.DDR` and `Clash.Xilinx.DDR`: 2 | - The constraints for the functions have been rewritten to use `DomainPeriod`, which makes them more readable and relaxes unnecessary constraints on the virtual DDR domain. The type-level variables for the domains have been renamed. `dom` is a real domain, `domDDR` is the virtual DDR domain. 3 | - The Xilinx and Intel primitives only support domains where the rising edge is the active edge. This is now enforced at the type level by adding a constraint. 4 | - The Xilinx and Intel primitives now directly support any data type that has a `BitPack` instance. 5 | -------------------------------------------------------------------------------- /changelog/2025-02-10T20_01_41+01_00_reorder_hedgehog_type_args: -------------------------------------------------------------------------------- 1 | CHANGED: Order of type arguments for functions in `clash-prelude-hedgehog` now follows _size_, _domain_, _monad_. 2 | -------------------------------------------------------------------------------- /changelog/2025-02-13T09_00_14+01_00_add_resize_functions: -------------------------------------------------------------------------------- 1 | ADDED: Resize functions `maybeResize` and `maybeTruncateB` to `Clash.Class.Resize`. Can be used to resize without loss of information. 2 | -------------------------------------------------------------------------------- /changelog/2025-03-04T15_40_21+01_00_account_for_simonly: -------------------------------------------------------------------------------- 1 | FIXED: `makeTopEntity` now accounts for `SimOnly` constructs. This can prevent warnings in situtations where the `SimOnly` type would contain types `makeTopEntity` cannot handle. 2 | -------------------------------------------------------------------------------- /changelog/2025-03-06T11_10_03+01_00_add_nfdatax_simonly: -------------------------------------------------------------------------------- 1 | ADDED: Added instance `NFDataX (SimOnly a)` 2 | -------------------------------------------------------------------------------- /changelog/2025-03-19T08_52_01+01_00_new_partial_signal_operators: -------------------------------------------------------------------------------- 1 | ADDED: Alongside the existing Eq-like and Ord-like signal operators like `.==.` and `.<=.` etc., there are now new functions for comparing with constants: `.==`, `==.`, `./=`, `/=.`, `.<=`, `<=.`, `.>=`, `>=.`, `.>`, `>.`, `.<`, `<.`, `.&&`, `&&.`, `.||`, `||.`. These are useful for comparing signals with constants in a more readable way. For example, `a .==. pure True` can now be replaced with `a .== True`. 2 | -------------------------------------------------------------------------------- /changelog/2025-03-30T20_42_00+02_00_add_clash_class_num_convert: -------------------------------------------------------------------------------- 1 | ADD: `Clash.Class.NumConvert`: Utilities for safely converting between various Clash number types 2 | -------------------------------------------------------------------------------- /changelog/2025-04-02T09_08_44+02_00_add_ghc967_support: -------------------------------------------------------------------------------- 1 | FIXED: Clash did not build on GHC 9.6.7 (but did on 9.6.6) [#2916](https://github.com/clash-lang/clash-compiler/issues/2916) 2 | -------------------------------------------------------------------------------- /changelog/2025-04-05T17_48_30+02_00_ignore_ticks: -------------------------------------------------------------------------------- 1 | INTERNAL FIX: Ignore `Tick`s in `TermLiteral Integer`, `TermLiteral Char`, `TermLiteral Natural`, and `TermLiteral (SNat n)` 2 | -------------------------------------------------------------------------------- /changelog/2025-04-18T15_27_46+02_00_less_knownnat: -------------------------------------------------------------------------------- 1 | CHANGED: Changed implementation of `(+>>)` to no longer require `KnownNat` 2 | -------------------------------------------------------------------------------- /changelog/2025-04-27T14_45_08+02_00_windows_910: -------------------------------------------------------------------------------- 1 | ADDED: Support for GHC 9.10 on Windows (macOS and Linux were already supported) 2 | -------------------------------------------------------------------------------- /changelog/2025-04-28T14_17_05+02_00_fix2542: -------------------------------------------------------------------------------- 1 | FIXED: Fixed laziness issue in internal black box `imap_go` [#2542](https://github.com/clash-lang/clash-compiler/issues/2542) 2 | -------------------------------------------------------------------------------- /changelog/2025-05-09T17_51_26+02_00_bitpack_char: -------------------------------------------------------------------------------- 1 | ADDED: Added a `BitPack` instance for `Char` 2 | -------------------------------------------------------------------------------- /changelog/README.md: -------------------------------------------------------------------------------- 1 | Inspired by [Solving Gitlab's CHANGELOG crisis](https://about.gitlab.com/blog/2018/07/03/solving-gitlabs-changelog-conflict-crisis/) 2 | we now use a single file per change. Of course, if you feel adding an entry to 3 | the CHANGELOG would only pollute it, feel free to not make a file. To keep it 4 | somewhat manageable: 5 | 6 | * Create a changelog file: `touch changelog/$(date --iso-8601=seconds | tr : _)_my_change_message` 7 | * We collect these files for each release and put their messages in 8 | `CHANGELOG.md`. The files are subsequently deleted. 9 | * Messages should be valid Markdown 10 | 11 | I've added an example to the commit introducing this change. 12 | -------------------------------------------------------------------------------- /clash-cosim/.gitignore: -------------------------------------------------------------------------------- 1 | # Object files 2 | *.o 3 | *.ko 4 | *.obj 5 | *.elf 6 | 7 | # Precompiled Headers 8 | *.gch 9 | *.pch 10 | 11 | # Libraries 12 | *.lib 13 | *.a 14 | *.la 15 | *.lo 16 | 17 | # Shared objects (inc. Windows DLLs) 18 | *.dll 19 | *.so 20 | *.so.* 21 | *.dylib 22 | 23 | # Executables 24 | *.exe 25 | *.out 26 | *.app 27 | *.i*86 28 | *.x86_64 29 | *.hex 30 | 31 | # Debug files 32 | *.dSYM/ 33 | *.su 34 | 35 | # VPI 36 | *.vvp 37 | *.vpi 38 | *.sl 39 | 40 | # Apple 41 | *.DS_Store 42 | 43 | # IntelliJ IDE 44 | .idea/ 45 | *.iml 46 | dist/ 47 | 48 | # generated by cabal 49 | src/prims/verilog/Clash_CoSim_CoSimInstances.primitives.yaml 50 | 51 | # Cabal 52 | dist-newstyle 53 | -------------------------------------------------------------------------------- /clash-cosim/src/Clash/CoSim/Paths_clash_cosim.hs: -------------------------------------------------------------------------------- 1 | module Clash.CoSim.Paths_clash_cosim where 2 | 3 | -- HACK, see: 4 | -- https://neilmitchell.blogspot.dk/2008/02/adding-data-files-using-cabal.html 5 | getDataFileName :: FilePath -> IO FilePath 6 | getDataFileName = return 7 | -------------------------------------------------------------------------------- /clash-cosim/src/cbits/traversing/cosim_traversing.h: -------------------------------------------------------------------------------- 1 | /*H********************************************************************** 2 | * FILENAME : cosim_traversing.h 3 | * 4 | * DESCRIPTION : 5 | * Traversing functions 6 | * needed for co-simulation between CLaSH and a Verilog simulator 7 | * 8 | * 9 | * AUTHOR : John Verheij DATE : August 14, 2016 10 | * 11 | * 12 | *H*/ 13 | 14 | /* Guard */ 15 | #ifndef COSIM_TRAVERSING_H_ 16 | #define COSIM_TRAVERSING_H_ 17 | 18 | #include "../types/cosim_types.h" 19 | 20 | int exchangePortNames(struct coSimState *state); 21 | 22 | int exchangePortBits(struct coSimState *state, int input); 23 | 24 | #endif -------------------------------------------------------------------------------- /clash-cosim/src/cbits/traversing/cosim_traversing_vpi.h: -------------------------------------------------------------------------------- 1 | /*H********************************************************************** 2 | * FILENAME : CoSimTypesVPI.h 3 | * 4 | * DESCRIPTION : 5 | * Traversing functions needed for VPI 6 | * needed for co-simulation between CLaSH and a Verilog simulator 7 | * 8 | * 9 | * AUTHOR : John Verheij DATE : August 14, 2016 10 | * 11 | * 12 | *H*/ 13 | 14 | /* Guard */ 15 | #ifndef COSIM_TRAVERSING_VPI_H_ 16 | #define COSIM_TRAVERSING_VPI_H_ 17 | 18 | #include "../types/cosim_types_vpi.h" 19 | 20 | int exchangeSeq(struct vpiState *state); 21 | 22 | int exchangePortSpecs(struct vpiState *state, int input); 23 | 24 | int getPortSpecs(vpiHandle handle, struct vpiState *state, char *moduleName); 25 | 26 | int getModuleSpecs(vpiHandle handle, struct vpiState *state); 27 | 28 | #endif -------------------------------------------------------------------------------- /clash-cosim/src/prims/verilog/README.md: -------------------------------------------------------------------------------- 1 | This directory will contain json primitive files after running `cabal build` and will subsequentially be removed after `cabal clean`. -------------------------------------------------------------------------------- /clash-dev.ps1: -------------------------------------------------------------------------------- 1 | $GHC_VERSION=(ghc --numeric-version) 2 | 3 | ghci ` 4 | -fobject-code ` 5 | -iclash-ghc/src-bin-common/ ` 6 | -iclash-lib/src ` 7 | -iclash-ghc/src-ghc ` 8 | -Wall -Wcompat -DTOOL_VERSION_ghc="`"`"`"$GHC_VERSION`"`"`"" ` 9 | -XBangPatterns -XBinaryLiterals -XDataKinds -XDefaultSignatures ` 10 | -XDeriveDataTypeable -XDeriveFoldable -XDeriveFunctor -XDeriveGeneric ` 11 | -XDeriveLift -XDeriveTraversable -XDerivingStrategies -XInstanceSigs ` 12 | -XKindSignatures -XPostfixOperators -XNoStarIsType -XScopedTypeVariables ` 13 | -XStandaloneDeriving -XTupleSections -XTypeApplications -XTypeOperators ` 14 | -XViewPatterns -XNoPolyKinds -DDEBUG ` 15 | Clash.hs 16 | -------------------------------------------------------------------------------- /clash-ffi/.gitignore: -------------------------------------------------------------------------------- 1 | lib/ 2 | *.v 3 | *.vvp 4 | *.vpl 5 | *.so 6 | -------------------------------------------------------------------------------- /clash-ffi/example/cabal.project: -------------------------------------------------------------------------------- 1 | packages: . .. ../../clash-ghc ../../clash-lib ../../clash-prelude 2 | 3 | write-ghc-environment-files: always 4 | 5 | allow-newer: 6 | hashable, 7 | derive-storable-plugin:ghc, 8 | derive-storable-plugin:ghci, 9 | string-interpolate:template-haskell, 10 | string-interpolate:text, 11 | hint:ghc 12 | -------------------------------------------------------------------------------- /clash-ffi/src/Clash/FFI/VPI/Net.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright: (C) 2022 Google Inc. 3 | License: BSD2 (see the file LICENSE) 4 | Maintainer: QBayLogic B.V. 5 | -} 6 | 7 | module Clash.FFI.VPI.Net 8 | ( Net(..) 9 | ) where 10 | 11 | import Control.DeepSeq (NFData) 12 | import Foreign.Storable (Storable) 13 | 14 | import Clash.FFI.VPI.Object 15 | 16 | -- | A net is a VPI object that is known to refer to something with the 17 | -- @vpiNet@ object type. 18 | -- 19 | -- Nets can be unsafely created from 'Object', although this is only safe if 20 | -- you first check the @vpiType@ property to confirm it is a net. Nets can be 21 | -- safely converted to the base object type using 'netObject'. 22 | -- 23 | newtype Net 24 | = Net { netObject :: Object } 25 | deriving stock (Show) 26 | deriving newtype (IsObject, NFData, Storable) 27 | -------------------------------------------------------------------------------- /clash-ffi/src/Clash/FFI/VPI/Reg.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright: (C) 2022 Google Inc. 3 | License: BSD2 (see the file LICENSE) 4 | Maintainer: QBayLogic B.V. 5 | -} 6 | 7 | module Clash.FFI.VPI.Reg 8 | ( Reg(..) 9 | ) where 10 | 11 | import Control.DeepSeq (NFData) 12 | import Foreign.Storable (Storable) 13 | 14 | import Clash.FFI.VPI.Object 15 | 16 | -- | A register is a VPI object that is known to refer to something with the 17 | -- @vpiRegister@ object type. 18 | -- 19 | -- Registers can be unsafely created from 'Object', although this is only safe 20 | -- if you first check the @vpiType@ property to confirm it is a register. 21 | -- Registers can be safely converted to the base object type using 22 | -- 'regObject'. 23 | -- 24 | newtype Reg 25 | = Reg { regObject :: Object } 26 | deriving stock (Show) 27 | deriving newtype (IsObject, NFData, Storable) 28 | -------------------------------------------------------------------------------- /clash-ffi/tests/cbits/Pipe.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include "Pipe.h" 7 | 8 | static int pipefd[2]; 9 | static FILE* f = NULL; 10 | 11 | int init_pipe(void) 12 | { 13 | if (pipe(pipefd) == -1) 14 | { 15 | perror("ERROR: Cannot create pipe.\n"); 16 | exit(EXIT_FAILURE); 17 | } 18 | 19 | f = fdopen(pipefd[PIPE_WRITE_END], "w"); 20 | 21 | return pipefd[PIPE_READ_END]; 22 | } 23 | 24 | void close_pipe(void) 25 | { 26 | close(pipefd[PIPE_WRITE_END]); 27 | } 28 | 29 | bool pipe_closed() 30 | { 31 | return f == NULL; 32 | } 33 | 34 | void send(char *restrict format, ...) 35 | { 36 | va_list ap; 37 | 38 | va_start(ap, format); 39 | vfprintf(f, format, ap); 40 | va_end(ap); 41 | } 42 | 43 | void commit_value() 44 | { 45 | fprintf(f, "\n"); 46 | fflush(f); 47 | } 48 | -------------------------------------------------------------------------------- /clash-ghc/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ../CHANGELOG.md -------------------------------------------------------------------------------- /clash-ghc/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /clash-ghc/src-bin-8.10/Clash/GHCi/Util.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE MagicHash, UnboxedTuples #-} 2 | 3 | -- | Utilities for GHCi. 4 | module Clash.GHCi.Util where 5 | 6 | -- NOTE: Avoid importing GHC modules here, because the primary purpose 7 | -- of this module is to not use UnboxedTuples in a module that imports 8 | -- lots of other modules. See issue#13101 for more info. 9 | 10 | import GHC.Exts 11 | import GHC.Types 12 | 13 | anyToPtr :: a -> IO (Ptr ()) 14 | anyToPtr x = 15 | IO (\s -> case anyToAddr# x s of 16 | (# s', addr #) -> (# s', Ptr addr #)) :: IO (Ptr ()) 17 | -------------------------------------------------------------------------------- /clash-ghc/src-bin-9.0/Clash/GHCi/Util.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE MagicHash, UnboxedTuples #-} 2 | 3 | -- | Utilities for GHCi. 4 | module Clash.GHCi.Util where 5 | 6 | -- NOTE: Avoid importing GHC modules here, because the primary purpose 7 | -- of this module is to not use UnboxedTuples in a module that imports 8 | -- lots of other modules. See issue#13101 for more info. 9 | 10 | import GHC.Exts 11 | import GHC.Types 12 | 13 | anyToPtr :: a -> IO (Ptr ()) 14 | anyToPtr x = 15 | IO (\s -> case anyToAddr# x s of 16 | (# s', addr #) -> (# s', Ptr addr #)) :: IO (Ptr ()) 17 | -------------------------------------------------------------------------------- /clash-ghc/src-bin-9.10/Clash/GHCi/Util.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE MagicHash, UnboxedTuples #-} 2 | 3 | -- | Utilities for GHCi. 4 | module Clash.GHCi.Util where 5 | 6 | -- NOTE: Avoid importing GHC modules here, because the primary purpose 7 | -- of this module is to not use UnboxedTuples in a module that imports 8 | -- lots of other modules. See issue#13101 for more info. 9 | 10 | import GHC.Exts 11 | import GHC.Types 12 | 13 | anyToPtr :: a -> IO (Ptr ()) 14 | anyToPtr x = 15 | IO (\s -> case anyToAddr# x s of 16 | (# s', addr #) -> (# s', Ptr addr #)) :: IO (Ptr ()) 17 | -------------------------------------------------------------------------------- /clash-ghc/src-bin-9.2/Clash/GHCi/Util.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE MagicHash, UnboxedTuples #-} 2 | 3 | -- | Utilities for GHCi. 4 | module Clash.GHCi.Util where 5 | 6 | -- NOTE: Avoid importing GHC modules here, because the primary purpose 7 | -- of this module is to not use UnboxedTuples in a module that imports 8 | -- lots of other modules. See issue#13101 for more info. 9 | 10 | import GHC.Exts 11 | import GHC.Types 12 | 13 | anyToPtr :: a -> IO (Ptr ()) 14 | anyToPtr x = 15 | IO (\s -> case anyToAddr# x s of 16 | (# s', addr #) -> (# s', Ptr addr #)) :: IO (Ptr ()) 17 | -------------------------------------------------------------------------------- /clash-ghc/src-bin-9.4/Clash/GHCi/Util.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE MagicHash, UnboxedTuples #-} 2 | 3 | -- | Utilities for GHCi. 4 | module Clash.GHCi.Util where 5 | 6 | -- NOTE: Avoid importing GHC modules here, because the primary purpose 7 | -- of this module is to not use UnboxedTuples in a module that imports 8 | -- lots of other modules. See issue#13101 for more info. 9 | 10 | import GHC.Exts 11 | import GHC.Types 12 | 13 | anyToPtr :: a -> IO (Ptr ()) 14 | anyToPtr x = 15 | IO (\s -> case anyToAddr# x s of 16 | (# s', addr #) -> (# s', Ptr addr #)) :: IO (Ptr ()) 17 | -------------------------------------------------------------------------------- /clash-ghc/src-bin-9.6/Clash/GHCi/Util.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE MagicHash, UnboxedTuples #-} 2 | 3 | -- | Utilities for GHCi. 4 | module Clash.GHCi.Util where 5 | 6 | -- NOTE: Avoid importing GHC modules here, because the primary purpose 7 | -- of this module is to not use UnboxedTuples in a module that imports 8 | -- lots of other modules. See issue#13101 for more info. 9 | 10 | import GHC.Exts 11 | import GHC.Types 12 | 13 | anyToPtr :: a -> IO (Ptr ()) 14 | anyToPtr x = 15 | IO (\s -> case anyToAddr# x s of 16 | (# s', addr #) -> (# s', Ptr addr #)) :: IO (Ptr ()) 17 | -------------------------------------------------------------------------------- /clash-ghc/src-bin-9.8/Clash/GHCi/Util.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE MagicHash, UnboxedTuples #-} 2 | 3 | -- | Utilities for GHCi. 4 | module Clash.GHCi.Util where 5 | 6 | -- NOTE: Avoid importing GHC modules here, because the primary purpose 7 | -- of this module is to not use UnboxedTuples in a module that imports 8 | -- lots of other modules. See issue#13101 for more info. 9 | 10 | import GHC.Exts 11 | import GHC.Types 12 | 13 | anyToPtr :: a -> IO (Ptr ()) 14 | anyToPtr x = 15 | IO (\s -> case anyToAddr# x s of 16 | (# s', addr #) -> (# s', Ptr addr #)) :: IO (Ptr ()) 17 | -------------------------------------------------------------------------------- /clash-ghc/src-ghc/Batch.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (C) 2013-2017, University of Twente 3 | License : BSD2 (see the file LICENSE) 4 | Maintainer : Christiaan Baaij 5 | 6 | Entry point for the @clash@ executable. 7 | -} 8 | 9 | module Main 10 | ( main -- :: IO () 11 | ) where 12 | 13 | import System.Environment ( getArgs ) 14 | import Clash.Main ( defaultMain ) 15 | 16 | main :: IO () 17 | main = getArgs >>= defaultMain 18 | -------------------------------------------------------------------------------- /clash-ghc/src-ghc/Clash/GHC/Evaluator.hs-boot: -------------------------------------------------------------------------------- 1 | module Clash.GHC.Evaluator where 2 | 3 | import Clash.Core.Term (Term) 4 | import Clash.Core.TyCon (TyConMap) 5 | import Clash.Core.Evaluator.Types (Step, Unwind, Machine) 6 | import Clash.Core.Var (Id) 7 | 8 | ghcStep :: Step 9 | ghcUnwind :: Unwind 10 | 11 | newLetBinding :: TyConMap -> Machine -> Term -> (Machine, Id) 12 | 13 | -------------------------------------------------------------------------------- /clash-ghc/src-ghc/Data/Text/Extra.hs: -------------------------------------------------------------------------------- 1 | module Data.Text.Extra 2 | ( showt 3 | , showtl 4 | ) where 5 | 6 | import Prelude 7 | import qualified Data.Text as TS 8 | import qualified Data.Text.Lazy as TL 9 | 10 | showt :: (Show a) => a -> TS.Text 11 | showt = TS.pack . show 12 | 13 | showtl :: (Show a) => a -> TL.Text 14 | showtl = TL.pack . show 15 | -------------------------------------------------------------------------------- /clash-ghc/src-ghc/Interactive.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (C) 2013-2017, University of Twente 3 | License : BSD2 (see the file LICENSE) 4 | Maintainer : Christiaan Baaij 5 | 6 | Entry point for the @clashi@ executable. 7 | -} 8 | 9 | module Main 10 | ( main -- :: IO () 11 | ) where 12 | 13 | import System.Environment ( getArgs ) 14 | import Clash.Main ( defaultMain ) 15 | 16 | main :: IO () 17 | main = getArgs >>= defaultMain . ("--interactive":) 18 | -------------------------------------------------------------------------------- /clash-lib/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ../CHANGELOG.md -------------------------------------------------------------------------------- /clash-lib/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /clash-lib/prims/common/Clash_Annotations_BitRepresentation_Deriving.primitives.yaml: -------------------------------------------------------------------------------- 1 | - BlackBox: 2 | name: Clash.Annotations.BitRepresentation.Deriving.dontApplyInHDL 3 | kind: Expression 4 | type: 'dontApplyInHDL 5 | :: (a -> b) -> a -> b' 6 | template: ~ARG[1] 7 | workInfo: Never 8 | -------------------------------------------------------------------------------- /clash-lib/prims/common/Clash_Explicit_Signal.primitives.yaml: -------------------------------------------------------------------------------- 1 | - BlackBox: 2 | name: Clash.Explicit.Signal.veryUnsafeSynchronizer 3 | kind: Expression 4 | type: |- 5 | veryUnsafeSynchronizer 6 | :: Either Int (Signal dom1 Int) -- ARG[0] 7 | -> Either Int (Signal dom2 Int) -- ARG[1] 8 | -> Signal dom1 a -- ARG[2] 9 | -> Signal dom2 a 10 | template: ~ARG[2] 11 | workInfo: Never 12 | - BlackBox: 13 | name: Clash.Explicit.Signal.unsafeSynchronizer 14 | kind: Expression 15 | type: |- 16 | unsafeSynchronizer 17 | :: ( KnownDomain dom1 -- ARG[0] 18 | , KnownDomain dom2 ) -- ARG[1] 19 | => Clock dom1 -- ARG[2] 20 | -> Clock dom2 -- ARG[3] 21 | -> Signal dom1 a -- ARG[4] 22 | -> Signal dom2 a 23 | template: ~ARG[4] 24 | workInfo: Never 25 | -------------------------------------------------------------------------------- /clash-lib/prims/common/Clash_Explicit_Testbench.primitives.yaml: -------------------------------------------------------------------------------- 1 | - BlackBox: 2 | name: Clash.Explicit.Testbench.unsafeSimSynchronizer 3 | kind: Expression 4 | type: |- 5 | unsafeSimSynchronizer 6 | :: forall dom1 dom2 a 7 | . ( KnownDomain dom1 -- ARG[0] 8 | , KnownDomain dom2 ) -- ARG[1] 9 | => Clock dom1 -- ARG[2] 10 | -> Clock dom2 -- ARG[3] 11 | -> Signal dom1 a -- ARG[4] 12 | -> Signal dom2 a 13 | template: ~ARG[4] 14 | warning: Clash.Explicit.Testbench.unsafeSimSynchronizer is not safely synthesizable! 15 | workInfo: Never 16 | -------------------------------------------------------------------------------- /clash-lib/prims/common/Clash_GHC_GHC2Core.primitives.yaml: -------------------------------------------------------------------------------- 1 | - Primitive: 2 | name: _CO_ 3 | primType: Constructor 4 | workInfo: Constant 5 | - Primitive: 6 | name: _TY_ 7 | primType: Constructor 8 | workInfo: Constant 9 | -------------------------------------------------------------------------------- /clash-lib/prims/common/Clash_Intel_ClockGen.primitives.yaml: -------------------------------------------------------------------------------- 1 | - BlackBox: 2 | name: Clash.Intel.ClockGen.unsafeAltpll 3 | format: Haskell 4 | includes: 5 | - name: altpll 6 | extension: qsys 7 | format: Haskell 8 | templateFunction: Clash.Primitives.Intel.ClockGen.altpllQsysTF 9 | kind: Declaration 10 | templateFunction: Clash.Primitives.Intel.ClockGen.altpllTF 11 | workInfo: Always 12 | - BlackBox: 13 | name: Clash.Intel.ClockGen.unsafeAlteraPll 14 | format: Haskell 15 | includes: 16 | - name: altera_pll 17 | extension: qsys 18 | format: Haskell 19 | templateFunction: Clash.Primitives.Intel.ClockGen.alteraPllQsysTF 20 | kind: Declaration 21 | templateFunction: Clash.Primitives.Intel.ClockGen.alteraPllTF 22 | workInfo: Always 23 | -------------------------------------------------------------------------------- /clash-lib/prims/common/Clash_Magic.primitives.yaml: -------------------------------------------------------------------------------- 1 | - Primitive: 2 | name: Clash.Magic.prefixName 3 | primType: Function 4 | - Primitive: 5 | name: Clash.Magic.suffixName 6 | primType: Function 7 | - Primitive: 8 | name: Clash.Magic.suffixNameFromNat 9 | primType: Function 10 | - Primitive: 11 | name: Clash.Magic.suffixNameP 12 | primType: Function 13 | - Primitive: 14 | name: Clash.Magic.suffixNameFromNatP 15 | primType: Function 16 | - Primitive: 17 | name: Clash.Magic.setName 18 | primType: Function 19 | - BlackBox: 20 | name: Clash.Magic.SimOnly 21 | kind: Expression 22 | type: 'SimOnly :: a -> SimOnly a' 23 | template: ~ERRORO 24 | workInfo: Constant 25 | -------------------------------------------------------------------------------- /clash-lib/prims/common/Clash_Normalize_Primitives.primitives.yaml: -------------------------------------------------------------------------------- 1 | - BlackBox: 2 | name: Clash.Normalize.Primitives.removedArg 3 | kind: Expression 4 | type: 'removedArg :: a' 5 | template: ~ERRORO 6 | workInfo: Constant 7 | - BlackBox: 8 | name: Clash.Normalize.Primitives.undefined 9 | kind: Expression 10 | type: 'undefined :: forall 11 | a . a' 12 | template: ~ERRORO 13 | workInfo: Constant 14 | - BlackBox: 15 | name: Clash.Normalize.Primitives.undefinedX 16 | kind: Expression 17 | type: 'undefinedX :: forall a . a' 18 | template: ~ERRORO 19 | workInfo: Constant 20 | - BlackBox: 21 | name: c$multiPrimSelect 22 | kind: Expression 23 | template: '!__SHOULD NOT BE RENDERED__! ~ARG[0]~ARG[1]' 24 | workInfo: Always 25 | -------------------------------------------------------------------------------- /clash-lib/prims/common/Clash_Promoted_Nat.primitives.yaml: -------------------------------------------------------------------------------- 1 | - BlackBox: 2 | name: Clash.Promoted.Nat.powSNat 3 | kind: Expression 4 | type: 'Clash.Promoted.Nat.powSNat 5 | :: SNat a -> SNat b -> SNat (a^b)' 6 | template: ~LIT[0] ** ~LIT[1] 7 | workInfo: Never 8 | -------------------------------------------------------------------------------- /clash-lib/prims/common/Clash_Promoted_Nat_Unsafe.primitives.yaml: -------------------------------------------------------------------------------- 1 | - BlackBox: 2 | name: Clash.Promoted.Nat.Unsafe.unsafeSNat 3 | kind: Expression 4 | type: 'Clash.Promoted.Nat.Unsafe.unsafeSNat 5 | :: Integer -> SNat k' 6 | template: ~LIT[0] 7 | workInfo: Never 8 | -------------------------------------------------------------------------------- /clash-lib/prims/common/Clash_Promoted_Symbol.primitives.yaml: -------------------------------------------------------------------------------- 1 | - BlackBox: 2 | name: Clash.Promoted.Symbol.SSymbol 3 | kind: Expression 4 | type: 'SSymbol :: KnownNat 5 | n => Proxy n -> SSymbol n' 6 | template: ~LIT[0] 7 | workInfo: Never 8 | - BlackBox: 9 | name: Clash.Promoted.Symbol.symbolToString 10 | kind: Expression 11 | type: 'symbolToString 12 | :: SSymbol n -> String' 13 | template: ~LIT[0] 14 | workInfo: Never 15 | -------------------------------------------------------------------------------- /clash-lib/prims/common/Clash_Signal_Bundle.primitives.yaml: -------------------------------------------------------------------------------- 1 | - Primitive: 2 | name: Clash.Signal.Bundle.vecBundle# 3 | primType: Function 4 | workInfo: Never 5 | -------------------------------------------------------------------------------- /clash-lib/prims/common/Clash_Signal_Internal.primitives.yaml: -------------------------------------------------------------------------------- 1 | - Primitive: 2 | name: Clash.Signal.Internal.signal# 3 | primType: Function 4 | workInfo: Never 5 | - Primitive: 6 | name: Clash.Signal.Internal.mapSignal# 7 | primType: Function 8 | workInfo: Never 9 | - Primitive: 10 | name: Clash.Signal.Internal.appSignal# 11 | primType: Function 12 | workInfo: Never 13 | - Primitive: 14 | name: Clash.Signal.Internal.foldr# 15 | primType: Function 16 | workInfo: Never 17 | - Primitive: 18 | name: Clash.Signal.Internal.traverse# 19 | primType: Function 20 | workInfo: Never 21 | - Primitive: 22 | name: Clash.Signal.Internal.joinSignal# 23 | primType: Function 24 | workInfo: Never 25 | -------------------------------------------------------------------------------- /clash-lib/prims/common/Clash_Sized_Internal_Signed.primitives.yaml: -------------------------------------------------------------------------------- 1 | - BlackBox: 2 | name: Clash.Sized.Internal.Signed.+# 3 | kind: Expression 4 | type: '(+#) :: KnownNat 5 | n => Signed n -> Signed n -> Signed n' 6 | template: ~ARG[1] + ~ARG[2] 7 | - BlackBox: 8 | name: Clash.Sized.Internal.Signed.-# 9 | kind: Expression 10 | type: '(-#) :: KnownNat 11 | n => Signed n -> Signed n -> Signed n' 12 | template: ~ARG[1] - ~ARG[2] 13 | -------------------------------------------------------------------------------- /clash-lib/prims/common/Clash_Sized_RTree.primitives.yaml: -------------------------------------------------------------------------------- 1 | - Primitive: 2 | name: Clash.Sized.RTree.tdfold 3 | primType: Function 4 | workInfo: Never 5 | -------------------------------------------------------------------------------- /clash-lib/prims/common/Clash_Xilinx_ClockGen.primitives.yaml: -------------------------------------------------------------------------------- 1 | - BlackBox: 2 | name: Clash.Xilinx.ClockGen.unsafeClockWizard 3 | kind: Declaration 4 | format: Haskell 5 | templateFunction: Clash.Primitives.Xilinx.ClockGen.clockWizardTF 6 | includes: 7 | - name: clk_wiz 8 | extension: clash.tcl 9 | format: Haskell 10 | templateFunction: Clash.Primitives.Xilinx.ClockGen.clockWizardTclTF 11 | workInfo: Always 12 | - BlackBox: 13 | name: Clash.Xilinx.ClockGen.unsafeClockWizardDifferential 14 | kind: Declaration 15 | format: Haskell 16 | templateFunction: Clash.Primitives.Xilinx.ClockGen.clockWizardDifferentialTF 17 | includes: 18 | - name: clk_wiz 19 | extension: clash.tcl 20 | format: Haskell 21 | templateFunction: Clash.Primitives.Xilinx.ClockGen.clockWizardDifferentialTclTF 22 | workInfo: Always 23 | -------------------------------------------------------------------------------- /clash-lib/prims/common/Debug_Trace.primitives.yaml: -------------------------------------------------------------------------------- 1 | - BlackBox: 2 | name: Debug.Trace.trace 3 | kind: Expression 4 | type: 'trace :: String 5 | -> a -> a' 6 | template: ~ARG[1] 7 | workInfo: Never 8 | -------------------------------------------------------------------------------- /clash-lib/prims/common/GHC_Base.primitives.yaml: -------------------------------------------------------------------------------- 1 | - Primitive: 2 | name: GHC.Base.$ 3 | primType: Function 4 | workInfo: Never 5 | -------------------------------------------------------------------------------- /clash-lib/prims/common/GHC_CString.primitives.yaml: -------------------------------------------------------------------------------- 1 | - BlackBox: 2 | name: GHC.CString.unpackCString# 3 | kind: Expression 4 | template: ~LIT[0] 5 | workInfo: Never 6 | - BlackBox: 7 | name: GHC.CString.unpackFoldrCString# 8 | kind: Expression 9 | template: ~LIT[0] 10 | workInfo: Never 11 | - Primitive: 12 | name: GHC.CString.unpackCStringUtf8# 13 | primType: Function 14 | workInfo: Never 15 | -------------------------------------------------------------------------------- /clash-lib/prims/common/GHC_Classes.primitives.yaml: -------------------------------------------------------------------------------- 1 | - BlackBox: 2 | name: GHC.Classes.gtInt 3 | kind: Expression 4 | type: 'gtInt :: Int -> 5 | Int -> Bool' 6 | template: ~ARG[0] > ~ARG[1] 7 | - BlackBox: 8 | name: GHC.Classes.geInt 9 | kind: Expression 10 | type: 'geInt :: Int -> 11 | Int -> Bool' 12 | template: ~ARG[0] >= ~ARG[1] 13 | - BlackBox: 14 | name: GHC.Classes.ltInt 15 | kind: Expression 16 | type: 'ltInt :: Int -> 17 | Int -> Bool' 18 | template: ~ARG[0] < ~ARG[1] 19 | - BlackBox: 20 | name: GHC.Classes.leInt 21 | kind: Expression 22 | type: 'leInt :: Int -> 23 | Int -> Bool' 24 | template: ~ARG[0] <= ~ARG[1] 25 | -------------------------------------------------------------------------------- /clash-lib/prims/common/GHC_Err.primitives.yaml: -------------------------------------------------------------------------------- 1 | - BlackBox: 2 | name: GHC.Err.error 3 | kind: Expression 4 | type: 'error :: forall r a . HasCallStack => [Char] -> a' 5 | template: ~ERRORO 6 | workInfo: Constant 7 | - BlackBox: 8 | name: GHC.Err.errorWithoutStackTrace 9 | kind: Expression 10 | type: 'errorWithoutStackTrace :: forall r a . [Char] -> a' 11 | template: ~ERRORO 12 | workInfo: Constant 13 | - BlackBox: 14 | name: GHC.Err.undefined 15 | kind: Expression 16 | type: 'undefined :: forall r a . HasCallStack => a' 17 | template: ~ERRORO 18 | workInfo: Constant 19 | -------------------------------------------------------------------------------- /clash-lib/prims/common/GHC_IO_Exception.primitives.yaml: -------------------------------------------------------------------------------- 1 | - BlackBox: 2 | name: GHC.IO.Exception.assertError 3 | comment: |- 4 | It would be nice if we could use a HDL assertion, however, 5 | because in HDL, case alternatives are evaluated 6 | concurrently, we would end up with the assertion being 7 | triggered, even when the result of that branch is not 8 | chosen in the multiplexer 9 | kind: Expression 10 | type: 'assertError :: 11 | HasCallStack => Bool -> a -> a' 12 | template: ~ARG[2] 13 | workInfo: Never 14 | -------------------------------------------------------------------------------- /clash-lib/prims/common/GHC_Internal_Debug_Trace.primitives.yaml: -------------------------------------------------------------------------------- 1 | - BlackBox: 2 | name: GHC.Internal.Debug.Trace.trace 3 | kind: Expression 4 | type: 'trace :: String 5 | -> a -> a' 6 | template: ~ARG[1] 7 | workInfo: Never 8 | -------------------------------------------------------------------------------- /clash-lib/prims/common/GHC_Internal_Err.primitives.yaml: -------------------------------------------------------------------------------- 1 | - BlackBox: 2 | name: GHC.Internal.Err.error 3 | kind: Expression 4 | type: 'error :: forall r a . HasCallStack => [Char] -> a' 5 | template: ~ERRORO 6 | workInfo: Constant 7 | - BlackBox: 8 | name: GHC.Internal.Err.errorWithoutStackTrace 9 | kind: Expression 10 | type: 'errorWithoutStackTrace :: forall r a . [Char] -> a' 11 | template: ~ERRORO 12 | workInfo: Constant 13 | - BlackBox: 14 | name: GHC.Internal.Err.undefined 15 | kind: Expression 16 | type: 'undefined :: forall r a . HasCallStack => a' 17 | template: ~ERRORO 18 | workInfo: Constant 19 | -------------------------------------------------------------------------------- /clash-lib/prims/common/GHC_Internal_TypeNats.primitives.yaml: -------------------------------------------------------------------------------- 1 | - BlackBox: 2 | name: GHC.Internal.TypeNats.natVal 3 | kind: Expression 4 | type: 'natVal :: forall 5 | n proxy. KnownNat n => proxy n -> Natural' 6 | template: ~ARG[0] 7 | workInfo: Never 8 | - Primitive: 9 | name: GHC.Internal.TypeNats.someNatVal 10 | primType: Function 11 | type: 'someNatVal :: Natural -> SomeNat' 12 | workInfo: Never 13 | - Primitive: 14 | name: GHC.Internal.TypeNats.withSomeSNat 15 | primType: Function 16 | type: 'withSomeSNat :: forall rep (r :: TYPE rep). Natural -> (forall n. SNat n -> r) -> r' 17 | workInfo: Never 18 | -------------------------------------------------------------------------------- /clash-lib/prims/common/GHC_Magic.primitives.yaml: -------------------------------------------------------------------------------- 1 | - Primitive: 2 | name: GHC.Magic.lazy 3 | primType: Function 4 | workInfo: Never 5 | - Primitive: 6 | name: GHC.Magic.noinline 7 | primType: Function 8 | type: forall a. a -> a 9 | workInfo: Never 10 | - Primitive: 11 | name: GHC.Magic.nospec 12 | primType: Function 13 | type: forall a. a -> a 14 | workInfo: Never 15 | - Primitive: 16 | name: GHC.Magic.runRW# 17 | primType: Function 18 | workInfo: Never 19 | -------------------------------------------------------------------------------- /clash-lib/prims/common/GHC_Prim_Panic.primitives.yaml: -------------------------------------------------------------------------------- 1 | - BlackBox: 2 | name: GHC.Prim.Panic.absentError 3 | kind: Expression 4 | type: 'absentError :: 5 | Addr# -> a' 6 | template: ~ERRORO 7 | workInfo: Constant 8 | -------------------------------------------------------------------------------- /clash-lib/prims/common/GHC_Real.primitives.yaml: -------------------------------------------------------------------------------- 1 | - BlackBox: 2 | name: GHC.Real.divZeroError 3 | kind: Expression 4 | type: 'divZeroError :: 5 | a' 6 | template: ~ERRORO 7 | workInfo: Constant 8 | - BlackBox: 9 | name: GHC.Real.ratioZeroDenominatorError 10 | kind: Expression 11 | type: 'ratioZeroDenominatorError 12 | :: a' 13 | template: ~ERRORO 14 | workInfo: Constant 15 | - BlackBox: 16 | name: GHC.Real.overflowError 17 | kind: Expression 18 | type: 'overflowError :: 19 | a' 20 | template: ~ERRORO 21 | workInfo: Constant 22 | -------------------------------------------------------------------------------- /clash-lib/prims/common/GHC_TypeNats.primitives.yaml: -------------------------------------------------------------------------------- 1 | - BlackBox: 2 | name: GHC.TypeNats.natVal 3 | kind: Expression 4 | type: 'natVal :: forall 5 | n proxy. KnownNat n => proxy n -> Natural' 6 | template: ~ARG[0] 7 | workInfo: Never 8 | - Primitive: 9 | name: GHC.TypeNats.someNatVal 10 | primType: Function 11 | type: 'someNatVal :: Natural -> SomeNat' 12 | workInfo: Never 13 | - Primitive: 14 | name: GHC.TypeNats.withSomeSNat 15 | primType: Function 16 | type: 'withSomeSNat :: forall rep (r :: TYPE rep). Natural -> (forall n. SNat n -> r) -> r' 17 | workInfo: Never 18 | -------------------------------------------------------------------------------- /clash-lib/prims/common/GHC_Typelits.primitives.yaml: -------------------------------------------------------------------------------- 1 | - BlackBox: 2 | name: GHC.TypeLits.natVal 3 | kind: Expression 4 | type: 'natVal :: forall 5 | n proxy. KnownNat n => proxy n -> Integer' 6 | template: ~ARG[0] 7 | workInfo: Never 8 | -------------------------------------------------------------------------------- /clash-lib/prims/common/GHC_Types.primitives.yaml: -------------------------------------------------------------------------------- 1 | - Primitive: 2 | name: GHC.Types.MkCoercible 3 | primType: Constructor 4 | workInfo: Never 5 | - BlackBox: 6 | name: GHC.Types.I# 7 | kind: Expression 8 | comment: Needed to make the evaluator handle this constructor strictly 9 | type: 'I# :: Int# -> Int' 10 | template: ~ARG[0] 11 | workInfo: Never 12 | - BlackBox: 13 | name: GHC.Types.W# 14 | kind: Expression 15 | comment: Needed to make the evaluator handle this constructor strictly 16 | type: 'W# :: Word# -> Word' 17 | template: ~ARG[0] 18 | workInfo: Never 19 | -------------------------------------------------------------------------------- /clash-lib/prims/common/Unsafe_Coerce.primitives.yaml: -------------------------------------------------------------------------------- 1 | - BlackBox: 2 | name: Unsafe.Coerce.unsafeCoerce 3 | kind: Expression 4 | type: 'unsafeCoerce :: 5 | a -> b' 6 | template: ~ARG[0] 7 | workInfo: Never 8 | -------------------------------------------------------------------------------- /clash-lib/prims/commonverilog/Clash_Class_BitPack.primitives.yaml: -------------------------------------------------------------------------------- 1 | - BlackBox: 2 | name: Clash.Class.BitPack.Internal.packChar# 3 | kind: Expression 4 | type: 'packChar# :: Char -> BitVector 21' 5 | template: ~ARG[0] 6 | workInfo: Never 7 | - BlackBox: 8 | name: Clash.Class.BitPack.Internal.unpackChar# 9 | kind: Expression 10 | type: 'unpackChar# :: BitVector 21 -> Char' 11 | template: ~ARG[0] 12 | workInfo: Never 13 | -------------------------------------------------------------------------------- /clash-lib/prims/commonverilog/Clash_Explicit_Testbench.primitives.yaml: -------------------------------------------------------------------------------- 1 | - BlackBox: 2 | name: Clash.Explicit.Testbench.tbEnableGen 3 | kind: Declaration 4 | type: 'tbEnableGen :: 5 | Enable dom' 6 | template: assign ~RESULT = 1'b1; 7 | workInfo: Always 8 | - BlackBox: 9 | name: Clash.Explicit.Testbench.clockToDiffClock 10 | kind: Expression 11 | template: '{~ARG[1], ~ ~ARG[1]}' 12 | -------------------------------------------------------------------------------- /clash-lib/prims/commonverilog/Clash_Magic.primitives.yaml: -------------------------------------------------------------------------------- 1 | - BlackBox: 2 | name: Clash.Magic.nameHint 3 | kind: Declaration 4 | type: |- 5 | nameHint 6 | :: SSymbol sym -- ARG[0] 7 | -> a -- ARG[1] 8 | -> a 9 | resultName: 10 | template: ~NAME[0] 11 | template: assign ~RESULT = ~ARG[1]; 12 | -------------------------------------------------------------------------------- /clash-lib/prims/commonverilog/Clash_Signal_Internal.primitives.yaml: -------------------------------------------------------------------------------- 1 | - BlackBox: 2 | name: Clash.Signal.Internal.unsafeFromReset 3 | kind: Expression 4 | type: 'unsafeFromReset 5 | :: Reset dom -> Signal dom Bool' 6 | template: ~ARG[0] 7 | workInfo: Never 8 | - BlackBox: 9 | name: Clash.Signal.Internal.unsafeToReset 10 | kind: Expression 11 | type: 'unsafeToReset :: 12 | KnownDomain dom => Signal dom Bool -> Reset dom' 13 | template: ~ARG[1] 14 | workInfo: Never 15 | -------------------------------------------------------------------------------- /clash-lib/prims/commonverilog/Clash_Sized_Vector.primitives.yaml: -------------------------------------------------------------------------------- 1 | - BlackBox: 2 | name: Clash.Sized.Vector.maxIndex 3 | kind: Expression 4 | type: 'maxIndex :: KnownNat 5 | n => Vec n a -> Int' 6 | template: ~SIZE[~TYPO]'sd~LIT[0] - ~SIZE[~TYPO]'sd1 7 | workInfo: Constant 8 | - BlackBox: 9 | name: Clash.Sized.Vector.length 10 | kind: Expression 11 | type: 'length :: KnownNat 12 | n => Vec n a -> Int' 13 | template: ~SIZE[~TYPO]'sd~LIT[0] 14 | workInfo: Constant 15 | -------------------------------------------------------------------------------- /clash-lib/prims/commonverilog/GHC_Base.primitives.yaml: -------------------------------------------------------------------------------- 1 | - BlackBox: 2 | name: GHC.Base.remInt 3 | kind: Expression 4 | type: 'remInt :: Int -> 5 | Int -> Int' 6 | template: ~ARG[0] % ~ARG[1] 7 | - BlackBox: 8 | name: GHC.Base.quotInt 9 | kind: Expression 10 | type: 'quotInt :: Int 11 | -> Int -> Int' 12 | template: ~ARG[0] / ~ARG[1] 13 | -------------------------------------------------------------------------------- /clash-lib/prims/commonverilog/GHC_Classes.primitives.yaml: -------------------------------------------------------------------------------- 1 | - BlackBox: 2 | name: GHC.Classes.eqInt 3 | kind: Expression 4 | type: 'eqInt :: Int -> 5 | Int -> Bool' 6 | template: ~ARG[0] == ~ARG[1] 7 | - BlackBox: 8 | name: GHC.Classes.neInt 9 | kind: Expression 10 | type: 'neInt :: Int -> 11 | Int -> Bool' 12 | template: ~ARG[0] != ~ARG[1] 13 | - BlackBox: 14 | name: GHC.Classes.&& 15 | kind: Expression 16 | type: '(&&) :: Bool -> 17 | Bool -> Bool' 18 | template: ~ARG[0] & ~ARG[1] 19 | - BlackBox: 20 | name: GHC.Classes.|| 21 | kind: Expression 22 | type: '(||) :: Bool -> 23 | Bool -> Bool' 24 | template: ~ARG[0] | ~ARG[1] 25 | - BlackBox: 26 | name: GHC.Classes.not 27 | kind: Expression 28 | type: 'not :: Bool -> 29 | Bool' 30 | template: ~ ~ARG[0] 31 | -------------------------------------------------------------------------------- /clash-lib/prims/commonverilog/GHC_Int.primitives.yaml: -------------------------------------------------------------------------------- 1 | - BlackBoxHaskell: 2 | name: GHC.Int.I8# 3 | templateFunction: Clash.Primitives.GHC.Int.intTF 4 | workInfo: Never 5 | - BlackBoxHaskell: 6 | name: GHC.Int.I16# 7 | templateFunction: Clash.Primitives.GHC.Int.intTF 8 | workInfo: Never 9 | - BlackBoxHaskell: 10 | name: GHC.Int.I32# 11 | templateFunction: Clash.Primitives.GHC.Int.intTF 12 | workInfo: Never 13 | - BlackBoxHaskell: 14 | name: GHC.Int.I64# 15 | templateFunction: Clash.Primitives.GHC.Int.intTF 16 | workInfo: Never 17 | -------------------------------------------------------------------------------- /clash-lib/prims/commonverilog/GHC_Integer_Logarithms.primitives.yaml: -------------------------------------------------------------------------------- 1 | - BlackBox: 2 | name: GHC.Integer.Logarithms.integerLogBase# 3 | imports: 4 | - ~INCLUDENAME[0].inc 5 | includes: 6 | - name: integerLogBase 7 | extension: inc 8 | template: |- 9 | // integer logBase 10 | function integer ~INCLUDENAME[0]; 11 | input integer base, value; 12 | begin 13 | for (~INCLUDENAME[0] = 0; value >= base; ~INCLUDENAME[0]=~INCLUDENAME[0]+1) 14 | value = value / base; 15 | end 16 | endfunction 17 | kind: Expression 18 | type: 'integerLogBase# 19 | :: Integer -> Integer -> Int#' 20 | template: ~INCLUDENAME[0](~ARG[0],~ARG[1]) 21 | warning: 'GHC.Integer.Logarithms.integerLogBase#: Integers are dynamically sized 22 | in simulation, but fixed-length after synthesis. Use carefully.' 23 | -------------------------------------------------------------------------------- /clash-lib/prims/commonverilog/GHC_Word.primitives.yaml: -------------------------------------------------------------------------------- 1 | - BlackBoxHaskell: 2 | name: GHC.Word.W8# 3 | templateFunction: Clash.Primitives.GHC.Word.wordTF 4 | workInfo: Never 5 | - BlackBoxHaskell: 6 | name: GHC.Word.W16# 7 | templateFunction: Clash.Primitives.GHC.Word.wordTF 8 | workInfo: Never 9 | - BlackBoxHaskell: 10 | name: GHC.Word.W32# 11 | templateFunction: Clash.Primitives.GHC.Word.wordTF 12 | workInfo: Never 13 | - BlackBoxHaskell: 14 | name: GHC.Word.W64# 15 | templateFunction: Clash.Primitives.GHC.Word.wordTF 16 | workInfo: Never 17 | -------------------------------------------------------------------------------- /clash-lib/prims/systemverilog/Clash_Prelude_ROM.primitives.yaml: -------------------------------------------------------------------------------- 1 | - BlackBox: 2 | name: Clash.Prelude.ROM.asyncRom# 3 | kind: Declaration 4 | type: |- 5 | asyncRom# 6 | :: ( KnownNat n -- ARG[0] 7 | , NFDataX a) -- ARG[1] 8 | => Vec n a -- ARG[2] 9 | -> Int -- ARG[3] 10 | -> a 11 | template: |- 12 | // asyncRom begin 13 | ~SIGD[~GENSYM[ROM][0]][2]; 14 | assign ~SYM[0] = ~CONST[2]; 15 | 16 | assign ~RESULT = ~FROMBV[~SYM[0][\~ARG[3]\]][~TYPO]; 17 | // asyncRom end 18 | -------------------------------------------------------------------------------- /clash-lib/prims/systemverilog/Clash_Prelude_ROM_Blob.primitives.yaml: -------------------------------------------------------------------------------- 1 | - BlackBox: 2 | name: Clash.Prelude.ROM.Blob.asyncRomBlob# 3 | kind: Declaration 4 | type: |- 5 | asyncRomBlob# 6 | :: MemBlob n m -- ARG[0] 7 | -> Int -- ARG[1] 8 | -> BitVector m 9 | template: |- 10 | // asyncRomBlob begin 11 | ~SIGD[~GENSYM[ROM][0]][0]; 12 | assign ~SYM[0] = ~CONST[0]; 13 | 14 | assign ~RESULT = ~SYM[0][~ARG[1]]; 15 | // asyncRomBlob end 16 | -------------------------------------------------------------------------------- /clash-lib/prims/systemverilog/Clash_Prelude_ROM_File.primitives.yaml: -------------------------------------------------------------------------------- 1 | - BlackBox: 2 | name: Clash.Prelude.ROM.File.asyncRomFile# 3 | kind: Declaration 4 | type: |- 5 | asyncRomFile :: KnownNat m -- ARG[0] 6 | => SNat n -- sz, ARG[1] 7 | -> FilePath -- file, ARG[2] 8 | -> Int -- rd, ARG[3] 9 | -> BitVector m 10 | template: |- 11 | // asyncRomFile begin 12 | ~SIGDO[~GENSYM[ROM][0]] [0:~LIT[1]-1]; 13 | 14 | initial begin 15 | $readmemb(~FILE[~LIT[2]],~SYM[0]); 16 | end 17 | 18 | assign ~RESULT = ~SYM[0][~ARG[3]]; 19 | // asyncRomFile end 20 | -------------------------------------------------------------------------------- /clash-lib/prims/systemverilog/Clash_Sized_RTree.primitives.yaml: -------------------------------------------------------------------------------- 1 | - BlackBox: 2 | name: Clash.Sized.RTree.treplicate 3 | kind: Expression 4 | type: 'replicate :: SNat 5 | d -> a -> RTree d a' 6 | template: '''{(2**~LIT[0]) {~TOBV[~ARG[1]][~TYP[1]]}}' 7 | workInfo: Never 8 | - BlackBox: 9 | name: Clash.Sized.RTree.textract 10 | kind: Expression 11 | type: 'textract :: RTree 12 | 0 a -> a' 13 | template: ~FROMBV[~VAR[tree][0][\0\]][~TYPO] 14 | workInfo: Never 15 | - BlackBox: 16 | name: Clash.Sized.RTree.tsplit 17 | kind: Expression 18 | type: 'tsplit:: RTree 19 | (d+1) a -> (RTree d a,RTree d a)' 20 | template: ~TOBV[~VAR[tree][0]][~TYP[0]] 21 | workInfo: Never 22 | -------------------------------------------------------------------------------- /clash-lib/prims/verilog/Clash_Prelude_ROM.primitives.yaml: -------------------------------------------------------------------------------- 1 | - BlackBox: 2 | name: Clash.Prelude.ROM.asyncRom# 3 | kind: Declaration 4 | type: |- 5 | asyncRom# 6 | :: ( KnownNat n -- ARG[0] 7 | , NFDataX a) -- ARG[1] 8 | => Vec n a -- ARG[2] 9 | -> Int -- ARG[3] 10 | -> a 11 | template: |- 12 | // asyncRom begin 13 | wire ~TYPO ~GENSYM[ROM][0] [0:~LIT[0]-1]; 14 | 15 | wire ~TYP[2] ~GENSYM[romflat][1]; 16 | assign ~SYM[1] = ~CONST[2]; 17 | genvar ~GENSYM[i][2]; 18 | ~GENERATE 19 | for (~SYM[2]=0; ~SYM[2] < ~LIT[0]; ~SYM[2]=~SYM[2]+1) begin : ~GENSYM[mk_array][3] 20 | assign ~SYM[0][(~LIT[0]-1)-~SYM[2]] = ~SYM[1][~SYM[2]*~SIZE[~TYPO]+:~SIZE[~TYPO]]; 21 | end 22 | ~ENDGENERATE 23 | 24 | assign ~RESULT = ~SYM[0][~ARG[3]]; 25 | // asyncRom end 26 | -------------------------------------------------------------------------------- /clash-lib/prims/verilog/Clash_Prelude_ROM_Blob.primitives.yaml: -------------------------------------------------------------------------------- 1 | - BlackBox: 2 | name: Clash.Prelude.ROM.Blob.asyncRomBlob# 3 | kind: Declaration 4 | type: |- 5 | asyncRomBlob# 6 | :: MemBlob n m -- ARG[0] 7 | -> Int -- ARG[1] 8 | -> BitVector m 9 | template: |- 10 | // asyncRomBlob begin 11 | wire ~TYPO ~GENSYM[ROM][0] [0:~LENGTH[~TYP[0]]-1]; 12 | 13 | wire ~TYP[0] ~GENSYM[romflat][1]; 14 | assign ~SYM[1] = ~CONST[0]; 15 | genvar ~GENSYM[i][2]; 16 | ~GENERATE 17 | for (~SYM[2]=0; ~SYM[2] < ~LENGTH[~TYP[0]]; ~SYM[2]=~SYM[2]+1) begin : ~GENSYM[mk_array][3] 18 | assign ~SYM[0][(~LENGTH[~TYP[0]]-1)-~SYM[2]] = ~SYM[1][~SYM[2]*~SIZE[~TYPO]+:~SIZE[~TYPO]]; 19 | end 20 | ~ENDGENERATE 21 | 22 | assign ~RESULT = ~SYM[0][~ARG[1]]; 23 | // asyncRomBlob end 24 | -------------------------------------------------------------------------------- /clash-lib/prims/verilog/Clash_Prelude_ROM_File.primitives.yaml: -------------------------------------------------------------------------------- 1 | - BlackBox: 2 | name: Clash.Prelude.ROM.File.asyncRomFile# 3 | kind: Declaration 4 | type: |- 5 | asyncRomFile :: KnownNat m -- ARG[0] 6 | => SNat n -- sz, ARG[1] 7 | -> FilePath -- file, ARG[2] 8 | -> Int -- rd, ARG[3] 9 | -> BitVector m 10 | template: |- 11 | // asyncRomFile begin 12 | reg ~TYPO ~GENSYM[ROM][0] [0:~LIT[1]-1]; 13 | 14 | initial begin 15 | $readmemb(~FILE[~LIT[2]],~SYM[0]); 16 | end 17 | 18 | assign ~RESULT = ~SYM[0][~ARG[3]]; 19 | // asyncRomFile end 20 | -------------------------------------------------------------------------------- /clash-lib/prims/verilog/Clash_Sized_RTree.primitives.yaml: -------------------------------------------------------------------------------- 1 | - BlackBox: 2 | name: Clash.Sized.RTree.treplicate 3 | kind: Expression 4 | type: 'replicate :: SNat 5 | d -> a -> RTree d a' 6 | template: '{(2**~LIT[0]) {~ARG[1]}}' 7 | workInfo: Never 8 | - BlackBox: 9 | name: Clash.Sized.RTree.textract 10 | kind: Expression 11 | type: 'textract :: RTree 12 | 0 a -> a' 13 | template: '~VAR[tree][0][~SIZE[~TYP[0]]-1 -: ~SIZE[~TYPO]]' 14 | workInfo: Never 15 | - BlackBox: 16 | name: Clash.Sized.RTree.tsplit 17 | kind: Expression 18 | type: 'tsplit:: RTree 19 | (d+1) a -> (RTree d a,RTree d a)' 20 | template: ~ARG[0] 21 | workInfo: Never 22 | -------------------------------------------------------------------------------- /clash-lib/prims/vhdl/Clash_Class_BitPack.primitives.yaml: -------------------------------------------------------------------------------- 1 | - BlackBox: 2 | name: Clash.Class.BitPack.Internal.packChar# 3 | kind: Expression 4 | type: 'packChar# :: Char -> BitVector 21' 5 | template: std_logic_vector(~ARG[0]) 6 | workInfo: Never 7 | - BlackBox: 8 | name: Clash.Class.BitPack.Internal.unpackChar# 9 | kind: Expression 10 | type: 'unpackChar# :: BitVector 21 -> Char' 11 | template: unsigned(~ARG[0]) 12 | workInfo: Never 13 | -------------------------------------------------------------------------------- /clash-lib/prims/vhdl/Clash_Explicit_SimIO.primitives.yaml: -------------------------------------------------------------------------------- 1 | - Primitive: 2 | name: Clash.Explicit.SimIO.mealyIO 3 | primType: Function 4 | - Primitive: 5 | name: Clash.Explicit.SimIO.fmapSimIO# 6 | primType: Function 7 | - Primitive: 8 | name: Clash.Explicit.SimIO.pureSimIO# 9 | primType: Function 10 | - Primitive: 11 | name: Clash.Explicit.SimIO.apSimIO# 12 | primType: Function 13 | - Primitive: 14 | name: Clash.Explicit.SimIO.bindSimIO# 15 | primType: Function 16 | - Primitive: 17 | name: Clash.Explicit.SimIO.unSimIO# 18 | primType: Function 19 | -------------------------------------------------------------------------------- /clash-lib/prims/vhdl/Clash_Magic.primitives.yaml: -------------------------------------------------------------------------------- 1 | - BlackBox: 2 | name: Clash.Magic.nameHint 3 | kind: Declaration 4 | type: |- 5 | nameHint 6 | :: SSymbol sym -- ARG[0] 7 | -> a -- ARG[1] 8 | -> a 9 | resultName: 10 | template: ~NAME[0] 11 | template: ~RESULT <= ~ARG[1]; 12 | -------------------------------------------------------------------------------- /clash-lib/prims/vhdl/Clash_Prelude_ROM_Blob.primitives.yaml: -------------------------------------------------------------------------------- 1 | - BlackBox: 2 | name: Clash.Prelude.ROM.Blob.asyncRomBlob# 3 | kind: Declaration 4 | type: |- 5 | asyncRomBlob# 6 | :: MemBlob n m -- ARG[0] 7 | -> Int -- ARG[1] 8 | -> BitVector m 9 | template: |- 10 | -- asyncRomBlob begin 11 | ~GENSYM[asyncRom][0] : block 12 | signal ~GENSYM[ROM][1] : ~TYP[0]; 13 | signal ~GENSYM[rd][2] : integer range 0 to ~LENGTH[~TYP[0]]-1; 14 | begin 15 | ~SYM[1] <= ~CONST[0]; 16 | 17 | ~SYM[2] <= to_integer(~VAR[rdI][1](31 downto 0)) 18 | -- pragma translate_off 19 | mod ~LENGTH[~TYP[0]] 20 | -- pragma translate_on 21 | ; 22 | ~RESULT <= ~SYM[1](~SYM[2]); 23 | end block; 24 | -- asyncRomBlob end 25 | -------------------------------------------------------------------------------- /clash-lib/prims/vhdl/Clash_Sized_RTree.primitives.yaml: -------------------------------------------------------------------------------- 1 | - BlackBox: 2 | name: Clash.Sized.RTree.treplicate 3 | kind: Expression 4 | type: 'replicate :: SNat 5 | n -> a -> RTree d a' 6 | template: ~TYPMO'(0 to (2**~LIT[0])-1 => ~IF~VIVADO~THEN~TOBV[~ARG[1]][~TYP[1]]~ELSE~ARG[1]~FI) 7 | workInfo: Never 8 | - BlackBox: 9 | name: Clash.Sized.RTree.textract 10 | kind: Expression 11 | type: 'textract :: RTree 12 | 0 a -> a' 13 | template: ~IF ~VIVADO ~THEN ~FROMBV[~VAR[t][0](0)][~TYPO] ~ELSE ~VAR[t][0](0) 14 | ~FI 15 | workInfo: Never 16 | - BlackBox: 17 | name: Clash.Sized.RTree.tsplit 18 | kind: Expression 19 | type: 'tsplit:: RTree 20 | (d+1) a -> (RTree d a,RTree d a)' 21 | template: (~VAR[t][0](0 to (2**(~DEPTH[~TYP[0]]-1))-1) ,~VAR[t][0](2**(~DEPTH[~TYP[0]]-1) 22 | to (2**~DEPTH[~TYP[0]])-1)) 23 | workInfo: Never 24 | -------------------------------------------------------------------------------- /clash-lib/prims/vhdl/GHC_Integer_Logarithms.primitives.yaml: -------------------------------------------------------------------------------- 1 | - BlackBox: 2 | name: GHC.Integer.Logarithms.integerLogBase# 3 | kind: Expression 4 | type: 'integerLogBase# 5 | :: Integer -> Integer -> Int#' 6 | template: integer(floor(log(real(~ARG[1]),real(~ARG[0])))) 7 | warning: 'GHC.Integer.Logarithms.integerLogBase#: Integers are dynamically sized 8 | in simulation, but fixed-length after synthesis. Use carefully.' 9 | -------------------------------------------------------------------------------- /clash-lib/prims/vhdl/GHC_Word.primitives.yaml: -------------------------------------------------------------------------------- 1 | - BlackBox: 2 | name: GHC.Word.W8# 3 | kind: Expression 4 | type: 'W8# :: Word# -> 5 | Word8' 6 | template: resize(~ARG[0],8) 7 | workInfo: Never 8 | - BlackBox: 9 | name: GHC.Word.W16# 10 | kind: Expression 11 | type: 'W16# :: Word# -> 12 | Word16' 13 | template: resize(~ARG[0],16) 14 | workInfo: Never 15 | - BlackBox: 16 | name: GHC.Word.W32# 17 | kind: Expression 18 | type: 'W32# :: Word# -> 19 | Word32' 20 | template: resize(~ARG[0],32) 21 | workInfo: Never 22 | - BlackBox: 23 | name: GHC.Word.W64# 24 | kind: Expression 25 | type: 'W64# :: Word# -> 26 | Word64' 27 | template: resize(~ARG[0],64) 28 | workInfo: Never 29 | -------------------------------------------------------------------------------- /clash-lib/src/Clash/Core/Subst.hs-boot: -------------------------------------------------------------------------------- 1 | {-# OPTIONS_GHC -fno-warn-orphans #-} 2 | 3 | module Clash.Core.Subst where 4 | 5 | import GHC.Stack (HasCallStack) 6 | import {-# SOURCE #-} Clash.Core.Type (Type) 7 | import Clash.Core.Var (TyVar) 8 | 9 | substTyWith 10 | :: HasCallStack 11 | => [TyVar] 12 | -> [Type] 13 | -> Type 14 | -> Type 15 | 16 | aeqType 17 | :: Type 18 | -> Type 19 | -> Bool 20 | 21 | instance Eq Type 22 | instance Ord Type 23 | -------------------------------------------------------------------------------- /clash-lib/src/Clash/Core/Term.hs-boot: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (C) 2012-2016, University of Twente 3 | License : BSD2 (see the file LICENSE) 4 | Maintainer : Christiaan Baaij 5 | -} 6 | 7 | {-# OPTIONS_GHC -fno-warn-missing-methods #-} 8 | 9 | module Clash.Core.Term where 10 | 11 | import GHC.Generics (Generic) 12 | import Clash.Core.Name (Name) 13 | 14 | data Term 15 | 16 | type TmName = Name Term 17 | 18 | instance Generic Term 19 | -------------------------------------------------------------------------------- /clash-lib/src/Clash/Core/TyCon.hs-boot: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (C) 2012-2016, University of Twente 3 | License : BSD2 (see the file LICENSE) 4 | Maintainer : Christiaan Baaij 5 | -} 6 | 7 | module Clash.Core.TyCon where 8 | 9 | import Clash.Core.Name (Name) 10 | 11 | data TyCon 12 | type TyConName = Name TyCon 13 | -------------------------------------------------------------------------------- /clash-lib/src/Clash/Debug.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | 3 | module Clash.Debug 4 | ( debugIsOn 5 | , traceIf 6 | , module Debug.Trace 7 | ) where 8 | 9 | import Debug.Trace 10 | 11 | debugIsOn :: Bool 12 | #if defined(DEBUG) 13 | debugIsOn = True 14 | #else 15 | debugIsOn = False 16 | #endif 17 | 18 | -- | Performs trace when first argument evaluates to 'True' 19 | traceIf :: Bool -> String -> a -> a 20 | traceIf True msg = trace msg 21 | traceIf False _ = id 22 | {-# INLINE traceIf #-} 23 | -------------------------------------------------------------------------------- /clash-lib/src/Clash/Netlist/BlackBox/Util.hs-boot: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (C) 2019, Google Inc 3 | License : BSD2 (see the file LICENSE) 4 | Maintainer : QBayLogic B.V. 5 | -} 6 | 7 | module Clash.Netlist.BlackBox.Util where 8 | 9 | import Data.Text.Lazy (Text) 10 | import Control.Monad.State (State) 11 | import Clash.Backend (Backend) 12 | import Clash.Netlist.Types (BlackBoxContext) 13 | import Clash.Netlist.BlackBox.Types (BlackBoxTemplate) 14 | 15 | renderTemplate 16 | :: Backend backend 17 | => BlackBoxContext -- ^ Context used to fill in the hole 18 | -> BlackBoxTemplate -- ^ Blackbox template 19 | -> State backend (Int -> Text) 20 | -------------------------------------------------------------------------------- /clash-lib/src/Clash/Netlist/Id.hs-boot: -------------------------------------------------------------------------------- 1 | module Clash.Netlist.Id where 2 | 3 | import {-# SOURCE #-} Clash.Netlist.Types (Identifier) 4 | import Data.Text (Text) 5 | 6 | toText :: Identifier -> Text 7 | -------------------------------------------------------------------------------- /clash-lib/src/Clash/Normalize/Primitives.hs-boot: -------------------------------------------------------------------------------- 1 | module Clash.Normalize.Primitives where 2 | 3 | import Clash.Core.Term (PrimInfo) 4 | 5 | undefined :: PrimInfo 6 | undefinedX :: PrimInfo 7 | -------------------------------------------------------------------------------- /clash-lib/src/Clash/Normalize/Strategy.hs-boot: -------------------------------------------------------------------------------- 1 | module Clash.Normalize.Strategy (constantPropagation, normalization) where 2 | 3 | import Clash.Normalize.Types (NormRewrite) 4 | 5 | normalization :: NormRewrite 6 | constantPropagation :: NormRewrite 7 | -------------------------------------------------------------------------------- /clash-lib/src/ClashDebug.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define ASSERT(e) if debugIsOn && not (e) then (assertPanic __FILE__ __LINE__) else 4 | #define ASSERT2(e,msg) if debugIsOn && not (e) then (assertPprPanic __FILE__ __LINE__ (msg)) else 5 | #define WARN( e, msg ) (warnPprTrace (e) __FILE__ __LINE__ (msg)) $ 6 | -------------------------------------------------------------------------------- /clash-lib/src/Data/Map/Ordered/Extra.hs: -------------------------------------------------------------------------------- 1 | {-# OPTIONS_GHC -Wno-orphans #-} 2 | 3 | module Data.Map.Ordered.Extra where 4 | 5 | import Control.DeepSeq (NFData(rnf)) 6 | import Data.Map.Ordered (OMap) 7 | import qualified Data.Map.Ordered as OMap 8 | 9 | instance (NFData k, NFData v) => NFData (OMap k v) where 10 | rnf = rnf . OMap.assocs 11 | -------------------------------------------------------------------------------- /clash-lib/src/Data/Monoid/Extra.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE FlexibleInstances #-} 2 | {-# LANGUAGE MultiParamTypeClasses #-} 3 | {-# LANGUAGE UndecidableInstances #-} 4 | 5 | {-# OPTIONS_GHC -Wno-orphans #-} 6 | 7 | module Data.Monoid.Extra where 8 | 9 | import Control.Monad.State (MonadState(..)) 10 | import Data.Monoid (Ap(Ap)) 11 | 12 | instance (MonadState s m) => MonadState s (Ap m) where 13 | get = Ap get 14 | put = Ap . put 15 | state = Ap . state 16 | 17 | -------------------------------------------------------------------------------- /clash-lib/src/Data/Set/Ordered/Extra.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (C) 2019,2021, QBayLogic B.V 3 | License : BSD2 (see the file LICENSE) 4 | Maintainer : QBayLogic B.V 5 | 6 | Convenience functions for "Data.Set.Ordered" from the package 7 | "ordered-containers". 8 | -} 9 | 10 | module Data.Set.Ordered.Extra 11 | ( OLSet 12 | , toListL 13 | ) where 14 | 15 | import Data.Coerce (coerce) 16 | import Data.Foldable (toList) 17 | import qualified Data.Set.Ordered as OSet 18 | 19 | type OLSet a = OSet.Bias OSet.L (OSet.OSet a) 20 | 21 | toListL :: forall a. OLSet a -> [a] 22 | toListL = toList . coerce @(OLSet a) @(OSet.OSet a) 23 | -------------------------------------------------------------------------------- /clash-lib/src/Data/Text/Extra.hs: -------------------------------------------------------------------------------- 1 | module Data.Text.Extra 2 | ( showt 3 | , showtl 4 | ) where 5 | 6 | import qualified Data.Text as TS 7 | import qualified Data.Text.Lazy as TL 8 | 9 | showt :: (Show a) => a -> TS.Text 10 | showt = TS.pack . show 11 | 12 | showtl :: (Show a) => a -> TL.Text 13 | showtl = TL.pack . show 14 | -------------------------------------------------------------------------------- /clash-lib/tests/Clash/Tests/Core/TermLiteral/Types.hs: -------------------------------------------------------------------------------- 1 | module Clash.Tests.Core.TermLiteral.Types where 2 | 3 | import Clash.Promoted.Nat 4 | 5 | data NatTypeArg n = NatTypeArg (SNat n) 6 | -------------------------------------------------------------------------------- /clash-lib/tests/doctests.hs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import System.Environment (getArgs) 4 | import Test.DocTest (mainFromCabal) 5 | 6 | main :: IO () 7 | main = mainFromCabal "clash-lib" =<< getArgs 8 | -------------------------------------------------------------------------------- /clash-prelude-hedgehog/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ../CHANGELOG.md -------------------------------------------------------------------------------- /clash-prelude-hedgehog/src/Clash/Hedgehog/Annotations/SynthesisAttributes.hs: -------------------------------------------------------------------------------- 1 | module Clash.Hedgehog.Annotations.SynthesisAttributes where 2 | 3 | import Clash.Annotations.SynthesisAttributes (Attr(..)) 4 | 5 | import Hedgehog 6 | import qualified Hedgehog.Gen as Gen 7 | 8 | genAttr :: forall m. MonadGen m => Range Int -> m (Attr String) 9 | genAttr range = 10 | Gen.choice 11 | [ BoolAttr <$> genAlphaNum <*> Gen.bool 12 | , IntegerAttr <$> genAlphaNum <*> genInteger 13 | , StringAttr <$> genAlphaNum <*> genAlphaNum 14 | , Attr <$> genAlphaNum 15 | ] 16 | where 17 | genAlphaNum = Gen.string range Gen.alphaNum 18 | genInteger = toInteger <$> Gen.integral range 19 | -------------------------------------------------------------------------------- /clash-prelude/AUTHORS.md: -------------------------------------------------------------------------------- 1 | ../AUTHORS.md -------------------------------------------------------------------------------- /clash-prelude/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ../CHANGELOG.md -------------------------------------------------------------------------------- /clash-prelude/benchmarks/BenchCommon.hs: -------------------------------------------------------------------------------- 1 | module BenchCommon where 2 | 3 | apSwapAp :: (a -> a -> a) -> (a,a) -> a 4 | apSwapAp f (a,b) = f (f a b) (f b a) 5 | {-# INLINE apSwapAp #-} 6 | 7 | apSwapAp2 :: (a -> a -> b) -> (b -> b -> c) -> (a,a) -> c 8 | apSwapAp2 f g (a,b) = g (f a b) (f b a) 9 | {-# INLINE apSwapAp2 #-} 10 | -------------------------------------------------------------------------------- /clash-prelude/benchmarks/benchmark-main.hs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Criterion.Main 4 | 5 | import BenchRAM 6 | import BenchBitVector 7 | import BenchFixed 8 | import BenchSigned 9 | import BenchUnsigned 10 | import BenchVector 11 | 12 | main :: IO () 13 | main = 14 | defaultMain 15 | [ ramBench 16 | , bitVectorBench 17 | , fixedBench 18 | , signedBench 19 | , unsignedBench 20 | , vectorBench 21 | ] 22 | -------------------------------------------------------------------------------- /clash-prelude/doc/linuwial-wrap-types.css: -------------------------------------------------------------------------------- 1 | @import "linuwial.css"; 2 | 3 | /* Re-enable wordwrapping in (parts of) type signatures */ 4 | #interface td.src { 5 | white-space: normal !important; 6 | } 7 | -------------------------------------------------------------------------------- /clash-prelude/doc/scanlPar.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clash-lang/clash-compiler/94bad165b71c0b3b46945e1b26361737080e2d66/clash-prelude/doc/scanlPar.graffle -------------------------------------------------------------------------------- /clash-prelude/src/Clash/Class/AutoReg.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (C) 2019, Google Inc. 3 | License : BSD2 (see the file LICENSE) 4 | Maintainer : Christiaan Baaij 5 | -} 6 | 7 | module Clash.Class.AutoReg 8 | ( AutoReg (autoReg) 9 | , deriveAutoReg 10 | ) where 11 | 12 | import Clash.Class.AutoReg.Internal 13 | import Clash.Class.AutoReg.Instances () 14 | -------------------------------------------------------------------------------- /clash-prelude/src/Clash/Class/HasDomain.hs: -------------------------------------------------------------------------------- 1 | {-# OPTIONS_GHC -Wno-deprecations #-} 2 | 3 | module Clash.Class.HasDomain {-# DEPRECATED "Experimental feature multiple hidden has been removed. This module will therefore be removed in Clash 1.12." #-} 4 | ( WithSpecificDomain 5 | , WithSingleDomain 6 | 7 | , HasDomain 8 | , TryDomain 9 | , TryDomainResult(..) 10 | , DomEq 11 | ) where 12 | 13 | -- Compilation is split across modules to maximize GHC parallelism 14 | import Clash.Class.HasDomain.HasSingleDomain 15 | import Clash.Class.HasDomain.HasSpecificDomain 16 | -------------------------------------------------------------------------------- /clash-prelude/src/Clash/Promoted/Nat/Unsafe.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (C) 2015-2016, University of Twente 3 | 2022 , QBayLogic B.V. 4 | License : BSD2 (see the file LICENSE) 5 | Maintainer : QBayLogic B.V. 6 | -} 7 | 8 | {-# LANGUAGE CPP #-} 9 | {-# LANGUAGE Unsafe #-} 10 | 11 | module Clash.Promoted.Nat.Unsafe 12 | (unsafeSNat) 13 | where 14 | 15 | import Data.Reflection (reifyNat) 16 | import Unsafe.Coerce (unsafeCoerce) 17 | 18 | import Clash.Annotations.Primitive (hasBlackBox) 19 | import Clash.Promoted.Nat (SNat, snatProxy) 20 | 21 | -- | I hope you know what you're doing 22 | unsafeSNat :: Integer -> SNat k 23 | unsafeSNat i = reifyNat i $ (\p -> unsafeCoerce (snatProxy p)) 24 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 25 | {-# CLASH_OPAQUE unsafeSNat #-} 26 | {-# ANN unsafeSNat hasBlackBox #-} 27 | -------------------------------------------------------------------------------- /clash-prelude/src/Clash/Sized/Internal.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (C) 2024 , QBayLogic B.V. 3 | License : BSD2 (see the file LICENSE) 4 | Maintainer : QBayLogic B.V. 5 | -} 6 | 7 | module Clash.Sized.Internal where 8 | 9 | -- | Format a range of numbers for use in error messages 10 | -- 11 | -- If the upper bound is below the lower bound, @"\"@ is returned. 12 | -- If the bounds are equal, @"[n]"@ is returned (for bounds equal to /n/). 13 | -- Otherwise, @formatRange n m@ returns @"[n..m]"@. 14 | formatRange :: 15 | (Ord a, Show a) => 16 | -- | Lower bound 17 | a -> 18 | -- | Upper bound 19 | a -> 20 | String 21 | formatRange n m 22 | | m < n = "" 23 | | m == n = '[' : shows n "]" 24 | | otherwise = '[' : show n ++ ".." ++ shows m "]" 25 | -------------------------------------------------------------------------------- /clash-prelude/src/Clash/Sized/Internal/BitVector.hs-boot: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (C) 2015-2016, University of Twente 3 | License : BSD2 (see the file LICENSE) 4 | Maintainer : Christiaan Baaij 5 | -} 6 | 7 | {-# LANGUAGE DataKinds #-} 8 | {-# LANGUAGE KindSignatures #-} 9 | {-# LANGUAGE RoleAnnotations #-} 10 | module Clash.Sized.Internal.BitVector where 11 | 12 | import GHC.TypeLits (KnownNat,Nat) 13 | import Data.Kind (Type) 14 | 15 | type role BitVector nominal 16 | data BitVector :: Nat -> Type 17 | data Bit 18 | 19 | undefError :: KnownNat n => String -> [BitVector n] -> a 20 | -------------------------------------------------------------------------------- /clash-prelude/src/Clash/Sized/Internal/Index.hs-boot: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (C) 2015-2016, University of Twente 3 | License : BSD2 (see the file LICENSE) 4 | Maintainer : Christiaan Baaij 5 | -} 6 | 7 | {-# LANGUAGE DataKinds #-} 8 | {-# LANGUAGE KindSignatures #-} 9 | {-# LANGUAGE MagicHash #-} 10 | {-# LANGUAGE RoleAnnotations #-} 11 | module Clash.Sized.Internal.Index where 12 | 13 | import Data.Kind (Type) 14 | import GHC.TypeLits (KnownNat, Nat) 15 | 16 | type role Index nominal 17 | data Index :: Nat -> Type 18 | 19 | instance KnownNat n => Num (Index n) 20 | toInteger# :: Index n -> Integer 21 | -------------------------------------------------------------------------------- /clash-prelude/src/Clash/Sized/Signed.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (C) 2013-2016, University of Twente 3 | License : BSD2 (see the file LICENSE) 4 | Maintainer : Christiaan Baaij 5 | -} 6 | 7 | {-# LANGUAGE Trustworthy #-} 8 | 9 | module Clash.Sized.Signed 10 | ( Signed 11 | ) 12 | where 13 | 14 | import Clash.Sized.Internal.Signed 15 | -------------------------------------------------------------------------------- /clash-prelude/src/Clash/Sized/Unsigned.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (C) 2013-2016, University of Twente 3 | License : BSD2 (see the file LICENSE) 4 | Maintainer : Christiaan Baaij 5 | -} 6 | 7 | {-# LANGUAGE Trustworthy #-} 8 | 9 | module Clash.Sized.Unsigned 10 | (Unsigned) 11 | where 12 | 13 | import Clash.Sized.Internal.Unsigned 14 | -------------------------------------------------------------------------------- /clash-prelude/src/Clash/XException.hs-boot: -------------------------------------------------------------------------------- 1 | module Clash.XException where 2 | 3 | import GHC.Stack (HasCallStack) 4 | 5 | isX :: a -> Either String a 6 | 7 | class ShowX a 8 | showsPrecX :: ShowX a => Int -> a -> ShowS 9 | 10 | class NFDataX a 11 | deepErrorX :: NFDataX a => HasCallStack => String -> a 12 | hasUndefined :: NFDataX a => a -> Bool 13 | rnfX :: NFDataX a => a -> () 14 | ensureSpine :: NFDataX a => a -> a 15 | 16 | errorX :: HasCallStack => String -> a 17 | -------------------------------------------------------------------------------- /clash-prelude/tests/Clash/Tests/DerivingDataReprTypes.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE QuasiQuotes #-} 2 | {-# LANGUAGE TemplateHaskell #-} 3 | {-# LANGUAGE TypeFamilies #-} 4 | 5 | module Clash.Tests.DerivingDataReprTypes where 6 | 7 | import Clash.Sized.Unsigned 8 | import Clash.Annotations.BitRepresentation.Deriving 9 | 10 | type SmallInt = Unsigned 2 11 | 12 | data Train 13 | = Passenger 14 | -- Number of wagons: 15 | SmallInt 16 | | Freight 17 | -- Number of wagons: 18 | SmallInt 19 | -- Max weight: 20 | SmallInt 21 | | Maintenance 22 | | Toy 23 | 24 | 25 | data RGB 26 | = R 27 | | G 28 | | B 29 | 30 | deriveDefaultAnnotation [t| RGB |] 31 | deriveBitPack [t| RGB |] 32 | 33 | data Headphones 34 | = InEar 35 | { _wireless :: Bool } 36 | | OverEar 37 | { _impedance :: SmallInt } 38 | 39 | data EarCup = SmallInt :<>: SmallInt 40 | -------------------------------------------------------------------------------- /clash-prelude/tests/Clash/Tests/SizedNum.hs: -------------------------------------------------------------------------------- 1 | module Clash.Tests.SizedNum where 2 | 3 | import Data.Bits 4 | import Data.Proxy 5 | import Test.QuickCheck.Classes.Base 6 | import Test.Tasty 7 | import Test.Tasty.QuickCheck 8 | 9 | laws1 :: (Eq a, Ord a, Show a, Num a, Arbitrary a, Integral a, FiniteBits a) => Proxy a -> [Laws] 10 | laws1 p = 11 | [ eqLaws p 12 | , ordLaws p 13 | , numLaws p 14 | , showLaws p 15 | , integralLaws p 16 | , bitsLaws p 17 | ] 18 | 19 | laws :: (Eq a, Ord a, Show a, Num a, Enum a, Bounded a, Arbitrary a, Integral a, FiniteBits a) => Proxy a -> [Laws] 20 | laws p = boundedEnumLaws p : laws1 p 21 | 22 | lawsToTest :: Laws -> TestTree 23 | lawsToTest (Laws name props) = 24 | testGroup name $ map (uncurry testProperty) props 25 | -------------------------------------------------------------------------------- /clash-prelude/tests/Hedgehog/Extra.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TypeApplications #-} 2 | 3 | module Hedgehog.Extra 4 | ( throwsException 5 | , throwsDeepException 6 | ) where 7 | 8 | import Control.DeepSeq (NFData, force) 9 | 10 | import Hedgehog (failure, MonadTest, success) 11 | import Hedgehog.Internal.Exception (tryEvaluate) 12 | import Hedgehog.Internal.Source (HasCallStack, withFrozenCallStack) 13 | 14 | throwsException 15 | :: ( MonadTest m 16 | , HasCallStack 17 | ) 18 | => a 19 | -> m () 20 | throwsException x = 21 | case (tryEvaluate x) of 22 | Left _ -> success 23 | Right _ -> withFrozenCallStack failure 24 | 25 | throwsDeepException 26 | :: ( MonadTest m 27 | , NFData a 28 | , HasCallStack 29 | ) 30 | => a 31 | -> m () 32 | throwsDeepException = 33 | throwsException . force 34 | -------------------------------------------------------------------------------- /clash-prelude/tests/Test/Tasty/Hedgehog/Extra.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (C) 2022, QBayLogic B.V. 3 | License : BSD2 (see the file LICENSE) 4 | Maintainer : QBayLogic B.V. 5 | 6 | Convenience functions \"missing\" in "Test.Tasty.Hedgehog" 7 | -} 8 | 9 | module Test.Tasty.Hedgehog.Extra (testPropertyXXX) where 10 | 11 | import Data.String (IsString(fromString)) 12 | import Hedgehog (Property) 13 | import Test.Tasty (TestName, TestTree) 14 | import Test.Tasty.Hedgehog (testPropertyNamed) 15 | 16 | -- | 'Test.Tasty.Hedgehog.testProperty' has been deprecated in favor of 17 | -- 'testPropertyNamed', but we've written our test cases in such a way that using 18 | -- it correctly is hard. To prevent deprecation warnings, we apply this workaround. 19 | testPropertyXXX :: TestName -> Property -> TestTree 20 | testPropertyXXX nm prop = testPropertyNamed nm (fromString nm) prop 21 | -------------------------------------------------------------------------------- /clash-prelude/tests/doctests.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | module Main where 3 | 4 | import Test.DocTest (mainFromCabal) 5 | import System.Environment (getArgs) 6 | 7 | main :: IO () 8 | main = mainFromCabal "clash-prelude" =<< fmap (extraArgs ++) getArgs 9 | 10 | extraArgs :: [String] 11 | extraArgs = map ("--ghc-arg=" ++) 12 | [ 13 | #if __GLASGOW_HASKELL__ >= 904 14 | "-DCLASH_OPAQUE=OPAQUE" 15 | #else 16 | "-DCLASH_OPAQUE=NOINLINE" 17 | #endif 18 | ] 19 | -------------------------------------------------------------------------------- /clash-term/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /clash-term/theme.ini: -------------------------------------------------------------------------------- 1 | [default] 2 | default.fg = #ffffff 3 | default.bg = #000000 4 | 5 | [other] 6 | focus.bg = #2f4f4f 7 | title.style = bold 8 | emph.style = bold 9 | Type.fg = brightYellow 10 | Keyword.fg = #ffa500 11 | LitS.fg = brightCyan 12 | Unique.fg = #606060 13 | Unique.style = [italic] 14 | Qualifier.style = italic 15 | search.style = [underline, italic] 16 | -------------------------------------------------------------------------------- /default.nix: -------------------------------------------------------------------------------- 1 | (import 2 | ( 3 | let lock = builtins.fromJSON (builtins.readFile ./flake.lock); 4 | in 5 | fetchTarball { 6 | url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; 7 | sha256 = lock.nodes.flake-compat.locked.narHash; 8 | } 9 | ) 10 | { src = ./.; } 11 | ).defaultNix 12 | -------------------------------------------------------------------------------- /docs/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ../CHANGELOG.md -------------------------------------------------------------------------------- /docs/build-docs.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -euo pipefail 4 | 5 | SCRIPT=$(basename $0) 6 | 7 | if [[ -z $(command -v python3) ]]; then 8 | echo "$SCRIPT: python3 is not installed" 9 | exit 127 10 | fi 11 | 12 | echo "$SCRIPT: Building HTML" 13 | /usr/bin/env python3 -msphinx -M html . _build 14 | 15 | echo "$SCRIPT: Building LaTeX" 16 | /usr/bin/env python3 -msphinx -M latexpdf . _build 17 | 18 | -------------------------------------------------------------------------------- /docs/changelog.rst: -------------------------------------------------------------------------------- 1 | .. toctree:: 2 | :maxdepth: 2 3 | :caption: Contents: 4 | 5 | ../CHANGELOG.md 6 | 7 | -------------------------------------------------------------------------------- /docs/developing-hardware/index.rst: -------------------------------------------------------------------------------- 1 | Developing Hardware with Clash 2 | ============================== 3 | 4 | .. toctree:: 5 | :maxdepth: 2 6 | :name: toc-clash 7 | 8 | language 9 | prelude 10 | flags 11 | 12 | -------------------------------------------------------------------------------- /docs/general/index.rst: -------------------------------------------------------------------------------- 1 | General 2 | ======= 3 | 4 | .. toctree:: 5 | :maxdepth: 1 6 | :name: toc-general 7 | 8 | intro 9 | relnotes 10 | faqs 11 | license 12 | 13 | -------------------------------------------------------------------------------- /docs/general/license.rst: -------------------------------------------------------------------------------- 1 | .. _license: 2 | 3 | License 4 | ======= 5 | 6 | .. literalinclude:: LICENSE 7 | :language: text 8 | 9 | -------------------------------------------------------------------------------- /docs/general/relnotes.rst: -------------------------------------------------------------------------------- 1 | .. _relnotes: 2 | 3 | Release Notes 4 | ============= 5 | 6 | Clash 1.0.1 7 | ----------- 8 | 9 | https://github.com/clash-lang/clash-compiler/releases/tag/v1.0.1 10 | 11 | Clash 1.0.0 12 | ----------- 13 | 14 | https://github.com/clash-lang/clash-compiler/releases/tag/v1.0.0 15 | 16 | -------------------------------------------------------------------------------- /docs/getting-started/index.rst: -------------------------------------------------------------------------------- 1 | Getting Started 2 | =============== 3 | 4 | .. toctree:: 5 | :maxdepth: 2 6 | :name: toc-getting-started 7 | 8 | installing 9 | first-circuit 10 | 11 | -------------------------------------------------------------------------------- /docs/hacking-on-clash/hacking.rst: -------------------------------------------------------------------------------- 1 | .. _hacking: 2 | 3 | .. include:: ../../HACKING.rst 4 | 5 | -------------------------------------------------------------------------------- /docs/hacking-on-clash/index.rst: -------------------------------------------------------------------------------- 1 | Hacking on Clash 2 | ================ 3 | 4 | .. toctree:: 5 | :maxdepth: 1 6 | :name: toc-hacking 7 | 8 | style 9 | hacking 10 | 11 | -------------------------------------------------------------------------------- /docs/hacking-on-clash/style.rst: -------------------------------------------------------------------------------- 1 | .. _style: 2 | 3 | .. include:: ../../STYLE.rst 4 | 5 | -------------------------------------------------------------------------------- /docs/requirements.txt: -------------------------------------------------------------------------------- 1 | Sphinx==4.0.2 2 | sphinx_rtd_theme==0.5.2 3 | recommonmark==0.7.1 4 | -------------------------------------------------------------------------------- /examples/ALU.hs: -------------------------------------------------------------------------------- 1 | module ALU where 2 | 3 | import Clash.Prelude 4 | 5 | data OPC = ADD | MUL | SUB 6 | 7 | topEntity :: OPC -> Integer -> Integer -> Integer 8 | topEntity SUB = (-) 9 | topEntity ADD = (+) 10 | topEntity MUL = (*) 11 | -------------------------------------------------------------------------------- /examples/BlockRamTest.hs: -------------------------------------------------------------------------------- 1 | module BlockRamTest where 2 | 3 | import Clash.Prelude 4 | 5 | topEntity 6 | :: Clock System 7 | -> Enable System 8 | -> Signal System (Unsigned 7) 9 | -> Signal System (Maybe (Unsigned 7,Unsigned 4)) 10 | -> Signal System (Unsigned 4) 11 | topEntity clk en = exposeEnable (exposeClock (blockRamPow2 (repeat 0)) clk) en 12 | -------------------------------------------------------------------------------- /examples/CalculatorTypes.hs: -------------------------------------------------------------------------------- 1 | module CalculatorTypes where 2 | 3 | import Clash.Prelude 4 | 5 | type Word = Signed 4 6 | data OPC a = ADD | MUL | Imm a | Pop | Push 7 | deriving Lift 8 | -------------------------------------------------------------------------------- /examples/crc32/CRC32Table.hs: -------------------------------------------------------------------------------- 1 | module CRC32Table where 2 | 3 | import Clash.Prelude 4 | 5 | -- | Table of CRC32 values for all values an 8-bit number can have. 6 | -- 7 | -- Must be in a separate file due to TH stage restrictions 8 | crc32Table :: Vec 256 (BitVector 32) 9 | crc32Table = map crcStep $(listToVecTH [0::BitVector 32 .. 255]) 10 | where 11 | crcStep = last . generate d8 go 12 | go c = shiftR c 1 `xor` if c .&. 1 /= 0 then 0xEDB88320 else 0 13 | -------------------------------------------------------------------------------- /examples/i2c/I2C/Types.hs: -------------------------------------------------------------------------------- 1 | module I2C.Types where 2 | 3 | import Clash.Prelude 4 | 5 | data I2CCommand = I2Cstart | I2Cstop | I2Cwrite | I2Cread | I2Cnop 6 | deriving (Eq, Ord, Generic, NFDataX) 7 | 8 | type BitCtrlSig = (I2CCommand,Bit) 9 | type BitRespSig = (Bool,Bool,Bit) 10 | 11 | type I2CIn = (Bit,Bit) 12 | type I2COut = (Bit,Bool,Bit,Bool) 13 | -------------------------------------------------------------------------------- /nix/devshell.nix: -------------------------------------------------------------------------------- 1 | { pkgs }: 2 | compilerVersion: 3 | let 4 | clashPkgs = pkgs."clashPackages-${compilerVersion}"; 5 | in 6 | pkgs.mkShell { 7 | inputsFrom = [ 8 | clashPkgs.clash-benchmark.env 9 | clashPkgs.clash-cosim.env 10 | clashPkgs.clash-ffi.env 11 | clashPkgs.clash-ghc.env 12 | clashPkgs.clash-lib.env 13 | clashPkgs.clash-lib-hedgehog.env 14 | clashPkgs.clash-prelude.env 15 | clashPkgs.clash-prelude-hedgehog.env 16 | clashPkgs.clash-profiling.env 17 | clashPkgs.clash-profiling-prepare.env 18 | clashPkgs.clash-term.env 19 | clashPkgs.clash-testsuite.env 20 | ]; 21 | 22 | buildInputs = [ 23 | clashPkgs.cabal-install 24 | clashPkgs.haskell-language-server 25 | 26 | pkgs.ghdl-llvm 27 | pkgs.nixpkgs-fmt 28 | pkgs.symbiyosys 29 | pkgs.verilator 30 | pkgs.verilog 31 | pkgs.yosys 32 | ]; 33 | } 34 | -------------------------------------------------------------------------------- /shell.nix: -------------------------------------------------------------------------------- 1 | (import 2 | ( 3 | let lock = builtins.fromJSON (builtins.readFile ./flake.lock); 4 | in 5 | fetchTarball { 6 | url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; 7 | sha256 = lock.nodes.flake-compat.locked.narHash; 8 | } 9 | ) 10 | { src = ./.; } 11 | ).shellNix 12 | -------------------------------------------------------------------------------- /stack.yaml: -------------------------------------------------------------------------------- 1 | resolver: lts-19.25 2 | 3 | ghc-options: 4 | "$locals": -Wall -Wcompat 5 | 6 | packages: 7 | - clash-prelude 8 | - clash-lib 9 | - clash-ghc 10 | - tests 11 | 12 | extra-deps: 13 | - ./clash-cosim 14 | - prettyprinter-interp-0.2.0.0@sha256:45299b61bd6c27d594c1a72b5a8dd5734e791a59828725e4f4e420f3cc37232b,2016 15 | - infinite-list-0.1@sha256:4de250517ce75e128c766fbc1f23b5a778ea964e695e47f8e83e0f3b293091bf,2383 16 | - tasty-1.5@sha256:c62c96da1e9d65bf61ce583e9f7085eed1daeb62a45f3106ca252bf9ef87025b,2763 17 | - attoparsec-aeson-2.1.0.0@sha256:fa83aba43bfa58490de8f274d19b9d58b6403a207b12cac5f93922102b084c52,1154 18 | - tasty-flaky-0.1.2.0@sha256:2f91ab9f55ae0c472474087f98bb54076aca18f8b058343479d24597a3aa181b,1858 19 | -------------------------------------------------------------------------------- /tests/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /tests/shouldfail/GADTs/T1311.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE GADTs #-} 2 | module T1311 where 3 | 4 | import Clash.Prelude 5 | 6 | data SomeSNat where 7 | SomeSNat :: forall m . SNat m -> SomeSNat 8 | 9 | topEntity :: SomeSNat -> Bool 10 | topEntity = const True 11 | -------------------------------------------------------------------------------- /tests/shouldfail/InvalidPrimitive/InvalidPrimitive.hs: -------------------------------------------------------------------------------- 1 | module InvalidPrimitive where 2 | import Clash.Prelude 3 | 4 | topEntity = True 5 | -------------------------------------------------------------------------------- /tests/shouldfail/InvalidPrimitive/InvalidPrimitive.primitives.yaml: -------------------------------------------------------------------------------- 1 | { "Not a valid": "primitive" } 2 | -------------------------------------------------------------------------------- /tests/shouldfail/LiftRecursiveGroup.hs: -------------------------------------------------------------------------------- 1 | module LiftRecursiveGroup where 2 | 3 | import Clash.Prelude 4 | 5 | topEntity x y z 6 | = let g p q k v = k (p + q) * v 7 | h = ((3 :: Integer) *) . (g x y f) 8 | f = ((4 :: Integer) *) . (g x y h) 9 | in f (h z) + h (f z) 10 | -------------------------------------------------------------------------------- /tests/shouldfail/Poly.hs: -------------------------------------------------------------------------------- 1 | module Poly where 2 | import Clash.Prelude 3 | 4 | topEntity x y = x && x 5 | -------------------------------------------------------------------------------- /tests/shouldfail/Poly2.hs: -------------------------------------------------------------------------------- 1 | module Poly2 where 2 | import Clash.Prelude 3 | 4 | topEntity :: (a ~ Bool) => a -> b -> a 5 | topEntity x y = x 6 | -------------------------------------------------------------------------------- /tests/shouldfail/PrimitiveGuards/DontTranslate.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | 3 | module DontTranslate where 4 | 5 | import Clash.Prelude 6 | import Clash.Annotations.Primitive (dontTranslate) 7 | 8 | primitive 9 | :: Signal System Int 10 | -> Signal System Int 11 | primitive i = 12 | (i+5) 13 | 14 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 15 | {-# CLASH_OPAQUE primitive #-} 16 | {-# ANN primitive dontTranslate #-} 17 | 18 | topEntity = primitive 19 | -------------------------------------------------------------------------------- /tests/shouldfail/PrimitiveGuards/HasBlackBox.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | 3 | module HasBlackBox where 4 | 5 | import Clash.Prelude 6 | import Clash.Annotations.Primitive (hasBlackBox) 7 | 8 | primitive 9 | :: Signal System Int 10 | -> Signal System Int 11 | primitive = 12 | (+5) 13 | 14 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 15 | {-# CLASH_OPAQUE primitive #-} 16 | {-# ANN primitive hasBlackBox #-} 17 | 18 | topEntity = primitive 19 | -------------------------------------------------------------------------------- /tests/shouldfail/RecursiveBoxed.hs: -------------------------------------------------------------------------------- 1 | {-# OPTIONS_GHC -fno-strictness #-} 2 | -- Disable the strictness analyzer 3 | -- Otherwise GHC will replace g with an EmptyCase, 4 | -- removing the recursion that we'd like to test for. 5 | 6 | module RecursiveBoxed where 7 | 8 | import Clash.Prelude 9 | 10 | data B a = B a 11 | 12 | g :: B (Int -> Int) 13 | g = case g of {B k -> B ((\x -> x) . k)} 14 | 15 | topEntity :: Int -> Int 16 | topEntity i = case g of {B f -> f i} 17 | -------------------------------------------------------------------------------- /tests/shouldfail/RecursiveDatatype.hs: -------------------------------------------------------------------------------- 1 | module RecursiveDatatype where 2 | 3 | import Clash.Prelude 4 | 5 | topEntity :: [Bool] 6 | topEntity = [True] 7 | -------------------------------------------------------------------------------- /tests/shouldfail/RecursivePoly.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE ScopedTypeVariables #-} 2 | module RecursivePoly where 3 | 4 | import Clash.Prelude 5 | 6 | topEntity :: Integer 7 | topEntity = f 0 8 | 9 | f :: (Integral b, Num b) => b -> b 10 | f x = let 11 | f1 :: Num a => a -> a 12 | f1 = \(y::a) -> (f1 y) + 1 + (fromInteger $ toInteger x) 13 | in 14 | f1 x 15 | -------------------------------------------------------------------------------- /tests/shouldfail/Signal/MAC.hs: -------------------------------------------------------------------------------- 1 | module MAC where 2 | 3 | import Clash.Prelude 4 | 5 | topEntity 6 | :: Integer 7 | -> Clock System 8 | -> Reset System 9 | -> Enable System 10 | -> (Signal System Integer, Signal System Integer) 11 | -> Signal System Integer 12 | topEntity i = exposeClockResetEnable (macT <^> i) 13 | 14 | macT s (x,y) = (s',o) 15 | where 16 | s' = s + (x * y) 17 | o = s 18 | -------------------------------------------------------------------------------- /tests/shouldfail/SynthesisAttributes/ProductInArgs.hs: -------------------------------------------------------------------------------- 1 | -- Test annotations on product types, but not their individual components. 2 | module ProductInArgs where 3 | 4 | import Clash.Prelude hiding (assert, (++)) 5 | import Clash.Annotations.SynthesisAttributes 6 | 7 | mac xy = mealy macT 0 xy 8 | where 9 | macT acc (x,y) = (acc',o) 10 | where 11 | acc' = acc + x * y 12 | o = acc 13 | 14 | topEntity 15 | :: SystemClockResetEnable 16 | => Signal System (Signed 9, Signed 9) `Annotate` 'StringAttr "args" "product" 17 | -> Signal System (Signed 9) 18 | topEntity xy = mac xy 19 | -------------------------------------------------------------------------------- /tests/shouldfail/SynthesisAttributes/ProductInResult.hs: -------------------------------------------------------------------------------- 1 | -- Test annotations on product types, but not their individual components. 2 | module ProductInResult where 3 | 4 | import Clash.Prelude hiding (assert, (++)) 5 | import Clash.Annotations.SynthesisAttributes 6 | 7 | mac xy = mealy macT 0 xy 8 | where 9 | macT acc (x,y) = (acc',o) 10 | where 11 | acc' = acc + x * y 12 | o = acc 13 | 14 | topEntity 15 | :: SystemClockResetEnable 16 | => Signal System (Signed 9, Signed 9) 17 | -> Signal System (Signed 9, Signed 9) `Annotate` 'StringAttr "result" "product" 18 | topEntity xy = bundle (s, s) 19 | where 20 | s = mac xy 21 | -------------------------------------------------------------------------------- /tests/shouldfail/Testbench/UnsafeOutputVerifier.hs: -------------------------------------------------------------------------------- 1 | module UnsafeOutputVerifier where 2 | 3 | import Clash.Prelude 4 | import Clash.Explicit.Testbench 5 | 6 | topEntity 7 | :: Clock XilinxSystem 8 | -> Clock IntelSystem 9 | -> Reset XilinxSystem 10 | -> Signal IntelSystem Int -- Note different domain 11 | -> Signal XilinxSystem Bool 12 | topEntity clkX clkI rst = outputVerifier clkX clkI rst (0 :> Nil) 13 | -------------------------------------------------------------------------------- /tests/shouldfail/TopEntity/T1033.hs: -------------------------------------------------------------------------------- 1 | module T1033 where 2 | 3 | import Clash.Explicit.Prelude 4 | import Clash.Prelude (HiddenClock, hasClock) 5 | import qualified Prelude as P 6 | 7 | {-# ANN topEntity 8 | (Synthesize 9 | { t_name = "top" 10 | , t_inputs = [ PortName "wrong"] 11 | , t_output = PortName "theOutput" 12 | } 13 | )#-} 14 | topEntity 15 | :: (Clock System, Reset System, Enable System) 16 | -> Signal System Int 17 | -> Signal System Int 18 | topEntity (clk, rst, en) i = 19 | register clk rst en 0 i 20 | 21 | -------------------------------------------------------------------------------- /tests/shouldfail/TopEntity/T1063.hs: -------------------------------------------------------------------------------- 1 | module T1063 where 2 | 3 | import Clash.Prelude 4 | 5 | {-# ANN topEntity (defSyn "top") 6 | {t_inputs = [PortProduct "wrong" [PortName "one", PortName "two"]]} 7 | #-} 8 | topEntity :: Int -> Int 9 | topEntity = id 10 | -------------------------------------------------------------------------------- /tests/shouldfail/ZeroWidth/FailGracefully1.hs: -------------------------------------------------------------------------------- 1 | -- See ZeroWidth.hs 2 | module FailGracefully1 where 3 | 4 | import Clash.Prelude.Testbench 5 | import Clash.Prelude 6 | import GHC.Generics 7 | import Clash.Annotations.BitRepresentation 8 | import Data.Maybe 9 | 10 | data SProduct 11 | = S Bool String 12 | | P Bool String Bool 13 | {-# ANN module ( DataReprAnn 14 | $(liftQ [t|SProduct|]) 15 | 3 16 | [ ConstrRepr 'S 0b100 0b100 [0b001, 0b000] 17 | , ConstrRepr 'P 0b100 0b000 [0b010, 0b000, 0b001] 18 | ] ) #-} 19 | 20 | topEntity :: SProduct -> SProduct 21 | topEntity (S b s) = S (not b) s 22 | topEntity (P b1 s b2) = P (not b1) s (not b2) 23 | -------------------------------------------------------------------------------- /tests/shouldfail/ZeroWidth/FailGracefully2.hs: -------------------------------------------------------------------------------- 1 | -- See ZeroWidth.hs 2 | module FailGracefully2 where 3 | 4 | import Clash.Prelude.Testbench 5 | import Clash.Prelude 6 | import GHC.Generics 7 | import Clash.Annotations.BitRepresentation 8 | import Data.Maybe 9 | 10 | data Product = Product Bool String 11 | {-# ANN module ( DataReprAnn 12 | $(liftQ [t|Product|]) 13 | 1 14 | [ ConstrRepr 'Product 0b0 0b0 [0b1, 0b0] ] ) #-} 15 | 16 | topEntity :: Product -> Product 17 | topEntity (Product b s) = Product (not b) s 18 | -------------------------------------------------------------------------------- /tests/shouldfail/ZeroWidth/FailGracefully3.hs: -------------------------------------------------------------------------------- 1 | -- See ZeroWidth.hs 2 | module FailGracefully3 where 3 | 4 | import Clash.Prelude.Testbench 5 | import Clash.Prelude 6 | import GHC.Generics 7 | import Clash.Annotations.BitRepresentation 8 | import Data.Maybe 9 | 10 | data Record = Record { myBool :: Bool, myString :: String } 11 | {-# ANN module ( DataReprAnn 12 | $(liftQ [t|Record|]) 13 | 1 14 | [ ConstrRepr 'Record 0b0 0b0 [0b1, 0b0] ] ) #-} 15 | 16 | topEntity :: Record -> Record 17 | topEntity (Record b s) = Record (not b) s 18 | -------------------------------------------------------------------------------- /tests/shouldwork/AutoReg/T1507.hs: -------------------------------------------------------------------------------- 1 | module T1507 where 2 | 3 | import Clash.Prelude 4 | 5 | topEntity :: 6 | SystemClockResetEnable => 7 | Signal System (Maybe Int) -> 8 | Signal System (Maybe Int) 9 | topEntity = autoReg (errorX "foo bar") 10 | -------------------------------------------------------------------------------- /tests/shouldwork/AutoReg/T1632.hs: -------------------------------------------------------------------------------- 1 | module T1632 where 2 | import Clash.Prelude 3 | 4 | data MCause 5 | = MCause (BitVector 4) 6 | deriving (Generic, NFDataX) 7 | deriveAutoReg ''MCause 8 | 9 | topEntity :: SystemClockResetEnable => Signal System MCause -> Signal System MCause 10 | topEntity = autoReg (MCause 0) 11 | -------------------------------------------------------------------------------- /tests/shouldwork/Basic/BangData.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE StrictData #-} 2 | module BangData where 3 | 4 | import Clash.Prelude 5 | 6 | data BangData 7 | = BangData 8 | { d1 :: !(Index 15) 9 | , d2 :: !(Unsigned 8) 10 | } 11 | 12 | topEntity (BangData x y) = BangData (x+1) (2*y) 13 | -------------------------------------------------------------------------------- /tests/shouldwork/Basic/CaseOfErr.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | 3 | {-# OPTIONS_GHC -fno-strictness #-} 4 | module CaseOfErr where 5 | 6 | import Clash.Prelude 7 | import qualified Prelude 8 | 9 | f :: Bool -> Int 10 | f x = if x then 1 else 0 11 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 12 | {-# CLASH_OPAQUE f #-} 13 | 14 | topEntity :: Int 15 | topEntity = f (Prelude.error "QQ") 16 | -------------------------------------------------------------------------------- /tests/shouldwork/Basic/CharTest.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | 3 | module CharTest where 4 | 5 | import Clash.Prelude 6 | import Clash.Explicit.Testbench 7 | import Data.Char 8 | 9 | topEntity :: (Int,Char) -> (Int,Char,Char) 10 | topEntity (i,c) = (ord c,chr i,'λ') 11 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 12 | {-# CLASH_OPAQUE topEntity #-} 13 | 14 | testBench :: Signal System Bool 15 | testBench = done 16 | where 17 | testInput = stimuliGenerator clk rst $(listToVecTH [(0::Int,'a'),(3,' '),(8,'\t'),(50,'8'),(600,'λ')]) 18 | expectedOutput = outputVerifier' clk rst $(listToVecTH ([(97,'\NUL','\955'),(32,'\ETX','\955'),(9,'\b','\955'),(56,'2','\955'),(955,'\600','\955')]::[(Int,Char,Char)])) 19 | done = expectedOutput (topEntity <$> testInput) 20 | clk = tbSystemClockGen (not <$> done) 21 | rst = systemResetGen 22 | -------------------------------------------------------------------------------- /tests/shouldwork/Basic/ClassOps.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | 3 | module ClassOps where 4 | 5 | import Clash.Prelude 6 | import Clash.Explicit.Testbench 7 | 8 | topEntity :: (Integer,Integer) -> Integer 9 | topEntity = uncurry mod 10 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 11 | {-# CLASH_OPAQUE topEntity #-} 12 | 13 | testBench :: Signal System Bool 14 | testBench = done 15 | where 16 | testInput = stimuliGenerator clk rst $(listToVecTH [(19,4)::(Integer,Integer),(7,3),(55,-10),(9,-2),(0,-10),(11,10)]) 17 | expectedOutput = outputVerifier' clk rst $(listToVecTH ([3::Integer,1,-5,-1,0,1])) 18 | done = expectedOutput (topEntity <$> testInput) 19 | clk = tbSystemClockGen (not <$> done) 20 | rst = systemResetGen 21 | -------------------------------------------------------------------------------- /tests/shouldwork/Basic/DeepseqX.hs: -------------------------------------------------------------------------------- 1 | module DeepseqX where 2 | 3 | import Clash.Prelude 4 | import Clash.Explicit.Testbench 5 | 6 | topEntity :: (Vec 2 Int, Vec 3 Int) -> Vec 3 Int 7 | topEntity (a, b) = deepseqX a (map (+1) b) 8 | 9 | 10 | testBench :: Signal System Bool 11 | testBench = done 12 | where 13 | testInput = stimuliGenerator clk rst ((10 :> 11 :> Nil, 5 :> 6 :> 7 :> Nil) :> Nil) 14 | expectedOutput = outputVerifier' clk rst ((6 :> 7 :> 8 :> Nil) :> Nil) 15 | done = expectedOutput (topEntity <$> testInput) 16 | clk = tbSystemClockGen (not <$> done) 17 | rst = systemResetGen 18 | -------------------------------------------------------------------------------- /tests/shouldwork/Basic/DivMod.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | 3 | module DivMod where 4 | 5 | import Clash.Prelude 6 | 7 | topEntity :: (Integer,Integer) 8 | topEntity = topEntity1 height depthInput filterHeight stride cycles 9 | where 10 | height = SNat @5 11 | filterHeight = SNat @3 12 | stride = SNat @2 13 | depthInput = SNat @2 14 | cycles = SNat @800 15 | 16 | topEntity1 height depthInput filterHeight stride cycles = snatToNum cycles `divMod` pools 17 | where 18 | pools :: Integer 19 | pools = 20 | rows * 21 | (((snatToNum height - snatToNum filterHeight) `div` snatToNum stride) + 1) * 22 | snatToNum depthInput 23 | 24 | rows :: Integer 25 | rows = ((snatToNum height - snatToNum filterHeight) `div` snatToNum stride) + 1 26 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 27 | {-# CLASH_OPAQUE topEntity1 #-} 28 | -------------------------------------------------------------------------------- /tests/shouldwork/Basic/IrrefError.hs: -------------------------------------------------------------------------------- 1 | module IrrefError where 2 | 3 | import Prelude 4 | 5 | topEntity :: Maybe Int -> Int 6 | topEntity ~(Just x) = x 7 | -------------------------------------------------------------------------------- /tests/shouldwork/Basic/NameOverlap.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | 3 | module NameOverlap where 4 | 5 | import Clash.Prelude 6 | 7 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 8 | {-# CLASH_OPAQUE topEntity #-} 9 | {-# ANN topEntity 10 | (Synthesize 11 | { t_name = "nameoverlap" 12 | , t_inputs = 13 | [ PortName "CLK_50MHZ" 14 | , PortName "RESET" 15 | , PortName "ENABLE" 16 | ] 17 | , t_output = PortName "LED" 18 | }) #-} 19 | topEntity 20 | :: Clock System 21 | -> Reset System 22 | -> Enable System 23 | -> Signal System Bit 24 | topEntity = exposeClockResetEnable $ let 25 | board = boolToBit <$> led 26 | led :: Signal System Bool 27 | led = register True $ complement <$> led 28 | in board 29 | -------------------------------------------------------------------------------- /tests/shouldwork/Basic/NestedPrimitives.hs: -------------------------------------------------------------------------------- 1 | module NestedPrimitives where 2 | 3 | import Clash.Prelude 4 | 5 | topEntity :: Vec 3 (Signed 16) 6 | topEntity = map resize o 7 | where 8 | o :: Vec 3 (Signed 32) 9 | o = replicate d3 (bit 31) 10 | -------------------------------------------------------------------------------- /tests/shouldwork/Basic/NestedPrimitives2.hs: -------------------------------------------------------------------------------- 1 | module NestedPrimitives2 where 2 | 3 | import Clash.Prelude 4 | 5 | topEntity :: Vec 5 (Vec 3 (Signed 32)) 6 | topEntity = map (take d3) o 7 | where 8 | o :: Vec 5 (Vec 5 (Signed 32)) 9 | o = replicate d5 (replicate d5 (bit 31)) 10 | -------------------------------------------------------------------------------- /tests/shouldwork/Basic/PatError.hs: -------------------------------------------------------------------------------- 1 | module PatError where 2 | 3 | import Prelude 4 | 5 | topEntity :: Maybe Int -> Int 6 | topEntity (Just x) = x 7 | -------------------------------------------------------------------------------- /tests/shouldwork/Basic/RecordSumOfProducts.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE DataKinds #-} 2 | {-# LANGUAGE TemplateHaskell #-} 3 | 4 | module RecordSumOfProducts where 5 | 6 | import Clash.Prelude 7 | import Control.Applicative 8 | 9 | data DbState = DbInitDisp (Unsigned 4) | DbWriteRam (Signed 14) (Signed 14) 10 | | DbDone 11 | deriving (Show, Eq, Generic, NFDataX) 12 | 13 | data DbS = DbS { dbS :: DbState } 14 | deriving (Generic, NFDataX) 15 | 16 | 17 | topEntity 18 | :: Clock System 19 | -> Reset System 20 | -> Enable System 21 | -> Signal System Bit 22 | -> Signal System Bit 23 | topEntity = exposeClockResetEnable (walkState <^> DbS (DbInitDisp 0)) 24 | 25 | walkState :: DbS 26 | -> Bit 27 | -> (DbS, Bit) 28 | 29 | walkState (DbS (DbInitDisp n )) i = (DbS (DbInitDisp (n+1) ), 0) 30 | walkState s i = (s , i) 31 | -------------------------------------------------------------------------------- /tests/shouldwork/Basic/Shift.hs: -------------------------------------------------------------------------------- 1 | module Shift where 2 | 3 | import Clash.Prelude 4 | 5 | topEntity :: Unsigned 32 -> Unsigned 32 6 | topEntity y = shift y (-1) 7 | -------------------------------------------------------------------------------- /tests/shouldwork/Basic/SimOnly.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | 3 | module SimOnly where 4 | 5 | import Clash.Explicit.Prelude 6 | import qualified Data.Map as Map 7 | 8 | type Ignore = SimOnly (Map.Map String [Int]) 9 | 10 | unionIgnore :: Ignore -> Ignore -> Ignore 11 | unionIgnore (SimOnly m1) (SimOnly m2) = SimOnly (Map.unionWith (<>) m1 m2) 12 | 13 | foo :: Int -> Int -> (Int, Ignore) 14 | foo a b = (a+b,SimOnly (Map.fromList [("foo",[a + b])])) 15 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 16 | {-# CLASH_OPAQUE foo #-} 17 | 18 | bar :: Int -> Int -> (Int, Ignore) 19 | bar a b = (a*b,SimOnly (Map.fromList [("bar",[a * b])])) 20 | 21 | topEntity :: Int -> Int -> (Int, Ignore) 22 | topEntity a b = 23 | let (z,np1) = foo a b 24 | (y,np2) = bar a b 25 | in (y - z, unionIgnore np1 np2) 26 | -------------------------------------------------------------------------------- /tests/shouldwork/Basic/SimpleConstructor.hs: -------------------------------------------------------------------------------- 1 | module SimpleConstructor where 2 | 3 | import Prelude 4 | 5 | data Option = Empty | Value Integer 6 | 7 | topEntity = Value 8 | -------------------------------------------------------------------------------- /tests/shouldwork/Basic/SomeNatVal.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE ScopedTypeVariables #-} 2 | module SomeNatVal where 3 | 4 | import Clash.Prelude hiding (someNatVal) 5 | import GHC.TypeNats (someNatVal) 6 | import GHC.Natural 7 | 8 | topEntity :: Bool 9 | topEntity = case (someNatVal 1, someNatVal 2) of 10 | (SomeNat y, SomeNat z) -> case sameNat y z of 11 | Just _ -> True 12 | _ -> False 13 | -------------------------------------------------------------------------------- /tests/shouldwork/Basic/T1012.hs: -------------------------------------------------------------------------------- 1 | module T1012 where 2 | 3 | import Clash.Prelude 4 | 5 | f :: BitVector 5 -> Maybe (Bit -> Bit -> Bit) 6 | f i = case slice d1 d0 i of 7 | 2 -> op 8 | 3 -> op 9 | _ -> Nothing 10 | where op :: Maybe (Bit -> Bit -> Bit) 11 | op = case (slice d4 d2 i, b) of 12 | (0, 0) -> Just (+) 13 | _ -> Nothing 14 | where b :: Bit 15 | b = case i ! 0 of 16 | 0 -> 0 17 | 1 -> 0 18 | 19 | topEntity :: BitVector 5 -> Bit -> Bit -> Maybe Bit 20 | topEntity = (sequenceA .) . sequenceA . f 21 | -------------------------------------------------------------------------------- /tests/shouldwork/Basic/T1240.hs: -------------------------------------------------------------------------------- 1 | module T1240 where 2 | 3 | import Clash.Prelude 4 | 5 | topEntity 6 | :: SystemClockResetEnable 7 | => Signal System (Vec 1 Bool) 8 | -> Signal System (Vec 1 Bool) 9 | topEntity = register @System $(lift (iterate d1 not True)) 10 | -------------------------------------------------------------------------------- /tests/shouldwork/Basic/T1292.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | 3 | module T1292 where 4 | 5 | import Clash.Prelude 6 | import Clash.Explicit.Testbench 7 | 8 | topEntity :: Maybe (Index 16, Unsigned 4) -> Index 16 9 | topEntity (Just (a,_)) = a 10 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 11 | {-# CLASH_OPAQUE topEntity #-} 12 | 13 | testBench :: Signal System Bool 14 | testBench = done 15 | where 16 | testInput = stimuliGenerator clk rst (Just (2,0):>Nil) 17 | expectedOutput = outputVerifier' clk rst (2:>Nil) 18 | done = expectedOutput (fmap topEntity testInput) 19 | clk = tbSystemClockGen (not <$> done) 20 | rst = systemResetGen 21 | -------------------------------------------------------------------------------- /tests/shouldwork/Basic/T1297.hs: -------------------------------------------------------------------------------- 1 | module T1297 where 2 | 3 | import Clash.Prelude 4 | import Numeric.Natural (Natural) 5 | 6 | topEntity :: Int 7 | topEntity = 8 | case compare (toInteger @Natural (0 - 1)) 0 of 9 | LT -> 2 10 | _ -> 3 11 | -------------------------------------------------------------------------------- /tests/shouldwork/Basic/T1304.hs: -------------------------------------------------------------------------------- 1 | module T1304 where 2 | 3 | topEntity = 'a' 4 | -------------------------------------------------------------------------------- /tests/shouldwork/Basic/T1305.hs: -------------------------------------------------------------------------------- 1 | module T1305 where 2 | 3 | import Clash.Prelude 4 | 5 | plus :: Signed 8 -> Signed 8 -> Signed 8 6 | plus a b = a + b 7 | 8 | topEntity :: Signed 8 -> Signed 8 -> Signed 8 9 | topEntity = plus 10 | -------------------------------------------------------------------------------- /tests/shouldwork/Basic/T1316.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | 3 | module T1316 where 4 | 5 | import Clash.Prelude 6 | 7 | incr :: Index 2 -> Index 2 8 | incr i = if i == maxBound then 0 else i + 1 9 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 10 | {-# CLASH_OPAQUE incr #-} 11 | 12 | topEntity :: Index 10 -> Index 2 13 | topEntity j = case j < 1 of 14 | False -> 15 | let xs = init (Cons 1 (Cons (incr (head xs)) Nil)) in last xs 16 | True -> 17 | let ys = init (Cons 2 (Cons (incr (last ys)) Nil)) in head ys 18 | -------------------------------------------------------------------------------- /tests/shouldwork/Basic/T1354A.hs: -------------------------------------------------------------------------------- 1 | module T1354A where 2 | 3 | import Clash.Prelude 4 | 5 | -- Clash should be able to compile this without getting stuck in an infinite 6 | -- loop. See https://github.com/clash-lang/clash-compiler/pull/1354#issuecomment-635430374 7 | 8 | f :: forall n. KnownNat n => Index (n + 1) -> Int -> Int 9 | f n = foldl (.) id lanes 10 | where 11 | lanes :: Vec (n + 1) (Int -> Int) 12 | lanes = map (\i -> if i < n then id else id) (iterateI succ 0) 13 | 14 | topEntity :: Int -> Int 15 | topEntity = f (1 :: Index 3) 16 | -------------------------------------------------------------------------------- /tests/shouldwork/Basic/T1402b.hs: -------------------------------------------------------------------------------- 1 | module T1402b where 2 | 3 | import Clash.Prelude 4 | import Clash.Sized.Internal.BitVector 5 | import GHC.Natural 6 | 7 | topEntity :: BitVector 128 -> Natural 8 | topEntity = unsafeMask 9 | -------------------------------------------------------------------------------- /tests/shouldwork/Basic/TagToEnum.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE MagicHash #-} 2 | module TagToEnum where 3 | 4 | import GHC.Exts 5 | import Prelude 6 | 7 | topEntity :: Bool -> (Int,Bool,Int,Bool) 8 | topEntity b = (I# (dataToTag# b),tagToEnum# (dataToTag# b),I# (dataToTag# True), tagToEnum# 1#) 9 | -------------------------------------------------------------------------------- /tests/shouldwork/Basic/TestIndex.hs: -------------------------------------------------------------------------------- 1 | module TestIndex where 2 | import Clash.Prelude 3 | 4 | type NrI = Index 8 5 | 6 | topEntity = c1 7 | 8 | c1 :: Signal System (Maybe NrI) -> Signal System (Maybe NrI) 9 | c1 = fmap (fmap (+1)) 10 | -------------------------------------------------------------------------------- /tests/shouldwork/Basic/Time.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | 3 | module Time where 4 | 5 | import Clash.Explicit.Prelude 6 | import Clash.Explicit.Testbench 7 | 8 | topEntity 9 | :: Clock System 10 | -> Reset System 11 | -> Enable System 12 | -> Signal System Int 13 | -> Signal System Int 14 | topEntity clk rst en ps = register clk rst en 0 (ps + 1) 15 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 16 | {-# CLASH_OPAQUE topEntity #-} 17 | 18 | testBench :: Signal System Bool 19 | testBench = done 20 | where 21 | testInput = stimuliGenerator clk rst (1 :> 2 :> 3 :> Nil) 22 | expectedOutput = outputVerifier' clk rst (0 :> 2 :> 3 :> Nil) 23 | done = expectedOutput (topEntity clk rst enableGen testInput) 24 | clk = tbSystemClockGen (not <$> done) 25 | rst = systemResetGen 26 | -------------------------------------------------------------------------------- /tests/shouldwork/Basic/Trace.hs: -------------------------------------------------------------------------------- 1 | module Trace where 2 | 3 | import Clash.Prelude 4 | import Debug.Trace 5 | 6 | topEntity :: Unsigned 32 -> Unsigned 32 7 | topEntity y = trace "some trace" y + traceShowId y 8 | -------------------------------------------------------------------------------- /tests/shouldwork/Basic/TwoFunctions.hs: -------------------------------------------------------------------------------- 1 | module TwoFunctions where 2 | 3 | import Clash.Prelude 4 | 5 | f :: Bool -> a -> a -> a 6 | f True x y = x 7 | f False x y = y 8 | 9 | g :: Bool -> b -> b -> b 10 | g True c d = d 11 | g False c d = c 12 | 13 | topEntity :: Bool -> Int -> Int -> (Int,Int) 14 | topEntity t a b = (f t a b, g t a b) 15 | -------------------------------------------------------------------------------- /tests/shouldwork/Basic/XToError.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE ViewPatterns #-} 2 | module XToError where 3 | 4 | import Clash.Prelude 5 | 6 | topEntity :: Bit -> BitVector 8 -> BitVector 8 7 | topEntity (xToError -> a) (xToError -> b) = slice d7 d0 (pack a ++# b) 8 | -------------------------------------------------------------------------------- /tests/shouldwork/Basic/precompiled/SimulationMagic2736a.hs: -------------------------------------------------------------------------------- 1 | {-# OPTIONS_GHC -O2 -fspec-constr #-} 2 | module SimulationMagic2736a where 3 | 4 | import Clash.Prelude 5 | 6 | f0 :: Int 7 | f0 | clashSimulation = 123 8 | | otherwise = 456 9 | -------------------------------------------------------------------------------- /tests/shouldwork/BitVector/CLZ.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | {-# LANGUAGE MagicHash #-} 3 | 4 | module CLZ where 5 | 6 | import GHC.Prim 7 | import GHC.Types 8 | import Clash.Prelude 9 | import Clash.Explicit.Testbench 10 | 11 | topEntity :: Word -> Word -> Word 12 | topEntity (W# w1) (W# w2) = W# (clz# (or# w1 w2)) 13 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 14 | {-# CLASH_OPAQUE topEntity #-} 15 | 16 | testBench :: Signal System Bool 17 | testBench = done 18 | where 19 | expectedOutput = outputVerifier' clk rst (61 :> Nil) 20 | done = expectedOutput (topEntity <$> pure 3 <*> pure 5) 21 | clk = tbSystemClockGen (not <$> done) 22 | rst = systemResetGen 23 | -------------------------------------------------------------------------------- /tests/shouldwork/BitVector/RePack.hs: -------------------------------------------------------------------------------- 1 | module RePack where 2 | 3 | import Clash.Prelude 4 | 5 | topEntity :: (Unsigned 1,Unsigned 1) 6 | topEntity = (unpack (pack True), unpack (pack False)) 7 | -------------------------------------------------------------------------------- /tests/shouldwork/BitVector/UnpackUndefined.hs: -------------------------------------------------------------------------------- 1 | module UnpackUndefined where 2 | import Clash.Prelude 3 | import Clash.Sized.Internal.BitVector 4 | 5 | -- https://github.com/clash-lang/clash-compiler/issues/804 6 | state = unpack undefined# :: Vec 3 Bit 7 | topEntity a = register @System state a 8 | -------------------------------------------------------------------------------- /tests/shouldwork/BlackBox/ExternalPrimitive.primitives: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "BlackBox": { 4 | "name": "ExternalPrimitive.jsonPrim", 5 | "kind": "Expression", 6 | "template": "fekkjruzth-json" 7 | } 8 | } 9 | ] 10 | -------------------------------------------------------------------------------- /tests/shouldwork/BlackBox/ExternalPrimitive.primitives.yaml: -------------------------------------------------------------------------------- 1 | - BlackBox: 2 | name: ExternalPrimitive.yamlPrim 3 | kind: Expression 4 | template: kod0x1ta1k-yaml 5 | -------------------------------------------------------------------------------- /tests/shouldwork/BoxedFunctions/DeadRecursiveBoxed.hs: -------------------------------------------------------------------------------- 1 | module DeadRecursiveBoxed where 2 | 3 | import Prelude 4 | 5 | topEntity :: Bool -> Bool 6 | topEntity y = f ((\x -> x) . (\y -> y)) y 7 | 8 | f x y = fst (x, f x y) y 9 | -------------------------------------------------------------------------------- /tests/shouldwork/CSignal/CBlockRamTest.hs: -------------------------------------------------------------------------------- 1 | module CBlockRamTest where 2 | 3 | import Clash.Explicit.Prelude 4 | 5 | createDomain vSystem{vName="DomA10", vPeriod=10} 6 | 7 | topEntity 8 | :: Clock DomA10 9 | -> Enable DomA10 10 | -> Signal DomA10 (Unsigned 7) 11 | -> Signal DomA10 (Maybe (Unsigned 7,Vec 4 Bit)) 12 | -> Signal DomA10 (Vec 4 Bit) 13 | topEntity clk en = 14 | blockRam clk en (replicate d128 (repeat high)) 15 | -------------------------------------------------------------------------------- /tests/shouldwork/CSignal/MAC.hs: -------------------------------------------------------------------------------- 1 | module MAC where 2 | 3 | import Clash.Explicit.Prelude 4 | 5 | createDomain vSystem{vName="DomA101", vPeriod=101} 6 | 7 | topEntity 8 | :: Clock DomA101 9 | -> Reset DomA101 10 | -> Enable DomA101 11 | -> (Signal DomA101 Integer, Signal DomA101 Integer) 12 | -> Signal DomA101 Integer 13 | topEntity clk rst en = mealyB clk rst en macT 0 14 | 15 | macT s (x,y) = (s', o) 16 | where 17 | s' = s + (x * y) 18 | o = s 19 | -------------------------------------------------------------------------------- /tests/shouldwork/CustomReprs/Indexed/Type.hs: -------------------------------------------------------------------------------- 1 | module Type where 2 | 3 | import Clash.Prelude 4 | 5 | data WithVector 6 | = MkTA (Vec 2 Bool) (Signed 2) 7 | | MkTB Bool 8 | -------------------------------------------------------------------------------- /tests/shouldwork/CustomReprs/T694.hs: -------------------------------------------------------------------------------- 1 | module T694 where 2 | 3 | import Clash.Prelude 4 | import Clash.Annotations.BitRepresentation 5 | 6 | data Color = R | G | B 7 | {-# ANN module (DataReprAnn 8 | $(liftQ [t|Color|]) 9 | 2 10 | [ ConstrRepr 'R 0b11 0b00 [] 11 | , ConstrRepr 'G 0b11 0b01 [] 12 | , ConstrRepr 'B 0b11 0b10 [] 13 | ]) #-} 14 | 15 | topEntity = map Just (R :> G :> B :> Nil) 16 | -------------------------------------------------------------------------------- /tests/shouldwork/Feedback/Fib.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | 3 | module Fib where 4 | 5 | import Clash.Prelude 6 | import Clash.Explicit.Testbench 7 | 8 | fib :: HiddenClockResetEnable dom => Signal dom (Unsigned 64) 9 | fib = register 1 fib + register 0 (register 0 fib) 10 | 11 | topEntity 12 | :: Clock System 13 | -> Reset System 14 | -> Enable System 15 | -> Signal System (Unsigned 64) 16 | topEntity = exposeClockResetEnable fib 17 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 18 | {-# CLASH_OPAQUE topEntity #-} 19 | 20 | testBench :: Signal System Bool 21 | testBench = done 22 | where 23 | expectedOutput = outputVerifier' clk rst $(listToVecTH [1 :: Unsigned 64,1,2,3,5]) 24 | done = expectedOutput (topEntity clk rst enableGen) 25 | clk = tbSystemClockGen (not <$> done) 26 | rst = systemResetGen 27 | -------------------------------------------------------------------------------- /tests/shouldwork/Fixed/SFixedTest.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | 3 | module SFixedTest where 4 | 5 | import Clash.Prelude 6 | import Clash.Explicit.Testbench 7 | 8 | type SF = SFixed 4 18 9 | 10 | topEntity :: SF -> SF 11 | topEntity x = x * 2.56 12 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 13 | {-# CLASH_OPAQUE topEntity #-} 14 | 15 | testBench :: Signal System Bool 16 | testBench = done 17 | where 18 | testInput = stimuliGenerator clk rst $(listToVecTH ([1.2, 1.8, 3.5] :: [SFixed 4 18] )) 19 | expectedOutput = outputVerifier' clk rst $(listToVecTH ([3.07199, 4.607991, 8.96] :: [SFixed 4 18])) 20 | done = expectedOutput (topEntity <$> testInput) 21 | clk = tbSystemClockGen (not <$> done) 22 | rst = systemResetGen 23 | -------------------------------------------------------------------------------- /tests/shouldwork/Fixed/SatWrap.hs: -------------------------------------------------------------------------------- 1 | module SatWrap where 2 | 3 | import Clash.Prelude 4 | 5 | topEntity:: (SFixed 2 6) -> (SFixed 2 6) -> (SFixed 2 6) 6 | topEntity = satAdd SatWrap 7 | -------------------------------------------------------------------------------- /tests/shouldwork/Fixed/ZeroInt.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | 3 | module ZeroInt where 4 | 5 | import Clash.Prelude 6 | import Clash.Explicit.Testbench 7 | 8 | topEntity :: (UFixed 0 8,UFixed 0 8) -> UFixed 0 8 9 | topEntity = uncurry (*) 10 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 11 | {-# CLASH_OPAQUE topEntity #-} 12 | 13 | testBench :: Signal System Bool 14 | testBench = done 15 | where 16 | testInput = pure (0.2,0.35) 17 | expectedOutput = outputVerifier' clk rst $(listToVecTH [0.06640625 :: UFixed 0 8]) 18 | done = expectedOutput (topEntity <$> testInput) 19 | clk = tbSystemClockGen (not <$> done) 20 | rst = systemResetGen 21 | -------------------------------------------------------------------------------- /tests/shouldwork/FixedNumber/FixedS.hs: -------------------------------------------------------------------------------- 1 | module FixedS where 2 | 3 | import Clash.Prelude 4 | 5 | type SF = SFixed 4 20 6 | 7 | topEntity :: SF -> SF 8 | topEntity x = x + 4.578 9 | 10 | testInput :: Signal SF 11 | testInput = stimuliGenerator $ $(v ([1.0, 2.0, 4.0, signum (-42.2), signum 0, signum 42.2] :: [SFixed 4 20] )) 12 | 13 | expectedOutput :: Signal SF -> Signal Bool 14 | expectedOutput = outputVerifier' $ $(v ([5.578, 6.578, 8.578, -1, 0, 1] :: [SFixed 4 20])) 15 | -------------------------------------------------------------------------------- /tests/shouldwork/Floating/FloatPack.hs: -------------------------------------------------------------------------------- 1 | module FloatPack where 2 | 3 | import Clash.Prelude 4 | 5 | topEntity :: (Float,Double,BitVector 32,BitVector 64) 6 | -> (BitVector 32, BitVector 64, Float, Double) 7 | topEntity (f,d,bv32,bv64) = (pack f, pack d, unpack bv32, unpack bv64) 8 | -------------------------------------------------------------------------------- /tests/shouldwork/GADTs/Head.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | 3 | module Head where 4 | 5 | import Clash.Prelude 6 | import Clash.Explicit.Testbench 7 | 8 | head' :: Vec (n+1) (Signed 16) -> Signed 16 9 | head' (Cons x xs) = x 10 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 11 | {-# CLASH_OPAQUE head' #-} 12 | 13 | topEntity :: Vec 3 (Signed 16) -> Signed 16 14 | topEntity = head' 15 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 16 | {-# CLASH_OPAQUE topEntity #-} 17 | 18 | testBench :: Signal System Bool 19 | testBench = done 20 | where 21 | testInput = stimuliGenerator clk rst ((1 :> 2 :> 3 :> Nil) :> Nil) 22 | expectedOutput = outputVerifier' clk rst (1 :> Nil) 23 | 24 | done = expectedOutput (topEntity <$> testInput) 25 | clk = tbSystemClockGen (not <$> done) 26 | rst = systemResetGen 27 | -------------------------------------------------------------------------------- /tests/shouldwork/GADTs/HeadM.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | 3 | module HeadM where 4 | 5 | import Clash.Prelude 6 | import Clash.Explicit.Testbench 7 | 8 | head' :: Vec 3 (Signed 16) -> Signed 16 9 | head' (Cons x xs) = x 10 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 11 | {-# CLASH_OPAQUE head' #-} 12 | 13 | topEntity :: Vec 3 (Signed 16) -> Signed 16 14 | topEntity = head' 15 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 16 | {-# CLASH_OPAQUE topEntity #-} 17 | 18 | testBench :: Signal System Bool 19 | testBench = done 20 | where 21 | testInput = stimuliGenerator clk rst ((1 :> 2 :> 3 :> Nil) :> Nil) 22 | expectedOutput = outputVerifier' clk rst (1 :> Nil) 23 | 24 | done = expectedOutput (topEntity <$> testInput) 25 | clk = tbSystemClockGen (not <$> done) 26 | rst = systemResetGen 27 | -------------------------------------------------------------------------------- /tests/shouldwork/GADTs/T1310.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | {-# LANGUAGE GADTs #-} 3 | module T1310 where 4 | 5 | import Clash.Prelude 6 | 7 | data Ex where 8 | Ex :: forall n . SNat n -> Bool -> Ex 9 | 10 | f :: Ex -> Bool 11 | f (Ex n y) = h (replicate n y) 12 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 13 | {-# CLASH_OPAQUE f #-} 14 | 15 | h :: Vec n Bool -> Bool 16 | h xs = foldr (||) True xs 17 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 18 | {-# CLASH_OPAQUE h #-} 19 | 20 | g :: Int -> Bool -> Ex 21 | g 0 b = Ex (SNat @3) b 22 | g n b = g (n-1) b 23 | 24 | topEntity :: Bool -> Bool 25 | topEntity b = f (g 1 b) 26 | -------------------------------------------------------------------------------- /tests/shouldwork/HOPrim/HOIdx.hs: -------------------------------------------------------------------------------- 1 | module HOIdx where 2 | 3 | import Clash.Prelude 4 | import Clash.Explicit.Testbench 5 | 6 | hoIdx ks i a = (ks !! i) a 7 | 8 | f g h = hoIdx (g :> h :> Nil) 9 | 10 | work :: Int -> Int -> Int -> Int -> Int 11 | work a b = f (+a) (*b) 12 | 13 | topEntity :: (Int,Int,Int,Int) -> Int 14 | topEntity (a,b,idx,x) = work a b idx x 15 | 16 | testBench :: Signal System Bool 17 | testBench = done 18 | where 19 | testInput = stimuliGenerator clk rst ((1,2,0,3):>(1,2,1,3):>Nil) 20 | expectedOutput = outputVerifier' clk rst (4:>6:>Nil) 21 | done = expectedOutput (topEntity <$> testInput) 22 | clk = tbSystemClockGen (not <$> done) 23 | rst = systemResetGen 24 | -------------------------------------------------------------------------------- /tests/shouldwork/HOPrim/Map2.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | 3 | module Map2 where 4 | 5 | import Clash.Prelude 6 | import Clash.Explicit.Testbench 7 | 8 | go 9 | :: Signal System () 10 | -> Signal System Bool 11 | go _ = pure True 12 | 13 | topEntity 14 | :: Signal System (Vec 4 ()) 15 | -> Signal System (Vec 4 Bool) 16 | topEntity = 17 | bundle . fmap go . unbundle 18 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 19 | {-# CLASH_OPAQUE topEntity #-} 20 | 21 | 22 | testBench :: SystemClockResetEnable => Signal System Bool 23 | testBench = done 24 | where 25 | testInput = stimuliGenerator clk rst ((repeat ()) :> Nil) 26 | expectedOutput = outputVerifier' clk rst ((repeat True):>Nil) 27 | done = expectedOutput (topEntity testInput) 28 | clk = tbSystemClockGen (not <$> done) 29 | rst = systemResetGen 30 | -------------------------------------------------------------------------------- /tests/shouldwork/HOPrim/Transpose.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | 3 | module Transpose where 4 | 5 | import Clash.Prelude 6 | import Clash.Explicit.Testbench 7 | 8 | topEntity = transposeV 9 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 10 | {-# CLASH_OPAQUE topEntity #-} 11 | 12 | transposeV :: Vec 3 (Vec 4 Int) -> Vec 4 (Vec 3 Int) 13 | transposeV = sequenceA 14 | 15 | testBench :: Signal System Bool 16 | testBench = done 17 | where 18 | testInput = pure ((1:>2:>3:>4:>Nil):>(5:>6:>7:>8:>Nil):>(9:>10:>11:>12:>Nil):>Nil) 19 | expectedOutput = outputVerifier' clk rst ((transpose ((1:>2:>3:>4:>Nil):>(5:>6:>7:>8:>Nil):>(9:>10:>11:>12:>Nil):>Nil)):>Nil) 20 | done = expectedOutput (topEntity <$> testInput) 21 | clk = tbSystemClockGen (not <$> done) 22 | rst = systemResetGen 23 | -------------------------------------------------------------------------------- /tests/shouldwork/HOPrim/VecFun.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | 3 | module VecFun where 4 | 5 | import Clash.Prelude 6 | import Clash.Explicit.Testbench 7 | 8 | topEntity = work 9 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 10 | {-# CLASH_OPAQUE topEntity #-} 11 | 12 | work :: Vec 3 Int -> Vec 3 Int 13 | work xs = zipWith sel xs funs where 14 | funs = fun:>fun:>fun:>Nil 15 | fun x = x + 1 16 | sel x f = f x 17 | 18 | testBench :: Signal System Bool 19 | testBench = done 20 | where 21 | testInput = pure (1:>2:>3:>Nil) 22 | expectedOutput = outputVerifier' clk rst ((2:>3:>4:>Nil):>Nil) 23 | done = expectedOutput (topEntity <$> testInput) 24 | clk = tbSystemClockGen (not <$> done) 25 | rst = systemResetGen 26 | -------------------------------------------------------------------------------- /tests/shouldwork/Issues/T1477.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | 3 | module T1477 where 4 | 5 | import Clash.Prelude 6 | import Data.Proxy 7 | 8 | type family QQ a 9 | type instance QQ (Signal dom a) = a 10 | 11 | f :: forall a . Proxy a -> QQ a -> QQ a 12 | f Proxy = id 13 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 14 | {-# CLASH_OPAQUE f #-} 15 | 16 | topEntity = f @(Signal System Bool) 17 | -------------------------------------------------------------------------------- /tests/shouldwork/Issues/T1606A.hs: -------------------------------------------------------------------------------- 1 | module T1606A where 2 | 3 | import Clash.Prelude 4 | 5 | data CRE = CRE (Clock System) (Reset System) (Enable System) 6 | 7 | topEntity 8 | :: Clock System 9 | -> Reset System 10 | -> Enable System 11 | -> Vec 2 (Signal System Bool, CRE) 12 | topEntity = \ c r e -> 13 | let 14 | term = CRE c r e 15 | vec = term :> term :> Nil 16 | result = fmap (\a -> (pure True, a)) vec 17 | in 18 | result 19 | -------------------------------------------------------------------------------- /tests/shouldwork/Issues/T1606B.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | 3 | {-# OPTIONS_GHC -O0 #-} 4 | module T1606B where 5 | 6 | import Clash.Prelude 7 | 8 | f :: Vec 8 (Clock System) 9 | -> Vec 8 (Clock System) 10 | f = id 11 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 12 | {-# CLASH_OPAQUE f #-} 13 | 14 | g :: Vec 8 (Clock System) 15 | -> Vec 8 (Clock System) 16 | g = f 17 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 18 | {-# CLASH_OPAQUE g #-} 19 | 20 | topEntity :: 21 | Vec 8 (Clock System) 22 | -> Vec 8 (Clock System) 23 | topEntity = g 24 | -------------------------------------------------------------------------------- /tests/shouldwork/Issues/T1615.hs: -------------------------------------------------------------------------------- 1 | module T1615 where 2 | 3 | import Clash.Prelude 4 | 5 | data T = A | B | C 6 | 7 | f A = (8 :: Unsigned 4) 8 | f B = 6 9 | f _ = 2 10 | 11 | topEntity = map @_ @_ @2 f 12 | -------------------------------------------------------------------------------- /tests/shouldwork/Issues/T1715.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | 3 | module T1715 where 4 | 5 | import Clash.Prelude 6 | import Clash.Explicit.Testbench 7 | 8 | topEntity :: (BitVector 16,BitVector 128) -> BitVector 128 9 | topEntity = uncurry (setSlice d127 d112) 10 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 11 | {-# CLASH_OPAQUE topEntity #-} 12 | 13 | testBench :: Signal System Bool 14 | testBench = done 15 | where 16 | testInput = stimuliGenerator clk rst ((maxBound,0):>Nil) 17 | expectedOutput = outputVerifier' clk rst (340277174624079928635746076935438991360:>Nil) 18 | done = expectedOutput (fmap topEntity testInput) 19 | clk = tbSystemClockGen (not <$> done) 20 | rst = systemResetGen 21 | -------------------------------------------------------------------------------- /tests/shouldwork/Issues/T1721.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | 3 | module T1721 where 4 | 5 | import Clash.Prelude 6 | 7 | type family G a 8 | type instance G () = Bool 9 | 10 | type family F a 11 | 12 | data T a = T a 13 | data TP a = TP Bool 14 | 15 | type instance F (T Bool) = TP Bool 16 | 17 | f :: F (T (G ())) 18 | -> F (T (G ())) 19 | f = id 20 | 21 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 22 | {-# CLASH_OPAQUE f #-} 23 | 24 | topEntity :: F (T (G ())) 25 | -> F (T (G ())) 26 | topEntity = f 27 | -------------------------------------------------------------------------------- /tests/shouldwork/Issues/T1756.hs: -------------------------------------------------------------------------------- 1 | module T1756 where 2 | 3 | import Clash.Prelude 4 | 5 | topEntity a = register @System (unconcat d2 (replicate d8 False)) a 6 | -------------------------------------------------------------------------------- /tests/shouldwork/Issues/T1996.hs: -------------------------------------------------------------------------------- 1 | module T1996 where 2 | 3 | import qualified Prelude as P 4 | import Data.List (isInfixOf) 5 | import System.Environment (getArgs) 6 | import System.FilePath ((), takeDirectory) 7 | 8 | import Clash.Prelude 9 | 10 | topEntity :: (Int, Int) -> (Int, Int) 11 | topEntity = id 12 | 13 | assertNotIn :: String -> String -> IO () 14 | assertNotIn needle haystack 15 | | needle `isInfixOf` haystack = 16 | P.error $ P.concat [ "Did not expect:\n\n ", needle 17 | , "\n\nIn:\n\n", haystack ] 18 | | otherwise = return () 19 | 20 | mainVHDL :: IO () 21 | mainVHDL = do 22 | [topDir] <- getArgs 23 | content <- readFile (topDir show 'topEntity "T1996_topEntity_types.vhdl") 24 | 25 | assertNotIn "T1996_topEntity_types." content 26 | -------------------------------------------------------------------------------- /tests/shouldwork/Issues/T2040.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | 3 | module T2040 where 4 | 5 | import Clash.Explicit.Prelude 6 | import Clash.Explicit.Testbench 7 | 8 | topEntity 9 | :: Signal System (Unsigned 8) 10 | -> Signal System (Unsigned 8) 11 | topEntity = id 12 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 13 | {-# CLASH_OPAQUE topEntity #-} 14 | 15 | testBench :: Signal System Bool 16 | testBench = done 17 | where 18 | testInput = register clk rst en 0 (testInput + 1) 19 | expectedOutput = 20 | outputVerifier' clk rst $(listToVecTH [0 :: Unsigned 8 .. 3]) 21 | done = expectedOutput $ topEntity testInput 22 | clk = tbSystemClockGen (not <$> done) 23 | rst = systemResetGen 24 | en = enableGen 25 | -------------------------------------------------------------------------------- /tests/shouldwork/Issues/T2046BType.hs: -------------------------------------------------------------------------------- 1 | module T2046BType where 2 | 3 | import Clash.Prelude 4 | 5 | type T2046B = 6 | ( (Index 1, Index 2) 7 | , (Unsigned 1, Unsigned 2) 8 | , (Signed 1, Signed 2) 9 | , (BitVector 1, BitVector 2) 10 | , Bit 11 | ) 12 | 13 | type T2046C = 14 | ( (Int, Int) 15 | , (Int, Int) 16 | , (Int, Int) 17 | , (Int, Int) 18 | , Int 19 | ) 20 | 21 | -------------------------------------------------------------------------------- /tests/shouldwork/Issues/T2046C.hs: -------------------------------------------------------------------------------- 1 | module T2046C where 2 | 3 | import Clash.Prelude 4 | import T2046BType 5 | 6 | inBit :: (Enum a) => a -> Bool 7 | inBit x = case fromEnum x of 8 | 0 -> True 9 | 1 -> True 10 | _ -> False 11 | 12 | topEntity :: Bool 13 | topEntity = 14 | let ((a,b),(c,d),(e,f),(g,h),i) = ((0,1),(0,1),(0,1),(0,1),0) :: T2046B 15 | in and [ inBit a, inBit b 16 | , inBit c, inBit d 17 | , inBit e, inBit f 18 | , inBit g, inBit h 19 | , inBit i 20 | ] 21 | 22 | -------------------------------------------------------------------------------- /tests/shouldwork/Issues/T2097.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE DeriveGeneric #-} 2 | 3 | module T2097 where 4 | 5 | import Clash.Prelude 6 | 7 | topEntity :: MyFloat 8 | topEntity = -1.0 9 | 10 | data MyFloat = MyFloat { 11 | negative :: Bool, 12 | exponent :: Unsigned 8, 13 | mantissa :: UFixed 0 23 14 | } deriving (Eq, Generic, BitPack) 15 | 16 | instance Num MyFloat where 17 | (-) a b = bitCoerce @Float (bitCoerce a - bitCoerce b) 18 | fromInteger = bitCoerce @Float . fromInteger 19 | 20 | instance Fractional MyFloat where 21 | fromRational = bitCoerce @Float . fromRational 22 | 23 | -------------------------------------------------------------------------------- /tests/shouldwork/Issues/T2154.hs: -------------------------------------------------------------------------------- 1 | module T2154 where 2 | 3 | import Clash.Explicit.Prelude 4 | 5 | topEntity (clk :: Clock System) rst = 6 | let r = unpack (pack ( errorX "T2154" :: (Index 10) 7 | , 3 :: Index 10 8 | )) :: Vec 2 (Index 10) 9 | s = register clk rst enableGen (seq r r) s 10 | in s 11 | -------------------------------------------------------------------------------- /tests/shouldwork/Issues/T2272.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | {-# LANGUAGE ImpredicativeTypes, TypeApplications, GADTs #-} 3 | module T2272 where 4 | 5 | import Clash.Prelude 6 | 7 | data Ex where 8 | ExT :: (forall a . String -> a) -> Ex 9 | 10 | f :: Ex 11 | f = ExT (errorX @(forall b . String -> b) "qq") 12 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 13 | {-# CLASH_OPAQUE f #-} 14 | 15 | topEntity :: Int 16 | topEntity = case f of 17 | ExT h -> h "kk" 18 | -------------------------------------------------------------------------------- /tests/shouldwork/Issues/T2325g.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | 3 | module T2325g where 4 | 5 | import Clash.Prelude 6 | 7 | import T2325h 8 | import T2325j 9 | 10 | g :: Unsigned 8 -> Unsigned 8 11 | g = h . j 12 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 13 | {-# CLASH_OPAQUE g #-} 14 | {-# ANN g (defSyn "g") #-} 15 | -------------------------------------------------------------------------------- /tests/shouldwork/Issues/T2325h.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | 3 | module T2325h where 4 | 5 | import Clash.Prelude 6 | 7 | h :: Unsigned 8 -> Unsigned 8 8 | h = (+ 5) 9 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 10 | {-# CLASH_OPAQUE h #-} 11 | {-# ANN h (defSyn "h") #-} 12 | -------------------------------------------------------------------------------- /tests/shouldwork/Issues/T2325j.hs: -------------------------------------------------------------------------------- 1 | 2 | {-# LANGUAGE CPP #-} 3 | 4 | module T2325j where 5 | 6 | import Clash.Prelude 7 | 8 | j :: Unsigned 8 -> Unsigned 8 9 | j = (+ 10) 10 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 11 | {-# CLASH_OPAQUE j #-} 12 | {-# ANN j (defSyn "j") #-} 13 | -------------------------------------------------------------------------------- /tests/shouldwork/Issues/T2342A.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | 3 | module T2342A where 4 | 5 | import Clash.Prelude 6 | import Data.Proxy 7 | 8 | foo :: forall n. KnownNat n => Proxy n -> Float 9 | foo Proxy = natToNum @n 10 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 11 | {-# CLASH_OPAQUE foo #-} 12 | 13 | topEntity :: Float 14 | topEntity = foo @10 Proxy 15 | -------------------------------------------------------------------------------- /tests/shouldwork/Issues/T2342B.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | 3 | module T2342B where 4 | 5 | import Clash.Prelude 6 | import Data.Proxy 7 | 8 | foo :: forall n. KnownNat n => Proxy n -> Double 9 | foo Proxy = natToNum @n 10 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 11 | {-# CLASH_OPAQUE foo #-} 12 | 13 | topEntity :: Double 14 | topEntity = foo @10 Proxy 15 | -------------------------------------------------------------------------------- /tests/shouldwork/Issues/T2360.hs: -------------------------------------------------------------------------------- 1 | module T2360 where 2 | 3 | import Clash.Prelude 4 | 5 | topEntity :: (BitVector 8) 6 | topEntity = deepErrorX "broken" 7 | -------------------------------------------------------------------------------- /tests/shouldwork/Issues/T2542.hs: -------------------------------------------------------------------------------- 1 | module T2542 where 2 | 3 | import qualified Prelude as P 4 | import Data.List (isInfixOf) 5 | import System.Environment (getArgs) 6 | import System.FilePath ((), takeDirectory) 7 | 8 | import Clash.Prelude 9 | 10 | topEntity :: (Index 2, Index 2) 11 | topEntity = case reverse (indicesI @2) of 12 | (a `Cons` b `Cons` Nil) -> (a,b) 13 | 14 | assertIn :: String -> String -> IO () 15 | assertIn needle haystack 16 | | needle `isInfixOf` haystack = return () 17 | | otherwise = P.error $ mconcat [ "Expected:\n\n ", needle 18 | , "\n\nIn:\n\n", haystack ] 19 | 20 | mainVHDL :: IO () 21 | mainVHDL = do 22 | [topDir] <- getArgs 23 | content <- readFile (topDir show 'topEntity "topEntity.vhdl") 24 | 25 | assertIn "to_unsigned(1,1)" content 26 | assertIn "to_unsigned(0,1)" content 27 | -------------------------------------------------------------------------------- /tests/shouldwork/Issues/T2593.hs: -------------------------------------------------------------------------------- 1 | module T2593 where 2 | 3 | import Clash.Prelude 4 | import Clash.Annotations.SynthesisAttributes 5 | 6 | topEntity :: 7 | Signal System Bit -> 8 | Signal System Bit `Annotate` 'StringAttr "breaka" "me" 9 | topEntity dIn = 10 | exposeClockResetEnable (register 0) clk rst en dIn 11 | where 12 | clk = clockGen 13 | rst = resetGen 14 | en = enableGen 15 | -------------------------------------------------------------------------------- /tests/shouldwork/Issues/T2623CaseConFVs.hs: -------------------------------------------------------------------------------- 1 | module T2623CaseConFVs where 2 | import Clash.Prelude 3 | 4 | topEntity = foo @System 5 | 6 | foo :: forall dom. Signal dom (Vec 1 (Signed 2)) -> Signal dom Bool 7 | foo = \input -> 8 | let 9 | scs :: Signal dom (Vec 1 Bool) 10 | scs = bundle $ map f $ unbundle input 11 | in 12 | fmap bar scs 13 | 14 | 15 | bar :: (KnownNat n) => Vec (n+1) Bool -> Bool 16 | bar = fold (&&) . map (id) 17 | 18 | f :: Signal dom a -> Signal dom Bool 19 | f = const $ pure $ True 20 | -------------------------------------------------------------------------------- /tests/shouldwork/Issues/T2831.hs: -------------------------------------------------------------------------------- 1 | module T2831 where 2 | 3 | import Clash.Prelude 4 | 5 | f :: forall n. SNat n -> Unsigned 4 6 | f n@SNat = case compareSNat n (SNat @15) of 7 | SNatLE -> at @n @(16 - n - 1) SNat vec 8 | SNatGT -> 0 9 | where 10 | vec :: Vec 16 (Unsigned 4) 11 | vec = repeat 1 12 | 13 | topEntity :: Unsigned 4 14 | topEntity = f d17 15 | -------------------------------------------------------------------------------- /tests/shouldwork/Issues/T2839.hs: -------------------------------------------------------------------------------- 1 | module T2839 where 2 | 3 | import Clash.Explicit.Prelude 4 | import Clash.Explicit.Testbench 5 | 6 | topEntity :: 7 | Signal System (Unsigned 8) 8 | topEntity = register clk noReset enableGen 100 0 9 | where 10 | cntr = register clk noReset enableGen (0 :: Unsigned 8) 0 11 | done = (== 100) <$> cntr 12 | clk = tbClockGen $ not <$> done 13 | -------------------------------------------------------------------------------- /tests/shouldwork/Issues/T2845.hs: -------------------------------------------------------------------------------- 1 | module T2845 where 2 | 3 | import Clash.Explicit.Prelude 4 | import Clash.Explicit.Testbench 5 | 6 | topEntity :: 7 | Signal System (Unsigned 8) 8 | topEntity = cntr + x 9 | where 10 | cntr = register clk noReset enableGen 0 0 11 | x = register clk noReset enableGen 100 0 12 | done = (== 100) <$> cntr 13 | clk = tbClockGen $ not <$> done 14 | -------------------------------------------------------------------------------- /tests/shouldwork/Issues/T2904.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | 3 | module T2904 where 4 | 5 | import Clash.Prelude 6 | import Clash.Explicit.Testbench 7 | 8 | topEntity :: Vec 3 (Unsigned 8) 9 | topEntity = case imap f (5 :> 6 :> 7 :> Nil) of 10 | (Cons x xs) -> Cons maxBound xs 11 | where 12 | f :: Index 3 -> Unsigned 8 -> Unsigned 8 13 | f i x = case i of 14 | 0 -> x + 1 15 | 1 -> x + 2 16 | _ -> x + 3 17 | {-# CLASH_OPAQUE topEntity #-} 18 | 19 | testBench :: Signal System Bool 20 | testBench = done 21 | where 22 | done = outputVerifier' clk rst ((maxBound :> 8 :> 10 :> Nil) :> Nil) (pure topEntity) 23 | clk = tbSystemClockGen (not <$> done) 24 | rst = systemResetGen 25 | {-# CLASH_OPAQUE testBench #-} 26 | -------------------------------------------------------------------------------- /tests/shouldwork/Issues/T359.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE DataKinds #-} 2 | 3 | -- Issue #359: https://github.com/clash-lang/clash-compiler/issues/359 4 | 5 | module T359 where 6 | 7 | import Clash.Prelude 8 | 9 | newtype Circuit a b c d = Circuit ((a,b) -> (c, d)) 10 | 11 | topEntity 12 | :: Clock System 13 | -> Reset System 14 | -> Enable System 15 | -> Circuit (Signal System Int) () () (Signal System Int) 16 | topEntity clk rst ena = 17 | withClockResetEnable clk rst ena $ 18 | Circuit $ \(i,()) -> ((), register 0 i) 19 | -------------------------------------------------------------------------------- /tests/shouldwork/LoadModules/T1796.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | {-# LANGUAGE NoImplicitPrelude #-} 3 | {-# LANGUAGE TypeApplications #-} 4 | 5 | module T1796 where 6 | 7 | import T1796a 8 | 9 | topEntity = tb 10 | -------------------------------------------------------------------------------- /tests/shouldwork/LoadModules/precompiled/T1796a.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | {-# LANGUAGE NoImplicitPrelude #-} 3 | {-# LANGUAGE TypeApplications #-} 4 | 5 | module T1796a where 6 | 7 | import Clash.Explicit.Prelude 8 | import Clash.Explicit.Testbench 9 | 10 | tb :: Signal System Bool 11 | tb = done 12 | where 13 | done = register clk rst enableGen False $ id (pure True) 14 | clk = tbClockGen @System (not <$> done) 15 | rst = resetGen @System 16 | -------------------------------------------------------------------------------- /tests/shouldwork/Naming/T967a.hs: -------------------------------------------------------------------------------- 1 | module T967a where 2 | 3 | import Clash.Prelude 4 | 5 | topEntity x = setName @"myRegister" (delay @System True x) 6 | -------------------------------------------------------------------------------- /tests/shouldwork/Naming/T967b.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE PartialTypeSignatures #-} 2 | {-# OPTIONS_GHC -Wno-partial-type-signatures #-} 3 | module T967b where 4 | 5 | import Clash.Prelude 6 | 7 | topEntity :: SystemClockResetEnable => Signal System Bool 8 | topEntity = setName @"myRegister" (delay @System True topEntity) 9 | -------------------------------------------------------------------------------- /tests/shouldwork/Naming/T967c.hs: -------------------------------------------------------------------------------- 1 | module T967c where 2 | 3 | import Clash.Prelude 4 | 5 | topEntity x = let (y :: Vec 2 Bool) = tail (lazyV (x:>y)) in y 6 | -------------------------------------------------------------------------------- /tests/shouldwork/Numbers/ExpWithClashCF.hs: -------------------------------------------------------------------------------- 1 | module ExpWithClashCF where 2 | 3 | import Clash.Prelude 4 | import Clash.Explicit.Testbench 5 | 6 | import qualified Exp 7 | import qualified ConstantFoldingUtil as CFU 8 | 9 | 10 | -- Constant folded topEntity (GHC/TemplateHaskell) 11 | expected = $(lift (pack Exp.packedExpectedOutputs)) 12 | 13 | -- Constant folded (?) topEntity (Clash) 14 | topEntity = pack Exp.packedExpectedOutputs -- map Exp.topEntity Exp.testInput 15 | 16 | testBench :: Signal System Bool 17 | testBench = done 18 | where 19 | expectedOutput = outputVerifierBitVector' clk rst (expected :> Nil) 20 | done = expectedOutput (pure topEntity) 21 | clk = tbSystemClockGen (not <$> done) 22 | rst = systemResetGen 23 | 24 | 25 | mainVHDL = CFU.mainVHDL 26 | mainVerilog = CFU.mainVHDL 27 | mainSystemVerilog = CFU.mainVHDL 28 | -------------------------------------------------------------------------------- /tests/shouldwork/Numbers/HalfAsBlackboxArg.hs: -------------------------------------------------------------------------------- 1 | module HalfAsBlackboxArg where 2 | 3 | import Clash.Prelude 4 | import Numeric.Half 5 | import Clash.Explicit.Testbench 6 | import Foreign.C.Types 7 | 8 | g :: KnownNat n => Vec n Half -> Half 9 | g v = 10 | case v of 11 | Nil -> Half 5 12 | Cons a as -> a 13 | 14 | topEntity = 15 | ( g (replicate d3 (Half 7)) 16 | , g (replace 0 (Half 8) (replicate d3 (Half 7))) 17 | ) 18 | -------------------------------------------------------------------------------- /tests/shouldwork/Numbers/IntegralTB.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | 3 | module IntegralTB where 4 | import Clash.Prelude 5 | import Clash.Explicit.Testbench 6 | import qualified Integral 7 | 8 | expected = $(lift $ map Integral.topEntity $ Integral.inputs) 9 | 10 | topEntity = Integral.topEntity 11 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 12 | {-# CLASH_OPAQUE topEntity #-} 13 | 14 | testBench :: Signal System Bool 15 | testBench = done 16 | where 17 | testInput = stimuliGenerator clk rst Integral.inputs 18 | expectedOutput = outputVerifier' clk rst expected 19 | done = expectedOutput (topEntity <$> testInput) 20 | clk = tbSystemClockGen (not <$> done) 21 | rst = systemResetGen 22 | -------------------------------------------------------------------------------- /tests/shouldwork/Numbers/NaturalToInteger.hs: -------------------------------------------------------------------------------- 1 | module NaturalToInteger where 2 | 3 | import Clash.Prelude 4 | import GHC.Natural 5 | 6 | topEntity :: Natural 7 | topEntity = snatToNum $ clogBaseSNat d2 d1024 8 | 9 | -------------------------------------------------------------------------------- /tests/shouldwork/Numbers/NegativeLits.hs: -------------------------------------------------------------------------------- 1 | module NegativeLits where 2 | import Clash.Prelude 3 | import Clash.Explicit.Testbench 4 | import Data.Int 5 | import Data.Word 6 | 7 | x :: Num a => a 8 | x = fromInteger (-4) 9 | 10 | topEntity :: (Unsigned 8, Word8, Signed 8, Int8) 11 | topEntity = (x,x,x,x) 12 | 13 | expectedBv :: BitVector 8 14 | expectedBv = 0b11111100 15 | 16 | testBench :: Signal System Bool 17 | testBench = done 18 | where 19 | expected = (unpack expectedBv, unpack expectedBv, unpack expectedBv, unpack expectedBv) :> Nil 20 | expectedOutput = outputVerifier' clk rst expected 21 | done = expectedOutput (pure topEntity) 22 | clk = tbSystemClockGen (not <$> done) 23 | rst = systemResetGen 24 | -------------------------------------------------------------------------------- /tests/shouldwork/Numbers/NumConstantFoldingTB_1.hs: -------------------------------------------------------------------------------- 1 | module NumConstantFoldingTB_1 where 2 | import Clash.Prelude 3 | import Clash.Explicit.Testbench 4 | import qualified NumConstantFolding_1 5 | 6 | expected = $(lift NumConstantFolding_1.topEntity) :> Nil 7 | 8 | topEntity = NumConstantFolding_1.topEntity 9 | 10 | testBench :: Signal System Bool 11 | testBench = done 12 | where 13 | expectedOutput = outputVerifier' clk rst expected 14 | done = expectedOutput (pure topEntity) 15 | clk = tbSystemClockGen (not <$> done) 16 | rst = systemResetGen 17 | -------------------------------------------------------------------------------- /tests/shouldwork/Numbers/NumConstantFoldingTB_2.hs: -------------------------------------------------------------------------------- 1 | module NumConstantFoldingTB_2 where 2 | import Clash.Prelude 3 | import Clash.Explicit.Testbench 4 | import qualified NumConstantFolding_2 5 | 6 | expected = $(lift NumConstantFolding_2.topEntity) :> Nil 7 | 8 | topEntity = NumConstantFolding_2.topEntity 9 | 10 | testBench :: Signal System Bool 11 | testBench = done 12 | where 13 | expectedOutput = outputVerifier' clk rst expected 14 | done = expectedOutput (pure topEntity) 15 | clk = tbSystemClockGen (not <$> done) 16 | rst = systemResetGen 17 | 18 | -------------------------------------------------------------------------------- /tests/shouldwork/Numbers/Resize.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | 3 | module Resize where 4 | 5 | import Clash.Prelude 6 | import Clash.Explicit.Testbench 7 | 8 | topEntity :: Signed 4 -> Signed 3 9 | topEntity = resize 10 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 11 | {-# CLASH_OPAQUE topEntity #-} 12 | 13 | testBench :: Signal System Bool 14 | testBench = done 15 | where 16 | testInput = stimuliGenerator clk rst $(listToVecTH ([minBound .. maxBound]::[Signed 4])) 17 | expectedOutput = outputVerifier' clk rst $(listToVecTH ([-4,-3,-2,-1,-4,-3,-2,-1,0,1,2,3,0,1,2,3]::[Signed 3])) 18 | done = expectedOutput (topEntity <$> testInput) 19 | clk = tbSystemClockGen (not <$> done) 20 | rst = systemResetGen 21 | -------------------------------------------------------------------------------- /tests/shouldwork/Numbers/Resize2.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | 3 | module Resize2 where 4 | 5 | import Clash.Prelude 6 | import Clash.Explicit.Testbench 7 | 8 | topEntity :: Signed 4 -> Signed 5 9 | topEntity = resize 10 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 11 | {-# CLASH_OPAQUE topEntity #-} 12 | 13 | testBench :: Signal System Bool 14 | testBench = done 15 | where 16 | testInput = stimuliGenerator clk rst $(listToVecTH ([minBound .. maxBound]::[Signed 4])) 17 | expectedOutput = outputVerifier' clk rst $(listToVecTH ([-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7]::[Signed 5])) 18 | done = expectedOutput (topEntity <$> testInput) 19 | clk = tbSystemClockGen (not <$> done) 20 | rst = systemResetGen 21 | -------------------------------------------------------------------------------- /tests/shouldwork/Numbers/Resize3.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | 3 | module Resize3 where 4 | 5 | import Clash.Prelude 6 | import Clash.Explicit.Testbench 7 | 8 | topEntity :: Signed 8 9 | topEntity = unpack (resize (pack (-2 :: Signed 4))) 10 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 11 | {-# CLASH_OPAQUE topEntity #-} 12 | 13 | testBench :: Signal System Bool 14 | testBench = done 15 | where 16 | expectedOutput = 17 | outputVerifier' 18 | clk 19 | rst 20 | ( 14 21 | :> $(lift (unpack (resize (pack (-2 :: Signed 4))) :: Signed 8)) 22 | :> Nil) 23 | done = expectedOutput (pure topEntity) 24 | clk = tbSystemClockGen (not <$> done) 25 | rst = systemResetGen 26 | -------------------------------------------------------------------------------- /tests/shouldwork/Numbers/SatMult.hs: -------------------------------------------------------------------------------- 1 | module SatMult where 2 | 3 | import Clash.Prelude 4 | 5 | topEntity :: Signed 3 -> Signed 3 -> Signed 3 6 | topEntity = satMul SatSymmetric 7 | -------------------------------------------------------------------------------- /tests/shouldwork/Numbers/T1019.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | 3 | module T1019 where 4 | 5 | import Clash.Prelude 6 | 7 | 8 | f :: SNat m -> Integer 9 | f = snatToInteger 10 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 11 | {-# CLASH_OPAQUE f #-} 12 | 13 | topEntity = f (SNat @(LCM 733301111 742)) 14 | -------------------------------------------------------------------------------- /tests/shouldwork/Numbers/T1351.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | 3 | module T1351 where 4 | 5 | import Clash.Prelude 6 | import Clash.Explicit.Testbench 7 | 8 | type F = Signed 8 9 | 10 | topEntity :: HiddenClockResetEnable System => Signal System F -> Signal System F 11 | topEntity i = boundedAdd <$> 0 <*> (last $ generate d1 (register 0) i) 12 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 13 | {-# CLASH_OPAQUE topEntity #-} 14 | 15 | testBench :: Signal System Bool 16 | testBench = done 17 | where 18 | testInput = stimuliGenerator clk rst (-4:>Nil) 19 | expectedOutput = outputVerifier' clk rst (0:>(-4):>Nil) 20 | done = expectedOutput (exposeClockResetEnable topEntity clk rst (enableGen) testInput) 21 | clk = tbSystemClockGen (not <$> done) 22 | rst = systemResetGen 23 | -------------------------------------------------------------------------------- /tests/shouldwork/Numbers/UndefinedConstantFoldingTB.hs: -------------------------------------------------------------------------------- 1 | module UndefinedConstantFoldingTB where 2 | import Clash.Prelude 3 | import Clash.Explicit.Testbench 4 | import qualified UndefinedConstantFolding 5 | 6 | expected = $(lift UndefinedConstantFolding.topEntity) :> Nil 7 | 8 | topEntity = UndefinedConstantFolding.topEntity 9 | 10 | testBench :: Signal System Bool 11 | testBench = done 12 | where 13 | expectedOutput = outputVerifier' clk rst expected 14 | done = expectedOutput (pure topEntity) 15 | clk = tbSystemClockGen (not <$> done) 16 | rst = systemResetGen 17 | -------------------------------------------------------------------------------- /tests/shouldwork/Polymorphism/ExistentialBoxed.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE ExistentialQuantification #-} 2 | module ExistentialBoxed where 3 | 4 | import Prelude 5 | 6 | data Obj = forall a . Obj a (a -> Int) 7 | 8 | topEntity = f (Obj 4 (const 8 . id)) 9 | 10 | f (Obj a g) = g a 11 | -------------------------------------------------------------------------------- /tests/shouldwork/Polymorphism/GADTExistential.hs: -------------------------------------------------------------------------------- 1 | module GADTExistential where 2 | 3 | import Clash.Prelude 4 | import Control.Lens 5 | import Data.Generics.Product 6 | import GHC.Generics 7 | 8 | data Thing = Thing 9 | { a :: Bool 10 | , a1 :: Bool 11 | } deriving Generic 12 | 13 | topEntity :: Signal System Thing -> Signal System Thing 14 | topEntity a = fmap (field @"a" %~ not) a 15 | -------------------------------------------------------------------------------- /tests/shouldwork/Polymorphism/LocalPoly.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE ExplicitForAll, ScopedTypeVariables, Rank2Types #-} 2 | module LocalPoly where 3 | 4 | import Clash.Prelude 5 | 6 | topEntity = f 7 | 8 | f (x :: Bool) = (second x False, second x high) 9 | where 10 | second :: Bool -> (forall a . a -> a) 11 | second a b = b 12 | -------------------------------------------------------------------------------- /tests/shouldwork/PrimitiveGuards/MultipleGuards.hs: -------------------------------------------------------------------------------- 1 | module MultipleGuards where 2 | import Clash.Prelude 3 | import Clash.Annotations.Primitive 4 | import Clash.Util.Interpolate (i) 5 | import Data.String.Interpolate (__i) 6 | 7 | test :: Bool 8 | test = True 9 | {-# NOINLINE test #-} 10 | {-# ANN test hasBlackBox #-} 11 | {-# ANN test (warnAlways "WARN1") #-} 12 | {-# ANN test (warnAlways "WARN2: You should know that ...") #-} 13 | {-# ANN test (warnAlways "WARN3") #-} 14 | {-# ANN test (InlineYamlPrimitive [VHDL] $ [__i| 15 | BlackBox: 16 | name: MultipleGuards.test 17 | kind: Expression 18 | template: "true" 19 | |]) #-} 20 | 21 | topEntity :: Bool 22 | topEntity = test 23 | -------------------------------------------------------------------------------- /tests/shouldwork/RTree/TFold.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE ScopedTypeVariables, UndecidableInstances #-} 2 | module TFold where 3 | 4 | import Clash.Prelude 5 | import GHC.TypeLits.Extra 6 | import Data.Kind (Type) 7 | 8 | import Data.Proxy 9 | import Data.Singletons hiding (type (+)) 10 | 11 | data IIndex (f :: TyFun Nat Type) :: Type 12 | type instance Apply IIndex l = Index ((2^l)+1) 13 | 14 | popCountT = tdfold (Proxy :: Proxy IIndex) fromIntegral (const add) 15 | 16 | popCount = popCountT . v2t . bv2v 17 | 18 | topEntity :: BitVector 16 -> Index 17 19 | topEntity = TFold.popCount 20 | -------------------------------------------------------------------------------- /tests/shouldwork/RTree/TRepeat.hs: -------------------------------------------------------------------------------- 1 | module TRepeat where 2 | 3 | import Clash.Prelude 4 | import Clash.Explicit.Testbench 5 | 6 | topEntity :: Signal System (RTree 2 Bool) 7 | topEntity = pure (trepeat True) 8 | 9 | -- Simulation test 10 | testBench :: Signal System Bool 11 | testBench = done 12 | where 13 | expectedOutput = outputVerifier' clk rst ($([| v2t (replicate d4 True) |]) :> Nil) 14 | done = expectedOutput topEntity 15 | clk = tbSystemClockGen (not <$> done) 16 | rst = systemResetGen 17 | -------------------------------------------------------------------------------- /tests/shouldwork/RTree/TRepeat2.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | 3 | module TRepeat2 where 4 | 5 | import Clash.Prelude 6 | import Clash.Explicit.Testbench 7 | 8 | topEntity x = register @System (trepeat @2 True) x 9 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 10 | {-# CLASH_OPAQUE topEntity #-} 11 | 12 | testBench :: Signal System Bool 13 | testBench = done 14 | where 15 | testInput = stimuliGenerator clk rst input 16 | expectedOutput = outputVerifier' clk rst expected 17 | done = expectedOutput $ withClockResetEnable clk rst en topEntity testInput 18 | clk = tbSystemClockGen (not <$> done) 19 | rst = systemResetGen 20 | en = enableGen 21 | 22 | input = replicate d2 $([| v2t (replicate d4 False) |]) 23 | expected = $([| v2t (replicate d4 $ True) :> v2t (replicate d4 (False)) :> Nil |]) 24 | -------------------------------------------------------------------------------- /tests/shouldwork/RTree/TZip.hs: -------------------------------------------------------------------------------- 1 | module TZip where 2 | 3 | import Clash.Prelude 4 | 5 | topEntity :: RTree 3 Int -> RTree 3 Bool -> RTree 3 (Int,Bool) 6 | topEntity = tzip 7 | 8 | -------------------------------------------------------------------------------- /tests/shouldwork/Signal/AlwaysHigh.hs: -------------------------------------------------------------------------------- 1 | module AlwaysHigh where 2 | 3 | import Clash.Prelude 4 | 5 | topEntity 6 | :: Clock System 7 | -> Reset System 8 | -> Enable System 9 | -> Signal System Bit 10 | topEntity = exposeClockResetEnable (register high (pure high)) 11 | -------------------------------------------------------------------------------- /tests/shouldwork/Signal/BangPatterns.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE BangPatterns #-} 2 | {-# LANGUAGE CPP #-} 3 | 4 | module BangPatterns where 5 | 6 | import Clash.Prelude 7 | import Clash.Explicit.Testbench 8 | 9 | topEntity :: Signal System (BitVector 1) 10 | topEntity = f @System (pure False) 11 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 12 | {-# CLASH_OPAQUE topEntity #-} 13 | 14 | f :: Signal dom Bool -> Signal dom (BitVector 1) 15 | f !e = fmap pack e 16 | 17 | testBench :: Signal System Bool 18 | testBench = done 19 | where 20 | expectedOutput = outputVerifier' clk rst (0 :> Nil) 21 | done = expectedOutput topEntity 22 | clk = tbSystemClockGen (not <$> done) 23 | rst = systemResetGen 24 | -------------------------------------------------------------------------------- /tests/shouldwork/Signal/BlockRamLazy.hs: -------------------------------------------------------------------------------- 1 | module BlockRamLazy where 2 | 3 | -- Issue: https://github.com/clash-lang/clash-compiler/issues/350 4 | 5 | import Clash.Prelude 6 | 7 | -- HACK to satisfy test runner 8 | topEntity :: Signal System (Unsigned 1) 9 | topEntity = pure 0 10 | 11 | -- Actual bug test 12 | bug :: SystemClockResetEnable => Signal System (Unsigned 1) 13 | bug = blockRamPow2 (repeat (0 :: Unsigned 1)) bug (pure Nothing) 14 | 15 | main = mapM printX $ sampleN @System 4 bug 16 | mainSystemVerilog = main 17 | mainVerilog = main 18 | mainVHDL = main 19 | -------------------------------------------------------------------------------- /tests/shouldwork/Signal/BlockRamTest.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE FlexibleInstances #-} 2 | module BlockRamTest where 3 | 4 | import Clash.Prelude 5 | 6 | topEntity 7 | :: Clock System 8 | -> Enable System 9 | -> Signal System (Unsigned 7) 10 | -> Signal System (Maybe (Unsigned 7, Vec 4 Bit)) 11 | -> Signal System (Vec 4 Bit) 12 | topEntity clk en = 13 | exposeEnable (exposeClock (blockRam (replicate d128 (repeat high))) clk) en 14 | -------------------------------------------------------------------------------- /tests/shouldwork/Signal/DualBlockRamTypes.hs: -------------------------------------------------------------------------------- 1 | module DualBlockRamTypes where 2 | 3 | import Clash.Explicit.Prelude 4 | 5 | data ThisOrThat 6 | = This (BitVector 32) 7 | | That (BitVector 17) 8 | deriving (Generic, BitPack, Show, ShowX, NFDataX, Lift, Eq) 9 | 10 | type Addr = Index 73 11 | 12 | type TdpRam (domA :: Domain) (domB :: Domain) = 13 | -- Clocks 14 | Clock domA -> 15 | Clock domB -> 16 | 17 | --Operations 18 | Signal domA (RamOp 73 ThisOrThat) -> 19 | Signal domB (RamOp 73 ThisOrThat) -> 20 | 21 | --Output 22 | ( Signal domA ThisOrThat 23 | , Signal domB ThisOrThat ) 24 | -------------------------------------------------------------------------------- /tests/shouldwork/Signal/NoCPR.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | {-# LANGUAGE DataKinds #-} 3 | 4 | module NoCPR where 5 | 6 | import Clash.Prelude 7 | 8 | {-# ANN example 9 | (Synthesize 10 | { t_name = "example" 11 | , t_inputs = [ PortName "a" 12 | ] 13 | , t_output = PortProduct "" 14 | [ PortName "b" 15 | , PortName "c" 16 | ] 17 | } 18 | )#-} 19 | 20 | example :: Signal System (BitVector 1) -> Signal System (BitVector 1, BitVector 1) 21 | example input = foo $ bundle (input, pure 0) 22 | 23 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 24 | {-# CLASH_OPAQUE foo #-} 25 | foo :: Signal dom (BitVector 1, BitVector 1) 26 | -> Signal dom (BitVector 1, BitVector 1) 27 | foo input = input 28 | -------------------------------------------------------------------------------- /tests/shouldwork/Signal/Ram/RMultiTop.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | 3 | module RMultiTop where 4 | 5 | import Clash.Explicit.Prelude 6 | 7 | import RMulti 8 | 9 | topEntity 10 | :: Clock P20 11 | -> Clock P10 12 | -> Signal P10 (Unsigned 1) 13 | -> Signal P20 (Maybe (Unsigned 1, Unsigned 2)) 14 | -> Signal P10 (Unsigned 2) 15 | topEntity = ram 16 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 17 | {-# CLASH_OPAQUE topEntity #-} 18 | 19 | testBench 20 | :: Signal P10 Bool 21 | testBench = tb topEntity 22 | $(listToVecTH $ sampleN 20 $ tbOutput ram clockGen clockGen) 23 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 24 | {-# CLASH_OPAQUE testBench #-} 25 | -------------------------------------------------------------------------------- /tests/shouldwork/Signal/SigP.hs: -------------------------------------------------------------------------------- 1 | module SigP where 2 | 3 | import Clash.Prelude 4 | 5 | topEntity 6 | :: Clock System 7 | -> Reset System 8 | -> Enable System 9 | -> Signal System (Bool, Bool) 10 | -> (Signal System Bool, Signal System Bool) 11 | topEntity = exposeClockResetEnable (unbundle . register (False,False)) 12 | -------------------------------------------------------------------------------- /tests/shouldwork/Signal/T1007.hs: -------------------------------------------------------------------------------- 1 | module T1007 where 2 | 3 | import Clash.Prelude 4 | 5 | topEntity clk rst = withClockResetEnable clk rst enableGen $ mealy @System f False 6 | 7 | f s x = (x,s) 8 | -------------------------------------------------------------------------------- /tests/shouldwork/SimIO/goldenInput00.txt: -------------------------------------------------------------------------------- 1 | abcdefghi 2 | -------------------------------------------------------------------------------- /tests/shouldwork/SimIO/goldenOutput00.txt: -------------------------------------------------------------------------------- 1 | aabcdefghi 2 | -------------------------------------------------------------------------------- /tests/shouldwork/TopEntity/T1139.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | 3 | module T1139 where 4 | import Clash.Prelude 5 | 6 | topEntity, otherTopEntity :: Bool -> Bool 7 | topEntity = not 8 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 9 | {-# CLASH_OPAQUE topEntity #-} 10 | 11 | otherTopEntity = topEntity 12 | {-# ANN otherTopEntity (defSyn "otherTopEntity") #-} 13 | -------------------------------------------------------------------------------- /tests/shouldwork/TopEntity/T701.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | 3 | module T701 where 4 | 5 | import Clash.Prelude 6 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 7 | {-# CLASH_OPAQUE myNot #-} 8 | {-# ANN myNot (defSyn "mynot") #-} 9 | myNot = not 10 | 11 | topEntity 12 | :: Signal System Bool 13 | -> Signal System Bool 14 | topEntity inp = myNot <$> inp 15 | -------------------------------------------------------------------------------- /tests/shouldwork/TopEntity/TopEntHOArg.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | 3 | module TopEntHOArg where 4 | 5 | import Clash.Prelude 6 | 7 | f :: Bit 8 | -> (Bool,(Bit,Bool),Maybe Bit) 9 | -> Bool 10 | -> (Bit,Bool,Maybe Bit,(Bit, Bool),Bool) 11 | f z (a,b,c) d = (z,a,c,b,d) 12 | {-# ANN f Synthesize {t_name = "f", t_inputs = [PortName "z",PortProduct "" []], t_output = PortProduct "" []} #-} 13 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 14 | {-# CLASH_OPAQUE f #-} 15 | 16 | g 17 | :: Bit 18 | -> Vec 2 (Bool,(Bit,Bool),Maybe Bit) 19 | -> Vec 2 Bool 20 | -> Vec 2 (Bit,Bool,Maybe Bit,(Bit, Bool), Bool) 21 | g b = zipWith (f b) 22 | {-# ANN g Synthesize {t_name = "g", t_inputs = [PortName "z", PortProduct "" []], t_output = PortProduct "" []} #-} 23 | -------------------------------------------------------------------------------- /tests/shouldwork/Types/NatExp.hs: -------------------------------------------------------------------------------- 1 | -- Make sure Clash can evaluate exponentation on type-level 'Nat's 2 | -- see https://github.com/clash-lang/clash-compiler/issues/960 3 | module NatExp where 4 | import Clash.Prelude 5 | 6 | triggered2 :: forall (n :: Nat) (d :: Nat) 7 | . ( KnownNat n,KnownNat d,1 <= n,1 <= d) 8 | => SNat n 9 | -> SNat d 10 | -> BitVector ((d*n)^2) 11 | triggered2 _ _ = pack (repeat False :: Vec ((d*n)^2) Bool) 12 | 13 | triggered3 :: forall (n :: Nat) (d :: Nat) 14 | . ( KnownNat n,KnownNat d,1 <= n,1 <= d) 15 | => SNat n 16 | -> SNat d 17 | -> BitVector ((d*n)^2) 18 | triggered3 _ _ = 0 19 | 20 | topEntity :: (BitVector 36, BitVector 36) 21 | topEntity = (triggered2 d2 d3, triggered3 d2 d3) 22 | -------------------------------------------------------------------------------- /tests/shouldwork/Unit/ZipWithTripleWithUnitMiddle.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | 3 | module ZipWithTripleWithUnitMiddle where 4 | 5 | import Clash.Prelude 6 | import Clash.Explicit.Testbench 7 | 8 | topEntity 9 | :: Vec 2 (Int,Int) 10 | -> Vec 2 ((Int,Int),(Int, (), Int)) 11 | topEntity xs = zipWith (,) xs (repeat (fst (head xs), (), snd (head xs))) 12 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 13 | {-# CLASH_OPAQUE topEntity #-} 14 | 15 | testBench :: Signal System Bool 16 | testBench = done 17 | where 18 | testInput = stimuliGenerator clk rst (repeat (2, 2) :> repeat (3, 4) :> Nil) 19 | expectedOutput = outputVerifier' clk rst (repeat ((2, 2), (2, (), 2)) :> repeat ((3, 4), (3, (), 4)) :> Nil) 20 | 21 | done = expectedOutput (topEntity <$> testInput) 22 | clk = tbSystemClockGen (not <$> done) 23 | rst = systemResetGen 24 | -------------------------------------------------------------------------------- /tests/shouldwork/Unit/ZipWithTupleWithUnitLeft.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | 3 | module ZipWithTupleWithUnitLeft where 4 | 5 | import Clash.Prelude 6 | import Clash.Explicit.Testbench 7 | 8 | topEntity 9 | :: Vec 2 (Int,Int) 10 | -> Vec 2 ((Int,Int),((), Int)) 11 | topEntity xs = zipWith (,) xs (repeat ((), fst (head xs))) 12 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 13 | {-# CLASH_OPAQUE topEntity #-} 14 | 15 | testBench :: Signal System Bool 16 | testBench = done 17 | where 18 | testInput = stimuliGenerator clk rst (repeat (2, 2) :> repeat (3, 4) :> Nil) 19 | expectedOutput = outputVerifier' clk rst (repeat ((2, 2), ((), 2)) :> repeat ((3, 4), ((), 3)) :> Nil) 20 | 21 | done = expectedOutput (topEntity <$> testInput) 22 | clk = tbSystemClockGen (not <$> done) 23 | rst = systemResetGen 24 | -------------------------------------------------------------------------------- /tests/shouldwork/Unit/ZipWithTupleWithUnitRight.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | 3 | module ZipWithTupleWithUnitRight where 4 | 5 | import Clash.Prelude 6 | import Clash.Explicit.Testbench 7 | 8 | topEntity 9 | :: Vec 2 (Int,Int) 10 | -> Vec 2 ((Int,Int),(Int, ())) 11 | topEntity xs = zipWith (,) xs (repeat (fst (head xs), ())) 12 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 13 | {-# CLASH_OPAQUE topEntity #-} 14 | 15 | testBench :: Signal System Bool 16 | testBench = done 17 | where 18 | testInput = stimuliGenerator clk rst (repeat (2, 2) :> repeat (3, 4) :> Nil) 19 | expectedOutput = outputVerifier' clk rst (repeat ((2, 2), (2, ())) :> repeat ((3, 4), (3, ())) :> Nil) 20 | 21 | done = expectedOutput (topEntity <$> testInput) 22 | clk = tbSystemClockGen (not <$> done) 23 | rst = systemResetGen 24 | -------------------------------------------------------------------------------- /tests/shouldwork/Unit/ZipWithUnitVector.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | 3 | module ZipWithUnitVector where 4 | 5 | import Clash.Prelude 6 | import Clash.Explicit.Testbench 7 | 8 | topEntity 9 | :: Vec 2 (Int,Int) 10 | -> Vec 2 ((Int,Int),()) 11 | topEntity xs = zipWith (,) xs (repeat ()) 12 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 13 | {-# CLASH_OPAQUE topEntity #-} 14 | 15 | testBench :: Signal System Bool 16 | testBench = done 17 | where 18 | testInput = stimuliGenerator clk rst (repeat (2, 2) :> repeat (3, 4) :> Nil) 19 | expectedOutput = outputVerifier' clk rst (repeat ((2, 2), ()) :> repeat ((3, 4), ()) :> Nil) 20 | 21 | done = expectedOutput (topEntity <$> testInput) 22 | clk = tbSystemClockGen (not <$> done) 23 | rst = systemResetGen 24 | -------------------------------------------------------------------------------- /tests/shouldwork/Vector/Concat.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | 3 | module Concat where 4 | 5 | import Clash.Prelude 6 | import Clash.Explicit.Testbench 7 | 8 | topEntity :: Vec 2 (Vec 3 (Unsigned 8)) -> Vec 6 (Unsigned 8) 9 | topEntity = concat 10 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 11 | {-# CLASH_OPAQUE topEntity #-} 12 | 13 | testBench :: Signal System Bool 14 | testBench = done 15 | where 16 | testInput = pure ((1 :> 2 :> 3 :> Nil) :> (4 :> 5 :> 6 :> Nil) :> Nil) 17 | expectedOutput = outputVerifier' clk rst ((1:>2:>3:>4:>5:>6:>Nil):>Nil) 18 | done = expectedOutput (topEntity <$> testInput) 19 | clk = tbSystemClockGen (not <$> done) 20 | rst = systemResetGen 21 | -------------------------------------------------------------------------------- /tests/shouldwork/Vector/EnumTypes.hs: -------------------------------------------------------------------------------- 1 | module EnumTypes where 2 | 3 | import Clash.Prelude 4 | 5 | data Valid = Valid | Invalid 6 | data Exec = Exec | NOP 7 | 8 | topEntity :: Vec 2 Valid -> Vec 2 Exec 9 | topEntity xs = map convert xs where 10 | convert Valid = Exec 11 | convert Invalid = NOP 12 | -------------------------------------------------------------------------------- /tests/shouldwork/Vector/FindIndex.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | 3 | module FindIndex where 4 | 5 | import Clash.Prelude 6 | import Clash.Explicit.Testbench 7 | 8 | topEntity :: Vec 7 (Unsigned 8) -> Maybe (Index 7) 9 | topEntity = findIndex (> 3) 10 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 11 | {-# CLASH_OPAQUE topEntity #-} 12 | 13 | testBench :: Signal System Bool 14 | testBench = done 15 | where 16 | testInput = pure (1:>3:>2:>4:>3:>5:>6:>Nil) 17 | expectedOutput = outputVerifier' clk rst ((Just 3) :> Nil) 18 | done = expectedOutput (topEntity <$> testInput) 19 | clk = tbSystemClockGen (not <$> done) 20 | rst = systemResetGen 21 | -------------------------------------------------------------------------------- /tests/shouldwork/Vector/Fold.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | 3 | module Fold where 4 | 5 | import Clash.Prelude 6 | import Clash.Explicit.Testbench 7 | 8 | topEntity :: Vec 8 Int -> Int 9 | topEntity = fold (+) 10 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 11 | {-# CLASH_OPAQUE topEntity #-} 12 | 13 | testBench :: Signal System Bool 14 | testBench = done 15 | where 16 | testInput = pure (1:>2:>3:>4:>5:>6:>7:>8:>Nil) 17 | expectedOutput = outputVerifier' clk rst (36 :> Nil) 18 | done = expectedOutput (topEntity <$> testInput) 19 | clk = tbSystemClockGen (not <$> done) 20 | rst = systemResetGen 21 | -------------------------------------------------------------------------------- /tests/shouldwork/Vector/FoldlFuns.hs: -------------------------------------------------------------------------------- 1 | -- see https://github.com/clash-lang/clash-compiler/issues/364 2 | module FoldlFuns where 3 | 4 | import Clash.Prelude 5 | 6 | func 7 | :: BitVector 8 8 | -> BitVector 8 9 | -> BitVector 32 10 | func d c = 0 11 | 12 | mod' 13 | :: forall dom 14 | . HiddenClockResetEnable dom 15 | => Signal dom (BitVector 32) 16 | mod' = o 17 | where 18 | 19 | x :: Signal dom (BitVector 8) = pure 0 20 | 21 | f :: Signal dom (BitVector 8) -> Signal dom (BitVector 32) 22 | f = foldl1 (\x y q -> liftA2 (.|.) (x q) (y q)) 23 | $ liftA2 func x 24 | :> liftA2 func x 25 | :> liftA2 func x 26 | :> Nil 27 | 28 | o :: Signal dom (BitVector 32) 29 | o = f (pure 0) 30 | 31 | topEntity clk rst en = withClockResetEnable @System clk rst en mod' 32 | -------------------------------------------------------------------------------- /tests/shouldwork/Vector/Foldr.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | 3 | module Foldr where 4 | 5 | import Clash.Prelude 6 | import Clash.Explicit.Testbench 7 | 8 | topEntity :: Vec 4 (Unsigned 8) -> (Unsigned 8) 9 | topEntity = foldr div 1 10 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 11 | {-# CLASH_OPAQUE topEntity #-} 12 | 13 | testBench :: Signal System Bool 14 | testBench = done 15 | where 16 | testInput = pure (24 :> 7 :> 4 :> 2 :> Nil) 17 | expectedOutput = outputVerifier' clk rst (8 :> Nil) 18 | done = expectedOutput (topEntity <$> testInput) 19 | clk = tbSystemClockGen (not <$> done) 20 | rst = systemResetGen 21 | -------------------------------------------------------------------------------- /tests/shouldwork/Vector/HOClock.hs: -------------------------------------------------------------------------------- 1 | module HOClock where 2 | 3 | import Clash.Prelude 4 | 5 | topEntity 6 | :: Clock System 7 | -> Reset System 8 | -> Enable System 9 | -> Vec 8 (Signal System (Int,Int)) 10 | -> Vec 8 (Signal System (Int,Int)) 11 | topEntity = exposeClockResetEnable (map (register (0,0))) 12 | -------------------------------------------------------------------------------- /tests/shouldwork/Vector/HOCon.hs: -------------------------------------------------------------------------------- 1 | module HOCon where 2 | 3 | import Clash.Prelude 4 | 5 | topEntity :: Vec 8 Int -> Vec 8 (Maybe Int) 6 | topEntity = map Just 7 | -------------------------------------------------------------------------------- /tests/shouldwork/Vector/HOPrim.hs: -------------------------------------------------------------------------------- 1 | module HOPrim where 2 | 3 | import Clash.Prelude 4 | 5 | topEntity :: Vec 4 Integer -> Vec 4 (Unsigned 4) 6 | topEntity = map fromInteger 7 | -------------------------------------------------------------------------------- /tests/shouldwork/Vector/Indices.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | 3 | module Indices where 4 | 5 | import Clash.Explicit.Prelude 6 | import Clash.Explicit.Testbench 7 | 8 | topEntity 9 | :: Vec 2 (Index 2) 10 | -> Vec 2 (Index 3) 11 | topEntity input = liftA2 add (indices SNat) input 12 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 13 | {-# CLASH_OPAQUE topEntity #-} 14 | 15 | testBench :: Signal System Bool 16 | testBench = done 17 | where 18 | expectedOutput = outputVerifier' clk aclr ((0 :> 2 :> Nil) :> Nil) 19 | testInput = stimuliGenerator clk aclr ((0 :> 1 :> Nil) :> Nil) 20 | done = expectedOutput (topEntity <$> testInput) 21 | clk = tbSystemClockGen (not <$> done) 22 | aclr = systemResetGen 23 | -------------------------------------------------------------------------------- /tests/shouldwork/Vector/Iterate.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | 3 | module Iterate where 4 | 5 | import Clash.Prelude 6 | import Clash.Explicit.Testbench 7 | 8 | topEntity :: Int -> Vec 2 Int 9 | topEntity = iterateI succ 10 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 11 | {-# CLASH_OPAQUE topEntity #-} 12 | 13 | testBench :: Signal System Bool 14 | testBench = done 15 | where 16 | output = $(lift (map (iterate d2 (succ @Int)) (333 :> 444 :> Nil))) 17 | testInput = stimuliGenerator clk rst (333 :> 444 :> Nil) 18 | expectedOutput = outputVerifier' clk rst output 19 | done = expectedOutput (topEntity <$> testInput) 20 | clk = tbSystemClockGen (not <$> done) 21 | rst = systemResetGen 22 | -------------------------------------------------------------------------------- /tests/shouldwork/Vector/Minimum.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | 3 | module Minimum where 4 | 5 | import Clash.Prelude 6 | import Clash.Explicit.Testbench 7 | 8 | topEntity :: Vec 3 Int -> Int 9 | topEntity = minimum 10 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 11 | {-# CLASH_OPAQUE topEntity #-} 12 | 13 | testBench :: Signal System Bool 14 | testBench = done 15 | where 16 | testInput = pure (4 :> 8 :> (-2) :> Nil) 17 | expectedOutput = outputVerifier' clk rst (singleton (-2)) 18 | done = expectedOutput (topEntity <$> testInput) 19 | clk = tbSystemClockGen (not <$> done) 20 | rst = systemResetGen 21 | -------------------------------------------------------------------------------- /tests/shouldwork/Vector/MovingAvg.hs: -------------------------------------------------------------------------------- 1 | module MovingAvg where 2 | 3 | import Clash.Prelude 4 | 5 | windowN 6 | :: HiddenClockResetEnable dom 7 | => Default a 8 | => KnownNat n 9 | => NFDataX a 10 | => SNat (n+1) 11 | -> Signal dom a 12 | -> Vec (n + 1) (Signal dom a) 13 | windowN size = window 14 | 15 | movingAvarageNaive size signal = fold (+) <$> bundle (windowN size signal) 16 | 17 | topEntity 18 | :: Clock System 19 | -> Reset System 20 | -> Enable System 21 | -> Signal System (Signed 9) 22 | -> Signal System (Signed 9) 23 | topEntity = exposeClockResetEnable (movingAvarageNaive d5) 24 | -------------------------------------------------------------------------------- /tests/shouldwork/Vector/PatHOCon.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TupleSections #-} 2 | module PatHOCon where 3 | 4 | import Clash.Prelude 5 | 6 | topEntity :: Vec 8 (Unsigned 8) -> Vec 8 (Unsigned 4,Unsigned 8) 7 | topEntity = map (4,) 8 | -------------------------------------------------------------------------------- /tests/shouldwork/Vector/Scatter.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | 3 | module Scatter where 4 | 5 | import Clash.Prelude 6 | import Clash.Explicit.Testbench 7 | 8 | topEntity :: Vec 5 (Unsigned 10) -> Vec 5 (Unsigned 10) 9 | topEntity = scatter defvec to 10 | where 11 | defvec = replicate d5 99 12 | to = 0 :> 4 :> 2 :> 3 :> 1 :> Nil 13 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 14 | {-# CLASH_OPAQUE topEntity #-} 15 | 16 | testBench :: Signal System Bool 17 | testBench = done 18 | where 19 | testInput = stimuliGenerator clk rst ((1 :> 2 :> 3 :> 4 :> 5 :> Nil) :> Nil) 20 | expectedOutput = outputVerifier' clk rst ((1 :> 5 :> 3 :> 4 :> 2 :> Nil) :> Nil) 21 | done = expectedOutput (topEntity <$> testInput) 22 | clk = tbSystemClockGen (not <$> done) 23 | rst = systemResetGen 24 | -------------------------------------------------------------------------------- /tests/shouldwork/Vector/Split.hs: -------------------------------------------------------------------------------- 1 | module Split where 2 | 3 | import Clash.Prelude 4 | 5 | topEntity :: Vec 7 Bit -> Vec 2 Bit 6 | topEntity vs = snd (splitAtI vs) 7 | -------------------------------------------------------------------------------- /tests/shouldwork/Vector/T1360.hs: -------------------------------------------------------------------------------- 1 | module T1360 where 2 | 3 | import Clash.Prelude 4 | 5 | data StatusA = InactiveA | ActiveA deriving (Generic,NFDataX) 6 | 7 | topEntity :: HiddenClockResetEnable System => 8 | Signal System (Vec 2 StatusA) -> Signal System (Index 2) -> Signal System (Vec 2 StatusA) 9 | topEntity input idx = out 10 | where 11 | out = replace <$> idx <*> pure InactiveA <*> input 12 | -------------------------------------------------------------------------------- /tests/shouldwork/Vector/T452.hs: -------------------------------------------------------------------------------- 1 | module T452 where 2 | 3 | import Clash.Prelude 4 | 5 | topEntity 6 | :: Vec 4 (Unsigned 4) 7 | -> Vec 4 (Unsigned 5) 8 | topEntity = map (add (3 :: Unsigned 4)) 9 | -------------------------------------------------------------------------------- /tests/shouldwork/Vector/T478.hs: -------------------------------------------------------------------------------- 1 | module T478 where 2 | 3 | import Clash.Prelude 4 | 5 | topEntity :: Vec 6 Bool -> Bool 6 | topEntity = (==) (pure False) 7 | -------------------------------------------------------------------------------- /tests/shouldwork/Vector/T895.hs: -------------------------------------------------------------------------------- 1 | module T895 where 2 | 3 | import Clash.Prelude 4 | 5 | topEntity :: Maybe (Vec 2 (Signed 8), Index 1) 6 | topEntity = Just (pure 0, 0) 7 | -------------------------------------------------------------------------------- /tests/shouldwork/Vector/ToList.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | 3 | module ToList where 4 | 5 | import Clash.Prelude 6 | import Clash.Explicit.Testbench 7 | import qualified Data.List as L 8 | 9 | topEntity :: Vec 3 Int -> Int 10 | topEntity xs = L.foldr (+) 0 (toList xs) 11 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 12 | {-# CLASH_OPAQUE topEntity #-} 13 | 14 | testBench :: Signal System Bool 15 | testBench = done 16 | where 17 | testInput = pure (1 :> 2 :> 3 :> Nil) 18 | expectedOutput = outputVerifier' clk rst (6 :> Nil) 19 | done = expectedOutput (topEntity <$> testInput) 20 | clk = tbSystemClockGen (not <$> done) 21 | rst = systemResetGen 22 | -------------------------------------------------------------------------------- /tests/shouldwork/Vector/Unconcat.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | 3 | module Unconcat where 4 | 5 | import Clash.Prelude 6 | import Clash.Explicit.Testbench 7 | 8 | topEntity :: Vec 6 (Unsigned 8) -> Vec 2 (Vec 3 (Unsigned 8)) 9 | topEntity = unconcatI 10 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 11 | {-# CLASH_OPAQUE topEntity #-} 12 | 13 | testBench :: Signal System Bool 14 | testBench = done 15 | where 16 | testInput = pure (1 :> 2 :> 3 :> 4 :> 5 :> 6 :> Nil) 17 | expectedOutput = outputVerifier' clk rst (((1 :> 2 :> 3 :> Nil) :> (4 :> 5 :> 6 :> Nil) :> Nil):>Nil) 18 | done = expectedOutput (topEntity <$> testInput) 19 | clk = tbSystemClockGen (not <$> done) 20 | rst = systemResetGen 21 | -------------------------------------------------------------------------------- /tests/shouldwork/Vector/VACC.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE DataKinds #-} 2 | module VACC where 3 | 4 | import Clash.Prelude 5 | 6 | topEntity :: Vec 8 Bit -> Vec 16 Bit 7 | topEntity x = o ++ p ++ q ++ k ++ l 8 | where 9 | y = take d4 x 10 | z = drop d4 x 11 | o = takeI y :: Vec 2 Bit 12 | p = dropI z :: Vec 2 Bit 13 | q = select d1 d2 d4 x 14 | k = generateI (xor low) high :: Vec 4 Bit 15 | l = iterateI (xor high) low :: Vec 4 Bit 16 | -------------------------------------------------------------------------------- /tests/shouldwork/Vector/VFold.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | 3 | module VFold where 4 | 5 | import Clash.Prelude 6 | import Clash.Explicit.Testbench 7 | 8 | csSort = vfold (const csRow) 9 | where 10 | cs a b = if a > b then (a,b) else (b,a) 11 | csRow y xs = let (y',xs') = mapAccumL cs y xs in xs' :< y' 12 | 13 | topEntity :: Vec 4 Int -> Vec 4 Int 14 | topEntity = csSort 15 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 16 | {-# CLASH_OPAQUE topEntity #-} 17 | 18 | testBench :: Signal System Bool 19 | testBench = done 20 | where 21 | testInput = pure (7 :> 3 :> 9 :> 1 :> Nil) 22 | expectedOutput = outputVerifier' clk rst ((1:>3:>7:>9:>Nil):>Nil) 23 | done = expectedOutput (topEntity <$> testInput) 24 | clk = tbSystemClockGen (not <$> done) 25 | rst = systemResetGen 26 | -------------------------------------------------------------------------------- /tests/shouldwork/Vector/VIndex.hs: -------------------------------------------------------------------------------- 1 | module VIndex where 2 | 3 | import Clash.Prelude 4 | 5 | topEntity :: (Integer,Vec 8 (Vec 8 (Maybe Int))) -> Vec 8 (Maybe Int) 6 | topEntity (i,as) = zipWith (!!) as (iterateI (+1) i) 7 | -------------------------------------------------------------------------------- /tests/shouldwork/Vector/VIndicesI.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | 3 | module VIndicesI where 4 | 5 | import Clash.Prelude 6 | import Clash.Explicit.Testbench 7 | 8 | topEntity :: Signal System (Vec 4 (Index 4)) 9 | topEntity = pure indicesI 10 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 11 | {-# CLASH_OPAQUE topEntity #-} 12 | 13 | testBench :: Signal System Bool 14 | testBench = done 15 | where 16 | expectedOutput = outputVerifier' clk rst ((0:>1:>2:>3:>Nil):>Nil) 17 | done = expectedOutput topEntity 18 | clk = tbSystemClockGen (not <$> done) 19 | rst = systemResetGen 20 | -------------------------------------------------------------------------------- /tests/shouldwork/Vector/VMapAccum.hs: -------------------------------------------------------------------------------- 1 | module VMapAccum where 2 | 3 | import Clash.Prelude 4 | 5 | ha a b = (a `xor` b, a .&. b) 6 | 7 | fa cin (a,b) = (cout,s) 8 | where 9 | (c1,z) = ha a b 10 | (c2,s) = ha z cin 11 | cout = c1 .|. c2 12 | 13 | topEntity :: Bit -> Vec 4 (Bit,Bit) -> ((Bit,Vec 4 Bit),(Bit, Vec 4 Bit)) 14 | topEntity acc xs = (mapAccumL fa acc xs,mapAccumR fa acc xs) 15 | -------------------------------------------------------------------------------- /tests/shouldwork/Vector/VMerge.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | 3 | module VMerge where 4 | 5 | import Clash.Prelude 6 | import Clash.Explicit.Testbench 7 | 8 | topEntity :: (Vec 2 Int,Vec 2 Int) -> Vec 4 Int 9 | topEntity (x,y) = merge x y 10 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 11 | {-# CLASH_OPAQUE topEntity #-} 12 | 13 | testBench :: Signal System Bool 14 | testBench = done 15 | where 16 | testInput = pure (iterateI (+1) 1,iterateI (+1) 3) 17 | expectedOutput = outputVerifier' clk rst ((1:>3:>2:>4:>Nil):>Nil) 18 | done = expectedOutput (topEntity <$> testInput) 19 | clk = tbSystemClockGen (not <$> done) 20 | rst = systemResetGen 21 | -------------------------------------------------------------------------------- /tests/shouldwork/Vector/VReverse.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | 3 | module VReverse where 4 | 5 | import Clash.Prelude 6 | import Clash.Explicit.Testbench 7 | 8 | topEntity :: Vec 4 Int -> Vec 4 Int 9 | topEntity = reverse 10 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 11 | {-# CLASH_OPAQUE topEntity #-} 12 | 13 | testBench :: Signal System Bool 14 | testBench = done 15 | where 16 | testInput = pure (iterateI (+1) 1) 17 | expectedOutput = outputVerifier' clk rst ((4:>3:>2:>1:>Nil):>Nil) 18 | done = expectedOutput (topEntity <$> testInput) 19 | clk = tbSystemClockGen (not <$> done) 20 | rst = systemResetGen 21 | -------------------------------------------------------------------------------- /tests/shouldwork/Vector/VRotate.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | 3 | module VRotate where 4 | 5 | import Clash.Prelude 6 | import Clash.Explicit.Testbench 7 | 8 | topEntity :: Vec 5 Int -> (Vec 5 Int,Vec 5 Int) 9 | topEntity v = (rotateLeftS v d2,rotateRightS v d2) 10 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 11 | {-# CLASH_OPAQUE topEntity #-} 12 | 13 | testBench :: Signal System Bool 14 | testBench = done 15 | where 16 | testInput = pure (1:>2:>3:>4:>5:>Nil) 17 | expectedOutput = outputVerifier' clk rst ((3:>4:>5:>1:>2:>Nil,4:>5:>1:>2:>3:>Nil):>Nil) 18 | done = expectedOutput (topEntity <$> testInput) 19 | clk = tbSystemClockGen (not <$> done) 20 | rst = systemResetGen 21 | -------------------------------------------------------------------------------- /tests/shouldwork/Vector/VScan.hs: -------------------------------------------------------------------------------- 1 | module VScan where 2 | 3 | import Clash.Prelude 4 | 5 | topEntity :: Vec 4 Int -> (Vec 4 Int,Vec 4 Int) 6 | topEntity vs = (postscanl (+) 0 vs, postscanr (+) 0 vs) 7 | 8 | -------------------------------------------------------------------------------- /tests/shouldwork/Vector/VSelect.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | 3 | module VSelect where 4 | 5 | import Clash.Prelude 6 | import Clash.Explicit.Testbench 7 | 8 | topEntity :: Vec 8 Int -> Vec 4 Int 9 | topEntity x = select d1 d2 d4 x 10 | -- See: https://github.com/clash-lang/clash-compiler/pull/2511 11 | {-# CLASH_OPAQUE topEntity #-} 12 | 13 | testBench :: Signal System Bool 14 | testBench = done 15 | where 16 | testInput = pure (iterateI (+1) 1) 17 | expectedOutput = outputVerifier' clk rst ((2:>4:>6:>8:>Nil):>Nil) 18 | done = expectedOutput (topEntity <$> testInput) 19 | clk = tbSystemClockGen (not <$> done) 20 | rst = systemResetGen 21 | -------------------------------------------------------------------------------- /tests/shouldwork/Vector/VZip.hs: -------------------------------------------------------------------------------- 1 | module VZip where 2 | 3 | import Clash.Prelude 4 | 5 | topEntity :: Vec 8 (Int,Int) -> Vec 8 (Int,Int) 6 | topEntity xs = zip ys zs 7 | where 8 | (ys,zs) = unzip xs 9 | -------------------------------------------------------------------------------- /tests/shouldwork/Vector/VecConst.hs: -------------------------------------------------------------------------------- 1 | module VecConst where 2 | 3 | import Clash.Prelude 4 | 5 | topEntity :: Vec 4 Int -> Vec 2 (Vec 4 Int) 6 | topEntity a = $(listToVecTH [1::Int,2,3,4]) :> a :> Nil 7 | -------------------------------------------------------------------------------- /tests/shouldwork/Vector/VecOfSum.hs: -------------------------------------------------------------------------------- 1 | module VecOfSum where 2 | 3 | import Clash.Prelude 4 | 5 | data Sum = Empty 6 | | Half Integer Integer Integer Integer 7 | | Full (Unsigned 4) (Signed 9) Bool Integer Bit (Maybe (Bool,Signed 3)) (Unsigned 3, Signed 4) 8 | 9 | topEntity :: Vec 3 Sum -> Vec 5 Sum 10 | topEntity xs = (Full 4 12 True 12 high (Just (False, 1)) (2,7)) :> Empty :> xs 11 | -------------------------------------------------------------------------------- /tests/src/Test/Tasty/Clash/CollectSimResults.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TemplateHaskell #-} 2 | {-# LANGUAGE QuasiQuotes #-} 3 | 4 | module Test.Tasty.Clash.CollectSimResults where 5 | import Clash.Prelude 6 | import Language.Haskell.TH.Lib 7 | 8 | -- | Creates vector literal out of the first n samples of the given signal. 9 | collectSimResults :: (KnownDomain dom, Lift a, NFDataX a) => Int -> Signal dom a -> ExpQ 10 | collectSimResults cycles entity = listToVecTH (sampleN cycles entity) 11 | --------------------------------------------------------------------------------