@@ -26,6 +26,17 @@ UhdmInfo = provider(
26
26
},
27
27
)
28
28
29
+ ExternalSynthesisInfo = provider (
30
+ "Surelog/UHDM based RTL representation" ,
31
+ fields = {
32
+ "env" : "Map of env variables" ,
33
+ "yosys_script" : "yosys script file" ,
34
+ "inputs" : "File inputs" ,
35
+ "verilog_files" : "Verilog Inputs" ,
36
+ "uhdm_files" : "UHDM files" ,
37
+ },
38
+ )
39
+
29
40
# Args:
30
41
# standard_cell_info: The StandardCellInfo provider this target was synthesized against.
31
42
# synthesized_netlist: The structural verilog syntheized with standard_cell_info
@@ -42,9 +53,12 @@ def _transitive_srcs(deps):
42
53
transitive = [dep [VerilogInfo ].dag for dep in deps ],
43
54
)
44
55
45
- def _create_flist (ctx , flist_tag , files ):
56
+ def _create_flist (ctx , flist_tag , files , short_path = False ):
46
57
flist = ctx .actions .declare_file ("{}_{}.flist" .format (flist_tag , ctx .attr .name ))
47
- ctx .actions .write (flist , "\n " .join ([f .path for f in files ]) + "\n " )
58
+ if short_path :
59
+ ctx .actions .write (flist , "\n " .join ([f .short_path for f in files ]) + "\n " )
60
+ else :
61
+ ctx .actions .write (flist , "\n " .join ([f .path for f in files ]) + "\n " )
48
62
return flist
49
63
50
64
def _synthesize_design_impl (ctx ):
@@ -80,6 +94,7 @@ def _synthesize_design_impl(ctx):
80
94
inputs .append (uhdm_flist )
81
95
inputs .extend (uhdm_files )
82
96
inputs .append (synth_tcl )
97
+ inputs .append (default_liberty_file )
83
98
84
99
(tool_inputs , input_manifests ) = ctx .resolve_tools (tools = [ctx .attr .yosys_tool ])
85
100
@@ -94,22 +109,31 @@ def _synthesize_design_impl(ctx):
94
109
args .add_all ("-l" , [log_file ]) # put output in log file
95
110
args .add_all ("-c" , [synth_tcl ]) # run synthesis tcl script
96
111
97
- env = {
98
- "FLIST" : verilog_flist . path ,
99
- "UHDM_FLIST" : uhdm_flist . path ,
112
+ script_env_files = {
113
+ "FLIST" : verilog_flist ,
114
+ "UHDM_FLIST" : uhdm_flist ,
100
115
"TOP" : ctx .attr .top_module ,
101
- "OUTPUT" : output_file .path ,
102
- "LIBERTY" : default_liberty_file .path ,
116
+ "OUTPUT" : output_file ,
117
+ "LIBERTY" : default_liberty_file ,
118
+ }
119
+
120
+ if ctx .attr .target_clock_period_pico_seconds :
121
+ script_env_files ["CLOCK_PERIOD" ] = str (ctx .attr .target_clock_period_pico_seconds )
122
+
123
+ env = {
103
124
"YOSYS_DATDIR" : yosys_runfiles_dir + "/at_clifford_yosys/techlibs/" ,
104
125
"ABC" : yosys_runfiles_dir + "/edu_berkeley_abc/abc" ,
105
126
}
106
127
107
- if ctx .attr .target_clock_period_pico_seconds :
108
- env ["CLOCK_PERIOD" ] = str (ctx .attr .target_clock_period_pico_seconds )
128
+ for k , v in script_env_files .items ():
129
+ if type (v ) == "File" :
130
+ env [k ] = v .path
131
+ else :
132
+ env [k ] = v
109
133
110
134
ctx .actions .run (
111
135
outputs = [output_file , log_file ],
112
- inputs = inputs + tool_inputs .to_list () + [ default_liberty_file ] ,
136
+ inputs = inputs + tool_inputs .to_list (),
113
137
arguments = [args ],
114
138
executable = ctx .executable .yosys_tool ,
115
139
tools = tool_inputs ,
@@ -129,8 +153,75 @@ def _synthesize_design_impl(ctx):
129
153
top_module = ctx .attr .top_module ,
130
154
log_file = log_file ,
131
155
),
156
+ ExternalSynthesisInfo (
157
+ env = script_env_files ,
158
+ yosys_script = synth_tcl ,
159
+ inputs = inputs ,
160
+ verilog_files = verilog_files ,
161
+ uhdm_files = uhdm_files ,
162
+ ),
132
163
]
133
164
165
+ def _synthesize_binary_impl (ctx ):
166
+ script = ""
167
+ external_info = ctx .attr .synthesize_rtl_rule [ExternalSynthesisInfo ]
168
+
169
+ env = dict (external_info .env )
170
+ env ["FLIST" ] = _create_flist (
171
+ ctx ,
172
+ flist_tag = "verilog" ,
173
+ files = external_info .verilog_files ,
174
+ short_path = True ,
175
+ )
176
+
177
+ env ["UHDM_FLIST" ] = _create_flist (
178
+ ctx ,
179
+ flist_tag = "uhdm" ,
180
+ files = external_info .uhdm_files ,
181
+ short_path = True ,
182
+ )
183
+
184
+ env ["OUTPUT" ] = "/tmp/{}.v" .format (ctx .attr .name )
185
+
186
+ script += "#!/bin/bash\n "
187
+
188
+ for k , v in env .items ():
189
+ script += "export {}='{}'\n " .format (k , v .short_path if type (v ) == "File" else v )
190
+
191
+ yosys_runfiles_dir = ctx .executable .yosys_tool .short_path + ".runfiles"
192
+
193
+ script += "export YOSYS_DATDIR='{}/at_clifford_yosys/techlibs/'\n " .format (yosys_runfiles_dir )
194
+ yosys = ctx .attr .yosys_tool [DefaultInfo ]
195
+ script += "${{PREFIX_COMMAND}} {} -c {}\n " .format (ctx .executable .yosys_tool .short_path , external_info .yosys_script .short_path )
196
+
197
+ binary = ctx .actions .declare_file ("{}_synth_binary.sh" .format (ctx .attr .name ))
198
+ ctx .actions .write (binary , script , is_executable = True )
199
+
200
+ return [
201
+ DefaultInfo (
202
+ executable = binary ,
203
+ runfiles = yosys .default_runfiles .merge_all (
204
+ [
205
+ ctx .runfiles (external_info .inputs ),
206
+ ctx .runfiles ([env ["UHDM_FLIST" ], env ["FLIST" ]]),
207
+ ],
208
+ ),
209
+ ),
210
+ ]
211
+
212
+ synthesis_binary = rule (
213
+ implementation = _synthesize_binary_impl ,
214
+ attrs = {
215
+ "synthesize_rtl_rule" : attr .label (providers = [ExternalSynthesisInfo ]),
216
+ "yosys_tool" : attr .label (
217
+ default = Label ("@at_clifford_yosys//:yosys" ),
218
+ executable = True ,
219
+ cfg = "target" ,
220
+ ),
221
+ },
222
+ executable = True ,
223
+ )
224
+
134
225
synthesize_rtl = rule (
135
226
implementation = _synthesize_design_impl ,
136
227
attrs = {
0 commit comments