A toy C compiler written in OCaml.
Let's print Hello, World!.
$ dune exec ccaml examples/valid/hello_world.c | gcc -xassembler - && ./a.out
Hello, World!The examples/valid/hello_world.c program is the following.
int putchar(int c);
int main() {
putchar(72);
putchar(101);
putchar(108);
putchar(108);
putchar(111);
putchar(44);
putchar(32);
putchar(87);
putchar(111);
putchar(114);
putchar(108);
putchar(100);
putchar(33);
putchar(10);
return 0;
}# Generate assembly
$ dune exec ccaml source.c
# Execute a program with GCC assembler
$ dune exec ccaml source.c | gcc -xassembler - && ./a.out
# Run test
$ dune test- Writing a C Compiler, Part 1
- Writing a C Compiler, Part 2
- Writing a C Compiler, Part 3
- Writing a C Compiler, Part 4
- Writing a C Compiler, Part 5
- Writing a C Compiler, Part 6
- Writing a C Compiler, Part 7
- C Compiler, Part 8: Loops
- C Compiler, Part 9: Functions
- nlsandler/nqcc: A compiler for a tiny (but growing!) subset of C, written in OCaml.
- 低レイヤを知りたい人のための C コンパイラ作成入門
- x86 アセンブリ言語での関数コール
- AT&T assembly syntax and IA-32 instructions
- Online GCC Assembler - online editor