• Stars
    star
    193
  • Rank 201,081 (Top 4 %)
  • Language
    C
  • License
    MIT License
  • Created almost 6 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Standalone C compiler/assembler/linker/libc for x86-64/aarch64/riscv64/wasm

XCC

Action Status Open in Gitpod

C compiler running on Linux or MacOS.

  • Supporting architecture: x86-64, aarch64 (arm64), wasm
  • Binary format: ELF64

Requirements

  • Linux (or MacOS)
  • 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
Hello, world!

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

Reference


WebAssembly

Compile C to WebAssembly/WASI binary.

Online demo

Requirements

  • node.js (>=16), npm

Setup:

$ npm ci

Build

$ make wcc

Generated files:

  • wcc: C compiler (including preprocessor, and output .wasm directly)

Usage

Compile:

$ ./wcc -o hello.wasm examples/hello.c

Command line options:

  • -o <filename>: Set output filename (default: a.wasm)
  • -I <path>: Add include path
  • -D <label>(=value): Define macro
  • --entry-point=func_name: Specify entry point (default: _start)
  • -e func_name,...: Export function names (comma separated)
  • --stack-size=<size>: Set stack size (default: 8192)
  • -nodefaultlibs: Ignore libc
  • -nostdlib: Ignore libc and crt0
  • --verbose: Output debug information

Run

$ node tool/runwasi.js hello.wasm
Hello, world!

Missing features

  • goto statement