mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-12 02:33:33 +00:00
Move printing of DEBUG_VALUE comments to target-independent place.
There is probably a more elegant way to do this. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@100573 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
d0910c4534
commit
0a580d30e0
@ -434,7 +434,59 @@ static void EmitKill(const MachineInstr *MI, AsmPrinter &AP) {
|
|||||||
AP.OutStreamer.AddBlankLine();
|
AP.OutStreamer.AddBlankLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void EmitDebugValueComment(const MachineInstr *MI, AsmPrinter &AP) {
|
||||||
|
char buf[100];
|
||||||
|
std::string Str = "\t";
|
||||||
|
Str += AP.MAI->getCommentString();
|
||||||
|
Str += "DEBUG_VALUE: ";
|
||||||
|
// This code handles only the 3-operand target-independent form.
|
||||||
|
assert(MI->getNumOperands() == 3);
|
||||||
|
|
||||||
|
// cast away const; DIetc do not take const operands for some reason.
|
||||||
|
DIVariable V((MDNode*)(MI->getOperand(2).getMetadata()));
|
||||||
|
Str += V.getName();
|
||||||
|
Str += " <- ";
|
||||||
|
|
||||||
|
// Register or immediate value. Register 0 means undef.
|
||||||
|
if (MI->getOperand(0).isFPImm()) {
|
||||||
|
APFloat APF = APFloat(MI->getOperand(0).getFPImm()->getValueAPF());
|
||||||
|
if (MI->getOperand(0).getFPImm()->getType()->isFloatTy()) {
|
||||||
|
sprintf(buf, "%e", APF.convertToFloat());
|
||||||
|
Str += buf;
|
||||||
|
} else if (MI->getOperand(0).getFPImm()->getType()->isDoubleTy()) {
|
||||||
|
sprintf(buf, "%e", APF.convertToDouble());
|
||||||
|
Str += buf;
|
||||||
|
} else {
|
||||||
|
// There is no good way to print long double. Convert a copy to
|
||||||
|
// double. Ah well, it's only a comment.
|
||||||
|
bool ignored;
|
||||||
|
APF.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven,
|
||||||
|
&ignored);
|
||||||
|
Str += "(long double) ";
|
||||||
|
sprintf(buf, "%e", APF.convertToDouble());
|
||||||
|
Str += buf;
|
||||||
|
}
|
||||||
|
} else if (MI->getOperand(0).isImm()) {
|
||||||
|
sprintf(buf, "%lld", MI->getOperand(0).getImm());
|
||||||
|
Str += buf;
|
||||||
|
} else if (MI->getOperand(0).isReg()) {
|
||||||
|
if (MI->getOperand(0).getReg() == 0) {
|
||||||
|
// Suppress offset, it is not meaningful here.
|
||||||
|
Str += "undef";
|
||||||
|
// NOTE: Want this comment at start of line, don't emit with AddComment.
|
||||||
|
AP.OutStreamer.EmitRawText(Twine(Str));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Str += AP.TM.getRegisterInfo()->getName(MI->getOperand(0).getReg());
|
||||||
|
} else
|
||||||
|
llvm_unreachable("Unknown operand type");
|
||||||
|
|
||||||
|
Str += '+';
|
||||||
|
sprintf(buf, "%lld", MI->getOperand(1).getImm());
|
||||||
|
Str += buf;
|
||||||
|
// NOTE: Want this comment at start of line, don't emit with AddComment.
|
||||||
|
AP.OutStreamer.EmitRawText(Twine(Str));
|
||||||
|
}
|
||||||
|
|
||||||
/// EmitFunctionBody - This method emits the body and trailer for a
|
/// EmitFunctionBody - This method emits the body and trailer for a
|
||||||
/// function.
|
/// function.
|
||||||
@ -473,6 +525,9 @@ void AsmPrinter::EmitFunctionBody() {
|
|||||||
case TargetOpcode::INLINEASM:
|
case TargetOpcode::INLINEASM:
|
||||||
EmitInlineAsm(II);
|
EmitInlineAsm(II);
|
||||||
break;
|
break;
|
||||||
|
case TargetOpcode::DBG_VALUE:
|
||||||
|
if (isVerbose()) EmitDebugValueComment(II, *this);
|
||||||
|
break;
|
||||||
case TargetOpcode::IMPLICIT_DEF:
|
case TargetOpcode::IMPLICIT_DEF:
|
||||||
if (isVerbose()) EmitImplicitDef(II, *this);
|
if (isVerbose()) EmitImplicitDef(II, *this);
|
||||||
break;
|
break;
|
||||||
@ -1236,7 +1291,7 @@ static void EmitGlobalConstantFP(const ConstantFP *CFP, unsigned AddrSpace,
|
|||||||
|
|
||||||
if (CFP->getType()->isX86_FP80Ty()) {
|
if (CFP->getType()->isX86_FP80Ty()) {
|
||||||
// all long double variants are printed as hex
|
// all long double variants are printed as hex
|
||||||
// api needed to prevent premature destruction
|
// API needed to prevent premature destruction
|
||||||
APInt API = CFP->getValueAPF().bitcastToAPInt();
|
APInt API = CFP->getValueAPF().bitcastToAPInt();
|
||||||
const uint64_t *p = API.getRawData();
|
const uint64_t *p = API.getRawData();
|
||||||
if (AP.isVerbose()) {
|
if (AP.isVerbose()) {
|
||||||
@ -1266,8 +1321,8 @@ static void EmitGlobalConstantFP(const ConstantFP *CFP, unsigned AddrSpace,
|
|||||||
|
|
||||||
assert(CFP->getType()->isPPC_FP128Ty() &&
|
assert(CFP->getType()->isPPC_FP128Ty() &&
|
||||||
"Floating point constant type not handled");
|
"Floating point constant type not handled");
|
||||||
// All long double variants are printed as hex api needed to prevent
|
// All long double variants are printed as hex
|
||||||
// premature destruction.
|
// API needed to prevent premature destruction.
|
||||||
APInt API = CFP->getValueAPF().bitcastToAPInt();
|
APInt API = CFP->getValueAPF().bitcastToAPInt();
|
||||||
const uint64_t *p = API.getRawData();
|
const uint64_t *p = API.getRawData();
|
||||||
if (AP.TM.getTargetData()->isBigEndian()) {
|
if (AP.TM.getTargetData()->isBigEndian()) {
|
||||||
|
@ -326,76 +326,10 @@ void X86MCInstLower::Lower(const MachineInstr *MI, MCInst &OutMI) const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void X86AsmPrinter::PrintDebugValueComment(const MachineInstr *MI,
|
|
||||||
raw_ostream &O) {
|
|
||||||
// FIXME: if this is implemented for another target before it goes
|
|
||||||
// away completely, the common part should be moved into AsmPrinter.
|
|
||||||
O << '\t' << MAI->getCommentString() << "DEBUG_VALUE: ";
|
|
||||||
unsigned NOps = MI->getNumOperands();
|
|
||||||
// cast away const; DIetc do not take const operands for some reason.
|
|
||||||
DIVariable V((MDNode*)(MI->getOperand(NOps-1).getMetadata()));
|
|
||||||
O << V.getName();
|
|
||||||
O << " <- ";
|
|
||||||
if (NOps==3) {
|
|
||||||
// Register or immediate value. Register 0 means undef.
|
|
||||||
assert(MI->getOperand(0).isReg() ||
|
|
||||||
MI->getOperand(0).isImm() ||
|
|
||||||
MI->getOperand(0).isFPImm());
|
|
||||||
if (MI->getOperand(0).isReg() && MI->getOperand(0).getReg() == 0) {
|
|
||||||
// Suppress offset in this case, it is not meaningful.
|
|
||||||
O << "undef";
|
|
||||||
OutStreamer.AddBlankLine();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (MI->getOperand(0).isFPImm()) {
|
|
||||||
// This is more naturally done in printOperand, but since the only use
|
|
||||||
// of such an operand is in this comment and that is temporary (and it's
|
|
||||||
// ugly), we prefer to keep this localized.
|
|
||||||
// The include of Type.h may be removable when this code is.
|
|
||||||
if (MI->getOperand(0).getFPImm()->getType()->isFloatTy() ||
|
|
||||||
MI->getOperand(0).getFPImm()->getType()->isDoubleTy())
|
|
||||||
MI->getOperand(0).print(O, &TM);
|
|
||||||
else {
|
|
||||||
// There is no good way to print long double. Convert a copy to
|
|
||||||
// double. Ah well, it's only a comment.
|
|
||||||
bool ignored;
|
|
||||||
APFloat APF = APFloat(MI->getOperand(0).getFPImm()->getValueAPF());
|
|
||||||
APF.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven,
|
|
||||||
&ignored);
|
|
||||||
O << "(long double) " << APF.convertToDouble();
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
printOperand(MI, 0, O);
|
|
||||||
} else {
|
|
||||||
if (MI->getOperand(0).isReg() && MI->getOperand(0).getReg() == 0) {
|
|
||||||
// Suppress offset in this case, it is not meaningful.
|
|
||||||
O << "undef";
|
|
||||||
OutStreamer.AddBlankLine();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Frame address. Currently handles register +- offset only.
|
|
||||||
assert(MI->getOperand(0).isReg() && MI->getOperand(3).isImm());
|
|
||||||
O << '['; printOperand(MI, 0, O); O << '+'; printOperand(MI, 3, O);
|
|
||||||
O << ']';
|
|
||||||
}
|
|
||||||
O << "+";
|
|
||||||
printOperand(MI, NOps-2, O);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void X86AsmPrinter::EmitInstruction(const MachineInstr *MI) {
|
void X86AsmPrinter::EmitInstruction(const MachineInstr *MI) {
|
||||||
X86MCInstLower MCInstLowering(OutContext, Mang, *this);
|
X86MCInstLower MCInstLowering(OutContext, Mang, *this);
|
||||||
switch (MI->getOpcode()) {
|
switch (MI->getOpcode()) {
|
||||||
case TargetOpcode::DBG_VALUE:
|
|
||||||
if (isVerbose() && OutStreamer.hasRawTextSupport()) {
|
|
||||||
std::string TmpStr;
|
|
||||||
raw_string_ostream OS(TmpStr);
|
|
||||||
PrintDebugValueComment(MI, OS);
|
|
||||||
OutStreamer.EmitRawText(StringRef(OS.str()));
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
|
|
||||||
case X86::MOVPC32r: {
|
case X86::MOVPC32r: {
|
||||||
MCInst TmpInst;
|
MCInst TmpInst;
|
||||||
// This is a pseudo op for a two instruction sequence with a label, which
|
// This is a pseudo op for a two instruction sequence with a label, which
|
||||||
|
Loading…
x
Reference in New Issue
Block a user