Add comprehensive instructions for working with this compiler project, including key commands, architecture overview, dependencies, and environment setup information.
1.5 KiB
1.5 KiB
Jompiler Agent Instructions
This is a C compiler that targets x86-64 ELF object files.
Key Commands
node index.js input.c- Compile and link input.c to produce a.outnode index.js input.c && ./a.out- Compile, link, and run the compiled program
Architecture
This is a single-file compiler written in JavaScript with the following phases:
- Lexing (tokenization) -
lex()function - Parsing (AST construction) -
parse()function - Lowering (x86-64 code generation) -
lower()function - Linking -
link()function that shells out togcc
Dependencies
The system requires:
- Node.js (tested with Node.js 22)
- GCC (for linking)
- LLVM tools (for development environment - installed via nix)
Important Details
- The compiler supports basic C constructs: integers, variables, basic arithmetic, function declarations, function calls, returns, and basic control flow
- Uses the standard C calling convention for x86-64
- Generates x86-64 ELF object files
- Has no support for complex C features like pointers, conditionals, loops, arrays
- Supports the same C standard as referenced in the comment: C11 (ISO/IEC 9899:2011)
- Has a specific test case in
input.cthat demonstrates basic functionality - The
dump-main.gdbfile is used for debugging and disassembly
Runtime Environment
- Uses Nix for environment setup:
nix-shellordirenvwith the providedshell.nix - Requires
nodeto be available from PATH - Requires
gccandgdbfor linking and debugging - Uses
spawnto execute external commands (GCC linking, GDB debugging)