Initial checkin of the InlineAsm class

llvm-svn: 25570
diff --git a/llvm/lib/VMCore/AsmWriter.cpp b/llvm/lib/VMCore/AsmWriter.cpp
index d0b8478..c6a3845 100644
--- a/llvm/lib/VMCore/AsmWriter.cpp
+++ b/llvm/lib/VMCore/AsmWriter.cpp
@@ -775,9 +775,9 @@
   if (!M->getTargetTriple().empty())
     Out << "target triple = \"" << M->getTargetTriple() << "\"\n";
 
-  if (!M->getInlineAsm().empty()) {
+  if (!M->getModuleInlineAsm().empty()) {
     // Split the string into lines, to make it easier to read the .ll file.
-    std::string Asm = M->getInlineAsm();
+    std::string Asm = M->getModuleInlineAsm();
     size_t CurPos = 0;
     size_t NewLine = Asm.find_first_of('\n', CurPos);
     while (NewLine != std::string::npos) {
@@ -1269,6 +1269,14 @@
   W.write(this);
 }
 
+void InlineAsm::print(std::ostream &o, AssemblyAnnotationWriter *AAW) const {
+  SlotMachine SlotTable(getParent());
+  AssemblyWriter W(o, SlotTable, getParent(), AAW);
+  
+  assert(0 && "Inline asm printing unimplemented!");
+  //W.write(this);
+}
+
 void BasicBlock::print(std::ostream &o, AssemblyAnnotationWriter *AAW) const {
   SlotMachine SlotTable(getParent());
   AssemblyWriter W(o, SlotTable,
diff --git a/llvm/lib/VMCore/Globals.cpp b/llvm/lib/VMCore/Globals.cpp
index be6c6eb..3ea8265 100644
--- a/llvm/lib/VMCore/Globals.cpp
+++ b/llvm/lib/VMCore/Globals.cpp
@@ -1,4 +1,4 @@
-//===-- Globals.cpp - Implement the Global object classes -----------------===//
+//===-- Globals.cpp - Implement the GlobalValue & GlobalVariable class ----===//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -12,8 +12,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "llvm/DerivedTypes.h"
 #include "llvm/GlobalVariable.h"
+#include "llvm/DerivedTypes.h"
 #include "llvm/Module.h"
 #include "llvm/SymbolTable.h"
 #include "llvm/Support/LeakDetector.h"
diff --git a/llvm/lib/VMCore/InlineAsm.cpp b/llvm/lib/VMCore/InlineAsm.cpp
new file mode 100644
index 0000000..1eed894
--- /dev/null
+++ b/llvm/lib/VMCore/InlineAsm.cpp
@@ -0,0 +1,50 @@
+//===-- InlineAsm.cpp - Implement the InlineAsm class ---------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by Chris Lattner and is distributed under the
+// University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements the InlineAsm class.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/InlineAsm.h"
+#include "llvm/DerivedTypes.h"
+#include "llvm/Module.h"
+#include "llvm/Support/LeakDetector.h"
+using namespace llvm;
+
+InlineAsm::InlineAsm(const FunctionType *Ty, const std::string &asmString,
+                     const std::string &constraints, bool hasSideEffects,
+                     const std::string &name, Module *ParentModule)
+  : Value(PointerType::get(Ty), Value::InlineAsmVal, name), 
+    Parent(0), AsmString(asmString), Constraints(constraints), 
+    AsmHasSideEffects(hasSideEffects) {
+  LeakDetector::addGarbageObject(this);
+
+  if (ParentModule)
+    ParentModule->getInlineAsmList().push_back(this);
+}
+
+const FunctionType *InlineAsm::getFunctionType() const {
+  return cast<FunctionType>(getType()->getElementType());
+}
+
+void InlineAsm::setParent(Module *parent) {
+  if (getParent())
+    LeakDetector::addGarbageObject(this);
+  Parent = parent;
+  if (getParent())
+    LeakDetector::removeGarbageObject(this);
+}
+
+void InlineAsm::removeFromParent() {
+  getParent()->getInlineAsmList().remove(this);
+}
+
+void InlineAsm::eraseFromParent() {
+  getParent()->getInlineAsmList().erase(this);
+}
diff --git a/llvm/lib/VMCore/Module.cpp b/llvm/lib/VMCore/Module.cpp
index de63b4ba..e9b28f9 100644
--- a/llvm/lib/VMCore/Module.cpp
+++ b/llvm/lib/VMCore/Module.cpp
@@ -44,17 +44,30 @@
   return Ret;
 }
 
+InlineAsm *ilist_traits<InlineAsm>::createSentinel() {
+  InlineAsm *Ret = new InlineAsm(FunctionType::get(Type::VoidTy, 
+                                    std::vector<const Type*>(), false), "", "",
+                                 false);
+  // This should not be garbage monitored.
+  LeakDetector::removeGarbageObject(Ret);
+  return Ret;
+}
+
 iplist<Function> &ilist_traits<Function>::getList(Module *M) {
   return M->getFunctionList();
 }
 iplist<GlobalVariable> &ilist_traits<GlobalVariable>::getList(Module *M) {
   return M->getGlobalList();
 }
+iplist<InlineAsm> &ilist_traits<InlineAsm>::getList(Module *M) {
+  return M->getInlineAsmList();
+}
 
 // Explicit instantiations of SymbolTableListTraits since some of the methods
-// are not in the public header file...
+// are not in the public header file.
 template class SymbolTableListTraits<GlobalVariable, Module, Module>;
 template class SymbolTableListTraits<Function, Module, Module>;
+template class SymbolTableListTraits<InlineAsm, Module, Module>;
 
 //===----------------------------------------------------------------------===//
 // Primitive Module methods.
@@ -66,6 +79,8 @@
   FunctionList.setParent(this);
   GlobalList.setItemParent(this);
   GlobalList.setParent(this);
+  InlineAsmList.setItemParent(this);
+  InlineAsmList.setParent(this);
   SymTab = new SymbolTable();
 }
 
@@ -75,6 +90,8 @@
   GlobalList.setParent(0);
   FunctionList.clear();
   FunctionList.setParent(0);
+  InlineAsmList.clear();
+  InlineAsmList.setParent(0);
   LibraryList.clear();
   delete SymTab;
 }