Compile a string?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Compile a string?

Daniel Waterworth
Hi,

I'm trying to compile a string into a Module so that I can link and
then JIT it. What would be the best way of doing this?

Thanks,

Daniel

--
active-thought.com
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Compile a string?

Eric Christopher-2



I'm trying to compile a string into a Module so that I can link and
then JIT it. What would be the best way of doing this?


Not quite sure what you mean, but if you're just trying to get a global variable into a module you can use a GlobalVariable for that purpose - there are some helper routines to create a string. If this isn't what you were wondering then would you give a bit more information?

Thanks!

-eric

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Compile a string?

Daniel Waterworth
Sorry, what I mean is I've trying to make/find a function like this:

Module *compile_string(const char *source)

that could be used like this:

Module *m = compile_string("int function(int a, int b) { return a + b; }");

I hope that makes things clearer. Does such a function exist within
clang, or will I have to setup the components to do that? As far as I
can tell, I'll have to use a Preprocessor to start with, but how do I
then generate the AST in order to lower to LLVM's IR.

Daniel

On 19 June 2010 10:33, Eric Christopher <[hidden email]> wrote:

>
>
>
> I'm trying to compile a string into a Module so that I can link and
> then JIT it. What would be the best way of doing this?
>
>
> Not quite sure what you mean, but if you're just trying to get a global
> variable into a module you can use a GlobalVariable for that purpose - there
> are some helper routines to create a string. If this isn't what you were
> wondering then would you give a bit more information?
> Thanks!
> -eric



--
active-thought.com
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Compile a string?

Eric Christopher-2

On Jun 19, 2010, at 5:22 AM, Daniel Waterworth wrote:

> Sorry, what I mean is I've trying to make/find a function like this:
>
> Module *compile_string(const char *source)
>
> that could be used like this:
>
> Module *m = compile_string("int function(int a, int b) { return a + b; }");
>
> I hope that makes things clearer. Does such a function exist within
> clang, or will I have to setup the components to do that? As far as I
> can tell, I'll have to use a Preprocessor to start with, but how do I
> then generate the AST in order to lower to LLVM's IR.

Aaah.  Entirely differently.  I'd look through the clang driver for ideas
on how to generate a module based on incoming C code (this is C
code yes?).

-eric
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Compile a string?

Daniel Dunbar
In reply to this post by Daniel Waterworth
Hi Daniel,

Take a look at the clang-interpreter example for most of it. Instead
of using CompilerInvocation::CreateFromArgs, you will want to
construct a CompilerInvocation by hand, including an input file name,
and then use the remapping arguments to associate your string with
that file.

 - Daniel

On Sat, Jun 19, 2010 at 1:33 AM, Daniel Waterworth
<[hidden email]> wrote:

> Hi,
>
> I'm trying to compile a string into a Module so that I can link and
> then JIT it. What would be the best way of doing this?
>
> Thanks,
>
> Daniel
>
> --
> active-thought.com
> _______________________________________________
> cfe-dev mailing list
> [hidden email]
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Compile a string?

Daniel Waterworth
Hi,

So I create the CompilerInvocation and remap with
addRemappedFile(llvm::StringRef From, const llvm::MemoryBuffer * To)
in PreprocessorOptions. Sounds easy enough [=

Thanks,

Daniel

On 23 June 2010 06:12, Daniel Dunbar <[hidden email]> wrote:

> Hi Daniel,
>
> Take a look at the clang-interpreter example for most of it. Instead
> of using CompilerInvocation::CreateFromArgs, you will want to
> construct a CompilerInvocation by hand, including an input file name,
> and then use the remapping arguments to associate your string with
> that file.
>
>  - Daniel
>
> On Sat, Jun 19, 2010 at 1:33 AM, Daniel Waterworth
> <[hidden email]> wrote:
>> Hi,
>>
>> I'm trying to compile a string into a Module so that I can link and
>> then JIT it. What would be the best way of doing this?
>>
>> Thanks,
>>
>> Daniel
>>
>> --
>> active-thought.com
>> _______________________________________________
>> cfe-dev mailing list
>> [hidden email]
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>>
>



--
active-thought.com

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev