summaryrefslogtreecommitdiff
path: root/frontends/ast/ast.cc
diff options
context:
space:
mode:
authorClifford Wolf <clifford@clifford.at>2013-12-05 12:53:49 +0100
committerClifford Wolf <clifford@clifford.at>2013-12-05 12:53:49 +0100
commit5c39948eadbcda58d0b880dc162572838dad01a2 (patch)
tree9b9559eb0fb352e776e7dd5984fac97d4bf20668 /frontends/ast/ast.cc
parent853538d78b0207ca218524cb766fd5cdb165478d (diff)
Added AstNode::mkconst_str API
Diffstat (limited to 'frontends/ast/ast.cc')
-rw-r--r--frontends/ast/ast.cc17
1 files changed, 17 insertions, 0 deletions
diff --git a/frontends/ast/ast.cc b/frontends/ast/ast.cc
index 10c7fc85..7d5295a6 100644
--- a/frontends/ast/ast.cc
+++ b/frontends/ast/ast.cc
@@ -658,6 +658,23 @@ AstNode *AstNode::mkconst_bits(const std::vector<RTLIL::State> &v, bool is_signe
return node;
}
+// create an AST node for a constant (using a string as value)
+AstNode *AstNode::mkconst_str(const std::string &str)
+{
+ std::vector<RTLIL::State> data;
+ data.reserve(str.size() * 8);
+ for (size_t i = 0; i < str.size(); i++) {
+ unsigned char ch = str[str.size() - i - 1];
+ for (int j = 0; j < 8; j++) {
+ data.push_back((ch & 1) ? RTLIL::S1 : RTLIL::S0);
+ ch = ch >> 1;
+ }
+ }
+ AstNode *node = AstNode::mkconst_bits(data, false);
+ node->str = str;
+ return node;
+}
+
RTLIL::Const AstNode::bitsAsConst(int width, bool is_signed)
{
std::vector<RTLIL::State> bits = this->bits;