[LLVMdev] Rolling my own LLVM assembly language parser
Jon Harrop
jon at ffconsultancy.com
Wed Mar 25 13:16:42 PDT 2009
On Wednesday 25 March 2009 17:12:34 John Criswell wrote:
> jstanier wrote:
> > Hi everyone,
> >
> > I'm currently in the first year of my PhD, and I'm going to be looking at
> > an experimental IR for my thesis. After looking at a variety of research
> > compilers I've come to the conclusion that LLVM is the nicest to work
> > with for my purposes. I was considering writing the code to construct
> > this experimental IR from LLVM assembly, and then at the end of the
> > process (i.e. new optimisations and transformations, etc.) I'll translate
> > back into LLVM assembly to allow compilation to continue. This keeps
> > everything modular, means I can work with "real" languages rather than
> > toy ones, and so on.
>
> It seems to me that an easier approach would be to convert in-memory
> LLVM IR to your experimental IR using the LLVM libraries, then do
> whatever you do with your experimental IR, and then convert the code
> back into in-memory LLVM IR for LLVM based optimizations and code
> generation. The libraries for manipulating LLVM IR are well designed,
> reasonably documented, and seem to me to be easier to work with than
> creating your own LLVM IR parser.
I assume James is only considering reinventing this wheel because he is not
using C++. LLVM does not play nice with other languages because C++ is quite
uninteroperable. There are C bindings to LLVM that make it a lot easier but,
of course, they are far from complete.
So I can fully appreciate the desire to do something like this. However, my
recommendation would be to augment LLVM with better interop rather than
reimplement bits of it in other languages. So I would advise James to work on
a more language agnostic machine-readable format for LLVM's IR (e.g. XML
based) and contribute code to LLVM that lets it IO in that format as well as
the current human-readable form.
As we discussed before, something like an autogenerated XML-RPC server to the
whole of LLVM would be a much better solution offering easy interop with a
huge variety of languages without having to write and maintain all of these
bindings.
--
Dr Jon Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/?e
More information about the llvm-dev
mailing list