sasho648
2021-09-01 16:28:49 UTC
It uses PCRE2 to parse the C file and match a huge regex composed of several .regex files stitched together one Perl script (main.pl). There are about 94 currently callouts placed inside it which invoke C++ code that reads named capture groups and calls the LLVM APIs appropriately to construct a program.
https://github.com/6a4h8/cparser2/tree/wip
This is an open source compiler using regular expressions and mainly focusing on the C89 (from fips pub 160 pdf document).
The backend was originally a huge C switch which I recently converted into C++ virtual functions - there are two pair of them - one for parsing - they can alter the match and one for producing.
The parsing one is mainly used for typedefs since they require context sensitive parsing inside functions.
Currently it doesn't implement: initialization, WIP on implementing conditional evaluation with the logical ops, incomplete types, un-prototyped functions.
Most importantly it doesn't support attributes and preprocessor directives.
It does implement: everything else hopefully.
Check out the WIP branch (lastly worked on Windows). Invocation:
cparser main.pl in_src.c
Expected output (llvm bitcode and IR representation):
in_src.c.bc
in_src.c.ll
It can be debugged if you uncomment the ending of line 6 in main.h. This will produce 2 output.txt files and significantly slow down the compilation process.
https://github.com/6a4h8/cparser2/tree/wip
This is an open source compiler using regular expressions and mainly focusing on the C89 (from fips pub 160 pdf document).
The backend was originally a huge C switch which I recently converted into C++ virtual functions - there are two pair of them - one for parsing - they can alter the match and one for producing.
The parsing one is mainly used for typedefs since they require context sensitive parsing inside functions.
Currently it doesn't implement: initialization, WIP on implementing conditional evaluation with the logical ops, incomplete types, un-prototyped functions.
Most importantly it doesn't support attributes and preprocessor directives.
It does implement: everything else hopefully.
Check out the WIP branch (lastly worked on Windows). Invocation:
cparser main.pl in_src.c
Expected output (llvm bitcode and IR representation):
in_src.c.bc
in_src.c.ll
It can be debugged if you uncomment the ending of line 6 in main.h. This will produce 2 output.txt files and significantly slow down the compilation process.