Integrating antlr4 with LLVM
Asked Answered
S

1

8

I am developing a compiler using ANTLR and LLVM. I have already implemented a lexer and a parser using ANTLR 4's Eclipse IDE. I want to implement a semantic analyzer and a code generator using LLVM. For this I want to know how to integrate the two. Most of the projects that I have seen online use ANTLR for semantic analysis (with visitor and walker functions) and LLVM for code generation only. I want to know how to pass ANTLR parser output as input to LLVM semantic analyser. Links to online examples illustrating this would be very useful.

Serving answered 20/8, 2015 at 5:57 Comment(3)
What have you tried so far? LLVM doesn't have any semantic analysis functionality beyond what is needed for the semantic analysis of the LLVM IR itself.Eburnation
What I have tried till now is to get the parser output in a file and my semantic analyzer is reading that file to store information like type, identifiers, etc in lists which I use to check the semantics of the code. But I think you are right - LLVM doesn't have much semantic functionality as it is getting more and more complex and difficult to implement. Was trying to see if anyone has used LLVM for semantic analysis.Serving
Did you manage to create one? Because I need to create a simple one using antlr and llvmShake
C
5

Although you mentioned ANTLR4 there is an example of using ANTLR3 to generate LLVM IR for a subset of C here https://theantlrguy.atlassian.net/wiki/spaces/ANTLR3/pages/2687062/LLVM It is very interesting and presents an example of how to use both tools together to create a working compiler.

Crucifix answered 8/9, 2017 at 19:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.