hctHyperlink::~hctHyperlink() { hctTextBlock_link *block = popBlock(); while (block) { delete block; block = popBlock(); } }
/* Compile the AST into a module */ void CodeGenContext::generateCode(Block& root) { std::cout << "Generating code...\n"; std::cout << "Nodes: " << root.statements.size() << "\n"; /* Create the top level interpreter function to call as entry */ vector<const Type*> argTypes; FunctionType *ftype = FunctionType::get(Type::getVoidTy(getGlobalContext()), argTypes, false); mainFunction = Function::Create(ftype, GlobalValue::InternalLinkage, "main", module); BasicBlock *bblock = BasicBlock::Create(getGlobalContext(), "entry", mainFunction, 0); /* Push a new variable/block context */ pushBlock(bblock); root.codeGen(*this); /* emit bytecode for the toplevel block */ ReturnInst::Create(getGlobalContext(), bblock); popBlock(); /* Print the bytecode in a human-readable format to see if our program compiled properly */ std::cout << "Code is generated.\n"; PassManager pm; pm.add(createPrintModulePass(&outs())); pm.run(*module); }
/* Compile the AST into a module */ void CodeGenContext::generateCode(ast::Program& root) { std::cout << "Generating code...\n"; /* Create the top level interpreter function to call as entry */ std::vector<Type*> argTypes; FunctionType *ftype = FunctionType::get(Type::getVoidTy(getGlobalContext()), makeArrayRef(argTypes), false); // change GlobalValue::InternalLinkage into ExternalLinkage mainFunction = Function::Create(ftype, GlobalValue::ExternalLinkage, "main", module); BasicBlock *bblock = BasicBlock::Create(getGlobalContext(), "entry", mainFunction, 0); CodeGenContext::printf = createPrintf(*this); /* Push a new variable/block context */ pushBlock(bblock); currentFunction = mainFunction; for (auto label:labels){ labelBlock[label]=BasicBlock::Create(getGlobalContext(), "label", mainFunction, 0); } root.CodeGen(*this); /* emit bytecode for the toplevel block */ ReturnInst::Create(getGlobalContext(), currentBlock()); popBlock(); // popBlock(); /* Print the bytecode in a human-readable format to see if our program compiled properly */ std::cout << "Code is generated.\n"; PassManager pm; pm.add(createPrintModulePass(outs())); //pm.run(*module); // write IR to stderr std::cout<<"code is gen~~~\n"; module->dump(); std::cout<<"code is gen~!~\n"; }
int StatementBlock::execIntern(AbstractQoreNode** return_value, ExceptionSink* xsink) { QORE_TRACE("StatementBlock::execImpl()"); int rc = 0; assert(xsink); //printd(5, "StatementBlock::execImpl() this=%p, lvars=%p, %ld vars\n", this, lvars, lvars->size()); bool obe = !on_block_exit_list.empty(); // push "on block exit" iterator if necessary if (obe) pushBlock(on_block_exit_list.end()); // execute block for (statement_list_t::iterator i = statement_list.begin(), e = statement_list.end(); i != e; ++i) if ((rc = (*i)->exec(return_value, xsink)) || xsink->isEvent()) break; // execute "on block exit" code if applicable if (obe) { ExceptionSink obe_xsink; int nrc = 0; bool error = *xsink; for (block_list_t::iterator i = popBlock(), e = on_block_exit_list.end(); i != e; ++i) { enum obe_type_e type = (*i).first; if (type == OBE_Unconditional || (!error && type == OBE_Success) || (error && type == OBE_Error)) if ((*i).second) nrc = (*i).second->execImpl(return_value, &obe_xsink); } if (obe_xsink) xsink->assimilate(obe_xsink); if (nrc) rc = nrc; } return rc; }