diff --git a/src/hir2mpl/bytecode_input/common/src/bc_function.cpp b/src/hir2mpl/bytecode_input/common/src/bc_function.cpp index f316a33783bbcce49bbec4cfca2142f2757c4387..e6e816f6e975c4cbf60eeef21501f3e4e3d099f0 100644 --- a/src/hir2mpl/bytecode_input/common/src/bc_function.cpp +++ b/src/hir2mpl/bytecode_input/common/src/bc_function.cpp @@ -86,7 +86,8 @@ bool BCFunction::GenerateAliasVars(const std::string &phaseName) { namemangler::EncodeName(std::get<0>(item))); MIRAliasVars aliasVar; aliasVar.mplStrIdx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(localVar->GetName(*mirType)); - aliasVar.tyIdx = mirType->GetTypeIndex(); + aliasVar.atk = ATK_type; + aliasVar.index = mirType->GetTypeIndex().GetIdx(); aliasVar.isLocal = !localVar->IsGlobal(); if (!std::get<2>(item).empty()) { aliasVar.sigStrIdx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(std::get<2>(item)); diff --git a/src/hir2mpl/common/src/fe_function.cpp b/src/hir2mpl/common/src/fe_function.cpp index 9a8e01aab3b2a3bc8ee4eb160d03d5cefd8e47e7..b9cad3e24b772d384f38b24b8db7a60dd293c2d3 100644 --- a/src/hir2mpl/common/src/fe_function.cpp +++ b/src/hir2mpl/common/src/fe_function.cpp @@ -858,11 +858,14 @@ void FEFunction::AddAliasInMIRScope(MIRScope *scope, const std::string &srcVarNa aliasVar.mplStrIdx = symbol->GetNameStrIdx(); aliasVar.isLocal = symbol->IsLocal(); if (sourceType != nullptr) { - aliasVar.tyIdx = sourceType->GetTypeIndex(); + aliasVar.atk = ATK_type; + aliasVar.index = sourceType->GetTypeIndex().GetIdx(); } else if (typeNameIdx != 0) { - aliasVar.srcTypeStrIdx = typeNameIdx; + aliasVar.atk = ATK_string; + aliasVar.index = typeNameIdx.GetIdx(); } else { - aliasVar.tyIdx = symbol->GetTyIdx(); + aliasVar.atk = ATK_type; + aliasVar.index = symbol->GetTyIdx().GetIdx(); } scope->SetAliasVarMap(nameIdx, aliasVar); }; diff --git a/src/mapleall/maple_ir/include/mir_scope.h b/src/mapleall/maple_ir/include/mir_scope.h index d36e55e87af4502445e54e42597d3f58ef56122a..1d86431359283df92b040976416c0206223ff5ae 100644 --- a/src/mapleall/maple_ir/include/mir_scope.h +++ b/src/mapleall/maple_ir/include/mir_scope.h @@ -21,10 +21,16 @@ namespace maple { // mapping src variable to mpl variables to display debug info +enum AliasTypeKind { + ATK_type, + ATK_string, + ATK_enum, +}; + struct MIRAliasVars { GStrIdx mplStrIdx; // maple varialbe name - TyIdx tyIdx; - GStrIdx srcTypeStrIdx; // src type name + AliasTypeKind atk; + unsigned index; bool isLocal; GStrIdx sigStrIdx; }; diff --git a/src/mapleall/maple_ir/src/bin_func_export.cpp b/src/mapleall/maple_ir/src/bin_func_export.cpp index cffdf1e75e31536fb48097d53af3fcbc64089a88..cf068215461cddfe8432e943c9a271346388a805 100644 --- a/src/mapleall/maple_ir/src/bin_func_export.cpp +++ b/src/mapleall/maple_ir/src/bin_func_export.cpp @@ -138,7 +138,8 @@ void BinaryMplExport::OutputAliasMap(MapleMap &aliasVarMa for (std::pair it : aliasVarMap) { OutputStr(it.first); OutputStr(it.second.mplStrIdx); - OutputType(it.second.tyIdx); + WriteNum(static_cast(it.second.atk)); + WriteNum(it.second.index); OutputStr(it.second.sigStrIdx); } } diff --git a/src/mapleall/maple_ir/src/bin_func_import.cpp b/src/mapleall/maple_ir/src/bin_func_import.cpp index b83f41af7f2ac39b9bfebbe488dd179e20582ce0..58f792bfa4d714d0a03dbfc1f537c7267823224f 100644 --- a/src/mapleall/maple_ir/src/bin_func_import.cpp +++ b/src/mapleall/maple_ir/src/bin_func_import.cpp @@ -153,7 +153,8 @@ void BinaryMplImport::ImportAliasMap(MIRFunction *func) { MIRAliasVars aliasvars; GStrIdx strIdx = ImportStr(); aliasvars.mplStrIdx = ImportStr(); - aliasvars.tyIdx = ImportType(); + aliasvars.atk = static_cast(ReadNum()); + aliasvars.index = static_cast(ReadNum()); (void)ImportStr(); // not assigning to mimic parser func->GetAliasVarMap()[strIdx] = aliasvars; } diff --git a/src/mapleall/maple_ir/src/debug_info.cpp b/src/mapleall/maple_ir/src/debug_info.cpp index ebba03fd8f52611724ce4eb585eb20e7c070400c..b3043f6327c121c826636b2901903bea90c9ad03 100644 --- a/src/mapleall/maple_ir/src/debug_info.cpp +++ b/src/mapleall/maple_ir/src/debug_info.cpp @@ -352,8 +352,9 @@ void DebugInfo::AddAliasDies(MapleMap &aliasMap) { DBGDie *vdie = CreateVarDie(var, i.first); // use src code type name for type if provided - if (i.second.srcTypeStrIdx.GetIdx()) { - DBGDie *typedefDie = GetOrCreateTypedefDie(i.second.srcTypeStrIdx, var->GetTyIdx()); + if (i.second.atk == ATK_string) { + GStrIdx idx(i.second.index); + DBGDie *typedefDie = GetOrCreateTypedefDie(idx, var->GetTyIdx()); // use negtive number to indicate DIE id instead of tyidx in normal cases (void)(vdie->SetAttr(DW_AT_type, -typedefDie->GetId())); } diff --git a/src/mapleall/maple_ir/src/mir_scope.cpp b/src/mapleall/maple_ir/src/mir_scope.cpp index c0882a82389812469577afb6a200dfc574bb3851..0f5659dad2369d25e31f735933759979576188df 100644 --- a/src/mapleall/maple_ir/src/mir_scope.cpp +++ b/src/mapleall/maple_ir/src/mir_scope.cpp @@ -124,11 +124,25 @@ void MIRScope::Dump(int32 indent) const { LogInfo::MapleLogger() << "ALIAS %" << GlobalTables::GetStrTable().GetStringFromStrIdx(it.first) << ((it.second.isLocal) ? " %" : " $") << GlobalTables::GetStrTable().GetStringFromStrIdx(it.second.mplStrIdx) << " "; - if (it.second.tyIdx) { - GlobalTables::GetTypeTable().GetTypeFromTyIdx(it.second.tyIdx)->Dump(0); - } else { - LogInfo::MapleLogger() << "\"" << GlobalTables::GetStrTable().GetStringFromStrIdx(it.second.srcTypeStrIdx) - << "\""; + switch (it.second.atk) { + case ATK_type: { + TyIdx idx(it.second.index); + GlobalTables::GetTypeTable().GetTypeFromTyIdx(TyIdx(idx))->Dump(0); + break; + } + case ATK_string: { + GStrIdx idx(it.second.index); + LogInfo::MapleLogger() << "\"" << GlobalTables::GetStrTable().GetStringFromStrIdx(idx) + << "\""; + break; + } + case ATK_enum: { + MIREnum *mirEnum = GlobalTables::GetEnumTable().enumTable[it.second.index]; + LogInfo::MapleLogger() << "$" << GlobalTables::GetStrTable().GetStringFromStrIdx(mirEnum->nameStrIdx); + break; + } + default : + break; } if (it.second.sigStrIdx) { LogInfo::MapleLogger() << " \"" << GlobalTables::GetStrTable().GetStringFromStrIdx(it.second.sigStrIdx) << "\""; diff --git a/src/mapleall/maple_ir/src/parser.cpp b/src/mapleall/maple_ir/src/parser.cpp index 746e1c8d64fe52ba4cac9b32951757921a14c4a2..552d22e1624ff830de6fdfc3e966a13068634e29 100644 --- a/src/mapleall/maple_ir/src/parser.cpp +++ b/src/mapleall/maple_ir/src/parser.cpp @@ -2596,31 +2596,48 @@ bool MIRParser::ParseOneAlias(GStrIdx &strIdx, MIRAliasVars &aliasVar) { } strIdx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(lexer.GetName()); nameTk = lexer.NextToken(); - bool isLocal; if (nameTk == TK_lname) { - isLocal = true; + aliasVar.isLocal = true; } else if (nameTk == TK_gname) { - isLocal = false; + aliasVar.isLocal = false; } else { Error("expect name in ALIAS but get "); return false; } GStrIdx mplStrIdx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(lexer.GetName()); aliasVar.mplStrIdx = mplStrIdx; - aliasVar.isLocal = isLocal; lexer.NextToken(); TokenKind tk = lexer.GetTokenKind(); TyIdx tyIdx(0); - if (tk == TK_string || tk == TK_gname) { + if (tk == TK_string) { // original type name from source code std::string typeName = lexer.GetName(); GStrIdx srcTypeStrIdx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(typeName); - aliasVar.tyIdx = TyIdx(0); - aliasVar.srcTypeStrIdx = srcTypeStrIdx; + aliasVar.atk = ATK_string; + aliasVar.index = srcTypeStrIdx.GetIdx(); + lexer.NextToken(); + } else if (tk == TK_gname) { + // type name or enum name + std::string typeName = lexer.GetName(); + GStrIdx strIdx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(typeName); + TyIdx tyIdx = mod.GetTypeNameTab()->GetTyIdxFromGStrIdx(strIdx); + if (tyIdx.GetIdx() != 0) { + aliasVar.atk = ATK_type; + aliasVar.index = tyIdx.GetIdx(); + } else { + unsigned size = GlobalTables::GetEnumTable().enumTable.size(); + for (unsigned i = 0; i < size; ++i) { + MIREnum *mirEnum = GlobalTables::GetEnumTable().enumTable[i]; + if (strIdx == mirEnum->nameStrIdx) { + aliasVar.atk = ATK_enum; + aliasVar.index = i; + } + } + } lexer.NextToken(); } else if (ParseType(tyIdx)) { - aliasVar.tyIdx = tyIdx; - aliasVar.srcTypeStrIdx = GStrIdx(0); + aliasVar.atk = ATK_type; + aliasVar.index = tyIdx.GetIdx(); } else { Error("parseType failed when parsing ALIAS "); return false;