[antlr-interest] Question: ANTLR and LLVM ... + Clang
Kevin J. Cummings
cummings at kjchome.homeip.net
Fri Jun 17 10:22:04 PDT 2011
On 06/17/2011 09:34 AM, Ruslan Zasukhin wrote:
> Hi Guys,
>
> Thank you very much for answers.
>
> Okay, so about LLVM is clear ... It is compillers - code generation.
>
> But exists yet Clang -- C/C++/ObjC frontend
>
> And I think Clang can be compared to ANTLR.
> Right?
No. CLang is a compiler frontend. It is a frontend for C/C++/ObjC.
(I must confess, I do not know enough about C-Lang to know what it uses
to parse its source code with, then again, I do not know what GCC uses
either....)
LLVM is a compiler backend (if you include all of the IR optimization
phases in your compiler's backend). It is defined at either the IR
level (via its C++ classes and methods), its bytecode level (.bc files),
or at the text level via its .ll file pseudo-machine-independent
assembly. LLVM contains many tools to convert between the 3 formats.
Generally, all of its "passes" operate on its IR and produce a new IR as
its output until you finally get to a code generator which is capable of
producing a machine specific object text file, an executable file
(through an LLVM linker), or a JIT file which can be executed by an LLVM
tool.
As referenced in one of your original responses, Ter worked up a quick
and dirty example of using an ANTLR front-end which produces an LLVM
assembly text which can be used for input to the LLVM toolchain using
his String Templates.
ANTLR is a tool which can help you build compiler front-ends. If you
were industrious enough, you could re-write CLang using ANTLR.
ANTLR is primarily a JAVA tool (you at least need JAVA to run the tool
to compile your grammar), but can be used to produce other targeted
languages (C/C++, Python, etc) for your actual front-end. While the C++
support is minimal in version 3 (better in version 2.7, but lacking in
some of the ST support) resulting in much use of C code which can be
compiled using C++, you could use it to interface directly to the LLVM
IR API if you wanted to. But, I think Ter's example is probably the way
to go, at least until Version 4 starts to grow and we see what kind of
C++ runtime support will exist for ANTLR v4.
> When one should prefer Clang vs ANTLR or reverse?
> Your opinions?
I think you are asking the wrong question here. Please compare apples
to apples, and not to cucumbers.
--
Kevin J. Cummings
kjchome at verizon.net
cummings at kjchome.homeip.net
cummings at kjc386.framingham.ma.us
Registered Linux User #1232 (http://counter.li.org)
More information about the antlr-interest
mailing list