xo-jit: initial commit (codegen constants + primitives, sort of)
This commit is contained in:
commit
432c369a66
11 changed files with 394 additions and 0 deletions
56
example/ex1/ex1.cpp
Normal file
56
example/ex1/ex1.cpp
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
/** @file ex1.cpp **/
|
||||
|
||||
#include "xo/jit/Jit.hpp"
|
||||
#include "xo/expression/Constant.hpp"
|
||||
#include "xo/expression/Primitive.hpp"
|
||||
#include <iostream>
|
||||
|
||||
int
|
||||
main() {
|
||||
using xo::jit::Jit;
|
||||
using xo::ast::make_constant;
|
||||
using xo::ast::make_primitive;
|
||||
using xo::xtag;
|
||||
using std::cerr;
|
||||
using std::endl;
|
||||
|
||||
//using xo::ast::make_constant;
|
||||
|
||||
auto jit = Jit::make();
|
||||
|
||||
{
|
||||
auto expr = make_constant(7.0);
|
||||
|
||||
auto llvm_ircode = jit->codegen(expr);
|
||||
|
||||
if (llvm_ircode) {
|
||||
/* note: llvm:errs() is 'raw stderr stream' */
|
||||
cerr << "ex1 llvm_ircode:" << endl;
|
||||
llvm_ircode->print(llvm::errs());
|
||||
cerr << endl;
|
||||
} else {
|
||||
cerr << "ex1: code generation failed"
|
||||
<< xtag("expr", expr)
|
||||
<< endl;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
auto expr = make_primitive("sqrt", ::sqrt);
|
||||
|
||||
auto llvm_ircode = jit->codegen(expr);
|
||||
|
||||
if (llvm_ircode) {
|
||||
/* note: llvm:errs() is 'raw stderr stream' */
|
||||
cerr << "ex1 llvm_ircode:" << endl;
|
||||
llvm_ircode->print(llvm::errs());
|
||||
cerr << endl;
|
||||
} else {
|
||||
cerr << "ex1: code generation failed"
|
||||
<< xtag("expr", expr)
|
||||
<< endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** end ex1.cpp **/
|
||||
Loading…
Add table
Add a link
Reference in a new issue