Skip to content

Instantly share code, notes, and snippets.

@QuantumFractal
Created May 2, 2021 00:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save QuantumFractal/30f68e5187d7fcc08cf20a76c29c3749 to your computer and use it in GitHub Desktop.
Save QuantumFractal/30f68e5187d7fcc08cf20a76c29c3749 to your computer and use it in GitHub Desktop.
Julia2Verilog.jl
using Cassette
Cassette.@context VCtx
mutable struct VMeta
module_name::String
f::IOStream
end
VMeta(module_name::String) = VMeta(module_name, open(module_name * ".v", "w"))
abstract type VType end
struct VWire <: VType
width::Int
end
function enter!(meta::VMeta, args)
println("Entering new module!", meta.module_name)
return nothing
end
function exit!(meta::VMeta)
println("Exiting new module!",meta.module_name)
write(meta.f, "HELLO FROM VERILOG")
close(meta.f)
return nothing
end
Cassette.prehook(ctx::VCtx, f, args::Vararg{T, N}) where {T<:VType, N} = enter!(ctx.metadata, args)
Cassette.posthook(ctx::VCtx, _, f, args::Vararg{T, N}) where {T<:VType, N} = exit!(ctx.metadata)
# TODO: input module name
f(x, y, z) = x
Cassette.overdub(VCtx(metadata = VMeta("f")), () -> f(VWire(1), VWire(1), VWire(1)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment