| 3939 | } |
| 3940 | |
| 3941 | UHDM::constant* CompileHelper::adjustSize(const UHDM::typespec* ts, |
| 3942 | DesignComponent* component, |
| 3943 | CompileDesign* compileDesign, |
| 3944 | ValuedComponentI* instance, |
| 3945 | UHDM::constant* c, bool uniquify, |
| 3946 | bool sizeMode) { |
| 3947 | UHDM::Serializer& s = compileDesign->getSerializer(); |
| 3948 | UHDM::constant* result = c; |
| 3949 | if (ts == nullptr) { |
| 3950 | return result; |
| 3951 | } |
| 3952 | FileSystem* const fileSystem = FileSystem::getInstance(); |
| 3953 | int32_t orig_size = c->VpiSize(); |
| 3954 | |
| 3955 | bool invalidValue = false; |
| 3956 | int32_t sizetmp = |
| 3957 | Bits(ts, invalidValue, component, compileDesign, Reduce::Yes, instance, |
| 3958 | fileSystem->toPathId(c->VpiFile(), |
| 3959 | compileDesign->getCompiler()->getSymbolTable()), |
| 3960 | c->VpiLineNo(), sizeMode); |
| 3961 | |
| 3962 | int32_t size = orig_size; |
| 3963 | if (c->VpiConstType() != vpiDecConst) { |
| 3964 | if (!invalidValue) size = sizetmp; |
| 3965 | } |
| 3966 | bool signedLhs = false; |
| 3967 | if (ts->UhdmType() == uhdmint_typespec) { |
| 3968 | int_typespec* its = (int_typespec*)ts; |
| 3969 | signedLhs = its->VpiSigned(); |
| 3970 | } else if (ts->UhdmType() == uhdmlogic_typespec) { |
| 3971 | logic_typespec* its = (logic_typespec*)ts; |
| 3972 | signedLhs = its->VpiSigned(); |
| 3973 | } else if (ts->UhdmType() == uhdmbit_typespec) { |
| 3974 | bit_typespec* its = (bit_typespec*)ts; |
| 3975 | signedLhs = its->VpiSigned(); |
| 3976 | } |
| 3977 | |
| 3978 | UHDM::ExprEval eval; |
| 3979 | int64_t val = eval.get_value(invalidValue, c); |
| 3980 | bool constantIsSigned = false; |
| 3981 | if (!invalidValue) { |
| 3982 | if (c->VpiConstType() == vpiUIntConst) { |
| 3983 | uint64_t mask = NumUtils::getMask(size); |
| 3984 | uint64_t uval = (uint64_t)val; |
| 3985 | uval = uval & mask; |
| 3986 | if (uniquify) { |
| 3987 | UHDM::ElaboratorContext elaboratorContext(&s, false, true); |
| 3988 | c = (UHDM::constant*)UHDM::clone_tree(c, &elaboratorContext); |
| 3989 | result = c; |
| 3990 | } |
| 3991 | c->VpiValue("UINT:" + std::to_string(uval)); |
| 3992 | c->VpiDecompile(std::to_string(uval)); |
| 3993 | c->VpiConstType(vpiUIntConst); |
| 3994 | c->VpiSize(size); |
| 3995 | } else if (c->VpiConstType() == vpiBinaryConst) { |
| 3996 | if (const ref_typespec* tstmp_rt = c->Typespec()) { |
| 3997 | if (const typespec* tstmp = tstmp_rt->Actual_typespec()) { |
| 3998 | if (tstmp->UhdmType() == uhdmint_typespec) { |
no test coverage detected