From 68a44dc4456277a13842fe4deaeaf34e2087fff1 Mon Sep 17 00:00:00 2001 From: Evan Cheng Date: Fri, 28 Apr 2006 21:19:05 +0000 Subject: [PATCH] Bare-bone X86 inline asm printer support. llvm-svn: 28014 --- llvm/lib/Target/X86/X86ATTAsmPrinter.cpp | 28 ++++++++++++++++++++++ llvm/lib/Target/X86/X86ATTAsmPrinter.h | 6 ++++- llvm/lib/Target/X86/X86IntelAsmPrinter.cpp | 28 ++++++++++++++++++++++ llvm/lib/Target/X86/X86IntelAsmPrinter.h | 6 ++++- 4 files changed, 66 insertions(+), 2 deletions(-) diff --git a/llvm/lib/Target/X86/X86ATTAsmPrinter.cpp b/llvm/lib/Target/X86/X86ATTAsmPrinter.cpp index e3c48180853d..3afa1f7a8edc 100755 --- a/llvm/lib/Target/X86/X86ATTAsmPrinter.cpp +++ b/llvm/lib/Target/X86/X86ATTAsmPrinter.cpp @@ -264,6 +264,34 @@ void X86ATTAsmPrinter::printPICLabel(const MachineInstr *MI, unsigned Op) { O << "\"L" << getFunctionNumber() << "$pb\":"; } +/// PrintAsmOperand - Print out an operand for an inline asm expression. +/// +bool X86ATTAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, + unsigned AsmVariant, + const char *ExtraCode) { + // Does this asm operand have a single letter operand modifier? + if (ExtraCode && ExtraCode[0]) { + if (ExtraCode[1] != 0) return true; // Unknown modifier. + + switch (ExtraCode[0]) { + default: return true; // Unknown modifier. + } + } + + printOperand(MI, OpNo); + return false; +} + +bool X86ATTAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, + unsigned OpNo, + unsigned AsmVariant, + const char *ExtraCode) { + if (ExtraCode && ExtraCode[0]) + return true; // Unknown modifier. + printMemReference(MI, OpNo); + return false; +} + /// printMachineInstruction -- Print out a single X86 LLVM instruction /// MI in Intel syntax to the current output stream. /// diff --git a/llvm/lib/Target/X86/X86ATTAsmPrinter.h b/llvm/lib/Target/X86/X86ATTAsmPrinter.h index 8d400e8c7722..d8196fe6bb4a 100755 --- a/llvm/lib/Target/X86/X86ATTAsmPrinter.h +++ b/llvm/lib/Target/X86/X86ATTAsmPrinter.h @@ -61,7 +61,11 @@ struct X86ATTAsmPrinter : public X86SharedAsmPrinter { printMemReference(MI, OpNo); } - void printMachineInstruction(const MachineInstr *MI); + bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, + unsigned AsmVariant, const char *ExtraCode); + bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo, + unsigned AsmVariant, const char *ExtraCode); + void printMachineInstruction(const MachineInstr *MI); void printSSECC(const MachineInstr *MI, unsigned Op); void printMemReference(const MachineInstr *MI, unsigned Op); void printPICLabel(const MachineInstr *MI, unsigned Op); diff --git a/llvm/lib/Target/X86/X86IntelAsmPrinter.cpp b/llvm/lib/Target/X86/X86IntelAsmPrinter.cpp index 5f758554b362..bf4dba739340 100755 --- a/llvm/lib/Target/X86/X86IntelAsmPrinter.cpp +++ b/llvm/lib/Target/X86/X86IntelAsmPrinter.cpp @@ -242,6 +242,34 @@ void X86IntelAsmPrinter::printPICLabel(const MachineInstr *MI, unsigned Op) { O << "\"L" << getFunctionNumber() << "$pb\":"; } +/// PrintAsmOperand - Print out an operand for an inline asm expression. +/// +bool X86IntelAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, + unsigned AsmVariant, + const char *ExtraCode) { + // Does this asm operand have a single letter operand modifier? + if (ExtraCode && ExtraCode[0]) { + if (ExtraCode[1] != 0) return true; // Unknown modifier. + + switch (ExtraCode[0]) { + default: return true; // Unknown modifier. + } + } + + printOperand(MI, OpNo); + return false; +} + +bool X86IntelAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, + unsigned OpNo, + unsigned AsmVariant, + const char *ExtraCode) { + if (ExtraCode && ExtraCode[0]) + return true; // Unknown modifier. + printMemReference(MI, OpNo); + return false; +} + /// printMachineInstruction -- Print out a single X86 LLVM instruction /// MI in Intel syntax to the current output stream. /// diff --git a/llvm/lib/Target/X86/X86IntelAsmPrinter.h b/llvm/lib/Target/X86/X86IntelAsmPrinter.h index 13d0ad6499ea..41900f5006ea 100755 --- a/llvm/lib/Target/X86/X86IntelAsmPrinter.h +++ b/llvm/lib/Target/X86/X86IntelAsmPrinter.h @@ -80,7 +80,11 @@ struct X86IntelAsmPrinter : public X86SharedAsmPrinter { printMemReference(MI, OpNo); } - void printMachineInstruction(const MachineInstr *MI); + bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, + unsigned AsmVariant, const char *ExtraCode); + bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo, + unsigned AsmVariant, const char *ExtraCode); + void printMachineInstruction(const MachineInstr *MI); void printOp(const MachineOperand &MO, const char *Modifier = 0); void printSSECC(const MachineInstr *MI, unsigned Op); void printMemReference(const MachineInstr *MI, unsigned Op);