C compiler for the CLI platform

Related tags

Compilers Cesium
Overview

Cesium Status Enfer

Cesium is a fully managed C compiler for CLI platform (.NET).

What? Cesium compiles standard C source code to a .NET assembly. No unmanaged/mixed mode (a-lá C++/CLI) code is generated; everything is fully managed (but may be unsafe).

Why? C programs are very useful in the modern world, and solve practical tasks. At the same time, deploying C code alongside .NET code may be tricky (especially if your application supports multiple platforms). Cesium is designed to resolve the problems of C code deployment, and lift it to the managed state (so it is cross-platform in the same way the underlying CIL code it is compiled to).

Implementation Status

TL;DR: is it ready for use?

Unfortunately, not yet. You won't be able to use Cesium for anything useful today. Probably, you'll be able to start after the next milestone is implemented. Stay tuned!

Dashboard

Have a question? Welcome to the discussions section!

Looking to contribute? Check open issues with the "help wanted" label. Cesium is a big project which lives thanks to its contributors.

If you're interested in certain project area, check the per-area issue labels:

Sneak peek

Currently, Cesium is able to compile a "Hello, world" C17 example to a .NET assembly:

#include <stdio.h>

int main(int argc, char *argv[])
{
    puts("Hello, world!");
    return 42;
}

The next milestone is #61: sha1collisiondetection, which is 0% complete.

Documentation

Usage

$ dotnet run --project Cesium.Compiler -- <path to the input .c file> <path to the output assembly>

For example, this will generate an assembly executable by .NET 6, .NET Framework, or Mono:

$ dotnet run --project Cesium.Compiler -- Cesium.Samples/minimal.c out.exe
$ dotnet ./out.exe # run with .NET 6
$ ./out.exe # only on Windows, run with .NET Framework
$ mono ./out.exe # run with Mono

Testing

In order to test changes please run following for fast-cycle testing

$ dotnet test

And if you want to run integration tests

$ pwsh -c ./Cesium.IntegrationTests/Run-Tests.ps1 -NoBuild

(don't pass -NoBuild if you want to automatically rebuild the compiler before running the integration tests)

If you debug integration tests and want to run just single test

pwsh -c ./Cesium.IntegrationTests/Run-Tests.ps1 -TestCaseName quoted_include_fallback.c

where quoted_include_fallback.c is path within Cesium.IntegrationTests folder.

Comments
  • (#354) CodeGen: implement the wide architecture set

    (#354) CodeGen: implement the wide architecture set

    Closes #354.

    TODO

    • [ ] present pointers as ~~long~~ CPtr<T> in codegen on Wide architecture
    • [ ] standard library enhancement
      • [x] create a CPtr<T> type
      • [x] add implicit conversions
      • [x] add codegen support
      • [ ] support CPtr interop
    • [ ] integration test
    opened by ForNeVeR 0
  • Struct layout calculation

    Struct layout calculation

    To statically determine struct layout (for 32b, 64b and wide architecture sets), we'll need to calculate struct layout.

    I am planning to make structures have Pack = 4 / 8 and LayoutKind.Explicit for these architectures.

    See the documentation on pack.

    Look for number 355 in the code when implementing this.

    kind:feature status:help-wanted area:compiler good-first-issue 
    opened by ForNeVeR 2
  • Wide architecture support

    Wide architecture support

    In scope of #132, we want to add the wide architecture support, which will use wide pointers (64-bit) everywhere.

    This will require some work in the standard library to properly support those (right now, I am thinking of implementing some generic type over pointers with separate casts from normal and from wide pointers, to not recompile the stdlib for every arch separately).

    When implementing, make sure to eliminate every instance of substring #354 in compiler's code and documentation.

    kind:feature area:cil-interop area:compiler area:stdlib 
    opened by ForNeVeR 1
  • Assembly target architecture support

    Assembly target architecture support

    In scope of #132, we want to introduce proper support of assembly target architectures:

    • 32b architecture set should target x86 and ARM32,
    • 64b architecture set should target x86_64 and ARM64,
    • all the others should still support any CPU (same as before).

    If it's impossible to emit same assembly for x64 and ARM32, or for x86_64 and ARM64, we should divide them further, thus removing the concept of an architecture set and introducing more standard concept of an architecture.

    When implementing, make sure to eliminate every instance of substring #353 in compiler's code and documentation.

    kind:feature status:help-wanted area:cil-interop good-first-issue 
    opened by ForNeVeR 0
  • Verification tests: check that all the gold files are used

    Verification tests: check that all the gold files are used

    Currently, it's easy to create some gold files (*.verified.txt) and leave them be, even if the methods they were created by were renamed or removed.

    We should add some kind of verification step that will check that there are no leftover gold files.

    status:help-wanted good-first-issue area:infrastructure 
    opened by ForNeVeR 0
  • Improve IL verifiability

    Improve IL verifiability

    Currently, ILVerify reports several errors in our programs. Namely, considering array/multidimensional.c integration test:

    $ dotnet tool install --global dotnet-ilverify
    $ pwsh Cesium.IntegrationTests/Run-Tests.ps1 -TestCaseName array/multidimensional.c
    $ cd Cesium.IntegrationTests/bin
    $ ilverify out_cs.exe -r "C:\Program Files\dotnet\shared\Microsoft.NETCore.App\7.0.0\*.dll" -r .\Cesium.Runtime.dll
    [IL]: Error [StackUnexpected]: [W:\Projects\Cesium\Cesium.IntegrationTests\bin\out_cs.exe : .<Module>::.cctor()][offset 0x00000006][found Native Int][expected Int32] Unexpected type on the stack.
    [IL]: Error [Unverifiable]: [W:\Projects\Cesium\Cesium.IntegrationTests\bin\out_cs.exe : .<Module>::main(int32, uint8**)][offset 0x00000006] Instruction cannot be verified.
    [IL]: Error [InitLocals]: [W:\Projects\Cesium\Cesium.IntegrationTests\bin\out_cs.exe : .<Module>::main(int32, uint8**)][offset 0x00000009] initlocals must be set for verifiable methods with one or more local variables.
    [IL]: Error [UnmanagedPointer]: [W:\Projects\Cesium\Cesium.IntegrationTests\bin\out_cs.exe : .<Module>::main(int32, uint8**)][offset 0x00000009] Unmanaged pointers are not a verifiable type.
    [IL]: Error [StackByRef]: [W:\Projects\Cesium\Cesium.IntegrationTests\bin\out_cs.exe : .<Module>::main(int32, uint8**)][offset 0x00000020][found Native Int] Expected ByRef on the stack.
    [IL]: Error [StackUnexpected]: [W:\Projects\Cesium\Cesium.IntegrationTests\bin\out_cs.exe : .<Module>::<SyntheticEntrypoint>(string[])][offset 0x00000002][found Native Int][expected Int32] Unexpected type on the stack.
    [IL]: Error [InitLocals]: [W:\Projects\Cesium\Cesium.IntegrationTests\bin\out_cs.exe : .<Module>::<SyntheticEntrypoint>(string[])][offset 0x0000000A] initlocals must be set for verifiable methods with one or more local variables.
    [IL]: Error [InitLocals]: [W:\Projects\Cesium\Cesium.IntegrationTests\bin\out_cs.exe : .<Module>::<SyntheticEntrypoint>(string[])][offset 0x00000012] initlocals must be set for verifiable methods with one or more local variables.
    [IL]: Error [InitLocals]: [W:\Projects\Cesium\Cesium.IntegrationTests\bin\out_cs.exe : .<Module>::<SyntheticEntrypoint>(string[])][offset 0x00000013] initlocals must be set for verifiable methods with one or more local variables.
    [IL]: Error [InitLocals]: [W:\Projects\Cesium\Cesium.IntegrationTests\bin\out_cs.exe : .<Module>::<SyntheticEntrypoint>(string[])][offset 0x0000001A] initlocals must be set for verifiable methods with one or more local variables.
    [IL]: Error [InitLocals]: [W:\Projects\Cesium\Cesium.IntegrationTests\bin\out_cs.exe : .<Module>::<SyntheticEntrypoint>(string[])][offset 0x0000001B] initlocals must be set for verifiable methods with one or more local variables.
    [IL]: Error [InitLocals]: [W:\Projects\Cesium\Cesium.IntegrationTests\bin\out_cs.exe : .<Module>::<SyntheticEntrypoint>(string[])][offset 0x0000001D] initlocals must be set for verifiable methods with one or more local variables.
    [IL]: Error [StackUnexpected]: [W:\Projects\Cesium\Cesium.IntegrationTests\bin\out_cs.exe : .<Module>::<SyntheticEntrypoint>(string[])][offset 0x00000024][found address of 'uint8*'][expected Native Int] Unexpected type on the stack.
    [IL]: Error [InitLocals]: [W:\Projects\Cesium\Cesium.IntegrationTests\bin\out_cs.exe : .<Module>::<SyntheticEntrypoint>(string[])][offset 0x00000035] initlocals must be set for verifiable methods with one or more local variables.
    [IL]: Error [InitLocals]: [W:\Projects\Cesium\Cesium.IntegrationTests\bin\out_cs.exe : .<Module>::<SyntheticEntrypoint>(string[])][offset 0x0000003C] initlocals must be set for verifiable methods with one or more local variables.
    15 Error(s) Verifying W:\Projects\Cesium\Cesium.IntegrationTests\bin\out_cs.exe
    

    We should investigate whether these issues are acceptable or not.

    They may be reason for the multidimensional.c test failing one time.

    kind:feature status:help-wanted area:compiler 
    opened by ForNeVeR 0
Owner
Friedrich von Never
Engineer, programmer, gentleman.
Friedrich von Never
A Small C Compiler

8cc C Compiler Note: 8cc is no longer an active project. The successor is chibicc. 8cc is a compiler for the C programming language. It's intended to

Rui Ueyama 5.8k Jan 8, 2023
A C compiler for LLVM. Supports C++11/14/1z C11

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies

LLVM 17.5k Jan 8, 2023
GNU Prolog is a native Prolog compiler

GNU Prolog is a native Prolog compiler with constraint solving over finite domains (FD)

Daniel Diaz 64 Dec 13, 2022
Take your first step in writing a compiler.

first-step Take your first step in writing a compiler. Building from Source Before building first-step, please make sure you have installed the follow

PKU Compiler Course 28 Aug 20, 2022
NCC is an ANSI/ISO-compliant optimizing C compiler.

The compiler is retargetable by design, but, at present, it only produces binaries for Linux/x86_64. As the compiler ABI differs somewhat from the System V ABI used by Linux, its code cannot be linked against Linux system libraries. It does, however, provide its own (incomplete) standard ANSI/Posix C library.

Charles E. Youse 0 Apr 1, 2022
nanoc is a tiny subset of C and a tiny compiler that targets 32-bit x86 machines.

nanoc is a tiny subset of C and a tiny compiler that targets 32-bit x86 machines. Tiny? The only types are: int (32-bit signed integer) char (8-

Ajay Tatachar 19 Nov 28, 2022
Smaller C is a simple and small single-pass C compiler

Smaller C is a simple and small single-pass C compiler, currently supporting most of the C language common between C89/ANSI C and C99 (minus some C89 and plus some C99 features).

Alexey Frunze 1.2k Jan 7, 2023
Microvm is a virtual machine and compiler

The aim of this project is to create a stack based language and virtual machine for microcontrollers. A mix of approaches is used. Separate memory is used for program and variable space (Harvard architecture). An interpreter, virtual machine and compiler are available. A demostration of the interpreter in action is presented below.

null 10 Aug 14, 2022
yadcc - Yet Another Distributed C++ Compiler

Yet Another Distributed C++ Compiler. yadcc是一套腾讯广告自研的分布式编译系统,用于支撑腾讯广告的日常开发及流水线。相对于已有的同类解决方案,我们针对实际的工业生产环境做了性能、可靠性、易用性等方面优化。

Tencent 276 Dec 29, 2022
Aheui JIT compiler for PC and web

아희짓 개요 아희짓은 아희 언어를 위한 JIT (Just in Time) 컴파일러입니다. 어셈블러와 유틸 라이브러리외에 외부 라이브러리에 전혀 의존하지 않고 JIT을 바닥부터 구현합니다. 지원 환경 64비트 windows, mac, linux (x86 아키텍쳐) 웹어셈

Sunho Kim 28 Sep 23, 2022
C implementation of the Tiny BASIC compiler found in an article by Dr. Austin Henley

Teeny Tiny Basic A C implementation of the Tiny BASIC compiler found in this article and this github repo by Dr. Austin Henley. I did pretty well in A

Gavin Morris 7 Oct 4, 2022
bcc is an interactive compiler of a language called b.

bcc is an interactive compiler of a language called b.

kparc 18 Nov 7, 2022
This is a compiler written from scratch in C

C Compiler This is a compiler written from scratch in C, with fully supporting C18 as a goal. It can currently compile itself, and most simple program

null 29 Jan 6, 2023
mrcceppc is a reimplementation project for the Metrowerks mwcceppc compiler.

Compiler | mrcceppc mrcceppc is a reimplementation project for the Metrowerks mwcceppc compiler. Compiling Run generate_{version}.bat for which versio

null 9 Nov 21, 2022
A C header that allow users to compile brainfuck programs within a C compiler.

brainfuck.h A C header that allow users to compile brainfuck programs within a C compiler. You can insert the header into the top of your brainfuck so

null 1 Dec 30, 2022
Gilbraltar is a version of the OCaml compiler to be able to build a MirageOS for RaspberryPi 4.

Gilbraltar is a version of the OCaml compiler to be able to build a MirageOS for RaspberryPi 4. It's a work in progress repository to provide a dune's toolchain (as ocaml-freestanding) specialized for Raspberry Pi 4.

Calascibetta Romain 49 Oct 30, 2022
NaiveCC: a compiler frontend for a subset of C

NaiveCC: a compiler frontend for a subset of C This is a toy compiler frontend for a subset of the C programming language based on the LR(1) parsing t

Yuxiang Wei 1 Nov 15, 2021
A LLVM and Clang compiler toolchain built for kernel development

Cosmic-Clang Toolchain This is a LLVM and Clang compiler toolchain built for kernel development. Builds are always made from the latest LLVM sources r

Ǥђ๏ຮ₮⌁Ⲙครtє࿐ 0 Apr 12, 2022
A compiler written in C++ to convert .hoi code to hoi4 code

What is HC4? HC4 is a compiler that converts .hoic filenames to Hearts of Iron IV's .txt. Usage Use hc4 in the terminal (./hc4 if on Unix) and it will

SaCode 1 Jul 31, 2022