Skip to content

9sako6/ccaml

Repository files navigation

CCaml

A toy C compiler written in OCaml.

Usage

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

References

  1. Writing a C Compiler, Part 1
  2. Writing a C Compiler, Part 2
  3. Writing a C Compiler, Part 3
  4. Writing a C Compiler, Part 4
  5. Writing a C Compiler, Part 5
  6. Writing a C Compiler, Part 6
  7. Writing a C Compiler, Part 7
  8. C Compiler, Part 8: Loops
  9. C Compiler, Part 9: Functions
  10. nlsandler/nqcc: A compiler for a tiny (but growing!) subset of C, written in OCaml.
  11. 低レイヤを知りたい人のための C コンパイラ作成入門
  12. x86 アセンブリ言語での関数コール
  13. AT&T assembly syntax and IA-32 instructions
  14. Online GCC Assembler - online editor

About

A toy C compiler written in OCaml

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published