aboutsummaryrefslogtreecommitdiff
path: root/src/main/stanza/compilers.stanza
blob: 3ca4f8da81b208772af2350a62d2857728ed8c69 (plain)
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
defpackage firrtl/compiler :
  import core
  import verse
  import firrtl/passes
  import firrtl/chirrtl
  import firrtl/errors
  ;import firrtl/flo
  ;import firrtl/verilog
  import firrtl/ir2
  import firrtl/ir-utils
  import firrtl/firrtl

;public defstruct StandardFlo <: Compiler :
;   with-output : (() -> False) -> False with: (as-method => true)
;public defmethod passes (c:StandardFlo) -> List<Pass> :
;   to-list $ [
;      RemoveSpecialChars()
;      RemoveScopes()
;      CheckHighForm()
;      ;; TempElimination()
;      ToWorkingIR()
;      ResolveKinds()
;      CheckKinds()
;      InferTypes()
;      CheckTypes()
;      ResolveGenders()
;      CheckGenders()
;      ExpandAccessors()
;      LowerToGround()
;      InlineIndexed()
;      ExpandWhens()
;      InferWidths()
;      Pad()
;      Inline()
;      SplitExp()
;      ToRealIR()
;      CheckWidths()
;      ;RemoveSpecialChars()
;      CheckHighForm()
;      CheckLowForm()
;      Flo(with-output(c))
;   ]

public defstruct StandardVerilog <: Compiler :
   with-output : (() -> False) -> False with: (as-method => true)
public defmethod backend (c:StandardVerilog) -> List<Pass> :
  to-list $ [ Verilog(with-output(c)) ]
public defmethod passes (c:StandardVerilog) -> List<Pass> :
   to-list $ [
      ;RemoveSpecialChars()     
      ;TempElimination()                 ; Needs to check number of uses
      ;===============
      CInferTypes()
      CInferMDir()
      RemoveCHIRRTL()            
      ;===============
      CheckHighForm()          
      ;===============
      ToWorkingIR()            
      ;===============
      ResolveKinds()
      InferTypes()
      CheckTypes()
      ResolveGenders()
      CheckGenders()
      InferWidths()
      CheckWidths()
      ;===============
      PullMuxes()
      ;===============
      ExpandConnects()
      ;===============
      RemoveAccesses()
      ;===============
      ExpandWhens()
      ;===============
      CheckInitialization()   
      ;===============
      ConstProp()
      ;===============
      SplitExp()
      ;===============
      ResolveKinds()
      InferTypes()
      CheckTypes()
      ResolveGenders()
      CheckGenders()
      InferWidths()
      CheckWidths()
      ;===============
      LowerTypes()
      ;===============
      ResolveKinds()
      InferTypes()
      CheckTypes()
      ResolveGenders()
      CheckGenders()
      InferWidths()
      CheckWidths()
      ;===============
      VerilogRename() 
      Verilog(with-output(c)) 
      ;===============
      ;ToRealIR()             
      ;Pad()                  
      ;CheckWidths()          
      ;CheckHighForm()        
      ;CheckLowForm()           
      ;Verilog(with-output(c)) 
   ]

public defstruct StandardFIRRTL <: Compiler :
   with-output : (() -> False) -> False with: (as-method => true)
public defmethod backend (c:StandardFIRRTL) -> List<Pass> :
  to-list $ [ FIRRTL(with-output(c)) ]
public defmethod passes (c:StandardFIRRTL) -> List<Pass> :
   to-list $ [
      CheckHighForm()
      FIRRTL(with-output(c))
    ]

public defstruct StandardLoFIRRTL <: Compiler :
   with-output : (() -> False) -> False with: (as-method => true)
public defmethod backend (c:StandardLoFIRRTL) -> List<Pass> :
  to-list $ [ FIRRTL(with-output(c)) ]
public defmethod passes (c:StandardLoFIRRTL) -> List<Pass> :
   to-list $ [
      ;===============
      RemoveCHIRRTL()            
      ;===============
      CheckHighForm()          
      ;===============
      ToWorkingIR()            
      ;===============
      ResolveKinds()           
      InferTypes()             
      CheckTypes()            
      ResolveGenders()         
      CheckGenders()          
      InferWidths()            
      CheckWidths()          
      ;===============
      Resolve()
      ;===============
      ExpandConnects()
      ;===============
      RemoveAccesses()
      ;===============
      ExpandWhens()
      ;===============
      CheckInitialization()   
      ;===============
      ConstProp()
      ;===============
      SplitExp()
      ;===============
      ResolveKinds()
      InferTypes()
      CheckTypes()
      ResolveGenders()
      CheckGenders()
      InferWidths()
      CheckWidths()
      ;===============
      LowerTypes()
      ;===============
      ResolveKinds()
      InferTypes()
      CheckTypes()
      ResolveGenders()
      CheckGenders()
      InferWidths()
      CheckWidths()
      ;===============
      FIRRTL(with-output(c))  
   ]

;============= DRIVER ======================================
public defn run-backend (c:Circuit,comp:Compiler) :
   run-passes(c,backend(comp))
public defn run-passes (c:Circuit,comp:Compiler) -> Circuit: 
   run-passes(c,passes(comp))
public defn run-passes (c:Circuit,ls:List<Pass>) -> Circuit:
   var c*:Circuit = c
   println("Compiling!")
   if PRINT-CIRCUITS : println("Original Circuit")
   if PRINT-CIRCUITS : print(c)
   ;val start-time = current-time-us()
   val start-time = to-int(to-string(current-time-us() / to-long(1000)))
   var t = start-time
   val time-table = Vector<[String,Int]>()
   for p in ls do : 
      println-all(["Starting " name(p)])
      if PRINT-CIRCUITS : println(name(p))
      c* = pass(p)(c*)
      if PRINT-CIRCUITS : print(c*)
      val current-time = to-int(to-string(current-time-us() / to-long(1000)))
      println-all(["Finished " name(p)])
      println-all(["Milliseconds since start: " current-time - start-time])
      println-all(["Milliseconds for this pass: " current-time - t])
      println-all(["\n"])
      ;println-all([current-time - t])
      add(time-table,[name(p), current-time - t])
      t = current-time

   println("===== Time Breakdown =====")
   for x in time-table do :
      println-all([x[0] " --- " to-float(x[1] as Int * 100) / to-float(t - start-time) "%" " --- " to-float(x[1] as Int * 100) "ms"])
   println-all(["Total Time --- " to-float(t - start-time) "ms"])
   println("==========================")
   println("Done!")
   c*