mingodad / xcc

Toy C compiler for x86-64

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

XCC

Action Status Open in Gitpod

  • C compiler for XV6 (64bit)
    • Also work on Linux
  • Assembler
  • Output ELF64 (x86-64) file format
  • Register allocation (Linear scan)
  • Self hosting

Requirements

  • Linux
  • C compiler (gcc or clang)
  • make

Build

$ make

Generated files:

  • xcc: Compiler entry
  • cpp: Preprocessor
  • cc1: C compiler
  • as: Assembler
  • ld: Linker

Usage

$ ./xcc -o hello examples/hello.c
$ ./hello

Command line options

  • -o <filename>: Set output filename (default: a.out)
  • -I <path>: Add include path
  • -D <label>(=value): Define macro
  • -S: Output assembly code
  • -E: Preprocess only
  • -c: Output object file
  • -nodefaultlibs: Ignore libc
  • -nostdlib: Ignore libc and crt0

TODO

  • Optimization
  • Archiver

Missing features

C compiler:

  • Bit field

WebAssembly

WCC: Compile C to WebAssembly.

Reference

About

Toy C compiler for x86-64


Languages

Language:C 86.1%Language:TypeScript 6.6%Language:Shell 3.2%Language:JavaScript 1.7%Language:Makefile 1.5%Language:HTML 0.4%Language:SCSS 0.4%Language:C++ 0.2%