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.
Asked
Active
Viewed 3,878 times
8
-
3What 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. – Joe Aug 20 '15 at 07:47
-
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. – NewGirl Aug 20 '15 at 16:01
-
Did you manage to create one? Because I need to create a simple one using antlr and llvm – fluffy Dec 22 '21 at 15:56
1 Answers
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.

prmottajr
- 1,816
- 1
- 13
- 22