2 * yosys -- Yosys Open SYnthesis Suite
4 * Copyright (C) 2012 Clifford Wolf <clifford@clifford.at>
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 * This is the AST frontend library.
22 * The AST frontend library is not a frontend on it's own but provides a
23 * generic abstract syntax tree (AST) abstraction for HDL code and can be
24 * used by HDL frontends. See "ast.h" for an overview of the API and the
25 * Verilog frontend for an usage example.
29 #include "kernel/log.h"
30 #include "libs/sha1/sha1.h"
39 using namespace AST_INTERNAL
;
41 // helper function for creating RTLIL code for unary operations
42 static RTLIL::SigSpec
uniop2rtlil(AstNode
*that
, std::string type
, int result_width
, const RTLIL::SigSpec
&arg
, bool gen_attributes
= true)
44 std::stringstream sstr
;
45 sstr
<< type
<< "$" << that
->filename
<< ":" << that
->linenum
<< "$" << (RTLIL::autoidx
++);
47 RTLIL::Cell
*cell
= new RTLIL::Cell
;
48 cell
->attributes
["\\src"] = stringf("%s:%d", that
->filename
.c_str(), that
->linenum
);
49 cell
->name
= sstr
.str();
51 current_module
->cells
[cell
->name
] = cell
;
53 RTLIL::Wire
*wire
= new RTLIL::Wire
;
54 wire
->attributes
["\\src"] = stringf("%s:%d", that
->filename
.c_str(), that
->linenum
);
55 wire
->name
= cell
->name
+ "_Y";
56 wire
->width
= result_width
;
57 current_module
->wires
[wire
->name
] = wire
;
59 RTLIL::SigChunk chunk
;
61 chunk
.width
= wire
->width
;
65 sig
.chunks
.push_back(chunk
);
66 sig
.width
= chunk
.width
;
69 for (auto &attr
: that
->attributes
) {
70 if (attr
.second
->type
!= AST_CONSTANT
)
71 log_error("Attribute `%s' with non-constant value at %s:%d!\n",
72 attr
.first
.c_str(), that
->filename
.c_str(), that
->linenum
);
73 cell
->attributes
[attr
.first
].str
= attr
.second
->str
;
74 cell
->attributes
[attr
.first
].bits
= attr
.second
->bits
;
77 cell
->parameters
["\\A_SIGNED"] = RTLIL::Const(that
->children
[0]->is_signed
);
78 cell
->parameters
["\\A_WIDTH"] = RTLIL::Const(arg
.width
);
79 cell
->connections
["\\A"] = arg
;
81 cell
->parameters
["\\Y_WIDTH"] = result_width
;
82 cell
->connections
["\\Y"] = sig
;
86 // helper function for creating RTLIL code for binary operations
87 static RTLIL::SigSpec
binop2rtlil(AstNode
*that
, std::string type
, int result_width
, const RTLIL::SigSpec
&left
, const RTLIL::SigSpec
&right
)
89 std::stringstream sstr
;
90 sstr
<< type
<< "$" << that
->filename
<< ":" << that
->linenum
<< "$" << (RTLIL::autoidx
++);
92 RTLIL::Cell
*cell
= new RTLIL::Cell
;
93 cell
->attributes
["\\src"] = stringf("%s:%d", that
->filename
.c_str(), that
->linenum
);
94 cell
->name
= sstr
.str();
96 current_module
->cells
[cell
->name
] = cell
;
98 RTLIL::Wire
*wire
= new RTLIL::Wire
;
99 wire
->attributes
["\\src"] = stringf("%s:%d", that
->filename
.c_str(), that
->linenum
);
100 wire
->name
= cell
->name
+ "_Y";
101 wire
->width
= result_width
;
102 current_module
->wires
[wire
->name
] = wire
;
104 RTLIL::SigChunk chunk
;
106 chunk
.width
= wire
->width
;
110 sig
.chunks
.push_back(chunk
);
111 sig
.width
= chunk
.width
;
113 for (auto &attr
: that
->attributes
) {
114 if (attr
.second
->type
!= AST_CONSTANT
)
115 log_error("Attribute `%s' with non-constant value at %s:%d!\n",
116 attr
.first
.c_str(), that
->filename
.c_str(), that
->linenum
);
117 cell
->attributes
[attr
.first
].str
= attr
.second
->str
;
118 cell
->attributes
[attr
.first
].bits
= attr
.second
->bits
;
121 cell
->parameters
["\\A_SIGNED"] = RTLIL::Const(that
->children
[0]->is_signed
);
122 cell
->parameters
["\\B_SIGNED"] = RTLIL::Const(that
->children
[1]->is_signed
);
124 cell
->parameters
["\\A_WIDTH"] = RTLIL::Const(left
.width
);
125 cell
->parameters
["\\B_WIDTH"] = RTLIL::Const(right
.width
);
127 cell
->connections
["\\A"] = left
;
128 cell
->connections
["\\B"] = right
;
130 cell
->parameters
["\\Y_WIDTH"] = result_width
;
131 cell
->connections
["\\Y"] = sig
;
135 // helper function for creating RTLIL code for multiplexers
136 static RTLIL::SigSpec
mux2rtlil(AstNode
*that
, const RTLIL::SigSpec
&cond
, const RTLIL::SigSpec
&left
, const RTLIL::SigSpec
&right
)
138 assert(cond
.width
== 1);
140 std::stringstream sstr
;
141 sstr
<< "$ternary$" << that
->filename
<< ":" << that
->linenum
<< "$" << (RTLIL::autoidx
++);
143 RTLIL::Cell
*cell
= new RTLIL::Cell
;
144 cell
->attributes
["\\src"] = stringf("%s:%d", that
->filename
.c_str(), that
->linenum
);
145 cell
->name
= sstr
.str();
147 current_module
->cells
[cell
->name
] = cell
;
149 RTLIL::Wire
*wire
= new RTLIL::Wire
;
150 wire
->attributes
["\\src"] = stringf("%s:%d", that
->filename
.c_str(), that
->linenum
);
151 wire
->name
= cell
->name
+ "_Y";
152 wire
->width
= left
.width
;
153 current_module
->wires
[wire
->name
] = wire
;
155 RTLIL::SigChunk chunk
;
157 chunk
.width
= wire
->width
;
161 sig
.chunks
.push_back(chunk
);
162 sig
.width
= chunk
.width
;
164 for (auto &attr
: that
->attributes
) {
165 if (attr
.second
->type
!= AST_CONSTANT
)
166 log_error("Attribute `%s' with non-constant value at %s:%d!\n",
167 attr
.first
.c_str(), that
->filename
.c_str(), that
->linenum
);
168 cell
->attributes
[attr
.first
].str
= attr
.second
->str
;
169 cell
->attributes
[attr
.first
].bits
= attr
.second
->bits
;
172 cell
->parameters
["\\WIDTH"] = RTLIL::Const(left
.width
);
174 cell
->connections
["\\A"] = right
;
175 cell
->connections
["\\B"] = left
;
176 cell
->connections
["\\S"] = cond
;
177 cell
->connections
["\\Y"] = sig
;
182 // helper class for converting AST always nodes to RTLIL processes
183 struct AST_INTERNAL::ProcessGenerator
185 // input and output structures
187 RTLIL::SigSpec skipSyncSignals
;
188 RTLIL::Process
*proc
;
189 const RTLIL::SigSpec
&outputSignals
;
191 // This always points to the RTLIL::CaseRule beeing filled at the moment
192 RTLIL::CaseRule
*current_case
;
194 // This two variables contain the replacement pattern to be used in the right hand side
195 // of an assignment. E.g. in the code "foo = bar; foo = func(foo);" the foo in the right
196 // hand side of the 2nd assignment needs to be replace with the temporary signal holding
197 // the value assigned in the first assignment. So when the first assignement is processed
198 // the according information is appended to subst_rvalue_from and subst_rvalue_to.
199 RTLIL::SigSpec subst_rvalue_from
, subst_rvalue_to
;
201 // This two variables contain the replacement pattern to be used in the left hand side
202 // of an assignment. E.g. in the code "always @(posedge clk) foo <= bar" the signal bar
203 // should not be connected to the signal foo. Instead it must be connected to the temporary
204 // signal that is used as input for the register that drives the signal foo.
205 RTLIL::SigSpec subst_lvalue_from
, subst_lvalue_to
;
207 // The code here generates a number of temprorary signal for each output register. This
208 // map helps generating nice numbered names for all this temporary signals.
209 std::map
<RTLIL::Wire
*, int> new_temp_count
;
211 ProcessGenerator(AstNode
*always
, RTLIL::SigSpec skipSyncSignalsArg
= RTLIL::SigSpec()) : always(always
), skipSyncSignals(skipSyncSignalsArg
), outputSignals(subst_lvalue_from
)
213 // generate process and simple root case
214 proc
= new RTLIL::Process
;
215 proc
->name
= stringf("$proc$%s:%d$%d", always
->filename
.c_str(), always
->linenum
, RTLIL::autoidx
++);
216 for (auto &attr
: always
->attributes
) {
217 if (attr
.second
->type
!= AST_CONSTANT
)
218 log_error("Attribute `%s' with non-constant value at %s:%d!\n",
219 attr
.first
.c_str(), always
->filename
.c_str(), always
->linenum
);
220 proc
->attributes
[attr
.first
].str
= attr
.second
->str
;
221 proc
->attributes
[attr
.first
].bits
= attr
.second
->bits
;
223 current_module
->processes
[proc
->name
] = proc
;
224 current_case
= &proc
->root_case
;
226 // create initial temporary signal for all output registers
227 collect_lvalues(subst_lvalue_from
, always
, true, true);
228 subst_lvalue_to
= new_temp_signal(subst_lvalue_from
);
230 bool found_anyedge_syncs
= false;
231 for (auto child
: always
->children
)
232 if (child
->type
== AST_EDGE
)
233 found_anyedge_syncs
= true;
235 if (found_anyedge_syncs
) {
236 log("Note: Assuming pure combinatorial block at %s:%d in\n", always
->filename
.c_str(), always
->linenum
);
237 log("compliance with IEC 62142(E):2005 / IEEE Std. 1364.1(E):2002. Recommending\n");
238 log("use of @* instead of @(...) for better match of synthesis and simulation.\n");
241 // create syncs for the process
242 bool found_clocked_sync
= false;
243 for (auto child
: always
->children
)
244 if (child
->type
== AST_POSEDGE
|| child
->type
== AST_NEGEDGE
) {
245 found_clocked_sync
= true;
246 if (found_anyedge_syncs
)
247 log_error("Found non-synthesizable event list at %s:%d!\n", always
->filename
.c_str(), always
->linenum
);
248 RTLIL::SyncRule
*syncrule
= new RTLIL::SyncRule
;
249 syncrule
->type
= child
->type
== AST_POSEDGE
? RTLIL::STp
: RTLIL::STn
;
250 syncrule
->signal
= child
->children
[0]->genRTLIL();
251 addChunkActions(syncrule
->actions
, subst_lvalue_from
, subst_lvalue_to
, true);
252 proc
->syncs
.push_back(syncrule
);
254 if (proc
->syncs
.empty()) {
255 RTLIL::SyncRule
*syncrule
= new RTLIL::SyncRule
;
256 syncrule
->type
= RTLIL::STa
;
257 syncrule
->signal
= RTLIL::SigSpec();
258 addChunkActions(syncrule
->actions
, subst_lvalue_from
, subst_lvalue_to
, true);
259 proc
->syncs
.push_back(syncrule
);
262 // create initial assignments for the temporary signals
263 if ((flag_nolatches
|| always
->attributes
.count("\\nolatches") > 0 || current_module
->attributes
.count("\\nolatches")) && !found_clocked_sync
) {
264 subst_rvalue_from
= subst_lvalue_from
;
265 subst_rvalue_to
= RTLIL::SigSpec(RTLIL::State::Sx
, subst_rvalue_from
.width
);
267 addChunkActions(current_case
->actions
, subst_lvalue_to
, subst_lvalue_from
);
271 for (auto child
: always
->children
)
272 if (child
->type
== AST_BLOCK
)
276 // create new temporary signals
277 RTLIL::SigSpec
new_temp_signal(RTLIL::SigSpec sig
)
280 for (size_t i
= 0; i
< sig
.chunks
.size(); i
++)
282 RTLIL::SigChunk
&chunk
= sig
.chunks
[i
];
283 if (chunk
.wire
== NULL
)
286 RTLIL::Wire
*wire
= new RTLIL::Wire
;
287 wire
->attributes
["\\src"] = stringf("%s:%d", always
->filename
.c_str(), always
->linenum
);
289 wire
->name
= stringf("$%d%s[%d:%d]", new_temp_count
[chunk
.wire
]++,
290 chunk
.wire
->name
.c_str(), chunk
.width
+chunk
.offset
-1, chunk
.offset
);;
291 } while (current_module
->wires
.count(wire
->name
) > 0);
292 wire
->width
= chunk
.width
;
293 current_module
->wires
[wire
->name
] = wire
;
301 // recursively traverse the AST an collect all assigned signals
302 void collect_lvalues(RTLIL::SigSpec
®
, AstNode
*ast
, bool type_eq
, bool type_le
, bool run_sort_and_unify
= true)
307 for (auto child
: ast
->children
)
308 if (child
!= ast
->children
[0]) {
309 assert(child
->type
== AST_COND
);
310 collect_lvalues(reg
, child
, type_eq
, type_le
, false);
317 for (auto child
: ast
->children
)
318 if (child
->type
== AST_BLOCK
)
319 collect_lvalues(reg
, child
, type_eq
, type_le
, false);
323 for (auto child
: ast
->children
) {
324 if (child
->type
== AST_ASSIGN_EQ
&& type_eq
)
325 reg
.append(child
->children
[0]->genRTLIL());
326 if (child
->type
== AST_ASSIGN_LE
&& type_le
)
327 reg
.append(child
->children
[0]->genRTLIL());
328 if (child
->type
== AST_CASE
|| child
->type
== AST_BLOCK
)
329 collect_lvalues(reg
, child
, type_eq
, type_le
, false);
337 if (run_sort_and_unify
)
338 reg
.sort_and_unify();
341 // remove all assignments to the given signal pattern in a case and all its children.
342 // e.g. when the last statement in the code "a = 23; if (b) a = 42; a = 0;" is processed this
343 // function is called to clean up the first two assignments as they are overwritten by
344 // the third assignment.
345 void removeSignalFromCaseTree(RTLIL::SigSpec pattern
, RTLIL::CaseRule
*cs
)
347 for (auto it
= cs
->actions
.begin(); it
!= cs
->actions
.end(); it
++)
348 it
->first
.remove2(pattern
, &it
->second
);
350 for (auto it
= cs
->switches
.begin(); it
!= cs
->switches
.end(); it
++)
351 for (auto it2
= (*it
)->cases
.begin(); it2
!= (*it
)->cases
.end(); it2
++)
352 removeSignalFromCaseTree(pattern
, *it2
);
355 // add an assignment (aka "action") but split it up in chunks. this way huge assignments
356 // are avoided and the generated $mux cells have a more "natural" size.
357 void addChunkActions(std::vector
<RTLIL::SigSig
> &actions
, RTLIL::SigSpec lvalue
, RTLIL::SigSpec rvalue
, bool inSyncRule
= false)
360 lvalue
.remove2(skipSyncSignals
, &rvalue
);
361 assert(lvalue
.width
== rvalue
.width
);
366 for (size_t i
= 0; i
< lvalue
.chunks
.size(); i
++) {
367 RTLIL::SigSpec lhs
= lvalue
.chunks
[i
];
368 RTLIL::SigSpec rhs
= rvalue
.extract(offset
, lvalue
.chunks
[i
].width
);
369 if (inSyncRule
&& lvalue
.chunks
[i
].wire
&& lvalue
.chunks
[i
].wire
->attributes
.count("\\nosync"))
370 rhs
= RTLIL::SigSpec(RTLIL::State::Sx
, rhs
.width
);
371 actions
.push_back(RTLIL::SigSig(lhs
, rhs
));
376 // recursively process the AST and fill the RTLIL::Process
377 void processAst(AstNode
*ast
)
382 for (auto child
: ast
->children
)
389 RTLIL::SigSpec unmapped_lvalue
= ast
->children
[0]->genRTLIL(), lvalue
= unmapped_lvalue
;
390 RTLIL::SigSpec rvalue
= ast
->children
[1]->genWidthRTLIL(lvalue
.width
, &subst_rvalue_from
, &subst_rvalue_to
);
391 lvalue
.replace(subst_lvalue_from
, subst_lvalue_to
);
393 if (ast
->type
== AST_ASSIGN_EQ
) {
394 subst_rvalue_from
.remove2(unmapped_lvalue
, &subst_rvalue_to
);
395 subst_rvalue_from
.append(unmapped_lvalue
);
396 subst_rvalue_from
.optimize();
397 subst_rvalue_to
.append(rvalue
);
398 subst_rvalue_to
.optimize();
401 removeSignalFromCaseTree(lvalue
, current_case
);
402 current_case
->actions
.push_back(RTLIL::SigSig(lvalue
, rvalue
));
408 RTLIL::SwitchRule
*sw
= new RTLIL::SwitchRule
;
409 sw
->signal
= ast
->children
[0]->genWidthRTLIL(-1, &subst_rvalue_from
, &subst_rvalue_to
);
410 current_case
->switches
.push_back(sw
);
412 for (auto &attr
: ast
->attributes
) {
413 if (attr
.second
->type
!= AST_CONSTANT
)
414 log_error("Attribute `%s' with non-constant value at %s:%d!\n",
415 attr
.first
.c_str(), ast
->filename
.c_str(), ast
->linenum
);
416 sw
->attributes
[attr
.first
].str
= attr
.second
->str
;
417 sw
->attributes
[attr
.first
].bits
= attr
.second
->bits
;
420 RTLIL::SigSpec this_case_eq_lvalue
;
421 collect_lvalues(this_case_eq_lvalue
, ast
, true, false);
423 RTLIL::SigSpec this_case_eq_ltemp
= new_temp_signal(this_case_eq_lvalue
);
425 RTLIL::SigSpec this_case_eq_rvalue
= this_case_eq_lvalue
;
426 this_case_eq_rvalue
.replace(subst_rvalue_from
, subst_rvalue_to
);
428 RTLIL::SigSpec backup_subst_lvalue_from
= subst_lvalue_from
;
429 RTLIL::SigSpec backup_subst_lvalue_to
= subst_lvalue_to
;
431 RTLIL::SigSpec backup_subst_rvalue_from
= subst_rvalue_from
;
432 RTLIL::SigSpec backup_subst_rvalue_to
= subst_rvalue_to
;
434 bool generated_default_case
= false;
435 RTLIL::CaseRule
*last_generated_case
= NULL
;
436 for (auto child
: ast
->children
)
438 if (child
== ast
->children
[0] || generated_default_case
)
440 assert(child
->type
== AST_COND
);
442 subst_lvalue_from
= backup_subst_lvalue_from
;
443 subst_lvalue_to
= backup_subst_lvalue_to
;
445 subst_rvalue_from
= backup_subst_rvalue_from
;
446 subst_rvalue_to
= backup_subst_rvalue_to
;
448 subst_lvalue_from
.remove2(this_case_eq_lvalue
, &subst_lvalue_to
);
449 subst_lvalue_from
.append(this_case_eq_lvalue
);
450 subst_lvalue_from
.optimize();
451 subst_lvalue_to
.append(this_case_eq_ltemp
);
452 subst_lvalue_to
.optimize();
454 RTLIL::CaseRule
*backup_case
= current_case
;
455 current_case
= new RTLIL::CaseRule
;
456 last_generated_case
= current_case
;
457 addChunkActions(current_case
->actions
, this_case_eq_ltemp
, this_case_eq_rvalue
);
458 for (auto node
: child
->children
) {
459 if (node
->type
== AST_DEFAULT
) {
460 generated_default_case
= true;
461 current_case
->compare
.clear();
462 } else if (node
->type
== AST_BLOCK
) {
464 } else if (!generated_default_case
)
465 current_case
->compare
.push_back(node
->genWidthRTLIL(sw
->signal
.width
, &subst_rvalue_from
, &subst_rvalue_to
));
467 sw
->cases
.push_back(current_case
);
468 current_case
= backup_case
;
471 if (last_generated_case
!= NULL
&& ast
->attributes
.count("\\full_case") > 0) {
472 last_generated_case
->compare
.clear();
473 } else if (!generated_default_case
) {
474 RTLIL::CaseRule
*default_case
= new RTLIL::CaseRule
;
475 addChunkActions(default_case
->actions
, this_case_eq_ltemp
, this_case_eq_rvalue
);
476 sw
->cases
.push_back(default_case
);
479 subst_lvalue_from
= backup_subst_lvalue_from
;
480 subst_lvalue_to
= backup_subst_lvalue_to
;
482 subst_rvalue_from
= backup_subst_rvalue_from
;
483 subst_rvalue_to
= backup_subst_rvalue_to
;
485 subst_rvalue_from
.remove2(this_case_eq_lvalue
, &subst_rvalue_to
);
486 subst_rvalue_from
.append(this_case_eq_lvalue
);
487 subst_rvalue_from
.optimize();
488 subst_rvalue_to
.append(this_case_eq_ltemp
);
489 subst_rvalue_to
.optimize();
491 this_case_eq_lvalue
.replace(subst_lvalue_from
, subst_lvalue_to
);
492 removeSignalFromCaseTree(this_case_eq_lvalue
, current_case
);
493 addChunkActions(current_case
->actions
, this_case_eq_lvalue
, this_case_eq_ltemp
);
507 // detect sign and width of an expression
508 void AstNode::detectSignWidthWorker(int &width_hint
, bool &sign_hint
)
510 std::string type_name
;
511 bool dummy_sign_hint
= true;
512 // int dummy_width_hint = -1;
517 width_hint
= std::max(width_hint
, int(bits
.size()));
523 if ((id2ast
&& !id2ast
->is_signed
) || children
.size() > 0)
525 width_hint
= std::max(width_hint
, genRTLIL().width
);
529 children
.at(0)->detectSignWidthWorker(width_hint
, dummy_sign_hint
);
532 case AST_TO_UNSIGNED
:
533 children
.at(0)->detectSignWidthWorker(width_hint
, dummy_sign_hint
);
539 width_hint
= std::max(width_hint
, genRTLIL().width
);
546 children
[0]->detectSignWidthWorker(width_hint
, sign_hint
);
553 for (auto child
: children
)
554 child
->detectSignWidthWorker(width_hint
, sign_hint
);
560 case AST_REDUCE_XNOR
:
561 case AST_REDUCE_BOOL
:
562 width_hint
= std::max(width_hint
, 1);
567 case AST_SHIFT_RIGHT
:
568 case AST_SHIFT_SLEFT
:
569 case AST_SHIFT_SRIGHT
:
570 children
[0]->detectSignWidthWorker(width_hint
, sign_hint
);
579 width_hint
= std::max(width_hint
, 1);
589 for (auto child
: children
)
590 child
->detectSignWidthWorker(width_hint
, sign_hint
);
596 width_hint
= std::max(width_hint
, 1);
601 children
.at(1)->detectSignWidthWorker(width_hint
, sign_hint
);
602 children
.at(2)->detectSignWidthWorker(width_hint
, sign_hint
);
608 width_hint
= std::max(width_hint
, current_module
->memories
.at(str
)->width
);
611 // everything should have been handled above -> print error if not.
613 for (auto f
: log_files
)
614 current_ast
->dumpAst(f
, "verilog-ast> ");
615 log_error("Don't know how to detect sign and width for %s node at %s:%d!\n",
616 type2str(type
).c_str(), filename
.c_str(), linenum
);
620 // detect sign and width of an expression
621 void AstNode::detectSignWidth(int &width_hint
, bool &sign_hint
)
623 width_hint
= -1, sign_hint
= true;
624 detectSignWidthWorker(width_hint
, sign_hint
);
627 // create RTLIL from an AST node
628 // all generated cells, wires and processes are added to the module pointed to by 'current_module'
629 // when the AST node is an expression (AST_ADD, AST_BIT_XOR, etc.), the result signal is returned.
631 // note that this function is influenced by a number of global variables that might be set when
632 // called from genWidthRTLIL(). also note that this function recursively calls itself to transform
633 // larger expressions into a netlist of cells.
634 RTLIL::SigSpec
AstNode::genRTLIL(int width_hint
, bool sign_hint
)
636 // in the following big switch() statement there are some uses of
637 // Clifford's Device (http://www.clifford.at/cfun/cliffdev/). In this
638 // cases this variable is used to hold the type of the cell that should
639 // be instanciated for this type of AST node.
640 std::string type_name
;
642 current_filename
= filename
;
643 set_line_num(linenum
);
647 // simply ignore this nodes.
648 // they are eighter leftovers from simplify() or are referenced by other nodes
649 // and are only accessed here thru this references
662 // create an RTLIL::Wire for an AST_WIRE node
664 if (current_module
->wires
.count(str
) != 0)
665 log_error("Re-definition of signal `%s' at %s:%d!\n",
666 str
.c_str(), filename
.c_str(), linenum
);
668 log_error("Signal `%s' with non-constant width at %s:%d!\n",
669 str
.c_str(), filename
.c_str(), linenum
);
671 if (range_left
< range_right
&& (range_left
!= -1 || range_right
!= 0)) {
672 int tmp
= range_left
;
673 range_left
= range_right
;
677 RTLIL::Wire
*wire
= new RTLIL::Wire
;
678 wire
->attributes
["\\src"] = stringf("%s:%d", filename
.c_str(), linenum
);
680 wire
->width
= range_left
- range_right
+ 1;
681 wire
->start_offset
= range_right
;
682 wire
->port_id
= port_id
;
683 wire
->port_input
= is_input
;
684 wire
->port_output
= is_output
;
685 current_module
->wires
[wire
->name
] = wire
;
687 for (auto &attr
: attributes
) {
688 if (attr
.second
->type
!= AST_CONSTANT
)
689 log_error("Attribute `%s' with non-constant value at %s:%d!\n",
690 attr
.first
.c_str(), filename
.c_str(), linenum
);
691 wire
->attributes
[attr
.first
].str
= attr
.second
->str
;
692 wire
->attributes
[attr
.first
].bits
= attr
.second
->bits
;
697 // create an RTLIL::Memory for an AST_MEMORY node
699 if (current_module
->memories
.count(str
) != 0)
700 log_error("Re-definition of memory `%s' at %s:%d!\n",
701 str
.c_str(), filename
.c_str(), linenum
);
703 assert(children
.size() >= 2);
704 assert(children
[0]->type
== AST_RANGE
);
705 assert(children
[1]->type
== AST_RANGE
);
707 if (!children
[0]->range_valid
|| !children
[1]->range_valid
)
708 log_error("Memory `%s' with non-constant width or size at %s:%d!\n",
709 str
.c_str(), filename
.c_str(), linenum
);
711 RTLIL::Memory
*memory
= new RTLIL::Memory
;
712 memory
->attributes
["\\src"] = stringf("%s:%d", filename
.c_str(), linenum
);
714 memory
->width
= children
[0]->range_left
- children
[0]->range_right
+ 1;
715 memory
->start_offset
= children
[0]->range_right
;
716 memory
->size
= children
[1]->range_left
- children
[1]->range_right
;
717 current_module
->memories
[memory
->name
] = memory
;
719 if (memory
->size
< 0)
721 memory
->size
+= std::min(children
[1]->range_left
, children
[1]->range_right
) + 1;
723 for (auto &attr
: attributes
) {
724 if (attr
.second
->type
!= AST_CONSTANT
)
725 log_error("Attribute `%s' with non-constant value at %s:%d!\n",
726 attr
.first
.c_str(), filename
.c_str(), linenum
);
727 memory
->attributes
[attr
.first
].str
= attr
.second
->str
;
728 memory
->attributes
[attr
.first
].bits
= attr
.second
->bits
;
733 // simply return the corresponding RTLIL::SigSpec for an AST_CONSTANT node
737 detectSignWidth(width_hint
, sign_hint
);
739 RTLIL::SigChunk chunk
;
741 chunk
.data
.bits
= bits
;
742 chunk
.width
= bits
.size();
746 sig
.chunks
.push_back(chunk
);
747 sig
.width
= chunk
.width
;
749 is_signed
= sign_hint
;
753 // simply return the corresponding RTLIL::SigSpec for an AST_IDENTIFIER node
754 // for identifiers with dynamic bit ranges (e.g. "foo[bar]" or "foo[bar+3:bar]") a
755 // shifter cell is created and the output signal of this cell is returned
758 RTLIL::Wire
*wire
= NULL
;
759 RTLIL::SigChunk chunk
;
761 if (id2ast
&& id2ast
->type
== AST_AUTOWIRE
&& current_module
->wires
.count(str
) == 0) {
762 RTLIL::Wire
*wire
= new RTLIL::Wire
;
763 wire
->attributes
["\\src"] = stringf("%s:%d", filename
.c_str(), linenum
);
765 if (width_hint
>= 0) {
766 wire
->width
= width_hint
;
767 log("Warning: Identifier `%s' is implicitly declared with width %d at %s:%d.\n",
768 str
.c_str(), width_hint
, filename
.c_str(), linenum
);
770 log("Warning: Identifier `%s' is implicitly declared at %s:%d.\n",
771 str
.c_str(), filename
.c_str(), linenum
);
773 wire
->auto_width
= true;
774 current_module
->wires
[str
] = wire
;
776 else if (id2ast
->type
== AST_PARAMETER
|| id2ast
->type
== AST_LOCALPARAM
) {
777 chunk
= RTLIL::Const(id2ast
->children
[0]->bits
);
778 goto use_const_chunk
;
780 else if (!id2ast
|| (id2ast
->type
!= AST_WIRE
&& id2ast
->type
!= AST_AUTOWIRE
&&
781 id2ast
->type
!= AST_MEMORY
) || current_module
->wires
.count(str
) == 0)
782 log_error("Identifier `%s' doesn't map to any signal at %s:%d!\n",
783 str
.c_str(), filename
.c_str(), linenum
);
785 if (id2ast
->type
== AST_MEMORY
)
786 log_error("Identifier `%s' does map to an unexpanded memory at %s:%d!\n",
787 str
.c_str(), filename
.c_str(), linenum
);
789 wire
= current_module
->wires
[str
];
791 chunk
.width
= wire
->width
;
795 if (children
.size() != 0) {
796 assert(children
[0]->type
== AST_RANGE
);
797 if (!children
[0]->range_valid
) {
798 AstNode
*left_at_zero_ast
= children
[0]->children
[0]->clone();
799 AstNode
*right_at_zero_ast
= children
[0]->children
.size() >= 2 ? children
[0]->children
[1]->clone() : left_at_zero_ast
->clone();
800 while (left_at_zero_ast
->simplify(true, true, false, 1)) { }
801 while (right_at_zero_ast
->simplify(true, true, false, 1)) { }
802 if (left_at_zero_ast
->type
!= AST_CONSTANT
|| right_at_zero_ast
->type
!= AST_CONSTANT
)
803 log_error("Unsupported expression on dynamic range select on signal `%s' at %s:%d!\n",
804 str
.c_str(), filename
.c_str(), linenum
);
805 int width
= left_at_zero_ast
->integer
- right_at_zero_ast
->integer
+ 1;
806 AstNode
*fake_ast
= new AstNode(AST_NONE
, clone(), children
[0]->children
.size() >= 2 ?
807 children
[0]->children
[1]->clone() : children
[0]->children
[0]->clone());
808 fake_ast
->children
[0]->delete_children();
809 RTLIL::SigSpec sig
= binop2rtlil(fake_ast
, "$shr", width
,
810 fake_ast
->children
[0]->genRTLIL(), fake_ast
->children
[1]->genRTLIL());
811 delete left_at_zero_ast
;
812 delete right_at_zero_ast
;
816 chunk
.offset
= children
[0]->range_right
- id2ast
->range_right
;
817 chunk
.width
= children
[0]->range_left
- children
[0]->range_right
+ 1;
818 if (children
[0]->range_left
> id2ast
->range_left
|| id2ast
->range_right
> children
[0]->range_right
)
819 log_error("Range select out of bounds on signal `%s' at %s:%d!\n",
820 str
.c_str(), filename
.c_str(), linenum
);
825 sig
.chunks
.push_back(chunk
);
826 sig
.width
= chunk
.width
;
828 if (genRTLIL_subst_from
&& genRTLIL_subst_to
)
829 sig
.replace(*genRTLIL_subst_from
, *genRTLIL_subst_to
);
831 is_signed
= children
.size() > 0 ? false : id2ast
->is_signed
&& sign_hint
;
835 // just pass thru the signal. the parent will evaluated the is_signed property and inperpret the SigSpec accordingly
837 case AST_TO_UNSIGNED
: {
838 RTLIL::SigSpec sig
= children
[0]->genRTLIL();
839 is_signed
= sign_hint
;
843 // concatenation of signals can be done directly using RTLIL::SigSpec
847 for (auto it
= children
.begin(); it
!= children
.end(); it
++) {
848 RTLIL::SigSpec s
= (*it
)->genRTLIL();
849 for (size_t i
= 0; i
< s
.chunks
.size(); i
++) {
850 sig
.chunks
.push_back(s
.chunks
[i
]);
851 sig
.width
+= s
.chunks
[i
].width
;
857 // replication of signals can be done directly using RTLIL::SigSpec
858 case AST_REPLICATE
: {
859 RTLIL::SigSpec left
= children
[0]->genRTLIL();
860 RTLIL::SigSpec right
= children
[1]->genRTLIL();
861 if (!left
.is_fully_const())
862 log_error("Left operand of replicate expression is not constant at %s:%d!\n", filename
.c_str(), linenum
);
863 int count
= left
.as_int();
865 for (int i
= 0; i
< count
; i
++)
871 // generate cells for unary operations: $not, $pos, $neg
872 if (0) { case AST_BIT_NOT
: type_name
= "$not"; }
873 if (0) { case AST_POS
: type_name
= "$pos"; }
874 if (0) { case AST_NEG
: type_name
= "$neg"; }
876 RTLIL::SigSpec arg
= children
[0]->genRTLIL(width_hint
, sign_hint
);
877 is_signed
= children
[0]->is_signed
;
878 int width
= arg
.width
;
879 if (width_hint
> 0) {
881 arg
.extend(width
, is_signed
);
883 return uniop2rtlil(this, type_name
, width
, arg
);
886 // generate cells for binary operations: $and, $or, $xor, $xnor
887 if (0) { case AST_BIT_AND
: type_name
= "$and"; }
888 if (0) { case AST_BIT_OR
: type_name
= "$or"; }
889 if (0) { case AST_BIT_XOR
: type_name
= "$xor"; }
890 if (0) { case AST_BIT_XNOR
: type_name
= "$xnor"; }
893 detectSignWidth(width_hint
, sign_hint
);
894 RTLIL::SigSpec left
= children
[0]->genRTLIL(width_hint
, sign_hint
);
895 RTLIL::SigSpec right
= children
[1]->genRTLIL(width_hint
, sign_hint
);
896 int width
= std::max(left
.width
, right
.width
);
899 is_signed
= children
[0]->is_signed
&& children
[1]->is_signed
;
900 return binop2rtlil(this, type_name
, width
, left
, right
);
903 // generate cells for unary operations: $reduce_and, $reduce_or, $reduce_xor, $reduce_xnor
904 if (0) { case AST_REDUCE_AND
: type_name
= "$reduce_and"; }
905 if (0) { case AST_REDUCE_OR
: type_name
= "$reduce_or"; }
906 if (0) { case AST_REDUCE_XOR
: type_name
= "$reduce_xor"; }
907 if (0) { case AST_REDUCE_XNOR
: type_name
= "$reduce_xnor"; }
909 RTLIL::SigSpec arg
= children
[0]->genRTLIL();
910 RTLIL::SigSpec sig
= uniop2rtlil(this, type_name
, 1, arg
);
914 // generate cells for unary operations: $reduce_bool
915 // (this is actually just an $reduce_or, but for clearity a different cell type is used)
916 if (0) { case AST_REDUCE_BOOL
: type_name
= "$reduce_bool"; }
918 RTLIL::SigSpec arg
= children
[0]->genRTLIL();
919 RTLIL::SigSpec sig
= arg
.width
> 1 ? uniop2rtlil(this, type_name
, 1, arg
) : arg
;
923 // generate cells for binary operations: $shl, $shr, $sshl, $sshr
924 if (0) { case AST_SHIFT_LEFT
: type_name
= "$shl"; }
925 if (0) { case AST_SHIFT_RIGHT
: type_name
= "$shr"; }
926 if (0) { case AST_SHIFT_SLEFT
: type_name
= "$sshl"; }
927 if (0) { case AST_SHIFT_SRIGHT
: type_name
= "$sshr"; }
930 detectSignWidth(width_hint
, sign_hint
);
931 RTLIL::SigSpec left
= children
[0]->genRTLIL(width_hint
, sign_hint
);
932 RTLIL::SigSpec right
= children
[1]->genRTLIL();
933 int width
= width_hint
> 0 ? width_hint
: left
.width
;
934 is_signed
= children
[0]->is_signed
;
935 return binop2rtlil(this, type_name
, width
, left
, right
);
938 // generate cells for binary operations: $lt, $le, $eq, $ne, $ge, $gt
939 if (0) { case AST_LT
: type_name
= "$lt"; }
940 if (0) { case AST_LE
: type_name
= "$le"; }
941 if (0) { case AST_EQ
: type_name
= "$eq"; }
942 if (0) { case AST_NE
: type_name
= "$ne"; }
943 if (0) { case AST_GE
: type_name
= "$ge"; }
944 if (0) { case AST_GT
: type_name
= "$gt"; }
946 width_hint
= -1, sign_hint
= true;
947 children
[0]->detectSignWidthWorker(width_hint
, sign_hint
);
948 children
[1]->detectSignWidthWorker(width_hint
, sign_hint
);
949 RTLIL::SigSpec left
= children
[0]->genRTLIL(width_hint
, sign_hint
);
950 RTLIL::SigSpec right
= children
[1]->genRTLIL(width_hint
, sign_hint
);
951 RTLIL::SigSpec sig
= binop2rtlil(this, type_name
, 1, left
, right
);
955 // generate cells for binary operations: $add, $sub, $mul, $div, $mod, $pow
956 if (0) { case AST_ADD
: type_name
= "$add"; }
957 if (0) { case AST_SUB
: type_name
= "$sub"; }
958 if (0) { case AST_MUL
: type_name
= "$mul"; }
959 if (0) { case AST_DIV
: type_name
= "$div"; }
960 if (0) { case AST_MOD
: type_name
= "$mod"; }
961 if (0) { case AST_POW
: type_name
= "$pow"; }
964 detectSignWidth(width_hint
, sign_hint
);
965 RTLIL::SigSpec left
= children
[0]->genRTLIL(width_hint
, sign_hint
);
966 RTLIL::SigSpec right
= children
[1]->genRTLIL(width_hint
, sign_hint
);
967 int width
= std::max(left
.width
, right
.width
);
968 if (width
> width_hint
&& width_hint
> 0)
970 if (width
< width_hint
) {
971 if (type
== AST_ADD
|| type
== AST_SUB
)
973 if (type
== AST_SUB
&& (!children
[0]->is_signed
|| !children
[1]->is_signed
))
976 width
= std::min(left
.width
+ right
.width
, width_hint
);
978 is_signed
= children
[0]->is_signed
&& children
[1]->is_signed
;
979 return binop2rtlil(this, type_name
, width
, left
, right
);
982 // generate cells for binary operations: $logic_and, $logic_or
983 if (0) { case AST_LOGIC_AND
: type_name
= "$logic_and"; }
984 if (0) { case AST_LOGIC_OR
: type_name
= "$logic_or"; }
986 RTLIL::SigSpec left
= children
[0]->genRTLIL();
987 RTLIL::SigSpec right
= children
[1]->genRTLIL();
988 return binop2rtlil(this, type_name
, 1, left
, right
);
991 // generate cells for unary operations: $logic_not
994 RTLIL::SigSpec arg
= children
[0]->genRTLIL();
995 return uniop2rtlil(this, "$logic_not", 1, arg
);
998 // generate multiplexer for ternary operator (aka ?:-operator)
1001 RTLIL::SigSpec cond
= children
[0]->genRTLIL();
1002 RTLIL::SigSpec val1
= children
[1]->genRTLIL(width_hint
, sign_hint
);
1003 RTLIL::SigSpec val2
= children
[2]->genRTLIL(width_hint
, sign_hint
);
1006 cond
= uniop2rtlil(this, "$reduce_bool", 1, cond
, false);
1008 int width
= std::max(val1
.width
, val2
.width
);
1009 is_signed
= children
[1]->is_signed
&& children
[2]->is_signed
;
1013 return mux2rtlil(this, cond
, val1
, val2
);
1016 // generate $memrd cells for memory read ports
1019 std::stringstream sstr
;
1020 sstr
<< "$memrd$" << str
<< "$" << filename
<< ":" << linenum
<< "$" << (RTLIL::autoidx
++);
1022 RTLIL::Cell
*cell
= new RTLIL::Cell
;
1023 cell
->attributes
["\\src"] = stringf("%s:%d", filename
.c_str(), linenum
);
1024 cell
->name
= sstr
.str();
1025 cell
->type
= "$memrd";
1026 current_module
->cells
[cell
->name
] = cell
;
1028 RTLIL::Wire
*wire
= new RTLIL::Wire
;
1029 wire
->attributes
["\\src"] = stringf("%s:%d", filename
.c_str(), linenum
);
1030 wire
->name
= cell
->name
+ "_DATA";
1031 wire
->width
= current_module
->memories
[str
]->width
;
1032 current_module
->wires
[wire
->name
] = wire
;
1035 while ((1 << addr_bits
) < current_module
->memories
[str
]->size
)
1038 cell
->connections
["\\CLK"] = RTLIL::SigSpec(RTLIL::State::Sx
, 1);
1039 cell
->connections
["\\ADDR"] = children
[0]->genRTLIL();
1040 cell
->connections
["\\DATA"] = RTLIL::SigSpec(wire
);
1042 cell
->parameters
["\\MEMID"] = RTLIL::Const(str
);
1043 cell
->parameters
["\\ABITS"] = RTLIL::Const(addr_bits
);
1044 cell
->parameters
["\\WIDTH"] = RTLIL::Const(wire
->width
);
1046 cell
->parameters
["\\CLK_ENABLE"] = RTLIL::Const(0);
1047 cell
->parameters
["\\CLK_POLARITY"] = RTLIL::Const(0);
1049 return RTLIL::SigSpec(wire
);
1052 // generate $memwr cells for memory write ports
1055 std::stringstream sstr
;
1056 sstr
<< "$memwr$" << str
<< "$" << filename
<< ":" << linenum
<< "$" << (RTLIL::autoidx
++);
1058 RTLIL::Cell
*cell
= new RTLIL::Cell
;
1059 cell
->attributes
["\\src"] = stringf("%s:%d", filename
.c_str(), linenum
);
1060 cell
->name
= sstr
.str();
1061 cell
->type
= "$memwr";
1062 current_module
->cells
[cell
->name
] = cell
;
1065 while ((1 << addr_bits
) < current_module
->memories
[str
]->size
)
1068 cell
->connections
["\\CLK"] = RTLIL::SigSpec(RTLIL::State::Sx
, 1);
1069 cell
->connections
["\\ADDR"] = children
[0]->genRTLIL();
1070 cell
->connections
["\\DATA"] = children
[1]->genRTLIL();
1071 cell
->connections
["\\EN"] = children
[2]->genRTLIL();
1073 cell
->parameters
["\\MEMID"] = RTLIL::Const(str
);
1074 cell
->parameters
["\\ABITS"] = RTLIL::Const(addr_bits
);
1075 cell
->parameters
["\\WIDTH"] = RTLIL::Const(current_module
->memories
[str
]->width
);
1077 cell
->parameters
["\\CLK_ENABLE"] = RTLIL::Const(0);
1078 cell
->parameters
["\\CLK_POLARITY"] = RTLIL::Const(0);
1082 // add entries to current_module->connections for assignments (outside of always blocks)
1085 if (children
[0]->type
== AST_IDENTIFIER
&& children
[0]->id2ast
&& children
[0]->id2ast
->type
== AST_AUTOWIRE
) {
1086 RTLIL::SigSpec right
= children
[1]->genRTLIL();
1087 RTLIL::SigSpec left
= children
[0]->genWidthRTLIL(right
.width
);
1088 current_module
->connections
.push_back(RTLIL::SigSig(left
, right
));
1090 RTLIL::SigSpec left
= children
[0]->genRTLIL();
1091 RTLIL::SigSpec right
= children
[1]->genWidthRTLIL(left
.width
);
1092 current_module
->connections
.push_back(RTLIL::SigSig(left
, right
));
1097 // create an RTLIL::Cell for an AST_CELL
1100 int port_counter
= 0, para_counter
= 0;
1101 RTLIL::Cell
*cell
= new RTLIL::Cell
;
1102 cell
->attributes
["\\src"] = stringf("%s:%d", filename
.c_str(), linenum
);
1104 for (auto it
= children
.begin(); it
!= children
.end(); it
++) {
1105 AstNode
*child
= *it
;
1106 if (child
->type
== AST_CELLTYPE
) {
1107 cell
->type
= child
->str
;
1110 if (child
->type
== AST_PARASET
) {
1111 if (child
->children
[0]->type
!= AST_CONSTANT
)
1112 log_error("Parameter `%s' with non-constant value at %s:%d!\n",
1113 child
->str
.c_str(), filename
.c_str(), linenum
);
1114 if (child
->str
.size() == 0) {
1116 snprintf(buf
, 100, "$%d", ++para_counter
);
1117 cell
->parameters
[buf
].str
= child
->children
[0]->str
;
1118 cell
->parameters
[buf
].bits
= child
->children
[0]->bits
;
1120 cell
->parameters
[child
->str
].str
= child
->children
[0]->str
;
1121 cell
->parameters
[child
->str
].bits
= child
->children
[0]->bits
;
1125 if (child
->type
== AST_ARGUMENT
) {
1127 if (child
->children
.size() > 0)
1128 sig
= child
->children
[0]->genRTLIL();
1129 if (child
->str
.size() == 0) {
1131 snprintf(buf
, 100, "$%d", ++port_counter
);
1132 cell
->connections
[buf
] = sig
;
1134 cell
->connections
[child
->str
] = sig
;
1140 for (auto &attr
: attributes
) {
1141 if (attr
.second
->type
!= AST_CONSTANT
)
1142 log_error("Attribute `%s' with non-constant value at %s:%d!\n",
1143 attr
.first
.c_str(), filename
.c_str(), linenum
);
1144 cell
->attributes
[attr
.first
].str
= attr
.second
->str
;
1145 cell
->attributes
[attr
.first
].bits
= attr
.second
->bits
;
1147 if (current_module
->cells
.count(cell
->name
) != 0)
1148 log_error("Re-definition of cell `%s' at %s:%d!\n",
1149 str
.c_str(), filename
.c_str(), linenum
);
1150 current_module
->cells
[str
] = cell
;
1154 // use ProcessGenerator for always blocks
1156 AstNode
*always
= this->clone();
1157 ProcessGenerator
generator(always
);
1158 ignoreThisSignalsInInitial
.append(generator
.outputSignals
);
1163 AstNode
*always
= this->clone();
1164 ProcessGenerator
generator(always
, ignoreThisSignalsInInitial
);
1168 // everything should have been handled above -> print error if not.
1170 for (auto f
: log_files
)
1171 current_ast
->dumpAst(f
, "verilog-ast> ");
1172 type_name
= type2str(type
);
1173 log_error("Don't know how to generate RTLIL code for %s node at %s:%d!\n",
1174 type_name
.c_str(), filename
.c_str(), linenum
);
1177 return RTLIL::SigSpec();
1180 // this is a wrapper for AstNode::genRTLIL() when a specific signal width is requested and/or
1181 // signals must be substituted before beeing used as input values (used by ProcessGenerator)
1182 // note that this is using some global variables to communicate this special settings to AstNode::genRTLIL().
1183 RTLIL::SigSpec
AstNode::genWidthRTLIL(int width
, RTLIL::SigSpec
*subst_from
, RTLIL::SigSpec
*subst_to
)
1185 RTLIL::SigSpec
*backup_subst_from
= genRTLIL_subst_from
;
1186 RTLIL::SigSpec
*backup_subst_to
= genRTLIL_subst_to
;
1189 genRTLIL_subst_from
= subst_from
;
1191 genRTLIL_subst_to
= subst_to
;
1193 bool sign_hint
= true;
1194 int width_hint
= width
;
1195 detectSignWidthWorker(width_hint
, sign_hint
);
1196 RTLIL::SigSpec sig
= genRTLIL(width_hint
, sign_hint
);
1198 genRTLIL_subst_from
= backup_subst_from
;
1199 genRTLIL_subst_to
= backup_subst_to
;
1202 sig
.extend(width
, is_signed
);