mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-28 03:25:23 +00:00
Use the LLVM standard name mangling infrastructure instead of reinventing the
wheel. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10891 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -27,6 +27,7 @@
|
|||||||
#include "llvm/CodeGen/MachineFunction.h"
|
#include "llvm/CodeGen/MachineFunction.h"
|
||||||
#include "llvm/CodeGen/MachineFunctionInfo.h"
|
#include "llvm/CodeGen/MachineFunctionInfo.h"
|
||||||
#include "llvm/CodeGen/MachineInstr.h"
|
#include "llvm/CodeGen/MachineInstr.h"
|
||||||
|
#include "llvm/Support/Mangler.h"
|
||||||
#include "Support/StringExtras.h"
|
#include "Support/StringExtras.h"
|
||||||
#include "Support/Statistic.h"
|
#include "Support/Statistic.h"
|
||||||
#include "SparcInternals.h"
|
#include "SparcInternals.h"
|
||||||
@@ -36,20 +37,6 @@ using namespace llvm;
|
|||||||
namespace {
|
namespace {
|
||||||
Statistic<> EmittedInsts("asm-printer", "Number of machine instrs printed");
|
Statistic<> EmittedInsts("asm-printer", "Number of machine instrs printed");
|
||||||
|
|
||||||
class GlobalIdTable: public Annotation {
|
|
||||||
static AnnotationID AnnotId;
|
|
||||||
friend class AsmPrinter; // give access to AnnotId
|
|
||||||
public:
|
|
||||||
// AnonymousObjectMap - map anonymous values to unique integer IDs
|
|
||||||
std::map<const Value*, unsigned> AnonymousObjectMap;
|
|
||||||
unsigned LastAnonIDUsed;
|
|
||||||
|
|
||||||
GlobalIdTable() : Annotation(AnnotId), LastAnonIDUsed(0) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
AnnotationID GlobalIdTable::AnnotId =
|
|
||||||
AnnotationManager::getID("ASM PRINTER GLOBAL TABLE ANNOT");
|
|
||||||
|
|
||||||
//===--------------------------------------------------------------------===//
|
//===--------------------------------------------------------------------===//
|
||||||
// Utility functions
|
// Utility functions
|
||||||
|
|
||||||
@@ -169,7 +156,9 @@ namespace {
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
class AsmPrinter {
|
class AsmPrinter {
|
||||||
GlobalIdTable* idTable;
|
// Mangle symbol names appropriately
|
||||||
|
Mangler *Mang;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::ostream &toAsm;
|
std::ostream &toAsm;
|
||||||
const TargetMachine &Target;
|
const TargetMachine &Target;
|
||||||
@@ -183,16 +172,15 @@ namespace {
|
|||||||
} CurSection;
|
} CurSection;
|
||||||
|
|
||||||
AsmPrinter(std::ostream &os, const TargetMachine &T)
|
AsmPrinter(std::ostream &os, const TargetMachine &T)
|
||||||
: idTable(0), toAsm(os), Target(T), CurSection(Unknown) {}
|
: /* idTable(0), */ toAsm(os), Target(T), CurSection(Unknown) {}
|
||||||
|
|
||||||
|
~AsmPrinter() {
|
||||||
|
delete Mang;
|
||||||
|
}
|
||||||
|
|
||||||
// (start|end)(Module|Function) - Callback methods invoked by subclasses
|
// (start|end)(Module|Function) - Callback methods invoked by subclasses
|
||||||
void startModule(Module &M) {
|
void startModule(Module &M) {
|
||||||
// Create the global id table if it does not already exist
|
Mang = new Mangler(M);
|
||||||
idTable = (GlobalIdTable*)M.getAnnotation(GlobalIdTable::AnnotId);
|
|
||||||
if (idTable == NULL) {
|
|
||||||
idTable = new GlobalIdTable();
|
|
||||||
M.addAnnotation(idTable);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintZeroBytesToPad(int numBytes) {
|
void PrintZeroBytesToPad(int numBytes) {
|
||||||
@@ -265,68 +253,21 @@ namespace {
|
|||||||
toAsm << "\n";
|
toAsm << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string getValidSymbolName(const std::string &S) {
|
// getID Wrappers - Ensure consistent usage
|
||||||
std::string Result;
|
// Symbol names in Sparc assembly language have these rules:
|
||||||
|
// (a) Must match { letter | _ | . | $ } { letter | _ | . | $ | digit }*
|
||||||
// Symbol names in Sparc assembly language have these rules:
|
// (b) A name beginning in "." is treated as a local name.
|
||||||
// (a) Must match { letter | _ | . | $ } { letter | _ | . | $ | digit }*
|
|
||||||
// (b) A name beginning in "." is treated as a local name.
|
|
||||||
//
|
|
||||||
if (isdigit(S[0]))
|
|
||||||
Result = "ll";
|
|
||||||
|
|
||||||
for (unsigned i = 0; i < S.size(); ++i) {
|
|
||||||
char C = S[i];
|
|
||||||
if (C == '_' || C == '.' || C == '$' || isalpha(C) || isdigit(C))
|
|
||||||
Result += C;
|
|
||||||
else {
|
|
||||||
Result += '_';
|
|
||||||
Result += char('0' + ((unsigned char)C >> 4));
|
|
||||||
Result += char('0' + (C & 0xF));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// getID - Return a valid identifier for the specified value. Base it on
|
|
||||||
// the name of the identifier if possible (qualified by the type), and
|
|
||||||
// use a numbered value based on prefix otherwise.
|
|
||||||
// FPrefix is always prepended to the output identifier.
|
|
||||||
//
|
|
||||||
std::string getID(const Value *V, const char *Prefix,
|
|
||||||
const char *FPrefix = "")
|
|
||||||
{
|
|
||||||
std::string Result = FPrefix; // "Forced prefix"
|
|
||||||
|
|
||||||
Result += V->hasName() ? V->getName() : std::string(Prefix);
|
|
||||||
|
|
||||||
// Qualify all internal names with a unique id.
|
|
||||||
if (!isa<GlobalValue>(V) || !cast<GlobalValue>(V)->hasExternalLinkage()) {
|
|
||||||
unsigned &ValID = idTable->AnonymousObjectMap[V];
|
|
||||||
if (ValID == 0)
|
|
||||||
ValID = ++idTable->LastAnonIDUsed;
|
|
||||||
|
|
||||||
Result += "_" + utostr(ValID);
|
|
||||||
|
|
||||||
// Replace or prefix problem characters in the name
|
|
||||||
Result = getValidSymbolName(Result);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// getID Wrappers - Ensure consistent usage...
|
|
||||||
std::string getID(const Function *F) {
|
std::string getID(const Function *F) {
|
||||||
return getID(F, "LLVMFunction_");
|
return Mang->getValueName(F);
|
||||||
}
|
}
|
||||||
std::string getID(const BasicBlock *BB) {
|
std::string getID(const BasicBlock *BB) {
|
||||||
return getID(BB, "LL", (".L_"+getID(BB->getParent())+"_").c_str());
|
return ".L_" + getID(BB->getParent()) + "_" + Mang->getValueName(BB);
|
||||||
}
|
}
|
||||||
std::string getID(const GlobalVariable *GV) {
|
std::string getID(const GlobalVariable *GV) {
|
||||||
return getID(GV, "LLVMGlobal_");
|
return Mang->getValueName(GV);
|
||||||
}
|
}
|
||||||
std::string getID(const Constant *CV) {
|
std::string getID(const Constant *CV) {
|
||||||
return getID(CV, "LLVMConst_", ".C_");
|
return ".C_" + Mang->getValueName(CV);
|
||||||
}
|
}
|
||||||
std::string getID(const GlobalValue *GV) {
|
std::string getID(const GlobalValue *GV) {
|
||||||
if (const GlobalVariable *V = dyn_cast<GlobalVariable>(GV))
|
if (const GlobalVariable *V = dyn_cast<GlobalVariable>(GV))
|
||||||
|
Reference in New Issue
Block a user