Skip to content

Instantly share code, notes, and snippets.

View andrewray's full-sized avatar

Andrew Ray andrewray

View GitHub Profile
@andrewray
andrewray / test.ml
Last active February 25, 2023 10:47
Query a hierarchical Hardcaml circuit by UID with full tracing
open Core
open Hardcaml
(* Set this before construcing the circuit so that stack traces are stored inside
signals. *)
let () = Caller_id.set_mode Full_trace
(* A simple hierarchical circuit *)
module Add_sub = struct
module I = struct
@andrewray
andrewray / install.md
Last active June 13, 2018 11:00
Working with the old version of Hardcaml

Working with the old version of Hardcaml

To use the old version of hardcaml

  1. Create a directory ie hardcaml_ujamjar and cd into it
  2. touch jbuild-workspace
  3. git clone ... the required repositories
  4. opam install ... the required dependencies
  5. jbuilder build @install will compile everything
@andrewray
andrewray / ctypes_strings.ml
Last active December 26, 2017 03:56
Using Ctypes with strings
#require "base,stdio,ctypes.foreign";;
open Base
open Stdio
open Ctypes
open Foreign
(* getenv
A string is passed and a string, which doesn't require deallocation, is
@andrewray
andrewray / cyclesim_generators2.ml
Created March 25, 2017 17:00
Updated version of cyclesim_generators.ml using interfaces
#require "delimcc";;
#require "hardcaml,hardcaml-waveterm,ppx_deriving_hardcaml";;
open Delimcc
open HardCaml
open Api
type ('a, 'b) t = Done | More of 'a * ('b -> ('a, 'b) t)
let gen f =
@andrewray
andrewray / .ocamlinit
Created March 24, 2017 00:49
Demonstrate SAT checking of hardcaml and verilog combinatorial logic using yosys and hardcaml-bloop
#require "hardcaml,ppx_deriving_hardcaml,hardcaml-waveterm,hardcaml-bloop,hardcaml-yosys";;
#mod_use "satvlog.ml";;
@andrewray
andrewray / test_waveform.ml
Created March 10, 2017 11:45
hardcaml-waveterm simple waveform configuration
#require "ppx_deriving_hardcaml,hardcaml-waveterm";;
open HardCaml
open Signal.Comb
module I = struct
type 'a t = {
arg_a : 'a[@bits 2];
arg_b : 'a[@bits 2];
}[@@deriving hardcaml]
@andrewray
andrewray / cyclesim_spawning_generators.ml
Last active March 25, 2017 12:33
Generators which allow spawning of new tasks, and some composability
#require "delimcc";;
#require "hardcaml,hardcaml-waveterm";;
open Delimcc
open HardCaml
open Api
type ('a, 'b) t = Done | More of 'a * ('b -> ('a, 'b) t)
let gen f =
@andrewray
andrewray / cyclesim_generators.ml
Created February 6, 2017 01:56
Experimental generators for simulation based on Delimcc
#require "delimcc";;
#require "hardcaml";;
open Delimcc
type ('a, 'b) t = Done | More of 'a * ('b -> ('a, 'b) t)
let gen f =
(*
* Note: the first value to yield gets thrown away as the generator
@andrewray
andrewray / test_hier2.ml
Created January 23, 2017 02:22
Hierarchy in hardcaml, with optional flattening and automatic wiring of clock
open HardCaml
(* different register types *)
module Seq = struct
open Signal
open Types
open Seq
module type S = sig
include Interface.S
val reg : Api.Comb.t t -> Signal.Types.register
@andrewray
andrewray / ppx_hardcaml.ml
Created December 14, 2016 01:45
ppx_hardcaml, using expression mapper
(*
build with:
ocamlbuild -use-ocamlfind -package compiler-libs.common -package ppx_tools.metaquot ppx_hardcaml.native
*)
open Ast_mapper
open Ast_helper