Skip to content

Commit

Permalink
Merge pull request #3806 from alainmarcel/alainmarcel-patch-1
Browse files Browse the repository at this point in the history
unsized val bug
  • Loading branch information
alaindargelas authored Aug 24, 2023
2 parents 5e3737e + de4e762 commit f11370a
Show file tree
Hide file tree
Showing 17 changed files with 93 additions and 55 deletions.
2 changes: 2 additions & 0 deletions include/Surelog/DesignCompile/CompileHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,8 @@ class CompileHelper final {
int32_t opIndex, UHDM::expr* rhs,
DesignComponent* component, CompileDesign* compileDesign,
ValuedComponentI* instance);

void adjustUnsized(UHDM::constant* c, int32_t size);

UHDM::any* defaultPatternAssignment(const UHDM::typespec* tps, UHDM::any* exp,
DesignComponent* component,
Expand Down
49 changes: 39 additions & 10 deletions src/DesignCompile/CompileHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3068,6 +3068,7 @@ UHDM::any* CompileHelper::defaultPatternAssignment(const UHDM::typespec* tps,
return result;
}
UHDM::Serializer& s = compileDesign->getSerializer();
FileSystem* const fileSystem = FileSystem::getInstance();
if (exp->UhdmType() == uhdmoperation) {
operation* op = (operation*)exp;
VectorOfany* operands = op->Operands();
Expand Down Expand Up @@ -3136,12 +3137,10 @@ UHDM::any* CompileHelper::defaultPatternAssignment(const UHDM::typespec* tps,
if (ptps->VpiName() == "default") {
bool invalidValue = false;
UHDM::ExprEval eval;
uint64_t val0 =
eval.get_value(invalidValue, (expr*)pattern->Pattern());
constant* c = s.MakeConstant();
c->VpiValue("UINT:" + std::to_string(val0));
c->VpiDecompile(std::to_string(val0));
c->VpiConstType(vpiUIntConst);
expr* expat = (expr*)pattern->Pattern();
constant* c = any_cast<constant*>(expat);
int32_t psize = expat->VpiSize();
int32_t ncsize = 32;
range* r = nullptr;
UHDM_OBJECT_TYPE ttps = tps->UhdmType();
UHDM_OBJECT_TYPE baseType = uhdmint_typespec;
Expand All @@ -3151,26 +3150,56 @@ UHDM::any* CompileHelper::defaultPatternAssignment(const UHDM::typespec* tps,
if (lts->Ranges() && !lts->Ranges()->empty()) {
r = (*lts->Ranges())[0];
}
ncsize = 1;
} else if (ttps == uhdmarray_typespec) {
array_typespec* lts = (array_typespec*)tps;
if (lts->Elem_typespec()) {
baseType = lts->Elem_typespec()->UhdmType();
if (lts->Ranges() && !lts->Ranges()->empty()) {
r = (*lts->Ranges())[0];
}
ncsize =
Bits(lts->Elem_typespec(), invalidValue, component,
compileDesign, Reduce::Yes, instance,
fileSystem->toPathId(
lts->Elem_typespec()->VpiFile(),
compileDesign->getCompiler()->getSymbolTable()),
lts->Elem_typespec()->VpiLineNo(), false);
}
} else if (ttps == uhdmpacked_array_typespec) {
packed_array_typespec* lts = (packed_array_typespec*)tps;
baseType = lts->Elem_typespec()->UhdmType();
if (lts->Ranges() && !lts->Ranges()->empty()) {
r = (*lts->Ranges())[0];
if (lts->Elem_typespec()) {
baseType = lts->Elem_typespec()->UhdmType();
if (lts->Ranges() && !lts->Ranges()->empty()) {
r = (*lts->Ranges())[0];
}
ncsize =
Bits(lts->Elem_typespec(), invalidValue, component,
compileDesign, Reduce::Yes, instance,
fileSystem->toPathId(
lts->Elem_typespec()->VpiFile(),
compileDesign->getCompiler()->getSymbolTable()),
lts->Elem_typespec()->VpiLineNo(), false);
}
} else if (ttps == uhdmbit_typespec) {
bit_typespec* lts = (bit_typespec*)tps;
baseType = uhdmbit_typespec;
if (lts->Ranges() && !lts->Ranges()->empty()) {
r = (*lts->Ranges())[0];
}
ncsize = 1;
} else if (ttps == uhdmint_typespec) {
ncsize = 32;
} else if (ttps == uhdminteger_typespec) {
ncsize = 32;
} else if (ttps == uhdmshort_int_typespec) {
ncsize = 16;
} else if (ttps == uhdmbyte_typespec) {
ncsize = 8;
}
if (psize == -1) {
adjustUnsized(c, ncsize);
c->VpiSize(ncsize);
}
if (r) {
bool invalidValue = false;
Expand Down Expand Up @@ -4589,7 +4618,7 @@ bool CompileHelper::isSelected(const FileContent* fC,
return false;
}

static void adjustUnsized(constant* c, int32_t size) {
void CompileHelper::adjustUnsized(constant* c, int32_t size) {
if (c == nullptr) return;
int32_t csize = c->VpiSize();
if (csize == -1) {
Expand Down
4 changes: 2 additions & 2 deletions tests/BlackParrotConf/BlackParrotConf.log
Original file line number Diff line number Diff line change
Expand Up @@ -20460,7 +20460,7 @@ assignment 2
begin 8
bit_select 2082
bit_typespec 42
constant 7456
constant 7450
cont_assign 8
design 1
enum_const 804
Expand Down Expand Up @@ -20504,7 +20504,7 @@ assignment 2
begin 8
bit_select 2082
bit_typespec 42
constant 7456
constant 7450
cont_assign 8
design 1
enum_const 804
Expand Down
4 changes: 2 additions & 2 deletions tests/BlackParrotParam/BlackParrotParam.log
Original file line number Diff line number Diff line change
Expand Up @@ -8879,7 +8879,7 @@ bit_typespec 44
class_defn 8
class_typespec 4
class_var 3
constant 5448
constant 5442
cont_assign 1
design 1
enum_const 307
Expand Down Expand Up @@ -8920,7 +8920,7 @@ bit_typespec 44
class_defn 8
class_typespec 4
class_var 3
constant 5448
constant 5442
cont_assign 2
design 1
enum_const 312
Expand Down
4 changes: 2 additions & 2 deletions tests/BlackParrotStructParam/BlackParrotStructParam.log
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ bit_typespec 4
class_defn 8
class_typespec 4
class_var 3
constant 132
constant 126
design 1
enum_const 9
enum_typespec 5
Expand Down Expand Up @@ -707,7 +707,7 @@ bit_typespec 4
class_defn 8
class_typespec 4
class_var 3
constant 132
constant 126
design 1
enum_const 14
enum_typespec 6
Expand Down
4 changes: 2 additions & 2 deletions tests/DefaultAssign/DefaultAssign.log
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ AST_DEBUG_END
[INF:UH0706] Creating UHDM Model...

=== UHDM Object Stats Begin (Non-Elaborated Model) ===
constant 28
constant 27
cont_assign 2
design 1
logic_net 3
Expand All @@ -190,7 +190,7 @@ tagged_pattern 6
[INF:UH0707] Elaborating UHDM...

=== UHDM Object Stats Begin (Elaborated Model) ===
constant 28
constant 27
cont_assign 3
design 1
logic_net 3
Expand Down
21 changes: 13 additions & 8 deletions tests/DefaultPatternInt/DefaultPatternInt.log
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ assign_stmt 1
assignment 1
begin 4
bit_select 8
constant 114
constant 109
design 1
for_stmt 1
func_call 3
Expand Down Expand Up @@ -442,7 +442,7 @@ assign_stmt 2
assignment 2
begin 5
bit_select 10
constant 114
constant 109
design 1
for_stmt 2
func_call 3
Expand Down Expand Up @@ -687,12 +687,13 @@ design: (work@main)
|vpiParent:
\_param_assign: , line:4:25, endln:4:47
|vpiExpr:
\_constant:
\_constant: , line:4:45, endln:4:46
|vpiDecompile:3
|vpiSize:64
|UINT:3
|vpiConstType:9
|vpiExpr:
\_constant:
\_constant: , line:4:45, endln:4:46
|vpiLhs:
\_parameter: (pack::V), line:4:25, endln:4:26
|vpiDefName:pack
Expand Down Expand Up @@ -920,17 +921,19 @@ design: (work@main)
|vpiParent:
\_param_assign: , line:4:25, endln:4:47
|vpiExpr:
\_constant:
\_constant: , line:4:45, endln:4:46
|vpiParent:
\_array_expr:
|vpiDecompile:3
|vpiSize:64
|UINT:3
|vpiConstType:9
|vpiExpr:
\_constant:
\_constant: , line:4:45, endln:4:46
|vpiParent:
\_array_expr:
|vpiDecompile:3
|vpiSize:64
|UINT:3
|vpiConstType:9
|vpiLhs:
Expand Down Expand Up @@ -1605,17 +1608,19 @@ design: (work@main)
|vpiParent:
\_param_assign: , line:4:25, endln:4:47
|vpiExpr:
\_constant: , line:19:5, endln:19:10
\_constant: , line:4:45, endln:4:46
|vpiParent:
\_operation: , line:19:5, endln:19:18
|vpiDecompile:3
|vpiSize:64
|UINT:3
|vpiConstType:9
|vpiExpr:
\_constant: , line:22:5, endln:22:10
\_constant: , line:4:45, endln:4:46
|vpiParent:
\_operation: , line:26:5, endln:26:18
|vpiDecompile:3
|vpiSize:64
|UINT:3
|vpiConstType:9
|vpiLhs:
Expand Down
9 changes: 5 additions & 4 deletions tests/DefaultPatternModule/DefaultPatternModule.log
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ assign_stmt 1
assignment 1
begin 4
bit_select 8
constant 57
constant 56
design 1
for_stmt 1
func_call 3
Expand Down Expand Up @@ -430,7 +430,7 @@ assign_stmt 2
assignment 2
begin 5
bit_select 10
constant 57
constant 56
design 1
for_stmt 2
func_call 3
Expand Down Expand Up @@ -1153,14 +1153,15 @@ design: (work@main)
|vpiTypespec:
\_array_typespec: , line:5:12, endln:5:31
|vpiExpr:
\_constant: , line:16:5, endln:16:10
\_constant: , line:5:45, endln:5:46
|vpiParent:
\_operation: , line:23:5, endln:23:18
|vpiDecompile:3
|vpiSize:64
|UINT:3
|vpiConstType:9
|vpiExpr:
\_constant: , line:16:5, endln:16:10
\_constant: , line:5:45, endln:5:46
|vpiLhs:
\_parameter: ([email protected]), line:5:25, endln:5:26
|vpiParamAssign:
Expand Down
4 changes: 2 additions & 2 deletions tests/PackageType/PackageType.log
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ AST_DEBUG_END
class_defn 8
class_typespec 4
class_var 3
constant 36
constant 31
design 1
enum_const 5
enum_typespec 1
Expand Down Expand Up @@ -438,7 +438,7 @@ typespec_member 12
class_defn 8
class_typespec 4
class_var 3
constant 36
constant 31
design 1
enum_const 10
enum_typespec 2
Expand Down
13 changes: 7 additions & 6 deletions tests/ParamArrayUnsizedPattern/ParamArrayUnsizedPattern.log
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ AST_DEBUG_END
=== UHDM Object Stats Begin (Non-Elaborated Model) ===
array_expr 1
array_typespec 9
constant 57
constant 56
design 1
int_typespec 12
module_inst 4
Expand All @@ -156,7 +156,7 @@ tagged_pattern 2
=== UHDM Object Stats Begin (Elaborated Model) ===
array_expr 1
array_typespec 9
constant 57
constant 56
design 1
int_typespec 12
module_inst 4
Expand Down Expand Up @@ -703,12 +703,13 @@ design: (work@test)
|vpiTypespec:
\_array_typespec: , line:4:13, endln:4:59
|vpiExpr:
\_constant:
|vpiDecompile:1
|UINT:1
\_constant: , line:4:73, endln:4:75
|vpiDecompile:4294967295
|vpiSize:32
|UINT:4294967295
|vpiConstType:9
|vpiExpr:
\_constant:
\_constant: , line:4:73, endln:4:75
|vpiLhs:
\_parameter: ([email protected]), line:4:26, endln:4:48
|vpiParamAssign:
Expand Down
4 changes: 2 additions & 2 deletions tests/ParamScope/ParamScope.log
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ AST_DEBUG_END
[INF:UH0706] Creating UHDM Model...

=== UHDM Object Stats Begin (Non-Elaborated Model) ===
constant 27
constant 21
design 1
import_typespec 1
int_typespec 18
Expand All @@ -253,7 +253,7 @@ tagged_pattern 10
[INF:UH0707] Elaborating UHDM...

=== UHDM Object Stats Begin (Elaborated Model) ===
constant 27
constant 21
design 1
import_typespec 1
int_typespec 18
Expand Down
4 changes: 2 additions & 2 deletions tests/PatternAssignLogic/PatternAssignLogic.log
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ AST_DEBUG_END
[INF:UH0706] Creating UHDM Model...

=== UHDM Object Stats Begin (Non-Elaborated Model) ===
constant 8
constant 7
design 1
logic_typespec 2
module_inst 4
Expand All @@ -87,7 +87,7 @@ tagged_pattern 2
[INF:UH0707] Elaborating UHDM...

=== UHDM Object Stats Begin (Elaborated Model) ===
constant 8
constant 7
design 1
logic_typespec 2
module_inst 4
Expand Down
4 changes: 2 additions & 2 deletions third_party/tests/CoresSweRV/CoresSweRV.log
Original file line number Diff line number Diff line change
Expand Up @@ -4825,7 +4825,7 @@ chandle_var 2
class_defn 613
class_typespec 8456
class_var 3302
constant 217351
constant 217350
constraint 4
cont_assign 7074
continue_stmt 52
Expand Down Expand Up @@ -4932,7 +4932,7 @@ chandle_var 2
class_defn 613
class_typespec 9905
class_var 21999
constant 217450
constant 217449
constraint 10
cont_assign 7123
continue_stmt 173
Expand Down
Loading

0 comments on commit f11370a

Please sign in to comment.