Reapply pieces of 78914 reverted in 78916, this has been fixed.
[oota-llvm.git] / lib / Target / MSIL / MSILWriter.h
index 6746d67a6805b174e8349505797edc283f5ac1ae..aa9e07540f9e340aa8a712bcc0720b49fd9a5754 100644 (file)
@@ -2,8 +2,8 @@
 //
 //                     The LLVM Compiler Infrastructure
 //
-// This file was developed by Roman Samoilov and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
 //
 //===----------------------------------------------------------------------===//
 //
 #include "llvm/Constants.h"
 #include "llvm/Module.h"
 #include "llvm/Instructions.h"
+#include "llvm/IntrinsicInst.h"
 #include "llvm/Pass.h"
 #include "llvm/PassManager.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Analysis/FindUsedTypes.h"
 #include "llvm/Analysis/LoopInfo.h"
+#include "llvm/Support/FormattedStream.h"
 #include "llvm/Support/GetElementPtrTypeIterator.h"
 #include "llvm/Target/TargetData.h"
 #include "llvm/Target/TargetMachine.h"
-#include "llvm/Target/TargetMachineRegistry.h"
 #include "llvm/Support/Mangler.h"
-#include <algorithm>
-#include <ios>
-using namespace llvm;
 
-namespace {
+namespace llvm {
+  extern Target TheMSILTarget;
 
   class MSILModule : public ModulePass {
     Module *ModulePtr;
@@ -37,10 +37,10 @@ namespace {
     const TargetData*& TD;
 
   public:
-    static const char ID;
+    static char ID;
     MSILModule(const std::set<const Type *>*& _UsedTypes,
                const TargetData*& _TD)
-      : ModulePass((intptr_t)&ID), UsedTypes(_UsedTypes), TD(_TD) {}
+      : ModulePass(&ID), UsedTypes(_UsedTypes), TD(_TD) {}
 
     void getAnalysisUsage(AnalysisUsage &AU) const {
       AU.addRequired<FindUsedTypes>();
@@ -55,7 +55,7 @@ namespace {
 
   };
 
-  class MSILWriter  : public FunctionPass {
+  class MSILWriter : public FunctionPass {
     struct StaticInitializer {
       const Constant* constant;
       uint64_t offset;
@@ -67,14 +67,14 @@ namespace {
         : constant(_constant), offset(_offset) {} 
     };
 
-    uint64_t UniqID;    
+    uint64_t UniqID;
 
     uint64_t getUniqID() {
       return ++UniqID;
     }
 
   public:
-    std::ostream &Out;
+    formatted_raw_ostream &Out;
     Module* ModulePtr;
     const TargetData* TD;
     Mangler* Mang;
@@ -83,8 +83,12 @@ namespace {
     std::map<const GlobalVariable*,std::vector<StaticInitializer> >
       StaticInitList;
     const std::set<const Type *>* UsedTypes;
-    static const char ID;
-    MSILWriter(std::ostream &o) : FunctionPass((intptr_t)&ID), Out(o) {
+    static char ID;
+    DenseMap<const Value*, unsigned> AnonValueNumbers;
+    unsigned NextAnonValueNumber;
+
+    MSILWriter(formatted_raw_ostream &o) : FunctionPass(&ID), Out(o),
+         NextAnonValueNumber(0) {
       UniqID = 0;
     }
 
@@ -119,6 +123,8 @@ namespace {
 
     virtual bool doFinalization(Module &M);
 
+    void printModuleStartup();
+
     bool isZeroValue(const Value* V);
 
     std::string getValueName(const Value* V);
@@ -137,15 +143,20 @@ namespace {
 
     std::string getPointerTypeName(const Type* Ty);
 
-    std::string getTypeName(const Type* Ty, bool isSigned = false);
+    std::string getTypeName(const Type* Ty, bool isSigned = false,
+                            bool isNested = false);
 
     ValueType getValueLocation(const Value* V);
 
     std::string getTypePostfix(const Type* Ty, bool Expand,
                                bool isSigned = false);
 
+    void printConvToPtr();
+
     void printPtrLoad(uint64_t N);
 
+    void printValuePtrLoad(const Value* V);
+
     void printConstLoad(const Constant* C);
 
     void printValueLoad(const Value* V);
@@ -170,10 +181,12 @@ namespace {
 
     void printIndirectLoad(const Value* V);
 
-    void printStoreInstruction(const Instruction* Inst);
+    void printIndirectSave(const Value* Ptr, const Value* Val);
+
+    void printIndirectSave(const Type* Ty);
 
     void printCastInstruction(unsigned int Op, const Value* V,
-                              const Type* Ty);
+                              const Type* Ty, const Type* SrcTy=0);
 
     void printGepInstruction(const Value* V, gep_type_iterator I,
                              gep_type_iterator E);
@@ -184,6 +197,8 @@ namespace {
 
     void printFunctionCall(const Value* FnVal, const Instruction* Inst);
 
+    void printIntrinsicCall(const IntrinsicInst* Inst);
+
     void printCallInstruction(const Instruction* Inst);
 
     void printICmpInstruction(unsigned Predicate, const Value* Left,
@@ -196,6 +211,10 @@ namespace {
 
     void printSwitchInstruction(const SwitchInst* Inst);
 
+    void printVAArgInstruction(const VAArgInst* Inst);
+
+    void printAllocaInstruction(const AllocaInst* Inst);
+
     void printInstruction(const Instruction* Inst);
 
     void printLoop(const Loop* L);
@@ -224,8 +243,17 @@ namespace {
 
     void printGlobalVariables();
 
+    const char* getLibraryName(const Function* F);
+
+    const char* getLibraryName(const GlobalVariable* GV); 
+    
+    const char* getLibraryForSymbol(const StringRef &Name, bool isFunction,
+                                    unsigned CallingConv);
+
     void printExternals();
   };
+
 }
 
 #endif
+