MCPcopy Create free account
hub / github.com/WheretIB/nullc / StartLLVMGeneration

Function StartLLVMGeneration

NULLC/SyntaxTreeLLVM.cpp:83–278  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

81
82llvm::Function *F = NULL;
83void StartLLVMGeneration(unsigned functionsInModules)
84{
85 InitializeNativeTarget();
86
87 delete TheModule;
88 TheModule = new llvm::Module("NULLCCode", llvm::getGlobalContext());
89
90 std::string ErrStr;
91 TheExecutionEngine = EngineBuilder(TheModule).setErrorStr(&ErrStr).create();
92 if(!TheExecutionEngine)
93 {
94 printf("Could not create ExecutionEngine: %s\n", ErrStr.c_str());
95 exit(1);
96 }
97 //TheExecutionEngine->InstallLazyFunctionCreator(funcCreator);
98
99 OurPM = new PassManager();
100
101 OurFPM = new FunctionPassManager(TheModule);
102
103 // Set up the optimizer pipeline. Start with registering info about how the
104 // target lays out data structures.
105 OurFPM->add(new TargetData(*TheExecutionEngine->getTargetData()));
106 // Promote allocas to registers.
107 OurFPM->add(createPromoteMemoryToRegisterPass());
108
109 // Do simple "peephole" optimizations and bit-twiddling optzns.
110 OurFPM->add(createInstructionCombiningPass());
111 // Reassociate expressions.
112 OurFPM->add(createReassociatePass());
113 // Eliminate Common SubExpressions.
114 OurFPM->add(createGVNPass());
115 // Simplify the control flow graph (deleting unreachable blocks, etc).
116 OurFPM->add(createCFGSimplificationPass());
117
118 OurFPM->add(createConstantPropagationPass());
119
120 OurPM->add(createFunctionInliningPass());
121
122 OurFPM->doInitialization();
123
124 //OurFPM->doFinalization();
125
126 // Generate types
127 typeVoid->llvmType = Type::getVoidTy(getGlobalContext());
128 typeChar->llvmType = Type::getInt8Ty(getGlobalContext());
129 typeShort->llvmType = Type::getInt16Ty(getGlobalContext());
130 typeInt->llvmType = Type::getInt32Ty(getGlobalContext());
131 typeLong->llvmType = Type::getInt64Ty(getGlobalContext());
132 typeFloat->llvmType = Type::getFloatTy(getGlobalContext());
133 typeDouble->llvmType = Type::getDoubleTy(getGlobalContext());
134 typeObject->llvmType = StructType::get(getGlobalContext(), (Type*)typeInt->llvmType, Type::getInt8PtrTy(getGlobalContext()), (Type*)NULL);
135 typeTypeid->llvmType = typeInt->llvmType;//StructType::get(getGlobalContext(), (Type*)typeInt->llvmType, (Type*)NULL);
136 typeAutoArray->llvmType = StructType::get(getGlobalContext(), (Type*)typeInt->llvmType, Type::getInt8PtrTy(getGlobalContext()), (Type*)typeInt->llvmType, (Type*)NULL);
137 std::vector<const Type*> typeList;
138 // Construct abstract types for all classes
139 for(unsigned int i = 0; i < CodeInfo::typeInfo.size(); i++)
140 {

Callers 1

CompileMethod · 0.85

Calls 8

assertFunction · 0.85
c_strMethod · 0.80
addMethod · 0.80
getMethod · 0.80
createMethod · 0.45
sizeMethod · 0.45
clearMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected