https://github.com/vaibhav-2303/minic-compiler
Compiler Front-End Code for a C-like language
https://github.com/vaibhav-2303/minic-compiler
antlr4 compiler-design llvm llvm-ir oops-in-cpp visitor-pattern
Last synced: 24 days ago
JSON representation
Compiler Front-End Code for a C-like language
- Host: GitHub
- URL: https://github.com/vaibhav-2303/minic-compiler
- Owner: VAIBHAV-2303
- Created: 2020-12-07T11:01:39.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2020-12-07T12:20:25.000Z (over 5 years ago)
- Last Synced: 2025-11-08T02:03:53.675Z (7 months ago)
- Topics: antlr4, compiler-design, llvm, llvm-ir, oops-in-cpp, visitor-pattern
- Language: C++
- Homepage:
- Size: 137 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# MiniC-Compiler
## Description
This repository contains code for a full-fledged Front-End for the MiniC language, more details regarding the language can be found in *LanguageManual.pdf*. The project was completed in the following phases:
### Parsing phase
The micro-syntax and macro-syntax can be found in *MiniC.g4*. The tokenizing and parsing is being automatically done using Antlr4-runtime and toolchanin.
### AST generation and Semantic Analysis phase
The code for building AST can be found in *Ast.h* and *BuildAstVisitor.h*. Visitor design pattern has been used to facilitate clean and efficient production. Semantic Analysis code can be found in *SemanticAnalysisVisitor.h* and Symbol Table class in *SymbolTable.h*. The checks being done are:
* Type Checking
* Variable Declaration
### LLVM IR generation phase
*IRGenVisitor.h* contains code for generating non-optimized LLVM IR for the code, which can be further executed using LLVM tools like the lli interpreter.
A decent amount of sample programs are available in *Sample Programs* directory which can be used for extensive testing and demonstration.
## How To Run
```bash
bar@foo:~/MiniC-Compiler/src$ make
```
Running *make* will compile the entire code and generate some Antlr files and two executables *main* and *bonus*.
```bash
bar@foo:~/MiniC-Compiler/src$ ./main
```
This will generate LLVM IR for the code in a file called *temp.ll*. This is in human readable format.
```bash
bar@foo:~/MiniC-Compiler/src$ llvm-as temp.ll
bar@foo:~/MiniC-Compiler/src$ lli temp.bc
```
This will convert the IR to bitcode format which is then ready to be executed by the LLVM Interpreter lli.
```bash
bar@foo:~/MiniC-Compiler/src$ ./bonus
```
This will automatically read the *temp.bc* file and print the Extended Basic Blocks from the Control Flow Graph which are used in Super Value Numbering.
```bash
bar@foo:~/MiniC-Compiler/src$ make clean
```
Use this to clean up the generated files and executables.
## Author
* Vaibhav Garg