Skip to content

tju compiler project, from simpleC to LLVM IR (based on llvmlite)

Notifications You must be signed in to change notification settings

soryxie/simpleC_compiler

Repository files navigation

simpleC_compiler

  • tju compiler project
  • from simpleC to LLVM IR

Features:

✅ Variable Initialisation

✅ Function Calls and Arguments

✅ Arrays (such as int arr[10][2])

✅ Break & Continue

✅ Function Return Value

✅ if else-if else

Outcomes

/* TEST CODE : array, expr, for, if ...*/
int binarySearch(int arr[10], int len, int val) {
    int l, r;
    for (l = 0, r = len; l < r; ) {
        int mid = l + (r - l) / 2;
        if (arr[mid] < val) {
            l = mid + 1;
        } else {
            r = mid;
        }
    }
    return (arr[l] == val);
}
C code <-> LLVM IR code

Brief Usage :

ℹ️ for LLVM output:

python3 ASTtoLLVM.py <C file> <output file>

ℹ️ for new action,goto table:

first, set the path to simpleC folder(for vscode debugging) in CtoAST.py L11

Then, uncomment these codes in CtoAST.py L16-L20

ℹ️ for human readable AST tree:

see this CtoAST.py L387

About

tju compiler project, from simpleC to LLVM IR (based on llvmlite)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published