Loading compilecontext.cpp +13 −2 Original line number Diff line number Diff line Loading @@ -183,8 +183,14 @@ void CompileContext::generateMain() { // FIXME main should be void -> int llvm::Function *main = helperCreateFunction("main"); //llvm::BasicBlock *mainLoop= & main->getEntryBlock(); //mainLoop->setName("infiniteLoop"); llvm::BasicBlock *mainLoop = llvm::BasicBlock::Create(llvm::getGlobalContext(), "infiniteLoop", main); "infiniteLoop"); irbuilder.CreateBr(mainLoop); // needed to have an enty without predecessor main->getBasicBlockList().push_back(mainLoop); irbuilder.SetInsertPoint(mainLoop); // call each state's 'do step' function Loading @@ -194,6 +200,11 @@ void CompileContext::generateMain() { // this is an infinite loop for now ;) irbuilder.CreateBr(mainLoop); llvm::BasicBlock *useless = llvm::BasicBlock::Create(llvm::getGlobalContext(), "useless_ret"); main->getBasicBlockList().push_back(useless); irbuilder.SetInsertPoint(useless); irbuilder.CreateRet(nullptr); } Loading @@ -211,7 +222,7 @@ llvm::Function *CompileContext::helperCreateFunction(const std::string &name, false); } ret = llvm::Function::Create(type, llvm::GlobalValue::CommonLinkage, ret = llvm::Function::Create(type, llvm::GlobalValue::ExternalLinkage, name, module.get()); // create a new Basic Block Loading compilecontext.hpp +5 −2 Original line number Diff line number Diff line Loading @@ -257,8 +257,11 @@ public: void addVariable(const std::string &name, Variable var = Variable()) { // create a new global variable if(!var.value) var.value = helperCreateVariable(variableName(name)); if(!var.value) { llvm::ConstantInt *zero = llvm::ConstantInt::get( llvm::Type::getInt32Ty(llvm::getGlobalContext()), 0, false); var.value = helperCreateVariable(variableName(name), zero); } variables[name] = var; Loading main.cpp +15 −2 Original line number Diff line number Diff line Loading @@ -7,6 +7,8 @@ #include <llvm/IR/PassManager.h> #include <llvm/LinkAllPasses.h> #include <llvm/Support/TargetRegistry.h> //extern "C" int yylex() {} extern int yyparse(); Loading Loading @@ -48,15 +50,26 @@ int main() { // now generate the code for the main() ccon.generateMain(); std::cout << "Done." << std::endl; std::cerr << "Code generated." << std::endl; llvm::ModulePassManager pm; llvm::ModulePass * printer = llvm::createPrintModulePass(llvm::outs()); MagicModulePass magic(printer); // FUUUUUCK.... // for a strange reason, my LLVM version have compile-time problems if // I give the printer ModulePass directly directly pm.addPass<MagicModulePass>(magic); pm.run(ccon.getModule()); std::cerr << "\nListing supported targets :" << std::endl; for(auto& target: llvm::TargetRegistry::targets()) { std::cerr << target.getName() << std::endl; } //llvm::TargetRegistry::printRegisteredTargetsForVersion(); //llvm::TargetMachine *armMachine = new llvm::ARM return 0; } node.cpp +2 −3 Original line number Diff line number Diff line Loading @@ -231,7 +231,6 @@ llvm::Value *NAutoItem::codeGen(CompileContext &ccon) { // add initialization function acon->activateDefinition(); stmts->codeGen(ccon); acon->terminateInitiliazer(); // add states : special case, need to "declare" all states before Loading @@ -256,7 +255,7 @@ llvm::Value *NState::codeGen(CompileContext &ccon) { // generate the init function thisState->activateInitializer(); stmts->codeGen(ccon); thisState->activateInitializer(); thisState->terminateInitiliazer(); // generate the polling function thisState->activateSignalPolling(); Loading Loading @@ -390,7 +389,7 @@ llvm::Value *NBitfieldVariable::assignCodeGen(CompileContext &ccon, if(!bitFrom && !bitTo) { Variable var = ccon.lookupVariable(ident->ident); if(var.value) { return ccon.builder().CreateStore(var.value, val); return ccon.builder().CreateStore(val, var.value); } else { if(ccon.lookupConstant(ident->ident)) { Loading Loading
compilecontext.cpp +13 −2 Original line number Diff line number Diff line Loading @@ -183,8 +183,14 @@ void CompileContext::generateMain() { // FIXME main should be void -> int llvm::Function *main = helperCreateFunction("main"); //llvm::BasicBlock *mainLoop= & main->getEntryBlock(); //mainLoop->setName("infiniteLoop"); llvm::BasicBlock *mainLoop = llvm::BasicBlock::Create(llvm::getGlobalContext(), "infiniteLoop", main); "infiniteLoop"); irbuilder.CreateBr(mainLoop); // needed to have an enty without predecessor main->getBasicBlockList().push_back(mainLoop); irbuilder.SetInsertPoint(mainLoop); // call each state's 'do step' function Loading @@ -194,6 +200,11 @@ void CompileContext::generateMain() { // this is an infinite loop for now ;) irbuilder.CreateBr(mainLoop); llvm::BasicBlock *useless = llvm::BasicBlock::Create(llvm::getGlobalContext(), "useless_ret"); main->getBasicBlockList().push_back(useless); irbuilder.SetInsertPoint(useless); irbuilder.CreateRet(nullptr); } Loading @@ -211,7 +222,7 @@ llvm::Function *CompileContext::helperCreateFunction(const std::string &name, false); } ret = llvm::Function::Create(type, llvm::GlobalValue::CommonLinkage, ret = llvm::Function::Create(type, llvm::GlobalValue::ExternalLinkage, name, module.get()); // create a new Basic Block Loading
compilecontext.hpp +5 −2 Original line number Diff line number Diff line Loading @@ -257,8 +257,11 @@ public: void addVariable(const std::string &name, Variable var = Variable()) { // create a new global variable if(!var.value) var.value = helperCreateVariable(variableName(name)); if(!var.value) { llvm::ConstantInt *zero = llvm::ConstantInt::get( llvm::Type::getInt32Ty(llvm::getGlobalContext()), 0, false); var.value = helperCreateVariable(variableName(name), zero); } variables[name] = var; Loading
main.cpp +15 −2 Original line number Diff line number Diff line Loading @@ -7,6 +7,8 @@ #include <llvm/IR/PassManager.h> #include <llvm/LinkAllPasses.h> #include <llvm/Support/TargetRegistry.h> //extern "C" int yylex() {} extern int yyparse(); Loading Loading @@ -48,15 +50,26 @@ int main() { // now generate the code for the main() ccon.generateMain(); std::cout << "Done." << std::endl; std::cerr << "Code generated." << std::endl; llvm::ModulePassManager pm; llvm::ModulePass * printer = llvm::createPrintModulePass(llvm::outs()); MagicModulePass magic(printer); // FUUUUUCK.... // for a strange reason, my LLVM version have compile-time problems if // I give the printer ModulePass directly directly pm.addPass<MagicModulePass>(magic); pm.run(ccon.getModule()); std::cerr << "\nListing supported targets :" << std::endl; for(auto& target: llvm::TargetRegistry::targets()) { std::cerr << target.getName() << std::endl; } //llvm::TargetRegistry::printRegisteredTargetsForVersion(); //llvm::TargetMachine *armMachine = new llvm::ARM return 0; }
node.cpp +2 −3 Original line number Diff line number Diff line Loading @@ -231,7 +231,6 @@ llvm::Value *NAutoItem::codeGen(CompileContext &ccon) { // add initialization function acon->activateDefinition(); stmts->codeGen(ccon); acon->terminateInitiliazer(); // add states : special case, need to "declare" all states before Loading @@ -256,7 +255,7 @@ llvm::Value *NState::codeGen(CompileContext &ccon) { // generate the init function thisState->activateInitializer(); stmts->codeGen(ccon); thisState->activateInitializer(); thisState->terminateInitiliazer(); // generate the polling function thisState->activateSignalPolling(); Loading Loading @@ -390,7 +389,7 @@ llvm::Value *NBitfieldVariable::assignCodeGen(CompileContext &ccon, if(!bitFrom && !bitTo) { Variable var = ccon.lookupVariable(ident->ident); if(var.value) { return ccon.builder().CreateStore(var.value, val); return ccon.builder().CreateStore(val, var.value); } else { if(ccon.lookupConstant(ident->ident)) { Loading