mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-15 06:29:05 +00:00
-- Bug fix: use byte offsets not typed offsets in output assembly!
-- Add support for ConstantExpr constants (only cast and add operators so far) -- Avoid generating label Bbss.bss, which sometimes came out twice. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@3578 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -107,7 +107,7 @@ public:
|
|||||||
case Text: toAsm << "\".text\""; break;
|
case Text: toAsm << "\".text\""; break;
|
||||||
case ReadOnlyData: toAsm << "\".rodata\",#alloc"; break;
|
case ReadOnlyData: toAsm << "\".rodata\",#alloc"; break;
|
||||||
case InitRWData: toAsm << "\".data\",#alloc,#write"; break;
|
case InitRWData: toAsm << "\".data\",#alloc,#write"; break;
|
||||||
case UninitRWData: toAsm << "\".bss\",#alloc,#write\nBbss.bss:"; break;
|
case UninitRWData: toAsm << "\".bss\",#alloc,#write"; break;
|
||||||
}
|
}
|
||||||
toAsm << "\n";
|
toAsm << "\n";
|
||||||
}
|
}
|
||||||
@@ -186,30 +186,36 @@ public:
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
// ConstantExprToString() - Convert a ConstantExpr to a C expression, and
|
// ConstantExprToString() - Convert a ConstantExpr to an asm expression
|
||||||
// return this as a string.
|
// and return this as a string.
|
||||||
//
|
|
||||||
std::string ConstantExprToString(const ConstantExpr* CE,
|
std::string ConstantExprToString(const ConstantExpr* CE,
|
||||||
const TargetMachine& target) {
|
const TargetMachine& target) {
|
||||||
std::string S;
|
std::string S;
|
||||||
|
|
||||||
switch(CE->getOpcode()) {
|
switch(CE->getOpcode()) {
|
||||||
case Instruction::GetElementPtr:
|
case Instruction::GetElementPtr:
|
||||||
{
|
{ // generate a symbolic expression for the byte address
|
||||||
const Value* ptrVal = CE->getOperand(0);
|
const Value* ptrVal = CE->getOperand(0);
|
||||||
valToExprString(ptrVal, target, S);
|
|
||||||
std::vector<Value*> idxVec(CE->op_begin()+1, CE->op_end());
|
std::vector<Value*> idxVec(CE->op_begin()+1, CE->op_end());
|
||||||
uint64_t byteOffset =
|
S += "(" + valToExprString(ptrVal, target) + ") + ("
|
||||||
target.DataLayout.getIndexedOffset(ptrVal->getType(), idxVec);
|
+ utostr(target.DataLayout.getIndexedOffset(ptrVal->getType(),idxVec))
|
||||||
|
+ ")";
|
||||||
const Type *PtrElTy =
|
|
||||||
cast<PointerType>(ptrVal->getType())->getElementType();
|
|
||||||
uint64_t eltSize = target.DataLayout.getTypeSize(PtrElTy);
|
|
||||||
|
|
||||||
S += " + " + utostr(byteOffset / eltSize);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case Instruction::Cast:
|
||||||
|
// Support only non-converting casts for now, i.e., a no-op.
|
||||||
|
// This assertion is not a complete check.
|
||||||
|
assert(target.DataLayout.getTypeSize(CE->getType()) ==
|
||||||
|
target.DataLayout.getTypeSize(CE->getOperand(0)->getType()));
|
||||||
|
S += "(" + valToExprString(CE->getOperand(0), target) + ")";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Instruction::Add:
|
||||||
|
S += "(" + valToExprString(CE->getOperand(0), target) + ") + ("
|
||||||
|
+ valToExprString(CE->getOperand(1), target) + ")";
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
assert(0 && "Unsupported operator in ConstantExprToString()");
|
assert(0 && "Unsupported operator in ConstantExprToString()");
|
||||||
break;
|
break;
|
||||||
@@ -221,8 +227,8 @@ public:
|
|||||||
// valToExprString - Helper function for ConstantExprToString().
|
// valToExprString - Helper function for ConstantExprToString().
|
||||||
// Appends result to argument string S.
|
// Appends result to argument string S.
|
||||||
//
|
//
|
||||||
void valToExprString(const Value* V, const TargetMachine& target,
|
std::string valToExprString(const Value* V, const TargetMachine& target) {
|
||||||
std::string& S) {
|
std::string S;
|
||||||
bool failed = false;
|
bool failed = false;
|
||||||
if (const Constant* CV = dyn_cast<Constant>(V)) { // symbolic or known
|
if (const Constant* CV = dyn_cast<Constant>(V)) { // symbolic or known
|
||||||
|
|
||||||
@@ -237,7 +243,7 @@ public:
|
|||||||
else if (isa<ConstantPointerNull>(CV))
|
else if (isa<ConstantPointerNull>(CV))
|
||||||
S += "0";
|
S += "0";
|
||||||
else if (const ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(CV))
|
else if (const ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(CV))
|
||||||
valToExprString(CPR->getValue(), target, S);
|
S += valToExprString(CPR->getValue(), target);
|
||||||
else if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV))
|
else if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV))
|
||||||
S += ConstantExprToString(CE, target);
|
S += ConstantExprToString(CE, target);
|
||||||
else
|
else
|
||||||
@@ -253,6 +259,7 @@ public:
|
|||||||
assert(0 && "Cannot convert value to string");
|
assert(0 && "Cannot convert value to string");
|
||||||
S += "<illegal-value>";
|
S += "<illegal-value>";
|
||||||
}
|
}
|
||||||
|
return S;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
@@ -860,8 +867,6 @@ void SparcModuleAsmPrinter::emitGlobalsAndConstants(const Module &M) {
|
|||||||
for (Module::const_giterator GI = M.gbegin(), GE = M.gend(); GI != GE; ++GI) {
|
for (Module::const_giterator GI = M.gbegin(), GE = M.gend(); GI != GE; ++GI) {
|
||||||
if (GI->hasInitializer() && GI->isConstant()) {
|
if (GI->hasInitializer() && GI->isConstant()) {
|
||||||
enterSection(AsmPrinter::ReadOnlyData); // read-only, initialized data
|
enterSection(AsmPrinter::ReadOnlyData); // read-only, initialized data
|
||||||
} else if (GI->hasInitializer() && !GI->isConstant()) { // read-write data
|
|
||||||
enterSection(AsmPrinter::ReadOnlyData); // read-only, initialized data
|
|
||||||
} else if (GI->hasInitializer() && !GI->isConstant()) { // read-write data
|
} else if (GI->hasInitializer() && !GI->isConstant()) { // read-write data
|
||||||
enterSection(AsmPrinter::InitRWData);
|
enterSection(AsmPrinter::InitRWData);
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user