Created
May 2, 2021 00:41
-
-
Save QuantumFractal/30f68e5187d7fcc08cf20a76c29c3749 to your computer and use it in GitHub Desktop.
Julia2Verilog.jl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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