[LLVMdev] Test compiler help

Misha Brukman brukman at gmail.com
Tue Aug 18 09:03:20 PDT 2009


On Sun, Aug 16, 2009 at 3:39 PM, Renato Golin <rengolin at systemcall.org>wrote:

> Hi all,
>
> I'm writing a test compiler to understand the overall structure of
> LLVM and I managed to produce IR for expressions, functions and
> function calls.
>
> I'm following the Kaleidoscope example and had a hard time de-tangling
> the language specifics from LLVM syntax. Anyhow, I got here and I'd
> like some more specific help to finish my example.
>
> My very simple language has global variables and static functions
> only, so I can focus on the code generation. My problems are below.
>
> 1. Kaleidoscope uses function calls, which I believe prepare the
> stack, saves the link register and so on, which I'm not interested at
> all, as everything is static. What's the correct way to create a
> simple jump instead of a call?


Jumps in LLVM are branches to BasicBlocks.


> 2. Each static function is called a "state". At the end, it MUST jump
> to the next state, even if it's itself. If it doesn't, the program
> must end. I also want create an end of the program whenever the token
> "end" is parsed. How can I do it?


I'm not sure I understand this.  (Are you implementing a Turing machine?)
It sounds like "state" here is global, rather than per-function, so make it
a global array.


> 3. When the program is running, I'd like to print some values. As
> Kaleidoscope "returns" the value to the JIT, it's easy to give the
> answer, but in my case it won't happen. Do I need to create a simple
> IR routine to print doubles or is there something easy to use for that
> purpose?
>

Yes, you'll probably need to implement printing functionality.


> PS: Where's the best place to find such information?


http://llvm.org/docs/ has a search box at the top of the page.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20090818/aec98886/attachment.html>


More information about the llvm-dev mailing list