mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-09 22:24:37 +00:00
PTX: patch to AsmPrinter
- immediate value cast as long not int - handles initializer for constant array Patch by Dan Bailey git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130352 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -226,7 +226,7 @@ void PTXAsmPrinter::printOperand(const MachineInstr *MI, int opNum,
|
|||||||
OS << *Mang->getSymbol(MO.getGlobal());
|
OS << *Mang->getSymbol(MO.getGlobal());
|
||||||
break;
|
break;
|
||||||
case MachineOperand::MO_Immediate:
|
case MachineOperand::MO_Immediate:
|
||||||
OS << (int) MO.getImm();
|
OS << (long) MO.getImm();
|
||||||
break;
|
break;
|
||||||
case MachineOperand::MO_MachineBasicBlock:
|
case MachineOperand::MO_MachineBasicBlock:
|
||||||
OS << *MO.getMBB()->getSymbol();
|
OS << *MO.getMBB()->getSymbol();
|
||||||
@ -308,34 +308,59 @@ void PTXAsmPrinter::EmitVariableDeclaration(const GlobalVariable *gv) {
|
|||||||
const PointerType* pointerTy = dyn_cast<const PointerType>(gv->getType());
|
const PointerType* pointerTy = dyn_cast<const PointerType>(gv->getType());
|
||||||
const Type* elementTy = pointerTy->getElementType();
|
const Type* elementTy = pointerTy->getElementType();
|
||||||
|
|
||||||
assert(elementTy->isArrayTy() && "Only pointers to arrays are supported");
|
|
||||||
|
|
||||||
const ArrayType* arrayTy = dyn_cast<const ArrayType>(elementTy);
|
|
||||||
elementTy = arrayTy->getElementType();
|
|
||||||
|
|
||||||
unsigned numElements = arrayTy->getNumElements();
|
|
||||||
|
|
||||||
while (elementTy->isArrayTy()) {
|
|
||||||
|
|
||||||
arrayTy = dyn_cast<const ArrayType>(elementTy);
|
|
||||||
elementTy = arrayTy->getElementType();
|
|
||||||
|
|
||||||
numElements *= arrayTy->getNumElements();
|
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME: isPrimitiveType() == false for i16?
|
|
||||||
assert(elementTy->isSingleValueType() &&
|
|
||||||
"Non-primitive types are not handled");
|
|
||||||
|
|
||||||
// Compute the size of the array, in bytes.
|
|
||||||
uint64_t arraySize = (elementTy->getPrimitiveSizeInBits() >> 3)
|
|
||||||
* numElements;
|
|
||||||
|
|
||||||
decl += ".b8 ";
|
decl += ".b8 ";
|
||||||
decl += gvsym->getName();
|
decl += gvsym->getName();
|
||||||
decl += "[";
|
decl += "[";
|
||||||
decl += utostr(arraySize);
|
|
||||||
|
if (elementTy->isArrayTy())
|
||||||
|
{
|
||||||
|
assert(elementTy->isArrayTy() && "Only pointers to arrays are supported");
|
||||||
|
|
||||||
|
const ArrayType* arrayTy = dyn_cast<const ArrayType>(elementTy);
|
||||||
|
elementTy = arrayTy->getElementType();
|
||||||
|
|
||||||
|
unsigned numElements = arrayTy->getNumElements();
|
||||||
|
|
||||||
|
while (elementTy->isArrayTy()) {
|
||||||
|
|
||||||
|
arrayTy = dyn_cast<const ArrayType>(elementTy);
|
||||||
|
elementTy = arrayTy->getElementType();
|
||||||
|
|
||||||
|
numElements *= arrayTy->getNumElements();
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME: isPrimitiveType() == false for i16?
|
||||||
|
assert(elementTy->isSingleValueType() &&
|
||||||
|
"Non-primitive types are not handled");
|
||||||
|
|
||||||
|
// Compute the size of the array, in bytes.
|
||||||
|
uint64_t arraySize = (elementTy->getPrimitiveSizeInBits() >> 3)
|
||||||
|
* numElements;
|
||||||
|
|
||||||
|
decl += utostr(arraySize);
|
||||||
|
}
|
||||||
|
|
||||||
decl += "]";
|
decl += "]";
|
||||||
|
|
||||||
|
// handle string constants (assume ConstantArray means string)
|
||||||
|
|
||||||
|
if (gv->hasInitializer())
|
||||||
|
{
|
||||||
|
Constant *C = gv->getInitializer();
|
||||||
|
if (const ConstantArray *CA = dyn_cast<ConstantArray>(C))
|
||||||
|
{
|
||||||
|
decl += " = {";
|
||||||
|
|
||||||
|
for (unsigned i = 0, e = C->getNumOperands(); i != e; ++i)
|
||||||
|
{
|
||||||
|
if (i > 0) decl += ",";
|
||||||
|
|
||||||
|
decl += "0x" + utohexstr(cast<ConstantInt>(CA->getOperand(i))->getZExtValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
decl += "}";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Note: this is currently the fall-through case and most likely generates
|
// Note: this is currently the fall-through case and most likely generates
|
||||||
|
Reference in New Issue
Block a user