<div dir="ltr"><div>When I set out on my "Pascal Compiler project", I had never written a compiler before - I had SOME experience in writing interpreters and other parser/parser-like projects. That's about 14 months ago. I think I started around end of February, and by the beginning of march, when I pushed the first commit to github, I already had small programs working. <br><br>I only spend (some of my) evenings and weekends on this project, and there have been periods where I didn't do any work for several weeks for one reason or another. I'm now at the a stage where the parser and semantic analysis is parsing the iso7185pat.pas ("pat = Pascal Acceptance Test"). It's not yet passing the code-gen phase - the current stumbling block is trampolining for nested function pointer calls, and I think there are going to be a few other problems along the way. Given that this file is "trying to do everything the ISO7185 standard allows", it's not surprising it finds a few interesting issues...<br><br>I have a few decent size home-grown tests, such as a sudoku solver that "works" - and because LLVM provides good optimisation, my compiler beats the "regular" Free Pascal compiler on all like-for-like comparisons I've made so far - in particular, the Sudoku solver is about 2x faster with my compiler than Free Pascal (ok, I cheat, some 5% of that comes from having implemented a "popcount" intrinsic that can take a "set" and give the number of elements in the set, which standard pascal or Free Pascal doesn't have). <br><br></div><div>Of course, like Renato says, for every small step towards "full functionality" gets harder - and the good thing with a hobby project is the ability to choose how much time you spend on what features, and how you implement them. <br><br></div><div>I thoroughly recommend "try it, see how it goes". I've found it surprisingly easy...  [Mostly because other people have done the REALLY hard part of making the LLVM IR to machine code phase! - Thanks guys!]<br><br>--<br></div><div>Mats<br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 3 August 2015 at 18:07, Renato Golin <span dir="ltr"><<a href="mailto:renato.golin@linaro.org" target="_blank">renato.golin@linaro.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 3 August 2015 at 16:29, Arno Bastenhof <<a href="mailto:arnobastenhof@gmail.com">arnobastenhof@gmail.com</a>> wrote:<br>
> Based on these<br>
> readings, as a matter of exercise I can take what I learnt from LCC to write<br>
> a small compiler in C targeting the LLVM IR for, say, a subset of Prolog.<br>
<br>
</span>Hi Arno,<br>
<br>
This is not a monumental task. There are many tutorials in the LLVM<br>
tree, and producing IR from a simple AST is actually simple and<br>
straight-forward.<br>
<br>
So many languages can target LLVM IR, that it's very hard that you'll<br>
find something that cannot be represented in IR. At least something<br>
that other implementations haven't found already, and worked around.<br>
<br>
With your broad knowledge in CS, I wouldn't expect you to take more<br>
than a month or two to get a front-end working with the JIT compiler<br>
on a reasonable subset of Prolog. Of course, the deeper you go, the<br>
more time it takes to progress the same 1%, but you can always stop<br>
when productivity drops as fast as enjoyment. :)<br>
<br>
But you won't need to understand the back-end at all, modulo some<br>
quirks on your platform of choice. The hint is to write the same logic<br>
in Prolog and C, compile the C with Clang and see what they do. If you<br>
spot hackery, the least resistance path is to replicate the hackery.<br>
Asking on the list is also a good way to understand why the hackery,<br>
and maybe even give you an entry point into changing the middle/back<br>
end to support a proper construct in IR for better codegen.<br>
<br>
>From there, I'd recommend you to try different targets. Get some<br>
board, device, phone you have at your disposal (RaspberryPi2 is a<br>
great inexpensive kit), and make it work. You'll take a lot less<br>
effort than you're imagining...<br>
<br>
cheers,<br>
--renato<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" rel="noreferrer" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" rel="noreferrer" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
</blockquote></div><br></div>