Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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