Skip to content

Commit dcf4080

Browse files
Merge pull request #51 from alainmarcel/fix_tests
fix tests: enum
2 parents 37dfd5a + 87e3112 commit dcf4080

32 files changed

Lines changed: 3218 additions & 663 deletions

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cmake_minimum_required(VERSION 3.20 FATAL_ERROR)
22

3-
project(uhdm2rtlil VERSION 1.0)
3+
project(uhdm2rtlil VERSION 1.86)
44

55
# Set C++ standard
66
set(CMAKE_CXX_STANDARD 17)

src/frontends/uhdm/expression.cpp

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -860,9 +860,39 @@ RTLIL::SigSpec UhdmImporter::import_ref_obj(const ref_obj* uhdm_ref, const UHDM:
860860
return RTLIL::SigSpec(RTLIL::Const(value, 32));
861861
}
862862

863-
// Check if the ref_obj has an Actual_group() that points to a parameter
863+
// Check if the ref_obj has an Actual_group() that points to a parameter or enum constant
864864
if (uhdm_ref->Actual_group()) {
865865
const any* actual = uhdm_ref->Actual_group();
866+
867+
// Check for enum constant
868+
if (actual->UhdmType() == uhdmenum_const) {
869+
const UHDM::enum_const* enum_val = any_cast<const UHDM::enum_const*>(actual);
870+
// Get the enum value - enum constants store their value in VpiValue
871+
std::string val_str = std::string(enum_val->VpiValue());
872+
873+
if (mode_debug)
874+
log("UHDM: Found enum constant %s with value %s\n", ref_name.c_str(), val_str.c_str());
875+
876+
// Parse value from format like "INT:0", "UINT:1", etc.
877+
RTLIL::Const enum_value;
878+
if (!val_str.empty()) {
879+
size_t colon_pos = val_str.find(':');
880+
if (colon_pos != std::string::npos) {
881+
std::string value_part = val_str.substr(colon_pos + 1);
882+
// Parse as integer
883+
enum_value = RTLIL::Const(std::stoi(value_part), 32);
884+
} else {
885+
// Try to parse as integer directly
886+
enum_value = RTLIL::Const(std::stoi(val_str), 32);
887+
}
888+
} else {
889+
// Default to 0 if no value specified
890+
enum_value = RTLIL::Const(0, 32);
891+
}
892+
893+
return RTLIL::SigSpec(enum_value);
894+
}
895+
866896
if (actual->VpiType() == vpiParameter) {
867897
const parameter* param = any_cast<const parameter*>(actual);
868898
// Get the parameter value - parameters typically store values as constants

src/frontends/uhdm/module.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,6 +1341,22 @@ int UhdmImporter::get_width_from_typespec(const UHDM::any* typespec, const UHDM:
13411341
return -1; // Special value to indicate interface type
13421342
}
13431343

1344+
// Check if this is an enum typespec - need to get the base type
1345+
if (typespec->UhdmType() == uhdmenum_typespec) {
1346+
log("UHDM: Found enum_typespec, getting base type\n");
1347+
if (auto enum_typespec = dynamic_cast<const UHDM::enum_typespec*>(typespec)) {
1348+
// Get the base typespec - this defines the actual width
1349+
if (auto base_typespec = enum_typespec->Base_typespec()) {
1350+
log("UHDM: Found base typespec for enum\n");
1351+
return get_width_from_typespec(base_typespec, inst);
1352+
} else {
1353+
// No explicit base type means default int type (32 bits in SystemVerilog)
1354+
log("UHDM: No base typespec for enum, defaulting to 32 bits\n");
1355+
return 32;
1356+
}
1357+
}
1358+
}
1359+
13441360
// Use UHDM::ExprEval to get the actual size of the typespec
13451361
UHDM::ExprEval eval;
13461362
bool invalidValue = false;

src/frontends/uhdm/process.cpp

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4573,6 +4573,7 @@ void UhdmImporter::import_case_stmt_sync(const case_stmt* uhdm_case, RTLIL::Sync
45734573
// First, collect all assignments from all case items
45744574
std::map<std::string, std::vector<std::pair<RTLIL::SigSpec, RTLIL::SigSpec>>> signal_assignments;
45754575
std::vector<RTLIL::SigSpec> case_conditions;
4576+
RTLIL::SigSpec all_non_default_conditions; // Track all non-default conditions
45764577

45774578
// Process each case item
45784579
if (auto case_items = uhdm_case->Case_items()) {
@@ -4582,6 +4583,7 @@ void UhdmImporter::import_case_stmt_sync(const case_stmt* uhdm_case, RTLIL::Sync
45824583
for (auto case_item : *case_items) {
45834584
// Get case expressions (values to match)
45844585
RTLIL::SigSpec case_condition;
4586+
bool is_default = false;
45854587

45864588
if (auto exprs = case_item->VpiExprs()) {
45874589
// Build equality comparison for this case
@@ -4603,8 +4605,19 @@ void UhdmImporter::import_case_stmt_sync(const case_stmt* uhdm_case, RTLIL::Sync
46034605
log_flush();
46044606
}
46054607
}
4608+
4609+
// Add this condition to the combined non-default conditions
4610+
if (!case_condition.empty()) {
4611+
if (all_non_default_conditions.empty()) {
4612+
all_non_default_conditions = case_condition;
4613+
} else {
4614+
// OR with other non-default conditions
4615+
all_non_default_conditions = create_or_cell(all_non_default_conditions, case_condition);
4616+
}
4617+
}
46064618
} else {
46074619
// This is a default case
4620+
is_default = true;
46084621
log(" Default case\n");
46094622
log_flush();
46104623
}
@@ -4618,7 +4631,23 @@ void UhdmImporter::import_case_stmt_sync(const case_stmt* uhdm_case, RTLIL::Sync
46184631
RTLIL::SigSpec prev_condition = current_condition;
46194632

46204633
// Set condition for nested statements
4621-
if (!case_condition.empty()) {
4634+
if (is_default) {
4635+
// For default case, use the negation of all other conditions
4636+
if (!all_non_default_conditions.empty()) {
4637+
// Create NOT of all non-default conditions
4638+
RTLIL::Wire* not_wire = module->addWire(NEW_ID, 1);
4639+
module->addNotGate(NEW_ID, all_non_default_conditions, not_wire);
4640+
RTLIL::SigSpec default_condition(not_wire);
4641+
4642+
if (current_condition.empty()) {
4643+
current_condition = default_condition;
4644+
} else {
4645+
// AND with existing condition
4646+
current_condition = create_and_cell(current_condition, default_condition);
4647+
}
4648+
log(" Using negation of all non-default conditions for default case\n");
4649+
}
4650+
} else if (!case_condition.empty()) {
46224651
if (current_condition.empty()) {
46234652
current_condition = case_condition;
46244653
} else {

0 commit comments

Comments
 (0)