From 5c39948eadbcda58d0b880dc162572838dad01a2 Mon Sep 17 00:00:00 2001 From: Clifford Wolf Date: Thu, 5 Dec 2013 12:53:49 +0100 Subject: Added AstNode::mkconst_str API --- frontends/ast/ast.cc | 17 +++++++++++++++++ frontends/ast/ast.h | 1 + 2 files changed, 18 insertions(+) (limited to 'frontends/ast') 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 &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 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 bits = this->bits; diff --git a/frontends/ast/ast.h b/frontends/ast/ast.h index ab1b9bec..e9dfa5ac 100644 --- a/frontends/ast/ast.h +++ b/frontends/ast/ast.h @@ -213,6 +213,7 @@ namespace AST // helper functions for creating AST nodes for constants static AstNode *mkconst_int(uint32_t v, bool is_signed, int width = 32); static AstNode *mkconst_bits(const std::vector &v, bool is_signed); + static AstNode *mkconst_str(const std::string &str); // helper function for creating sign-extended const objects RTLIL::Const bitsAsConst(int width, bool is_signed); -- cgit v1.2.3