SigSpec refactoring: change RTLIL::SigSpec::size() to be read-only

This commit is contained in:
Clifford Wolf 2014-07-22 20:39:13 +02:00
parent 4b4048bc5f
commit 7bffde6abd
3 changed files with 18 additions and 94 deletions

View File

@ -56,15 +56,6 @@ static RTLIL::SigSpec uniop2rtlil(AstNode *that, std::string type, int result_wi
wire->width = result_width; wire->width = result_width;
current_module->wires[wire->name] = wire; current_module->wires[wire->name] = wire;
RTLIL::SigChunk chunk;
chunk.wire = wire;
chunk.width = wire->width;
chunk.offset = 0;
RTLIL::SigSpec sig;
sig.chunks().push_back(chunk);
sig.size() = chunk.width;
if (gen_attributes) if (gen_attributes)
for (auto &attr : that->attributes) { for (auto &attr : that->attributes) {
if (attr.second->type != AST_CONSTANT) if (attr.second->type != AST_CONSTANT)
@ -78,8 +69,8 @@ static RTLIL::SigSpec uniop2rtlil(AstNode *that, std::string type, int result_wi
cell->connections["\\A"] = arg; cell->connections["\\A"] = arg;
cell->parameters["\\Y_WIDTH"] = result_width; cell->parameters["\\Y_WIDTH"] = result_width;
cell->connections["\\Y"] = sig; cell->connections["\\Y"] = wire;
return sig; return wire;
} }
// helper function for extending bit width (preferred over SigSpec::extend() because of correct undef propagation in ConstEval) // helper function for extending bit width (preferred over SigSpec::extend() because of correct undef propagation in ConstEval)
@ -105,15 +96,6 @@ static void widthExtend(AstNode *that, RTLIL::SigSpec &sig, int width, bool is_s
wire->width = width; wire->width = width;
current_module->wires[wire->name] = wire; current_module->wires[wire->name] = wire;
RTLIL::SigChunk chunk;
chunk.wire = wire;
chunk.width = wire->width;
chunk.offset = 0;
RTLIL::SigSpec new_sig;
new_sig.chunks().push_back(chunk);
new_sig.size() = chunk.width;
if (that != NULL) if (that != NULL)
for (auto &attr : that->attributes) { for (auto &attr : that->attributes) {
if (attr.second->type != AST_CONSTANT) if (attr.second->type != AST_CONSTANT)
@ -127,8 +109,8 @@ static void widthExtend(AstNode *that, RTLIL::SigSpec &sig, int width, bool is_s
cell->connections["\\A"] = sig; cell->connections["\\A"] = sig;
cell->parameters["\\Y_WIDTH"] = width; cell->parameters["\\Y_WIDTH"] = width;
cell->connections["\\Y"] = new_sig; cell->connections["\\Y"] = wire;
sig = new_sig; sig = wire;
} }
// helper function for creating RTLIL code for binary operations // helper function for creating RTLIL code for binary operations
@ -149,15 +131,6 @@ static RTLIL::SigSpec binop2rtlil(AstNode *that, std::string type, int result_wi
wire->width = result_width; wire->width = result_width;
current_module->wires[wire->name] = wire; current_module->wires[wire->name] = wire;
RTLIL::SigChunk chunk;
chunk.wire = wire;
chunk.width = wire->width;
chunk.offset = 0;
RTLIL::SigSpec sig;
sig.chunks().push_back(chunk);
sig.size() = chunk.width;
for (auto &attr : that->attributes) { for (auto &attr : that->attributes) {
if (attr.second->type != AST_CONSTANT) if (attr.second->type != AST_CONSTANT)
log_error("Attribute `%s' with non-constant value at %s:%d!\n", log_error("Attribute `%s' with non-constant value at %s:%d!\n",
@ -175,8 +148,8 @@ static RTLIL::SigSpec binop2rtlil(AstNode *that, std::string type, int result_wi
cell->connections["\\B"] = right; cell->connections["\\B"] = right;
cell->parameters["\\Y_WIDTH"] = result_width; cell->parameters["\\Y_WIDTH"] = result_width;
cell->connections["\\Y"] = sig; cell->connections["\\Y"] = wire;
return sig; return wire;
} }
// helper function for creating RTLIL code for multiplexers // helper function for creating RTLIL code for multiplexers
@ -199,15 +172,6 @@ static RTLIL::SigSpec mux2rtlil(AstNode *that, const RTLIL::SigSpec &cond, const
wire->width = left.size(); wire->width = left.size();
current_module->wires[wire->name] = wire; current_module->wires[wire->name] = wire;
RTLIL::SigChunk chunk;
chunk.wire = wire;
chunk.width = wire->width;
chunk.offset = 0;
RTLIL::SigSpec sig;
sig.chunks().push_back(chunk);
sig.size() = chunk.width;
for (auto &attr : that->attributes) { for (auto &attr : that->attributes) {
if (attr.second->type != AST_CONSTANT) if (attr.second->type != AST_CONSTANT)
log_error("Attribute `%s' with non-constant value at %s:%d!\n", log_error("Attribute `%s' with non-constant value at %s:%d!\n",
@ -220,9 +184,9 @@ static RTLIL::SigSpec mux2rtlil(AstNode *that, const RTLIL::SigSpec &cond, const
cell->connections["\\A"] = right; cell->connections["\\A"] = right;
cell->connections["\\B"] = left; cell->connections["\\B"] = left;
cell->connections["\\S"] = cond; cell->connections["\\S"] = cond;
cell->connections["\\Y"] = sig; cell->connections["\\Y"] = wire;
return sig; return wire;
} }
// helper class for converting AST always nodes to RTLIL processes // helper class for converting AST always nodes to RTLIL processes
@ -1001,9 +965,7 @@ RTLIL::SigSpec AstNode::genRTLIL(int width_hint, bool sign_hint)
} }
} }
RTLIL::SigSpec sig; RTLIL::SigSpec sig(chunk);
sig.chunks().push_back(chunk);
sig.size() = chunk.width;
if (genRTLIL_subst_from && genRTLIL_subst_to) if (genRTLIL_subst_from && genRTLIL_subst_to)
sig.replace(*genRTLIL_subst_from, *genRTLIL_subst_to); sig.replace(*genRTLIL_subst_from, *genRTLIL_subst_to);
@ -1025,14 +987,8 @@ RTLIL::SigSpec AstNode::genRTLIL(int width_hint, bool sign_hint)
// concatenation of signals can be done directly using RTLIL::SigSpec // concatenation of signals can be done directly using RTLIL::SigSpec
case AST_CONCAT: { case AST_CONCAT: {
RTLIL::SigSpec sig; RTLIL::SigSpec sig;
sig.size() = 0; for (auto it = children.begin(); it != children.end(); it++)
for (auto it = children.begin(); it != children.end(); it++) { sig.append((*it)->genRTLIL());
RTLIL::SigSpec s = (*it)->genRTLIL();
for (size_t i = 0; i < s.chunks().size(); i++) {
sig.chunks().push_back(s.chunks()[i]);
sig.size() += s.chunks()[i].width;
}
}
if (sig.size() < width_hint) if (sig.size() < width_hint)
sig.extend_u0(width_hint, false); sig.extend_u0(width_hint, false);
return sig; return sig;

View File

@ -357,50 +357,25 @@ constant:
sigspec: sigspec:
constant { constant {
RTLIL::SigChunk chunk; $$ = new RTLIL::SigSpec(*$1);
chunk.wire = NULL;
chunk.width = $1->bits.size();
chunk.offset = 0;
chunk.data = *$1;
$$ = new RTLIL::SigSpec;
$$->chunks().push_back(chunk);
$$->size() = chunk.width;
delete $1; delete $1;
} | } |
TOK_ID { TOK_ID {
if (current_module->wires.count($1) == 0) if (current_module->wires.count($1) == 0)
rtlil_frontend_ilang_yyerror(stringf("ilang error: wire %s not found", $1).c_str()); rtlil_frontend_ilang_yyerror(stringf("ilang error: wire %s not found", $1).c_str());
RTLIL::SigChunk chunk; $$ = new RTLIL::SigSpec(current_module->wires[$1]);
chunk.wire = current_module->wires[$1];
chunk.width = current_module->wires[$1]->width;
chunk.offset = 0;
$$ = new RTLIL::SigSpec;
$$->chunks().push_back(chunk);
$$->size() = chunk.width;
free($1); free($1);
} | } |
TOK_ID '[' TOK_INT ']' { TOK_ID '[' TOK_INT ']' {
if (current_module->wires.count($1) == 0) if (current_module->wires.count($1) == 0)
rtlil_frontend_ilang_yyerror(stringf("ilang error: wire %s not found", $1).c_str()); rtlil_frontend_ilang_yyerror(stringf("ilang error: wire %s not found", $1).c_str());
RTLIL::SigChunk chunk; $$ = new RTLIL::SigSpec(current_module->wires[$1], 1, $3);
chunk.wire = current_module->wires[$1];
chunk.offset = $3;
chunk.width = 1;
$$ = new RTLIL::SigSpec;
$$->chunks().push_back(chunk);
$$->size() = 1;
free($1); free($1);
} | } |
TOK_ID '[' TOK_INT ':' TOK_INT ']' { TOK_ID '[' TOK_INT ':' TOK_INT ']' {
if (current_module->wires.count($1) == 0) if (current_module->wires.count($1) == 0)
rtlil_frontend_ilang_yyerror(stringf("ilang error: wire %s not found", $1).c_str()); rtlil_frontend_ilang_yyerror(stringf("ilang error: wire %s not found", $1).c_str());
RTLIL::SigChunk chunk; $$ = new RTLIL::SigSpec(current_module->wires[$1], $3 - $5 + 1, $5);
chunk.wire = current_module->wires[$1];
chunk.width = $3 - $5 + 1;
chunk.offset = $5;
$$ = new RTLIL::SigSpec;
$$->chunks().push_back(chunk);
$$->size() = chunk.width;
free($1); free($1);
} | } |
'{' sigspec_list '}' { '{' sigspec_list '}' {
@ -410,14 +385,8 @@ sigspec:
sigspec_list: sigspec_list:
sigspec_list sigspec { sigspec_list sigspec {
$$ = new RTLIL::SigSpec; $$ = new RTLIL::SigSpec;
for (auto it = $2->chunks().begin(); it != $2->chunks().end(); it++) { $$->append(*$2);
$$->chunks().push_back(*it); $$->append(*$1);
$$->size() += it->width;
}
for (auto it = $1->chunks().begin(); it != $1->chunks().end(); it++) {
$$->chunks().push_back(*it);
$$->size() += it->width;
}
delete $1; delete $1;
delete $2; delete $2;
} | } |

View File

@ -504,8 +504,7 @@ public:
std::vector<RTLIL::SigChunk> &chunks() { return chunks_; } std::vector<RTLIL::SigChunk> &chunks() { return chunks_; }
const std::vector<RTLIL::SigChunk> &chunks() const { return chunks_; } const std::vector<RTLIL::SigChunk> &chunks() const { return chunks_; }
int &size() { return width_; } int size() const { return width_; }
const int &size() const { return width_; }
SigSpec(); SigSpec();
SigSpec(const RTLIL::Const &data); SigSpec(const RTLIL::Const &data);