本文整理汇总了C++中ModulePtr::build方法的典型用法代码示例。如果您正苦于以下问题:C++ ModulePtr::build方法的具体用法?C++ ModulePtr::build怎么用?C++ ModulePtr::build使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ModulePtr
的用法示例。
在下文中一共展示了ModulePtr::build方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: run
int32_t Context::run(ModulePtr module) {
typedef int32_t (*ReturnMainPoint)();
// JIT the function, returning a function pointer.
module->build();
llvm::Module* backendModule = module->getMetadata()->getBackendModule();
llvm::Function* mainFunc = backendModule->getFunction("__start");
if (mainFunc) {
void *pointFunc = m_metadata->getBackendEngine()->getPointerToFunction(mainFunc);
ReturnMainPoint main = reinterpret_cast<ReturnMainPoint>(reinterpret_cast<intptr_t>(pointFunc));
return main();
}
BOOST_THROW_EXCEPTION(Exception()
<< exception_format("Not found `main` function in module `%1%`", module->getName()));
}
示例2: main
int main(int argc, char const *argv[]) {
kiwi::ManagedStatic guard;
int opt = 0;
// Declare the supported options.
po::options_description desc("Allowed options");
desc.add_options()
("help", "produce help message")
("version", "dump version")
("optimization,O", po::value<int>(&opt)->default_value(0), "optimization level [0-3]")
("debug", "debug parser and scanner")
("ir-dump", "dump generated LLVM module")
("run", "run script, even if --ir-dump enabled")
("input-file", po::value< std::vector< std::string > >(), "input file")
;
// Add position for files
po::positional_options_description p;
p.add("input-file", -1);
// Load options from console
po::variables_map vm;
try {
po::store(po::command_line_parser(argc, argv).
options(desc).positional(p).run(), vm);
po::notify(vm);
} catch (boost::program_options::error & ex ) {
std::cerr << "Error: " << ex.what() << "\n";
return 2;
}
/// Run application
ContextPtr context = Context::create();
context->setOptimizationLevel(opt);
context->setDebug(vm.count("debug"));
if (vm.count("input-file")) {
std::vector< std::string > files = vm["input-file"].as< std::vector< std::string > >();
try {
// create script module
ModulePtr module = Module::create("Kiwi::Script", context);
for (std::vector< std::string >::iterator i = files.begin(); i != files.end(); ++i) {
module->includeFile(*i);
}
// build module and dump or execute
if (vm.count("ir-dump")) {
module->build();
module->dump();
}
if (!vm.count("ir-dump") || vm.count("run")) {
return context->run(module);
}
} catch (Exception& ex) {
std::cerr << ex << "\n";
return 1;
}
} else if (vm.count("help")) {
std::cout << desc << "\n";
} else if (vm.count("version")) {
printVersion();
return 0;
}
return 0;
}