//
// 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.
//
//===----------------------------------------------------------------------===//
//
#ifndef MSILWRITER_H
#define MSILWRITER_H
+#include "llvm/CallingConv.h"
#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;
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>();
};
- class MSILWriter : public FunctionPass {
+ class MSILWriter : public FunctionPass {
struct StaticInitializer {
const Constant* constant;
uint64_t offset;
: 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;
LoopInfo *LInfo;
std::vector<StaticInitializer>* InitListPtr;
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;
}
virtual bool doFinalization(Module &M);
+ void printModuleStartup();
+
bool isZeroValue(const Value* V);
std::string getValueName(const Value* V);
std::string getLabelName(const std::string& Name);
- std::string getConvModopt(unsigned CallingConvID);
+ std::string getConvModopt(CallingConv::ID CallingConvID);
std::string getArrayTypeName(Type::TypeID TyID, const Type* Ty);
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);
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);
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,
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);
void printGlobalVariables();
+ const char* getLibraryName(const Function* F);
+
+ const char* getLibraryName(const GlobalVariable* GV);
+
+ const char* getLibraryForSymbol(const StringRef &Name, bool isFunction,
+ CallingConv::ID CallingConv);
+
void printExternals();
};
+
}
#endif
+