[go: nahoru, domu]

Skip to content

Commit

Permalink
enum const constant pushing
Browse files Browse the repository at this point in the history
  • Loading branch information
alaindargelas committed Nov 14, 2023
1 parent 0098e46 commit a7e8d79
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- mode:cmake -*-
cmake_minimum_required(VERSION 3.20 FATAL_ERROR)

project(UHDM VERSION 1.79)
project(UHDM VERSION 1.80)

# Detect build type, fallback to release and throw a warning if use didn't
# specify any
Expand Down
2 changes: 1 addition & 1 deletion templates/ExprEval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ std::string ExprEval::toBinary(const constant *c) {
return result;
}

static std::vector<std::string_view> tokenizeMulti(
std::vector<std::string_view> ExprEval::tokenizeMulti(
std::string_view str, std::string_view multichar_separator) {
std::vector<std::string_view> result;
if (str.empty()) return result;
Expand Down
3 changes: 3 additions & 0 deletions templates/ExprEval.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ class ExprEval {
}

UHDM::task_func* getTaskFunc(std::string_view name, const any* inst);

std::vector<std::string_view> tokenizeMulti(
std::string_view str, std::string_view multichar_separator);
#endif
private:
GetObjectFunctor getObjectFunctor = nullptr;
Expand Down
73 changes: 72 additions & 1 deletion templates/UhdmAdjuster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ void UhdmAdjuster::leaveCase_stmt(const case_stmt* object, vpiHandle handle) {
if (isInUhdmAllIterator()) return;
// Make all expressions match the largest expression size per LRM
int32_t maxsize = 0;
updateParentWithReducedExpression(object->VpiCondition(), object);
bool is_overall_unsigned = false;
{
// Find maxsize and is any expression is unsigned
Expand Down Expand Up @@ -195,6 +196,16 @@ void UhdmAdjuster::leaveModule_inst(const module_inst* object,
currentInstance_ = nullptr;
}

void UhdmAdjuster::enterPackage(const package* object,
vpiHandle handle) {
currentInstance_ = object;
}

void UhdmAdjuster::leavePackage(const package* object,
vpiHandle handle) {
currentInstance_ = nullptr;
}

void UhdmAdjuster::enterGen_scope(const gen_scope* object, vpiHandle handle) {
currentInstance_ = object;
}
Expand Down Expand Up @@ -290,7 +301,8 @@ void UhdmAdjuster::updateParentWithReducedExpression(const any* object, const an
expr* tmp =
eval.reduceExpr(object, invalidValue, currentInstance_, parent, true);
if (invalidValue) return;
if (tmp && tmp->UhdmType() == UHDM_OBJECT_TYPE::uhdmconstant) {
if (tmp == nullptr) return;
if (tmp->UhdmType() == UHDM_OBJECT_TYPE::uhdmconstant) {
tmp->VpiFile(object->VpiFile());
tmp->VpiLineNo(object->VpiLineNo());
tmp->VpiColumnNo(object->VpiColumnNo());
Expand Down Expand Up @@ -337,6 +349,65 @@ void UhdmAdjuster::updateParentWithReducedExpression(const any* object, const an
if (pselect->VpiIndex() == object) {
pselect->VpiIndex(tmp);
}
} else if (parent->UhdmType() == UHDM_OBJECT_TYPE::uhdmreturn_stmt) {
return_stmt* stmt = (return_stmt*)parent;
stmt->VpiCondition(tmp);
} else if (parent->UhdmType() == UHDM_OBJECT_TYPE::uhdmcase_stmt) {
case_stmt* stmt = (case_stmt*)parent;
stmt->VpiCondition(tmp);
} else if (parent->UhdmType() == UHDM_OBJECT_TYPE::uhdmcase_item) {
case_item* poper = (case_item*)parent;
VectorOfany* operands = poper->VpiExprs();
if (operands) {
uint64_t index = 0;
for (any* oper : *operands) {
if (oper == object) {
operands->at(index) = tmp;
break;
}
index++;
}
}
}
}

void UhdmAdjuster::leaveFunc_call(const func_call* object, vpiHandle handle) {
if (isInUhdmAllIterator()) return;
const std::string_view name = object->VpiName();
if (name.find("::") != std::string::npos) {
ExprEval eval;
std::vector<std::string_view> res = eval.tokenizeMulti(name, "::");
const std::string_view packName = res[0];
const std::string_view funcName = res[1];
if (design_->TopPackages()) {
for (package* pack : *design_->TopPackages()) {
if (pack->VpiName() == packName) {
if (pack->Task_funcs()) {
for (task_func* tf : *pack->Task_funcs()) {
if (tf->VpiName() == funcName) {
if (tf->UhdmType() == uhdmfunction)
((func_call*)object)->Function((function*)tf);
}
}
}
break;
}
}
}
}
}

void UhdmAdjuster::leaveReturn_stmt(const return_stmt* object, vpiHandle) {
if (isInUhdmAllIterator()) return;
updateParentWithReducedExpression(object->VpiCondition(), object);
}

void UhdmAdjuster::leaveCase_item(const case_item* object, vpiHandle handle) {
if (isInUhdmAllIterator()) return;
if (object->VpiExprs()) {
for (auto ex : *object->VpiExprs()) {
updateParentWithReducedExpression(ex, object);
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions templates/UhdmAdjuster.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,16 @@ class UhdmAdjuster final : public VpiListener {
void leaveCase_stmt(const case_stmt* object, vpiHandle handle) final;
void leaveOperation(const operation* object, vpiHandle handle) final;
void leaveSys_func_call(const sys_func_call* object, vpiHandle handle) final;
void leaveFunc_call(const func_call* object, vpiHandle handle) final;
void leaveConstant(const constant* object, vpiHandle handle) final;
void enterModule_inst(const module_inst* object, vpiHandle handle) final;
void leaveModule_inst(const module_inst* object, vpiHandle handle) final;
void enterPackage(const package* object, vpiHandle handle) final;
void leavePackage(const package* object, vpiHandle handle) final;
void leaveCase_item(const case_item* object, vpiHandle handle) final;
void enterGen_scope(const gen_scope* object, vpiHandle handle) final;
void leaveGen_scope(const gen_scope* object, vpiHandle handle) final;
void leaveReturn_stmt(const return_stmt* object, vpiHandle) final;
const any* resize(const any* object, int32_t maxsize, bool is_unsigned);
void updateParentWithReducedExpression(const any* object, const any* parent);
Serializer* serializer_ = nullptr;
Expand Down

0 comments on commit a7e8d79

Please sign in to comment.