xo-jit: + compile Apply expressions [wip]
This commit is contained in:
parent
432c369a66
commit
69dfaa931a
3 changed files with 91 additions and 0 deletions
|
|
@ -3,6 +3,7 @@
|
|||
#include "xo/jit/Jit.hpp"
|
||||
#include "xo/expression/Constant.hpp"
|
||||
#include "xo/expression/Primitive.hpp"
|
||||
#include "xo/expression/Apply.hpp"
|
||||
#include <iostream>
|
||||
|
||||
int
|
||||
|
|
@ -10,6 +11,7 @@ main() {
|
|||
using xo::jit::Jit;
|
||||
using xo::ast::make_constant;
|
||||
using xo::ast::make_primitive;
|
||||
using xo::ast::make_apply;
|
||||
using xo::xtag;
|
||||
using std::cerr;
|
||||
using std::endl;
|
||||
|
|
@ -51,6 +53,28 @@ main() {
|
|||
<< endl;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
/* (sqrt 2) */
|
||||
|
||||
auto fn = make_primitive("sqrt", ::sqrt);
|
||||
auto arg = make_constant(2.0);
|
||||
|
||||
auto call = make_apply(fn, arg);
|
||||
|
||||
auto llvm_ircode = jit->codegen(call);
|
||||
|
||||
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", call)
|
||||
<< endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** end ex1.cpp **/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue