https://github.com/tyfkda/xcc
Standalone C compiler/assembler/linker/libc for x86-64/aarch64/riscv64/wasm
https://github.com/tyfkda/xcc
aarch64 arm64 assembler c c-compiler compiler elf64 linker mach-o posix preprocessor riscv64 self-hosting wasi wasm x86-64
Last synced: 21 days ago
JSON representation
Standalone C compiler/assembler/linker/libc for x86-64/aarch64/riscv64/wasm
- Host: GitHub
- URL: https://github.com/tyfkda/xcc
- Owner: tyfkda
- License: mit
- Created: 2019-01-17T22:38:21.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2024-10-29T13:31:32.000Z (6 months ago)
- Last Synced: 2024-10-29T16:05:22.579Z (6 months ago)
- Topics: aarch64, arm64, assembler, c, c-compiler, compiler, elf64, linker, mach-o, posix, preprocessor, riscv64, self-hosting, wasi, wasm, x86-64
- Language: C
- Homepage: https://tyfkda.github.io/xcc/
- Size: 5.23 MB
- Stars: 252
- Watchers: 8
- Forks: 17
- Open Issues: 26
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
XCC
===[](https://github.com/tyfkda/xcc)
[](https://gitpod.io/#https://github.com/tyfkda/xcc)C compiler running on Linux or MacOS.
* Supporting architecture: x86-64, aarch64 (arm64), riscv64, wasm
* Binary format: ELF64### Requirements
* Linux (or MacOS)
* C compiler (gcc or clang)
* make### Build
```sh
$ make
```Generated files:
* `xcc`: Compiler entry
* `cpp`: Preprocessor
* `cc1`: C compiler
* `as`: Assembler
* `ld`: Linker### Usage
```sh
$ ./xcc -o hello examples/hello.c
$ ./hello
Hello, world!
```#### Command line options
* `-o `: Set output filename (default: `a.out`)
* `-I `: Add include path
* `-D (=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
* [低レイヤを知りたい人のためのCコンパイラ作成入門](https://www.sigbus.info/compilerbook)
* [rui314/9cc: A Small C Compiler](https://github.com/rui314/9cc)----
### WebAssembly
Compile C to WebAssembly/WASI binary.
[Online demo](https://tyfkda.github.io/xcc/)
#### Requirements
* node.js, npm
* `llvm-ar`#### Set up
```sh
$ npm ci
```#### Build
```sh
$ make wcc
```Generated files:
* `wcc`: C compiler (including preprocessor, and output .wasm directly)
#### Usage
Compile:
```sh
$ ./wcc -o hello.wasm examples/hello.c
```Command line options:
* `-o `: Set output filename (default: `a.wasm`)
* `-I `: Add include path
* `-D (=value)`: Define macro
* `-E`: Preprocess only
* `-c`: Output object file
* `--entry-point=func_name`: Specify entry point (default: `_start`)
* `-e func_name,...`: Export function names (comma separated)
* `--stack-size=`: Set stack size (default: 8192)
* `-nodefaultlibs`: Ignore libc
* `-nostdlib`: Ignore libc and crt0
* `--verbose`: Output debug information#### Run
```sh
$ ./tool/runwasi hello.wasm
Hello, world!
```You can also use WASM/WASI runtime (Wasmtime, Wasmer, etc.), too.
#### Missing features
* `goto` statement