Initial checkin of the InlineAsm class
[oota-llvm.git] / lib / VMCore / InlineAsm.cpp
1 //===-- InlineAsm.cpp - Implement the InlineAsm class ---------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by Chris Lattner and is distributed under the
6 // University of Illinois Open Source License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the InlineAsm class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "llvm/InlineAsm.h"
15 #include "llvm/DerivedTypes.h"
16 #include "llvm/Module.h"
17 #include "llvm/Support/LeakDetector.h"
18 using namespace llvm;
19
20 InlineAsm::InlineAsm(const FunctionType *Ty, const std::string &asmString,
21                      const std::string &constraints, bool hasSideEffects,
22                      const std::string &name, Module *ParentModule)
23   : Value(PointerType::get(Ty), Value::InlineAsmVal, name), 
24     Parent(0), AsmString(asmString), Constraints(constraints), 
25     AsmHasSideEffects(hasSideEffects) {
26   LeakDetector::addGarbageObject(this);
27
28   if (ParentModule)
29     ParentModule->getInlineAsmList().push_back(this);
30 }
31
32 const FunctionType *InlineAsm::getFunctionType() const {
33   return cast<FunctionType>(getType()->getElementType());
34 }
35
36 void InlineAsm::setParent(Module *parent) {
37   if (getParent())
38     LeakDetector::addGarbageObject(this);
39   Parent = parent;
40   if (getParent())
41     LeakDetector::removeGarbageObject(this);
42 }
43
44 void InlineAsm::removeFromParent() {
45   getParent()->getInlineAsmList().remove(this);
46 }
47
48 void InlineAsm::eraseFromParent() {
49   getParent()->getInlineAsmList().erase(this);
50 }