From 80cd11561892a639a2628d19815af0695b5dbcaa Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 25 Jan 2006 22:26:05 +0000 Subject: [PATCH] Print InlineAsm objects git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25617 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/VMCore/AsmWriter.cpp | 16 ++++++++++++---- lib/VMCore/InlineAsm.cpp | 20 +++++++++++++++----- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/lib/VMCore/AsmWriter.cpp b/lib/VMCore/AsmWriter.cpp index a5ac8f03311..ec70454e0bb 100644 --- a/lib/VMCore/AsmWriter.cpp +++ b/lib/VMCore/AsmWriter.cpp @@ -556,9 +556,18 @@ static void WriteAsOperandInternal(std::ostream &Out, const Value *V, Out << getLLVMName(V->getName()); else { const Constant *CV = dyn_cast(V); - if (CV && !isa(CV)) + if (CV && !isa(CV)) { WriteConstantInt(Out, CV, PrintName, TypeTable, Machine); - else { + } else if (const InlineAsm *IA = dyn_cast(V)) { + Out << "asm "; + if (IA->hasSideEffects()) + Out << "sideeffect "; + Out << '"'; + PrintEscapedString(IA->getAsmString(), Out); + Out << "\", \""; + PrintEscapedString(IA->getConstraintString(), Out); + Out << '"'; + } else { int Slot; if (Machine) { Slot = Machine->getSlot(V); @@ -1271,8 +1280,7 @@ void Function::print(std::ostream &o, AssemblyAnnotationWriter *AAW) const { } void InlineAsm::print(std::ostream &o, AssemblyAnnotationWriter *AAW) const { - assert(0 && "Inline asm printing unimplemented!"); - //W.write(this); + WriteAsOperand(o, this, true, true, 0); } void BasicBlock::print(std::ostream &o, AssemblyAnnotationWriter *AAW) const { diff --git a/lib/VMCore/InlineAsm.cpp b/lib/VMCore/InlineAsm.cpp index 00842bb3244..cc817e3795a 100644 --- a/lib/VMCore/InlineAsm.cpp +++ b/lib/VMCore/InlineAsm.cpp @@ -13,20 +13,30 @@ #include "llvm/InlineAsm.h" #include "llvm/DerivedTypes.h" -#include "llvm/Module.h" -#include "llvm/Support/LeakDetector.h" using namespace llvm; +// NOTE: when memoizing the function type, we have to be careful to handle the +// case when the type gets refined. + +InlineAsm *InlineAsm::get(const FunctionType *Ty, const std::string &AsmString, + const std::string &Constraints, bool hasSideEffects) { + // FIXME: memoize! + return new InlineAsm(Ty, AsmString, Constraints, hasSideEffects); +} + InlineAsm::InlineAsm(const FunctionType *Ty, const std::string &asmString, const std::string &constraints, bool hasSideEffects) : Value(PointerType::get(Ty), Value::InlineAsmVal), AsmString(asmString), Constraints(constraints), HasSideEffects(hasSideEffects) { - LeakDetector::addGarbageObject(this); - // FIXME: do various checks on the constraint string and type. - + // Do various checks on the constraint string and type. + assert(Verify(Ty, constraints) && "Function type not legal for constraints!"); } const FunctionType *InlineAsm::getFunctionType() const { return cast(getType()->getElementType()); } + +bool InlineAsm::Verify(const FunctionType *Ty, const std::string &Constraints) { + return true; +}