From 6d193685175f4a285239ea6e327e964949e71d26 Mon Sep 17 00:00:00 2001 From: Wen HU Date: Tue, 19 Jul 2022 06:48:24 -0700 Subject: [PATCH] mapping C source code type name --- src/mapleall/maple_ir/include/debug_info.h | 2 + src/mapleall/maple_ir/src/debug_info.cpp | 49 ++++++++++++++++++---- 2 files changed, 42 insertions(+), 9 deletions(-) diff --git a/src/mapleall/maple_ir/include/debug_info.h b/src/mapleall/maple_ir/include/debug_info.h index 9a07c2a274..dd55274ecf 100644 --- a/src/mapleall/maple_ir/include/debug_info.h +++ b/src/mapleall/maple_ir/include/debug_info.h @@ -770,6 +770,8 @@ class DebugInfo { DBGDie *GetOrCreateStructTypeDie(const MIRType *type); DBGDie *GetOrCreateTypedefDie(GStrIdx stridx, TyIdx tyidx); + GStrIdx GetPrimTypeCName(PrimType pty); + void AddAliasDies(MapleMap &aliasMap); void AddScopeDie(MIRScope *scope); void CollectScopePos(MIRFunction *func, MIRScope *scope); diff --git a/src/mapleall/maple_ir/src/debug_info.cpp b/src/mapleall/maple_ir/src/debug_info.cpp index 2d2c6d3c4c..178ec9c0e2 100644 --- a/src/mapleall/maple_ir/src/debug_info.cpp +++ b/src/mapleall/maple_ir/src/debug_info.cpp @@ -244,11 +244,36 @@ void DebugInfo::Init() { } } +GStrIdx DebugInfo::GetPrimTypeCName(PrimType pty) { + GStrIdx strIdx = GStrIdx(0); + switch (pty) { +#define TYPECNAME(p, n) case PTY_##p: strIdx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(n); break; + TYPECNAME(i8, "char"); + TYPECNAME(i16, "short"); + TYPECNAME(i32, "int"); + TYPECNAME(i64, "long long"); + TYPECNAME(i128, "int128"); + TYPECNAME(u8, "unsigned char"); + TYPECNAME(u16, "unsigned short"); + TYPECNAME(u32, "unsigned int"); + TYPECNAME(u64, "unsigned long long"); + TYPECNAME(u128, "uint128"); + TYPECNAME(u1, "bool"); + TYPECNAME(f32, "float"); + TYPECNAME(f64, "double"); + TYPECNAME(f128, "float128"); + TYPECNAME(c64, "complex"); + TYPECNAME(c128, "double complex"); + default: break; + } + return strIdx; +} + void DebugInfo::SetupCU() { compUnit->SetWithChildren(true); /* Add the Producer (Compiler) Information */ const char *producer = strdup((std::string("Maple Version ") + Version::GetVersionStr()).c_str()); - GStrIdx strIdx = module->GetMIRBuilder()->GetOrCreateStringIndex(producer); + GStrIdx strIdx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(producer); delete producer; producer = nullptr; compUnit->AddAttr(DW_AT_producer, DW_FORM_strp, strIdx.GetIdx()); @@ -258,8 +283,7 @@ void DebugInfo::SetupCU() { /* Add the compiled source file information */ compUnit->AddAttr(DW_AT_name, DW_FORM_strp, mplSrcIdx.GetIdx()); - strIdx = module->GetMIRBuilder()->GetOrCreateStringIndex("/to/be/done/current/path"); - compUnit->AddAttr(DW_AT_comp_dir, DW_FORM_strp, strIdx.GetIdx()); + compUnit->AddAttr(DW_AT_comp_dir, DW_FORM_strp, 0); compUnit->AddAttr(DW_AT_low_pc, DW_FORM_addr, kDbgDefaultVal); compUnit->AddAttr(DW_AT_high_pc, DW_FORM_data8, kDbgDefaultVal); @@ -759,16 +783,24 @@ DBGDie *DebugInfo::GetOrCreatePrimTypeDie(MIRType *ty) { DBGDie *die = module->GetMemPool()->New(module, DW_TAG_base_type); die->SetTyIdx(static_cast(pty)); - if (ty->GetNameStrIdx().GetIdx() == 0) { - const char *name = GetPrimTypeName(ty->GetPrimType()); - std::string pname = std::string(name); - GStrIdx strIdx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(pname); + GStrIdx strIdx = ty->GetNameStrIdx(); + if (strIdx.GetIdx() == 0) { + std::string pname = std::string(GetPrimTypeName(ty->GetPrimType())); + strIdx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(pname); ty->SetNameStrIdx(strIdx); } die->AddAttr(DW_AT_byte_size, DW_FORM_data4, GetPrimTypeSize(pty)); die->AddAttr(DW_AT_encoding, DW_FORM_data4, GetAteFromPTY(pty)); - die->AddAttr(DW_AT_name, DW_FORM_strp, ty->GetNameStrIdx().GetIdx()); + + // use C type name, int for i32 etc + if (module->IsCModule()) { + GStrIdx idx = GetPrimTypeCName(ty->GetPrimType()); + if (idx.GetIdx() != 0) { + strIdx = idx; + } + } + die->AddAttr(DW_AT_name, DW_FORM_strp, strIdx.GetIdx()); compUnit->AddSubVec(die); tyIdxDieIdMap[static_cast(pty)] = die->GetId(); @@ -1523,7 +1555,6 @@ void DBGDie::Dump(int indent) { } } LogInfo::MapleLogger() << std::endl; - ; for (auto it : attrVec) { it->Dump(indent + 1); } -- Gitee