Start adding code generation
This commit is contained in:
32
src/code_gen/main.jl
Normal file
32
src/code_gen/main.jl
Normal file
@@ -0,0 +1,32 @@
|
||||
using DataStructures
|
||||
|
||||
function gen_code(graph::DAG)
|
||||
code = Vector{Expr}()
|
||||
sizehint!(code, length(graph.nodes))
|
||||
|
||||
nodeQueue = PriorityQueue{Node, Int}()
|
||||
inputSyms = Vector{Symbol}()
|
||||
|
||||
for node in get_entry_nodes(graph)
|
||||
enqueue!(nodeQueue, node => 1)
|
||||
push!(inputSyms, Symbol("data_$(replace(string(node.id), "-"=>"_"))_in"))
|
||||
end
|
||||
|
||||
node = nothing
|
||||
while !isempty(nodeQueue)
|
||||
prio = peek(nodeQueue)[2]
|
||||
node = dequeue!(nodeQueue)
|
||||
|
||||
push!(code, get_expression(node))
|
||||
for parent in node.parents
|
||||
if (!haskey(nodeQueue, parent))
|
||||
enqueue!(nodeQueue, parent => prio + length(parent.children))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# node is now the last node we looked at -> the output node
|
||||
outSym = Symbol("data_$(replace(string(node.id), "-"=>"_"))")
|
||||
|
||||
return (code = Expr(:block, code...), inputSymbols = inputSyms, outputSymbol = outSym)
|
||||
end
|
Reference in New Issue
Block a user