[LLVMdev] standalone llvm
Simon Burton
simon at arrowtheory.com
Wed Apr 12 23:48:05 PDT 2006
On Wed, 12 Apr 2006 23:02:12 -0500 (CDT)
Chris Lattner <sabre at nondot.org> wrote:
>
> > I'd like to directly create executable code that i can
> > stick in memory somewhere and jump into (call).
>
> Take a look at the llvm/examples directory. There are several small
> programs that create LLVM IR on the fly and JIT compile it.
I'm trying to take assembly and create machine code I can execute.
How close am I ?
Simon.
int main() {
Module *M = NULL;
char *AsmString = "; ModuleID = 'test'\n\
\n\
implementation ; Functions:\n\
\n\
int %add1(int %AnArg) {\n\
EntryBlock:\n\
%addresult = add int 1, %AnArg ; <int> [#uses=1]\n\
ret int %addresult\n\
}\n\
";
M = ParseAssemblyString(AsmString, NULL);
ExistingModuleProvider* MP = new ExistingModuleProvider(M);
ExecutionEngine* EE = ExecutionEngine::create(MP, false);
std::cout << "We just constructed this LLVM module:\n\n" << *M;
Function *F = M->getNamedFunction("add1");
assert(F!=NULL);
int (*add1)(int);
add1 = (int (*)(int))EE->getPointerToFunction(F);
std::cout << "Got:" << add1(55) << "\n"; // <----------- Bombs here <---------------
return 0;
}
--
Simon Burton, B.Sc.
Licensed PO Box 8066
ANU Canberra 2601
Australia
Ph. 61 02 6249 6940
http://arrowtheory.com
More information about the llvm-dev
mailing list