https://github.com/coditva/uc-to-llvm
A small uC compiler front-end for LLVM
https://github.com/coditva/uc-to-llvm
compiler compiler-construction lex llvm llvm-c llvm-ir yacc
Last synced: 5 months ago
JSON representation
A small uC compiler front-end for LLVM
- Host: GitHub
- URL: https://github.com/coditva/uc-to-llvm
- Owner: coditva
- License: mit
- Created: 2018-04-09T06:02:14.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-04-13T20:06:19.000Z (almost 8 years ago)
- Last Synced: 2025-05-20T10:45:14.644Z (9 months ago)
- Topics: compiler, compiler-construction, lex, llvm, llvm-c, llvm-ir, yacc
- Language: Yacc
- Homepage:
- Size: 63.5 KB
- Stars: 1
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Micro C (*uC)* to *LLVM* compiler
Micro C or *uC* is a subset of C language. This compiler compiles it to
*LLVM* for execution.
### How to
Make sure you have *LLVM* library installed before compiling
```bash
make # compile
make test # run tests
make clean # cleanup
TEST=test0.uc make test # run tests on test0.uc only
./uc FILENAME # generate the LLVM IR
llvm-as a.ll # convert the IR to bytecode
lli a.bc # run the bytecode
```
The IR generated can be found in `a.ll` and the byte-code is in `a.bc`.
### About *uC*
The *uC* is a subset of C with very basic functionality. The implemented
version of *uC* supports the following:
- All variable are of type `int32`.
- Every statement ends with `;`.
- Variable can be assigned as: `a = 10;` or `a = b;` given `b` is defined before
- Arguments can be input as `a = $1;`.
- There are _no_ functions. Everything is assumed to be in `main`.
- Comments start with `//` and go on till end of line.
- `if (condition) { statements }`
- `if (condition) { statements } else { statements }`
- `while (condition) { statments }`
- `for (expression; condition; expression) { statements }`
- `do { statements } while (condition);`
- If there is only one statement, `{` and `}` can be dropped.
- Loops and conditional statements _cannot_ be nested.
- All operators from C are supported.
- `break` and `return` are supported.
See programs in `tests/` for sample.
### Author
Utkarsh Maheshwari
### License
MIT