MCPcopy Create free account
hub / github.com/chipsalliance/Surelog / decompileHelper

Method decompileHelper

src/DesignCompile/CompileHelper.cpp:2538–2588  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2536}
2537
2538std::string CompileHelper::decompileHelper(const any* sel) {
2539 std::string path_name;
2540 UHDM::ExprEval eval;
2541 if (sel == nullptr) {
2542 return "";
2543 }
2544 if (sel->UhdmType() == uhdmconstant) {
2545 const std::string_view ind = ((expr*)sel)->VpiDecompile();
2546 path_name.append(ind);
2547 } else if (sel->UhdmType() == uhdmref_obj) {
2548 const std::string_view ind = ((expr*)sel)->VpiName();
2549 path_name.append(ind);
2550 } else if (sel->UhdmType() == uhdmoperation) {
2551 path_name.append(eval.prettyPrint(sel));
2552 } else if (sel->UhdmType() == uhdmbit_select) {
2553 bit_select* bsel = (bit_select*)sel;
2554 const expr* index = bsel->VpiIndex();
2555 if (index->UhdmType() == uhdmconstant) {
2556 const std::string_view ind = ((expr*)index)->VpiDecompile();
2557 path_name.append("[").append(ind).append("]");
2558 } else if (index->UhdmType() == uhdmref_obj) {
2559 const std::string_view ind = ((expr*)index)->VpiName();
2560 path_name.append("[").append(ind).append("]");
2561 } else if (index->UhdmType() == uhdmoperation) {
2562 path_name.append("[" + eval.prettyPrint(index) + "]");
2563 }
2564 } else if (const part_select* pselect = any_cast<const part_select*>(sel)) {
2565 std::string selectRange =
2566 StrCat("[", decompileHelper(pselect->Left_range()), ":",
2567 decompileHelper(pselect->Right_range()), "]");
2568 path_name += selectRange;
2569 } else if (const indexed_part_select* pselect =
2570 any_cast<const indexed_part_select*>(sel)) {
2571 std::string selectRange = StrCat(
2572 "[", decompileHelper(pselect->Base_expr()),
2573 ((pselect->VpiIndexedPartSelectType() == vpiPosIndexed) ? "+" : "-"),
2574 ":", decompileHelper(pselect->Width_expr()), "]");
2575 path_name += selectRange;
2576 } else if (const var_select* pselect = any_cast<const var_select*>(sel)) {
2577 std::string selectRange;
2578 VectorOfexpr* exprs = pselect->Exprs();
2579 for (auto ex : *exprs) {
2580 std::string tmp = decompileHelper(ex);
2581 if ((!tmp.empty()) && tmp[0] != '[') selectRange += StrCat("[");
2582 selectRange += StrCat(tmp);
2583 if ((!tmp.empty()) && tmp[0] != '[') selectRange += StrCat("]");
2584 }
2585 path_name += selectRange;
2586 }
2587 return path_name;
2588}
2589
2590std::pair<std::vector<UHDM::module_array*>, std::vector<UHDM::ref_module*>>
2591CompileHelper::compileInstantiation(ModuleDefinition* mod,

Callers

nothing calls this directly

Calls 2

StrCatFunction · 0.85
appendMethod · 0.45

Tested by

no test coverage detected