-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJuliog.jl
131 lines (109 loc) · 3.73 KB
/
Juliog.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
struct pancake
funcSymbol::Symbol
funcName::String
parameterizedBlock::Expr
sanitizedBlock::Expr
verilogBlock::String
juliaBlock::Expr
end
global funcStack = Array{pancake}(0)
global exSymbols = Array{Symbol}(0)
global exBlocks = Array{Expr}(0)
function loadJULIOGexpr(ex::Expr)
# Remove the REPL line number indicators
# If they're not already obsolete, they will be, soon
ex = removelinenumbers(ex)
if ex.head == :Function
push!(exSymbols, ex.args[1].args[1])
push!(exBlocks, ex)
else
# ex.head must equal :block
l = length(ex.args)
for i = 1:l
push!(exSymbols, ex.args[i].args[1].args[1])
push!(exBlocks, ex.args[i])
end
end
end
function overwriteJULIOGexpr(ex::Expr)
global exSymbols = Array{Symbol}(0)
global exBlocks = Array{Expr}(0)
# Remove the REPL line number indicators
# If they're not already obsolete, they will be, soon
ex = removelinenumbers(ex)
if ex.head == :Function
push!(exSymbols, ex.args[1].args[1])
push!(exBlocks, ex)
else
# ex.head must equal :block
l = length(ex.args)
for i = 1:l
push!(exSymbols, ex.args[i].args[1].args[1])
push!(exBlocks, ex.args[i])
end
end
end
function parsefile(filename::String)
file = open(filename)
str = readstring(file)
return parse(str)
end
function removelinenumbers(ex::Expr)
l = length(ex.args)
i = 1
while i <= l
if isa(ex.args[i], Expr)
if ex.args[i].head == :line
deleteat!(ex.args, i)
i = i - 1
l = l - 1
else
ex.args[i] = removelinenumbers(ex.args[i])
end
end
i = i + 1
end
return ex
end
# TODO Figure out how to remember hieararchy in funcStack
# Will come in handy when I need to unroll recursion in verilog
macro block(func::Symbol, name::String, arguments::Expr)
if !isdefined(:exSymbols)
error("No expression loaded. Cannot call @block without loaded JULIOG")
end
if !in(func, exSymbols)
error("No Symbol matching $(func) was found in loaded JULIOG expression")
end
if !isdefined(:funcStack)
global funcStack = Array{pancake}(0)
else
global funcStack
end
ref = findlast(exSymbols .== func)
blockToInterpret = exBlocks[ref]
push!(funcStack, pancake(func, name, Expr(:function), Expr(:function), "", Expr(:function)))
l = length(funcStack)
# parameterize the block
# solve for function statics
parameterizedBlock = parameterize(blockToInterpret, arguments)
# Print parameterizedBlock to a file
# prettyprintPB(sanitizedBlock)
funcStack[l] = pancake(func, name, parameterizedBlock, Expr(:function), "", Expr(:function))
# Create Data structure of wires created
# add wire instantiations when lacking
sanitizedBlock, arrowDict = sanitize(parameterizedBlock)
funcStack[l] = pancake(func, name, parameterizedBlock, sanitizedBlock, "", Expr(:function))
# Convert the block to a string of verilog text
verilogBlock = JuliogToVerilog(sanitizedBlock, arrowDict)
# Print verilogBlock to a file
# prettyprintJV(verilogBlock)
funcStack[l] = pancake(func, name, parameterizedBlock, sanitizedBlock, verilogBlock, Expr(:function))
#juliaBlock = JuliogToJulia(sanitizedBlock)
juliaBlock = Expr(:function)
# Print juliaBlock to a file
# prettyprintJB(juliaBlock)
#funcStack[l] = pancake(func, name, parameterizedBlock, sanitizedBlock, verilogBlock, juliaBlock)
println("At end of @block")
end
# TODO write a pretty print function for exprs
# TODO write a print to file for verilog