0

I am looking for a compiler framework that I can use to write some code optimizations and dataflow analysis for C source code. I know there is LLVM but I would like to work with source code rather than bytecode. I was looking into LLVM-dragonegg but I am not sure how easy would it be to implement dataflow passes using that?

JRR
  • 6,014
  • 6
  • 39
  • 59
  • To those who voted for closing this question: I would like to know why this is an off-topic question. I am just asking to see what are the available options out there, not for a recommendation or endorsement. – JRR Oct 15 '14 at 08:59
  • 1
    Try Clang, it's got a decent and easy to use API, even with nice Python wrapper (cindex). – SK-logic Oct 15 '14 at 10:02
  • P.S. Another option is to work on LLVM IR level, while keeping the debugging metadata in order to maintain a mapping from your modified IR to the original source code. Depending on what you want to do it may be a better way than analysing Clang ASTs. – SK-logic Oct 15 '14 at 10:04

1 Answers1

1

A compiler don't work on textual source code (but it parses source code). It works on internal representations, such as ASTs. Each compiler has its own internal representation(s) and most of the optimization work of a compiler is to transform its internal representations.

If you decide to work with a recent GCC you could extend it with MELT (or, more painfully, with your own GCC plugin). But of course you'll need to understand in details the internal representations (Gimple, Generic Trees) and the compilation passes.

MELT is a lispy domain specific language, implemented as a GCC plugin, to extend GCC.

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547