Make the release build work
[oota-llvm.git] / lib / VMCore / Function.cpp
index aa0d08b0a2db35c18b59d7e8b1f5c36e350588f3..c5e9e2181928ffc11ab20d171109ce7e72d573c7 100644 (file)
@@ -1,6 +1,7 @@
-//===-- Method.cpp - Implement the Method class ------------------*- C++ -*--=//
+//===-- Function.cpp - Implement the Global object classes -------*- C++ -*--=//
 //
-// This file implements the Method class for the VMCore library.
+// This file implements the Function & GlobalVariable classes for the VMCore
+// library.
 //
 //===----------------------------------------------------------------------===//
 
@@ -8,24 +9,29 @@
 #include "llvm/DerivedTypes.h"
 #include "llvm/SymbolTable.h"
 #include "llvm/Module.h"
-#include "llvm/Method.h"
+#include "llvm/Function.h"
+#include "llvm/GlobalVariable.h"
 #include "llvm/BasicBlock.h"
 #include "llvm/iOther.h"
 
+//===----------------------------------------------------------------------===//
+// Function Implementation
+//===----------------------------------------------------------------------===//
+
+
 // Instantiate Templates - This ugliness is the price we have to pay
 // for having a ValueHolderImpl.h file seperate from ValueHolder.h!  :(
 //
-template class ValueHolder<MethodArgument, Method>;
-template class ValueHolder<BasicBlock    , Method>;
-
-Method::Method(const MethodType *Ty, const string &name) 
-  : SymTabValue(Ty, Value::MethodVal, name), BasicBlocks(this), 
-    ArgumentList(this, this) {
-  assert(Ty->isMethodType() && "Method signature must be of method type!");
-  Parent = 0;
+template class ValueHolder<FunctionArgument, Function, Function>;
+template class ValueHolder<BasicBlock    , Function, Function>;
+
+Function::Function(const FunctionType *Ty, bool isInternal,
+                   const std::string &name)
+  : GlobalValue(PointerType::get(Ty), Value::FunctionVal, isInternal, name),
+    SymTabValue(this), BasicBlocks(this), ArgumentList(this, this) {
 }
 
-Method::~Method() {
+Function::~Function() {
   dropAllReferences();    // After this it is safe to delete instructions.
 
   // TODO: Should remove from the end, not the beginning of vector!
@@ -39,26 +45,28 @@ Method::~Method() {
 }
 
 // Specialize setName to take care of symbol table majik
-void Method::setName(const string &name) {
+void Function::setName(const std::string &name, SymbolTable *ST) {
   Module *P;
+  assert((ST == 0 || (!getParent() || ST == getParent()->getSymbolTable())) &&
+        "Invalid symtab argument!");
   if ((P = getParent()) && hasName()) P->getSymbolTable()->remove(this);
   Value::setName(name);
   if (P && getName() != "") P->getSymbolTableSure()->insert(this);
 }
 
-void Method::setParent(Module *parent) {
+void Function::setParent(Module *parent) {
   Parent = parent;
 
   // Relink symbol tables together...
   setParentSymTab(Parent ? Parent->getSymbolTableSure() : 0);
 }
 
-const Type *Method::getReturnType() const { 
-  return ((const MethodType *)getType())->getReturnType(); 
+const FunctionType *Function::getFunctionType() const {
+  return cast<FunctionType>(getType()->getElementType());
 }
 
-const MethodType *Method::getMethodType() const { 
-  return (const MethodType *)getType();
+const Type *Function::getReturnType() const { 
+  return getFunctionType()->getReturnType();
 }
 
 // dropAllReferences() - This function causes all the subinstructions to "let
@@ -69,6 +77,28 @@ const MethodType *Method::getMethodType() const {
 // valid on an object that has "dropped all references", except operator 
 // delete.
 //
-void Method::dropAllReferences() {
+void Function::dropAllReferences() {
   for_each(begin(), end(), std::mem_fun(&BasicBlock::dropAllReferences));
 }
+
+//===----------------------------------------------------------------------===//
+// GlobalVariable Implementation
+//===----------------------------------------------------------------------===//
+
+GlobalVariable::GlobalVariable(const Type *Ty, bool constant, bool isIntern,
+                              Constant *Initializer = 0,
+                              const std::string &Name = "")
+  : GlobalValue(PointerType::get(Ty), Value::GlobalVariableVal, isIntern, Name),
+    isConstantGlobal(constant) {
+  if (Initializer) Operands.push_back(Use((Value*)Initializer, this));
+}
+
+// Specialize setName to take care of symbol table majik
+void GlobalVariable::setName(const std::string &name, SymbolTable *ST) {
+  Module *P;
+  assert((ST == 0 || (!getParent() || ST == getParent()->getSymbolTable())) &&
+        "Invalid symtab argument!");
+  if ((P = getParent()) && hasName()) P->getSymbolTable()->remove(this);
+  Value::setName(name);
+  if (P && getName() != "") P->getSymbolTableSure()->insert(this);
+}