//
// 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;
const TargetData*& TD;
public:
+ static char ID;
MSILModule(const std::set<const Type *>*& _UsedTypes,
const TargetData*& _TD)
- : 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;
std::map<const GlobalVariable*,std::vector<StaticInitializer> >
StaticInitList;
const std::set<const Type *>* UsedTypes;
+ static char ID;
+ DenseMap<const Value*, unsigned> AnonValueNumbers;
+ unsigned NextAnonValueNumber;
- MSILWriter(std::ostream &o) : Out(o) {
+ 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 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,
+ unsigned CallingConv);
+
void printExternals();
};
+
}
#endif
+