I!=E; ++I) {
std::string Name = Mang->getValueName(I);
std::string Target;
+
+ const GlobalValue *GV = cast<GlobalValue>(I->getAliasedGlobal());
+ Target = Mang->getValueName(GV);
- if (const GlobalValue *GV = I->getAliasedGlobal())
- Target = Mang->getValueName(GV);
- else
- assert(0 && "Unsupported aliasee");
-
- if (I->hasExternalLinkage())
+ if (I->hasExternalLinkage() || !TAI->getWeakRefDirective())
O << "\t.globl\t" << Name << "\n";
else if (I->hasWeakLinkage())
O << TAI->getWeakRefDirective() << Name << "\n";
assert(0 && "Invalid alias linkage");
O << TAI->getSetDirective() << Name << ", " << Target << "\n";
+
+ // If the aliasee has external weak linkage it can be referenced only by
+ // alias itself. In this case it can be not in ExtWeakSymbols list. Emit
+ // weak reference in such case.
+ if (GV->hasExternalWeakLinkage())
+ if (TAI->getWeakRefDirective())
+ O << TAI->getWeakRefDirective() << Target << "\n";
+ else
+ O << "\t.globl\t" << Target << "\n";
}
}
return false;
}
+std::string AsmPrinter::getCurrentFunctionEHName(const MachineFunction *MF) {
+ assert(MF && "No machine function?");
+ return Mang->makeNameProper(MF->getFunction()->getName() + ".eh",
+ TAI->getGlobalPrefix());
+}
+
void AsmPrinter::SetupMachineFunction(MachineFunction &MF) {
// What's my mangled name?
CurrentFnName = Mang->getValueName(MF.getFunction());
/// special global used by LLVM. If so, emit it and return true, otherwise
/// do nothing and return false.
bool AsmPrinter::EmitSpecialLLVMGlobal(const GlobalVariable *GV) {
+ if (GV->getName() == "llvm.used") {
+ if (TAI->getUsedDirective() != 0) // No need to emit this at all.
+ EmitLLVMUsedList(GV->getInitializer());
+ return true;
+ }
+
// Ignore debug and non-emitted data.
if (GV->getSection() == "llvm.metadata") return true;
assert(GV->hasInitializer() && "Not a special LLVM global!");
- if (GV->getName() == "llvm.used") {
- if (TAI->getUsedDirective() != 0) // No need to emit this at all.
- EmitLLVMUsedList(GV->getInitializer());
- return true;
- }
-
const TargetData *TD = TM.getTargetData();
unsigned Align = Log2_32(TD->getPointerPrefAlignment());
if (GV->getName() == "llvm.global_ctors" && GV->use_empty()) {
}
+/// EmitFile - Emit a .file directive.
+void AsmPrinter::EmitFile(unsigned Number, const std::string &Name) const {
+ O << "\t.file\t" << Number << " \"";
+ for (unsigned i = 0, N = Name.size(); i < N; ++i) {
+ unsigned char C = Name[i];
+ printStringChar(O, C);
+ }
+ O << "\"";
+}
+
+
//===----------------------------------------------------------------------===//
// EmitAlignment - Emit an alignment directive to the specified power of
if (CVA->isString()) {
EmitString(CVA);
} else { // Not a string. Print the values in successive locations
- for (unsigned i = 0, e = CVA->getNumOperands(); i != e; ++i)
+ for (unsigned i = 0, e = CVA->getNumOperands(); i != e; ++i) {
EmitGlobalConstant(CVA->getOperand(i));
+ const Type* EltTy = CVA->getType()->getElementType();
+ uint64_t padSize = TD->getABITypeSize(EltTy) - TD->getTypeSize(EltTy);
+ EmitZeros(padSize);
+ }
}
return;
} else if (const ConstantStruct *CVS = dyn_cast<ConstantStruct>(CV)) {
} else if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) {
// FP Constants are printed as integer constants to avoid losing
// precision...
- double Val = CFP->getValue();
if (CFP->getType() == Type::DoubleTy) {
+ double Val = CFP->getValueAPF().convertToDouble(); // for comment only
+ uint64_t i = CFP->getValueAPF().convertToAPInt().getZExtValue();
if (TAI->getData64bitsDirective())
- O << TAI->getData64bitsDirective() << DoubleToBits(Val) << "\t"
+ O << TAI->getData64bitsDirective() << i << "\t"
<< TAI->getCommentString() << " double value: " << Val << "\n";
else if (TD->isBigEndian()) {
- O << TAI->getData32bitsDirective() << unsigned(DoubleToBits(Val) >> 32)
+ O << TAI->getData32bitsDirective() << unsigned(i >> 32)
<< "\t" << TAI->getCommentString()
<< " double most significant word " << Val << "\n";
- O << TAI->getData32bitsDirective() << unsigned(DoubleToBits(Val))
+ O << TAI->getData32bitsDirective() << unsigned(i)
<< "\t" << TAI->getCommentString()
<< " double least significant word " << Val << "\n";
} else {
- O << TAI->getData32bitsDirective() << unsigned(DoubleToBits(Val))
+ O << TAI->getData32bitsDirective() << unsigned(i)
<< "\t" << TAI->getCommentString()
<< " double least significant word " << Val << "\n";
- O << TAI->getData32bitsDirective() << unsigned(DoubleToBits(Val) >> 32)
+ O << TAI->getData32bitsDirective() << unsigned(i >> 32)
<< "\t" << TAI->getCommentString()
<< " double most significant word " << Val << "\n";
}
return;
- } else {
- O << TAI->getData32bitsDirective() << FloatToBits(Val)
+ } else if (CFP->getType() == Type::FloatTy) {
+ float Val = CFP->getValueAPF().convertToFloat(); // for comment only
+ O << TAI->getData32bitsDirective()
+ << CFP->getValueAPF().convertToAPInt().getZExtValue()
<< "\t" << TAI->getCommentString() << " float " << Val << "\n";
return;
- }
+ } else if (CFP->getType() == Type::X86_FP80Ty) {
+ // all long double variants are printed as hex
+ // api needed to prevent premature destruction
+ APInt api = CFP->getValueAPF().convertToAPInt();
+ const uint64_t *p = api.getRawData();
+ if (TD->isBigEndian()) {
+ O << TAI->getData16bitsDirective() << uint16_t(p[0] >> 48)
+ << "\t" << TAI->getCommentString()
+ << " long double most significant halfword\n";
+ O << TAI->getData16bitsDirective() << uint16_t(p[0] >> 32)
+ << "\t" << TAI->getCommentString()
+ << " long double next halfword\n";
+ O << TAI->getData16bitsDirective() << uint16_t(p[0] >> 16)
+ << "\t" << TAI->getCommentString()
+ << " long double next halfword\n";
+ O << TAI->getData16bitsDirective() << uint16_t(p[0])
+ << "\t" << TAI->getCommentString()
+ << " long double next halfword\n";
+ O << TAI->getData16bitsDirective() << uint16_t(p[1])
+ << "\t" << TAI->getCommentString()
+ << " long double least significant halfword\n";
+ } else {
+ O << TAI->getData16bitsDirective() << uint16_t(p[1])
+ << "\t" << TAI->getCommentString()
+ << " long double least significant halfword\n";
+ O << TAI->getData16bitsDirective() << uint16_t(p[0])
+ << "\t" << TAI->getCommentString()
+ << " long double next halfword\n";
+ O << TAI->getData16bitsDirective() << uint16_t(p[0] >> 16)
+ << "\t" << TAI->getCommentString()
+ << " long double next halfword\n";
+ O << TAI->getData16bitsDirective() << uint16_t(p[0] >> 32)
+ << "\t" << TAI->getCommentString()
+ << " long double next halfword\n";
+ O << TAI->getData16bitsDirective() << uint16_t(p[0] >> 48)
+ << "\t" << TAI->getCommentString()
+ << " long double most significant halfword\n";
+ }
+ return;
+ } else if (CFP->getType() == Type::PPC_FP128Ty) {
+ // all long double variants are printed as hex
+ // api needed to prevent premature destruction
+ APInt api = CFP->getValueAPF().convertToAPInt();
+ const uint64_t *p = api.getRawData();
+ if (TD->isBigEndian()) {
+ O << TAI->getData32bitsDirective() << uint32_t(p[0] >> 32)
+ << "\t" << TAI->getCommentString()
+ << " long double most significant word\n";
+ O << TAI->getData32bitsDirective() << uint32_t(p[0])
+ << "\t" << TAI->getCommentString()
+ << " long double next word\n";
+ O << TAI->getData32bitsDirective() << uint32_t(p[1] >> 32)
+ << "\t" << TAI->getCommentString()
+ << " long double next word\n";
+ O << TAI->getData32bitsDirective() << uint32_t(p[1])
+ << "\t" << TAI->getCommentString()
+ << " long double least significant word\n";
+ } else {
+ O << TAI->getData32bitsDirective() << uint32_t(p[1])
+ << "\t" << TAI->getCommentString()
+ << " long double least significant word\n";
+ O << TAI->getData32bitsDirective() << uint32_t(p[1] >> 32)
+ << "\t" << TAI->getCommentString()
+ << " long double next word\n";
+ O << TAI->getData32bitsDirective() << uint32_t(p[0])
+ << "\t" << TAI->getCommentString()
+ << " long double next word\n";
+ O << TAI->getData32bitsDirective() << uint32_t(p[0] >> 32)
+ << "\t" << TAI->getCommentString()
+ << " long double most significant word\n";
+ }
+ return;
+ } else assert(0 && "Floating point constant type not handled");
} else if (CV->getType() == Type::Int64Ty) {
if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
uint64_t Val = CI->getZExtValue();
// Count the number of register definitions.
unsigned NumDefs = 0;
- for (; MI->getOperand(NumDefs).isReg() && MI->getOperand(NumDefs).isDef();
+ for (; MI->getOperand(NumDefs).isRegister() && MI->getOperand(NumDefs).isDef();
++NumDefs)
assert(NumDefs != NumOperands-1 && "No asm string?");
void AsmPrinter::printBasicBlockLabel(const MachineBasicBlock *MBB,
bool printColon,
bool printComment) const {
- O << TAI->getPrivateGlobalPrefix() << "BB" << FunctionNumber << "_"
+ O << TAI->getPrivateGlobalPrefix() << "BB" << getFunctionNumber() << "_"
<< MBB->getNumber();
if (printColon)
O << ':';
}
break;
case Type::FloatTyID: case Type::DoubleTyID:
+ case Type::X86_FP80TyID: case Type::FP128TyID: case Type::PPC_FP128TyID:
assert (0 && "Should have already output floating point constant.");
default:
assert (0 && "Can't handle printing this type of thing");