50 for (
size_t i = 0; i < digits.size(); i++) {
52 digits[i] += carry * 10;
53 carry = digits[i] % 2;
56 while (!digits.empty() && !digits.front())
57 digits.erase(digits.begin());
65 while (x != 0 && x != -1) {
73 static void my_strtobin(std::vector<RTLIL::State> &data,
const char *str,
int len_in_bits,
int base,
char case_type)
76 std::vector<uint8_t> digits;
79 if (
'0' <= *str && *str <=
'9')
80 digits.push_back(*str -
'0');
81 else if (
'a' <= *str && *str <=
'f')
82 digits.push_back(10 + *str -
'a');
83 else if (
'A' <= *str && *str <=
'F')
84 digits.push_back(10 + *str -
'A');
85 else if (*str ==
'x' || *str ==
'X')
86 digits.push_back(0xf0);
87 else if (*str ==
'z' || *str ==
'Z')
88 digits.push_back(0xf1);
90 digits.push_back(0xf2);
96 if (len_in_bits < 0) {
97 while (!digits.empty())
99 while (data.size() < 32)
100 data.push_back(RTLIL::S0);
102 for (
int i = 0; i < len_in_bits; i++)
108 int bits_per_digit =
my_ilog2(base-1);
110 len_in_bits = std::max<int>(digits.size() * bits_per_digit, 32);
113 data.resize(len_in_bits);
115 for (
int i = 0; i < len_in_bits; i++) {
116 int bitmask = 1 << (i % bits_per_digit);
117 int digitidx = digits.size() - (i / bits_per_digit) - 1;
123 }
else if (digits[digitidx] == 0xf0)
125 else if (digits[digitidx] == 0xf1)
127 else if (digits[digitidx] == 0xf2)
140 log_warning(
"Yosys does not support tri-state logic at the moment. (%s:%d)\n",
145 const char *str = code.c_str();
149 int len = strlen(str) - 2;
150 std::vector<RTLIL::State> data;
151 data.reserve(len * 8);
152 for (
int i = 0; i < len; i++) {
153 unsigned char ch = str[len - i];
154 for (
int j = 0; j < 8; j++) {
164 for (
size_t i = 0; i < code.size(); i++)
165 if (code[i] ==
'_' || code[i] ==
' ' || code[i] ==
'\t' || code[i] ==
'\r' || code[i] ==
'\n')
166 code.erase(code.begin()+(i--));
170 long len_in_bits = strtol(str, &endptr, 10);
174 std::vector<RTLIL::State> data;
188 std::vector<RTLIL::State> data;
189 bool is_signed =
false;
190 if (*(endptr+1) ==
's') {
198 my_strtobin(data, endptr+2, len_in_bits, 2, case_type);
202 my_strtobin(data, endptr+2, len_in_bits, 8, case_type);
206 my_strtobin(data, endptr+2, len_in_bits, 10, case_type);
210 my_strtobin(data, endptr+2, len_in_bits, 16, case_type);
215 if (len_in_bits < 0) {
216 if (is_signed && data.back() ==
RTLIL::S1)
218 while (data.size() < 32)
void log_warning(const char *format,...)
static AstNode * mkconst_bits(const std::vector< RTLIL::State > &v, bool is_signed)
#define YOSYS_NAMESPACE_END
static int my_decimal_div_by_two(std::vector< uint8_t > &digits)
int frontend_verilog_yyget_lineno(void)
#define log_assert(_assert_expr_)
std::string current_filename
#define YOSYS_NAMESPACE_BEGIN
AST::AstNode * const2ast(std::string code, char case_type=0, bool warn_z=false)
static bool find(V &ts, const T &t)
std::vector< RTLIL::State > bits
static void my_strtobin(std::vector< RTLIL::State > &data, const char *str, int len_in_bits, int base, char case_type)
static int my_ilog2(int x)