diff options
author | Tom Stellard <[email protected]> | 2012-08-17 15:52:15 +0000 |
---|---|---|
committer | Tom Stellard <[email protected]> | 2012-08-23 15:00:48 +0000 |
commit | e30b4644b613a130318cdf240ad237b0afbc525a (patch) | |
tree | 4f97417b47aa25c8d7d799534cdb656c5a8f8daf /src/gallium/drivers/radeon/AMDGPUMCInstLower.cpp | |
parent | e61c54cb6b220dea243568919a001e5dc7c01303 (diff) |
radeon/llvm: Add AsmPrinter
Diffstat (limited to 'src/gallium/drivers/radeon/AMDGPUMCInstLower.cpp')
-rw-r--r-- | src/gallium/drivers/radeon/AMDGPUMCInstLower.cpp | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/gallium/drivers/radeon/AMDGPUMCInstLower.cpp b/src/gallium/drivers/radeon/AMDGPUMCInstLower.cpp new file mode 100644 index 00000000000..53bd561a2fe --- /dev/null +++ b/src/gallium/drivers/radeon/AMDGPUMCInstLower.cpp @@ -0,0 +1,48 @@ + +#include "AMDGPUMCInstLower.h" +#include "AMDGPUAsmPrinter.h" +#include "llvm/CodeGen/MachineInstr.h" +#include "llvm/Constants.h" +#include "llvm/MC/MCInst.h" +#include "llvm/MC/MCStreamer.h" +#include "llvm/Support/ErrorHandling.h" + +using namespace llvm; + +AMDGPUMCInstLower::AMDGPUMCInstLower() { } + +void AMDGPUMCInstLower::Lower(const MachineInstr *MI, MCInst &OutMI) const { + OutMI.setOpcode(MI->getOpcode()); + + for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { + const MachineOperand &MO = MI->getOperand(i); + + MCOperand MCOp; + switch (MO.getType()) { + default: + MI->dump(); + llvm_unreachable("unknown operand type"); + case MachineOperand::MO_FPImmediate: { + const APFloat &FloatValue = MO.getFPImm()->getValueAPF(); + assert(&FloatValue.getSemantics() == &APFloat::IEEEsingle && + "Only floating point immediates are supported at the moment."); + MCOp = MCOperand::CreateFPImm(FloatValue.convertToFloat()); + break; + } + case MachineOperand::MO_Immediate: + MCOp = MCOperand::CreateImm(MO.getImm()); + break; + case MachineOperand::MO_Register: + MCOp = MCOperand::CreateReg(MO.getReg()); + break; + } + OutMI.addOperand(MCOp); + } +} + +void AMDGPUAsmPrinter::EmitInstruction(const MachineInstr *MI) { + AMDGPUMCInstLower MCInstLowering; + MCInst TmpInst; + MCInstLowering.Lower(MI, TmpInst); + OutStreamer.EmitInstruction(TmpInst); +} |