From a7e8d79beaf4b2dfb19fb8b58fcc238956bf6a6b Mon Sep 17 00:00:00 2001 From: Alain Dargelas Date: Mon, 13 Nov 2023 18:58:27 -0800 Subject: [PATCH] enum const constant pushing --- CMakeLists.txt | 2 +- templates/ExprEval.cpp | 2 +- templates/ExprEval.h | 3 ++ templates/UhdmAdjuster.cpp | 73 +++++++++++++++++++++++++++++++++++++- templates/UhdmAdjuster.h | 5 +++ 5 files changed, 82 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3e1c5134..57ba3a3c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/templates/ExprEval.cpp b/templates/ExprEval.cpp index 3acd4350..395d0baa 100644 --- a/templates/ExprEval.cpp +++ b/templates/ExprEval.cpp @@ -214,7 +214,7 @@ std::string ExprEval::toBinary(const constant *c) { return result; } -static std::vector tokenizeMulti( +std::vector ExprEval::tokenizeMulti( std::string_view str, std::string_view multichar_separator) { std::vector result; if (str.empty()) return result; diff --git a/templates/ExprEval.h b/templates/ExprEval.h index 5555198c..178b7600 100644 --- a/templates/ExprEval.h +++ b/templates/ExprEval.h @@ -156,6 +156,9 @@ class ExprEval { } UHDM::task_func* getTaskFunc(std::string_view name, const any* inst); + + std::vector tokenizeMulti( + std::string_view str, std::string_view multichar_separator); #endif private: GetObjectFunctor getObjectFunctor = nullptr; diff --git a/templates/UhdmAdjuster.cpp b/templates/UhdmAdjuster.cpp index 8230262d..5c9b9f03 100644 --- a/templates/UhdmAdjuster.cpp +++ b/templates/UhdmAdjuster.cpp @@ -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 @@ -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; } @@ -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()); @@ -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 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); + } } } diff --git a/templates/UhdmAdjuster.h b/templates/UhdmAdjuster.h index b0b6bfb4..ce502339 100644 --- a/templates/UhdmAdjuster.h +++ b/templates/UhdmAdjuster.h @@ -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;