[LLVMdev] seeking advice

mats petersson mats at planetcatfish.com
Mon Aug 3 10:57:01 PDT 2015


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.

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...

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).

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.

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!]

--
Mats


On 3 August 2015 at 18:07, Renato Golin <renato.golin at linaro.org> wrote:

> On 3 August 2015 at 16:29, Arno Bastenhof <arnobastenhof at gmail.com> wrote:
> > Based on these
> > readings, as a matter of exercise I can take what I learnt from LCC to
> write
> > a small compiler in C targeting the LLVM IR for, say, a subset of Prolog.
>
> Hi Arno,
>
> This is not a monumental task. There are many tutorials in the LLVM
> tree, and producing IR from a simple AST is actually simple and
> straight-forward.
>
> So many languages can target LLVM IR, that it's very hard that you'll
> find something that cannot be represented in IR. At least something
> that other implementations haven't found already, and worked around.
>
> With your broad knowledge in CS, I wouldn't expect you to take more
> than a month or two to get a front-end working with the JIT compiler
> on a reasonable subset of Prolog. Of course, the deeper you go, the
> more time it takes to progress the same 1%, but you can always stop
> when productivity drops as fast as enjoyment. :)
>
> But you won't need to understand the back-end at all, modulo some
> quirks on your platform of choice. The hint is to write the same logic
> in Prolog and C, compile the C with Clang and see what they do. If you
> spot hackery, the least resistance path is to replicate the hackery.
> Asking on the list is also a good way to understand why the hackery,
> and maybe even give you an entry point into changing the middle/back
> end to support a proper construct in IR for better codegen.
>
> From there, I'd recommend you to try different targets. Get some
> board, device, phone you have at your disposal (RaspberryPi2 is a
> great inexpensive kit), and make it work. You'll take a lot less
> effort than you're imagining...
>
> cheers,
> --renato
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150803/e7b4f2ed/attachment.html>


More information about the llvm-dev mailing list