MCPcopy Create free account
hub / github.com/chipsalliance/Surelog / compileConst

Function compileConst

src/DesignCompile/CompileExpression.cpp:449–739  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

447}
448
449constant *compileConst(const FileContent *fC, NodeId child, Serializer &s) {
450 VObjectType objtype = fC->Type(child);
451 constant *result = nullptr;
452 switch (objtype) {
453 case VObjectType::slIntConst: {
454 // Do not evaluate the constant, keep it as in the source text:
455 UHDM::constant *c = s.MakeConstant();
456 fC->populateCoreMembers(child, child, c);
457 std::string value = std::string(fC->SymName(child));
458 value.erase(std::remove(value.begin(), value.end(), '_'), value.end());
459 std::string v;
460 c->VpiDecompile(value);
461 bool tickNumber = (value.find('\'') != std::string::npos);
462 if (tickNumber || largeInt(value)) {
463 char base = 'd';
464 uint32_t i = 0;
465 bool isSigned = false;
466 std::string size(value);
467 if (tickNumber) {
468 for (i = 0; i < value.size(); i++) {
469 if (value[i] == '\'') {
470 base = value[i + 1];
471 if (base == 's' || base == 'S') base = value[i + 2];
472 break;
473 }
474 }
475 if (value.find_first_of("sS") != std::string::npos) {
476 isSigned = true;
477 v = value.substr(i + 3);
478 } else {
479 v = value.substr(i + 2);
480 }
481 } else {
482 v = value;
483 size = "";
484 }
485 v = StringUtils::replaceAll(v, "#", "");
486 v = StringUtils::replaceAll(v, "_", "");
487 size = StringUtils::rtrim_until(size, '\'');
488 if (size.empty()) {
489 c->VpiSize(-1);
490 } else {
491 int32_t s = 0;
492 if (NumUtils::parseInt32(size, &s) == nullptr) {
493 s = 0;
494 }
495 c->VpiSize(s);
496 }
497 if (isSigned) {
498 int_typespec *tps = s.MakeInt_typespec();
499 tps->VpiSigned(true);
500 ref_typespec *const rt = s.MakeRef_typespec();
501 rt->VpiParent(c);
502 c->Typespec(rt);
503 rt->Actual_typespec(tps);
504 }
505 switch (base) {
506 case 'h':

Callers 1

compileExpressionMethod · 0.85

Calls 10

largeIntFunction · 0.85
parseInt32Function · 0.85
StrCatFunction · 0.85
parseUint64Function · 0.85
populateCoreMembersMethod · 0.80
TypeMethod · 0.45
SymNameMethod · 0.45
appendMethod · 0.45
ChildMethod · 0.45
SiblingMethod · 0.45

Tested by

no test coverage detected