On Sun, Aug 16, 2009 at 3:39 PM, Renato Golin <span dir="ltr"><<a href="mailto:rengolin@systemcall.org">rengolin@systemcall.org</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hi all,<br>
<br>
I'm writing a test compiler to understand the overall structure of<br>
LLVM and I managed to produce IR for expressions, functions and<br>
function calls.<br>
<br>
I'm following the Kaleidoscope example and had a hard time de-tangling<br>
the language specifics from LLVM syntax. Anyhow, I got here and I'd<br>
like some more specific help to finish my example.<br>
<br>
My very simple language has global variables and static functions<br>
only, so I can focus on the code generation. My problems are below.<br>
<br>
1. Kaleidoscope uses function calls, which I believe prepare the<br>
stack, saves the link register and so on, which I'm not interested at<br>
all, as everything is static. What's the correct way to create a<br>
simple jump instead of a call?</blockquote><div><br></div><div>Jumps in LLVM are branches to BasicBlocks.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
2. Each static function is called a "state". At the end, it MUST jump<br>
to the next state, even if it's itself. If it doesn't, the program<br>
must end. I also want create an end of the program whenever the token<br>
"end" is parsed. How can I do it?</blockquote><div><br></div><div>I'm not sure I understand this.  (Are you implementing a Turing machine?)</div><div>It sounds like "state" here is global, rather than per-function, so make it a global array.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">3. When the program is running, I'd like to print some values. As<br>
Kaleidoscope "returns" the value to the JIT, it's easy to give the<br>
answer, but in my case it won't happen. Do I need to create a simple<br>
IR routine to print doubles or is there something easy to use for that<br>
purpose?<br></blockquote><div><br></div><div>Yes, you'll probably need to implement printing functionality.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
PS: Where's the best place to find such information?</blockquote><div><br></div><div><a href="http://llvm.org/docs/">http://llvm.org/docs/</a> has a search box at the top of the page.</div></div>