1

I'm writing a DSL front end using ANTLR v4 that I'd like to bolt on to GCC framework. The goal is to have a C language AST to leverage the rest of the GCC framework.

I haven't found any info or preexisting work to use an example of how to proceed. What I'm looking for is how to move the ANTLR 4 AST to GCC Generic/GIMBLE.

ANTLR 4 does not support a C language target, so I'll have to cludge up the C++ target to the GCC C language framework.

Help is appreciated

garyM
  • 802
  • 2
  • 12
  • 29

1 Answers1

0

Gluing a C++ implementation of ANTLR into GCC so that GCC will call it is likely to be the easy step. [Don't expect to be easy; GCC wants to be GCC, not your pet. You might get some help from GCC Melt, a package for interfacing to GCC machinery.]

The AST produced for an arbitrary (e.g., your custom DSL) language doesn't "just move (easily)" to a C AST or to the GCC Gimple (not GIMBLE) framework.

You will have to build, in essence, your DSL-AST to C-AST translator, or your DSL-AST to Gimple translator. There is no a priori reason to believe that building such a translator is easy; for example, you didn't tell us your DSL was "just like C except ...". So, you're going to have to build a translator. In the absence of evidence this is easy, you'll have to translate your DSL concepts to C concepts. The better ("non C-like") your DSL is, the harder this is going to be.

This SO link discusses the issues behind translation in more detail: What kinds of patterns could I enforce on the code to make it easier to translate to another programming language?

Community
  • 1
  • 1
Ira Baxter
  • 93,541
  • 22
  • 172
  • 341
  • Thanks for the advise, helpful links and pointing out the GIMBLE/Gimple. iPad auto-correct was not cooperating and I failed to notice.. I didn't think GCC is my pet or friendly, and integrating an ANTLR parser is NOT a trivial task. That was the primary reason for posting the question. The DSL is a ascii char set, canonical subset of category theory for tensors with hints directing GPU constructs and distributed workflows via RDMA and MPI (not like tensorflow). I'm mapping the DSL to a C lang AST to leverage existing libraries. Lang details were omitted to stay focused on topic. – garyM Nov 14 '16 at 21:51
  • @garyM: You might be better off simply transforming the DSL to C as a *source* language. Then you can implement your translator without fighting battles to integrate it into a particular compiler. If you are interested in how to build a translator that maps source-level constructs to source level constructs, you should consider a program transformation system (see http://en.wikipedia.org/wiki/Program_transformation) and not something which is *just* a parser. If you want to see examples of source to source transforms, see http://www.semdesigns.com/Products/DMS/DMSRewriteRules.html – Ira Baxter Nov 14 '16 at 22:00