Skip to content

Commit 9a72254

Browse files
Merge pull request #945 from alainmarcel/alainmarcel-patch-1
part_select fix
2 parents 82f7514 + 71f53e3 commit 9a72254

File tree

1 file changed

+27
-35
lines changed

1 file changed

+27
-35
lines changed

templates/ExprEval.cpp

Lines changed: 27 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,31 @@ std::string ExprEval::toBinary(const UHDM::constant *c) {
152152
result = NumUtils::toBinary(c->VpiSize(), res);
153153
break;
154154
}
155+
case vpiScalar: {
156+
sv.remove_prefix(std::string_view("SCAL:").length());
157+
uint64_t res = 0;
158+
if (NumUtils::parseBinary(sv, &res) == nullptr) {
159+
res = 0;
160+
}
161+
result = NumUtils::toBinary(c->VpiSize(), res);
162+
break;
163+
}
164+
case vpiStringConst: {
165+
sv.remove_prefix(std::string_view("STRING:").length());
166+
if (sv.size() > 32) {
167+
return result;
168+
}
169+
uint64_t res = 0;
170+
for (uint32_t i = 0; i < sv.size(); i++) {
171+
res += (sv[i] << ((sv.size() - (i + 1)) * 8));
172+
}
173+
result = NumUtils::toBinary(c->VpiSize(), res);
174+
break;
175+
}
176+
case vpiRealConst: {
177+
// Don't do the double precision math, leave it to client tools
178+
break;
179+
}
155180
default: {
156181
if (sv.find("UINT:") == 0) {
157182
sv.remove_prefix(std::string_view("UINT:").length());
@@ -1584,19 +1609,8 @@ expr *ExprEval::reduceBitSelect(expr *op, uint32_t index_val,
15841609
expr *result = nullptr;
15851610
expr *exp = reduceExpr(op, invalidValue, inst, pexpr, muteError);
15861611
if (exp && (exp->UhdmType() == uhdmconstant)) {
1587-
std::string binary;
15881612
constant *cexp = (constant *)exp;
1589-
if (cexp->VpiConstType() == vpiBinaryConst) {
1590-
binary = cexp->VpiValue();
1591-
binary = binary.substr(std::string_view("BIN:").length());
1592-
} else if (cexp->VpiConstType() == vpiHexConst) {
1593-
std::string_view hex = cexp->VpiValue();
1594-
hex.remove_prefix(std::string_view("HEX:").length());
1595-
binary = NumUtils::hexToBin(hex);
1596-
} else {
1597-
int64_t val = get_value(invalidValue, exp);
1598-
binary = NumUtils::toBinary(exp->VpiSize(), val);
1599-
}
1613+
std::string binary = toBinary(cexp);
16001614
uint64_t wordSize = 1;
16011615
if (typespec *cts = (typespec *)cexp->Typespec()) {
16021616
if (cts->UhdmType() == uhdmint_typespec) {
@@ -2456,12 +2470,6 @@ any *ExprEval::hierarchicalSelector(std::vector<std::string> &select_path,
24562470
return nullptr;
24572471
}
24582472

2459-
static std::string hexToBinary(char input[2]) {
2460-
uint32_t x = std::stoul(input, nullptr, 16);
2461-
std::string result = std::bitset<4>(x).to_string();
2462-
return result;
2463-
}
2464-
24652473
expr *ExprEval::reduceExpr(const any *result, bool &invalidValue,
24662474
const any *inst, const any *pexpr, bool muteError) {
24672475
if (!result) return nullptr;
@@ -3944,23 +3952,7 @@ expr *ExprEval::reduceExpr(const any *result, bool &invalidValue,
39443952
}
39453953
if (object && (object->UhdmType() == uhdmconstant)) {
39463954
constant *co = (constant *)object;
3947-
std::string binary;
3948-
if (co->VpiConstType() == vpiBinaryConst) {
3949-
binary = co->VpiValue();
3950-
binary.erase(0, 4);
3951-
} else if (co->VpiConstType() == vpiHexConst) {
3952-
std::string_view val = co->VpiValue();
3953-
val.remove_prefix(4);
3954-
for (char ch : val) {
3955-
char tmp[2] = {ch, '\0'};
3956-
binary += hexToBinary(tmp);
3957-
}
3958-
} else {
3959-
int64_t val = get_value(invalidValue, co);
3960-
if (invalidValue == false) {
3961-
binary = NumUtils::toBinary(co->VpiSize(), val);
3962-
}
3963-
}
3955+
std::string binary = toBinary(co);
39643956
int64_t l = get_value(
39653957
invalidValue,
39663958
reduceExpr(sel->Left_range(), invalidValue, inst, pexpr, muteError));

0 commit comments

Comments
 (0)