Kreijstal/Pascal-Compiler
Pascal Compiler written in C. Takes Pascal code and outputs gcc-targeted x86-64 assembly. Mileage may vary!
Kreijstal Gwinn Pascal Compiler (KGPC)
Fork based on gwinndr/Pascal-Compiler
Overview
KGPC is a Pascal Compiler written in C. It takes Pascal code and outputs gcc-targeted x86-64 assembly.
Goal: The true goal of this repository is merely bootstrapping Free Pascal Compiler (FPC) without needing FPC nor proprietary compilers. A very basic RTL was written, and FPC is used as the golden standard. If FPC can do it but we can't, it is a bug.
Architecture
The compiler consists of several distinct stages:
- Parser: Uses
cparsercombinator library to generate an AST. - Semantic Analysis: Performs type checking, scope resolution, and builds a unified
GpcTypesystem. - Optimizer: Performs passes like Dead Code Elimination and Constant Folding.
- Code Generator: Outputs x86-64 assembly (Intel syntax).
Dependencies
- Build System:
meson - Assembler/Linker:
gccorclang(KGPC only generates assembly; GCC/Clang is used to assemble and link)
How to Build and Run
This project uses the Meson build system. It works on Windows, Linux, and Wine (checked in CI).
Building
meson setup build
meson compile -C buildTesting
meson test -C buildUsage
After building, the compiler executable kgpc will be in the build directory.
./build/kgpc [Input File] [Output File] [Optional Flags]Example:
./build/kgpc test.p test.s
gcc -o test test.s
./testLicense
This project is licensed under the GNU Affero General Public License v3.0 (AGPLv3). See the LICENSE file for details.