#include "llvm/Support/Debug.h"
#include "llvm/Support/Dwarf.h"
#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/Format.h"
#include "llvm/Support/FormattedStream.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/raw_ostream.h"
case CallingConv::AnyReg: Out << "anyregcc"; break;
case CallingConv::PreserveMost: Out << "preserve_mostcc"; break;
case CallingConv::PreserveAll: Out << "preserve_allcc"; break;
+ case CallingConv::CXX_FAST_TLS: Out << "cxx_fast_tlscc"; break;
case CallingConv::GHC: Out << "ghccc"; break;
case CallingConv::X86_StdCall: Out << "x86_stdcallcc"; break;
case CallingConv::X86_FastCall: Out << "x86_fastcallcc"; break;
// the value back and get the same value.
//
bool ignored;
- bool isHalf = &CFP->getValueAPF().getSemantics()==&APFloat::IEEEhalf;
bool isDouble = &CFP->getValueAPF().getSemantics()==&APFloat::IEEEdouble;
bool isInf = CFP->getValueAPF().isInfinity();
bool isNaN = CFP->getValueAPF().isNaN();
- if (!isHalf && !isInf && !isNaN) {
+ if (!isInf && !isNaN) {
double Val = isDouble ? CFP->getValueAPF().convertToDouble() :
CFP->getValueAPF().convertToFloat();
SmallString<128> StrVal;
// x86, so we must not use these types.
static_assert(sizeof(double) == sizeof(uint64_t),
"assuming that double is 64 bits!");
- char Buffer[40];
APFloat apf = CFP->getValueAPF();
- // Halves and floats are represented in ASCII IR as double, convert.
+ // Floats are represented in ASCII IR as double, convert.
if (!isDouble)
apf.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven,
&ignored);
- Out << "0x" <<
- utohex_buffer(uint64_t(apf.bitcastToAPInt().getZExtValue()),
- Buffer+40);
+ Out << format_hex(apf.bitcastToAPInt().getZExtValue(), 0, /*Upper=*/true);
return;
}
// These appear as a magic letter identifying the type, then a
// fixed number of hex digits.
Out << "0x";
- // Bit position, in the current word, of the next nibble to print.
- int shiftcount;
-
+ APInt API = CFP->getValueAPF().bitcastToAPInt();
if (&CFP->getValueAPF().getSemantics() == &APFloat::x87DoubleExtended) {
Out << 'K';
- // api needed to prevent premature destruction
- APInt api = CFP->getValueAPF().bitcastToAPInt();
- const uint64_t* p = api.getRawData();
- uint64_t word = p[1];
- shiftcount = 12;
- int width = api.getBitWidth();
- for (int j=0; j<width; j+=4, shiftcount-=4) {
- unsigned int nibble = (word>>shiftcount) & 15;
- if (nibble < 10)
- Out << (unsigned char)(nibble + '0');
- else
- Out << (unsigned char)(nibble - 10 + 'A');
- if (shiftcount == 0 && j+4 < width) {
- word = *p;
- shiftcount = 64;
- if (width-j-4 < 64)
- shiftcount = width-j-4;
- }
- }
+ Out << format_hex_no_prefix(API.getHiBits(16).getZExtValue(), 4,
+ /*Upper=*/true);
+ Out << format_hex_no_prefix(API.getLoBits(64).getZExtValue(), 16,
+ /*Upper=*/true);
return;
} else if (&CFP->getValueAPF().getSemantics() == &APFloat::IEEEquad) {
- shiftcount = 60;
Out << 'L';
+ Out << format_hex_no_prefix(API.getLoBits(64).getZExtValue(), 16,
+ /*Upper=*/true);
+ Out << format_hex_no_prefix(API.getHiBits(64).getZExtValue(), 16,
+ /*Upper=*/true);
} else if (&CFP->getValueAPF().getSemantics() == &APFloat::PPCDoubleDouble) {
- shiftcount = 60;
Out << 'M';
+ Out << format_hex_no_prefix(API.getLoBits(64).getZExtValue(), 16,
+ /*Upper=*/true);
+ Out << format_hex_no_prefix(API.getHiBits(64).getZExtValue(), 16,
+ /*Upper=*/true);
} else if (&CFP->getValueAPF().getSemantics() == &APFloat::IEEEhalf) {
- shiftcount = 12;
Out << 'H';
+ Out << format_hex_no_prefix(API.getZExtValue(), 4,
+ /*Upper=*/true);
} else
llvm_unreachable("Unsupported floating point type");
- // api needed to prevent premature destruction
- APInt api = CFP->getValueAPF().bitcastToAPInt();
- const uint64_t* p = api.getRawData();
- uint64_t word = *p;
- int width = api.getBitWidth();
- for (int j=0; j<width; j+=4, shiftcount-=4) {
- unsigned int nibble = (word>>shiftcount) & 15;
- if (nibble < 10)
- Out << (unsigned char)(nibble + '0');
- else
- Out << (unsigned char)(nibble - 10 + 'A');
- if (shiftcount == 0 && j+4 < width) {
- word = *(++p);
- shiftcount = 64;
- if (width-j-4 < 64)
- shiftcount = width-j-4;
- }
- }
return;
}
: Out(Out), TypePrinter(TypePrinter), Machine(Machine), Context(Context) {
}
void printTag(const DINode *N);
+ void printMacinfoType(const DIMacroNode *N);
void printString(StringRef Name, StringRef Value,
bool ShouldSkipEmpty = true);
void printMetadata(StringRef Name, const Metadata *MD,
Out << N->getTag();
}
+void MDFieldPrinter::printMacinfoType(const DIMacroNode *N) {
+ Out << FS << "type: ";
+ if (const char *Type = dwarf::MacinfoString(N->getMacinfoType()))
+ Out << Type;
+ else
+ Out << N->getMacinfoType();
+}
+
void MDFieldPrinter::printString(StringRef Name, StringRef Value,
bool ShouldSkipEmpty) {
if (ShouldSkipEmpty && Value.empty())
Printer.printMetadata("subprograms", N->getRawSubprograms());
Printer.printMetadata("globals", N->getRawGlobalVariables());
Printer.printMetadata("imports", N->getRawImportedEntities());
+ Printer.printMetadata("macros", N->getRawMacros());
Printer.printInt("dwoId", N->getDWOId());
Out << ")";
}
Out << ")";
}
+static void writeDIMacro(raw_ostream &Out, const DIMacro *N,
+ TypePrinting *TypePrinter, SlotTracker *Machine,
+ const Module *Context) {
+ Out << "!DIMacro(";
+ MDFieldPrinter Printer(Out, TypePrinter, Machine, Context);
+ Printer.printMacinfoType(N);
+ Printer.printInt("line", N->getLine());
+ Printer.printString("name", N->getName());
+ Printer.printString("value", N->getValue());
+ Out << ")";
+}
+
+static void writeDIMacroFile(raw_ostream &Out, const DIMacroFile *N,
+ TypePrinting *TypePrinter, SlotTracker *Machine,
+ const Module *Context) {
+ Out << "!DIMacroFile(";
+ MDFieldPrinter Printer(Out, TypePrinter, Machine, Context);
+ Printer.printInt("line", N->getLine());
+ Printer.printMetadata("file", N->getRawFile(), /* ShouldSkipNull */ false);
+ Printer.printMetadata("nodes", N->getRawElements());
+ Out << ")";
+}
+
static void writeDIModule(raw_ostream &Out, const DIModule *N,
TypePrinting *TypePrinter, SlotTracker *Machine,
const Module *Context) {
writeOperand(LPI->getClause(i), true);
}
- } else if (const auto *CPI = dyn_cast<CatchPadInst>(&I)) {
+ } else if (const auto *CatchSwitch = dyn_cast<CatchSwitchInst>(&I)) {
+ Out << " within ";
+ writeOperand(CatchSwitch->getParentPad(), /*PrintType=*/false);
Out << " [";
- for (unsigned Op = 0, NumOps = CPI->getNumArgOperands(); Op < NumOps;
- ++Op) {
+ unsigned Op = 0;
+ for (const BasicBlock *PadBB : CatchSwitch->handlers()) {
if (Op > 0)
Out << ", ";
- writeOperand(CPI->getArgOperand(Op), /*PrintType=*/true);
- }
- Out << "]\n to ";
- writeOperand(CPI->getNormalDest(), /*PrintType=*/true);
- Out << " unwind ";
- writeOperand(CPI->getUnwindDest(), /*PrintType=*/true);
- } else if (const auto *TPI = dyn_cast<TerminatePadInst>(&I)) {
- Out << " [";
- for (unsigned Op = 0, NumOps = TPI->getNumArgOperands(); Op < NumOps;
- ++Op) {
- if (Op > 0)
- Out << ", ";
- writeOperand(TPI->getArgOperand(Op), /*PrintType=*/true);
+ writeOperand(PadBB, /*PrintType=*/true);
+ ++Op;
}
Out << "] unwind ";
- if (TPI->hasUnwindDest())
- writeOperand(TPI->getUnwindDest(), /*PrintType=*/true);
+ if (const BasicBlock *UnwindDest = CatchSwitch->getUnwindDest())
+ writeOperand(UnwindDest, /*PrintType=*/true);
else
Out << "to caller";
- } else if (const auto *CPI = dyn_cast<CleanupPadInst>(&I)) {
+ } else if (const auto *FPI = dyn_cast<FuncletPadInst>(&I)) {
+ Out << " within ";
+ writeOperand(FPI->getParentPad(), /*PrintType=*/false);
Out << " [";
- for (unsigned Op = 0, NumOps = CPI->getNumOperands(); Op < NumOps; ++Op) {
+ for (unsigned Op = 0, NumOps = FPI->getNumArgOperands(); Op < NumOps;
+ ++Op) {
if (Op > 0)
Out << ", ";
- writeOperand(CPI->getOperand(Op), /*PrintType=*/true);
+ writeOperand(FPI->getArgOperand(Op), /*PrintType=*/true);
}
- Out << "]";
+ Out << ']';
} else if (isa<ReturnInst>(I) && !Operand) {
Out << " void";
} else if (const auto *CRI = dyn_cast<CatchReturnInst>(&I)) {
- Out << ' ';
- writeOperand(CRI->getCatchPad(), /*PrintType=*/false);
+ Out << " from ";
+ writeOperand(CRI->getOperand(0), /*PrintType=*/false);
Out << " to ";
- writeOperand(CRI->getSuccessor(), /*PrintType=*/true);
+ writeOperand(CRI->getOperand(1), /*PrintType=*/true);
} else if (const auto *CRI = dyn_cast<CleanupReturnInst>(&I)) {
- Out << ' ';
- writeOperand(CRI->getCleanupPad(), /*PrintType=*/false);
+ Out << " from ";
+ writeOperand(CRI->getOperand(0), /*PrintType=*/false);
Out << " unwind ";
if (CRI->hasUnwindDest())
- writeOperand(CRI->getUnwindDest(), /*PrintType=*/true);
- else
- Out << "to caller";
- } else if (const auto *CEPI = dyn_cast<CatchEndPadInst>(&I)) {
- Out << " unwind ";
- if (CEPI->hasUnwindDest())
- writeOperand(CEPI->getUnwindDest(), /*PrintType=*/true);
- else
- Out << "to caller";
- } else if (const auto *CEPI = dyn_cast<CleanupEndPadInst>(&I)) {
- Out << ' ';
- writeOperand(CEPI->getCleanupPad(), /*PrintType=*/false);
-
- Out << " unwind ";
- if (CEPI->hasUnwindDest())
- writeOperand(CEPI->getUnwindDest(), /*PrintType=*/true);
+ writeOperand(CRI->getOperand(1), /*PrintType=*/true);
else
Out << "to caller";
} else if (const CallInst *CI = dyn_cast<CallInst>(&I)) {