A Modern C11 compiler (STILL EARLY)

Overview

Cuik (pronounced 'Quick')

warning: unfinished

The plan is a modern C11 compiler which can mostly work with Clang, GCC, and MSVC while also introducing some new ideas.

Why write a C compiler?

  • To improve the compile times on debug builds without sacrificing features like I would with TCC.
  • To test out my upcoming (and currently private) compiler backend.
  • To add some extensions to improve the workflow of C programmers.
  • Because I can.

How to install?

Mac & Linux aren't ready yet but i'll be moving forward to those platforms in the upcoming months

You'll need MSVC installed on windows (i use link.exe for now... sorry, i'll write a linker soon enough)

Just take a C compiler and compile the compile.c file and run it, if you want an optimized build add RELEASE_BUILD as a preprocessor define with -D or /D. Then you should have a cuik executable in your build/ directory, you can add that directory to your path if you want.

How am I doing?

mostly aight, thanks for asking.

What are some cool new things?

One of my favorite new features are the live compiler (essentially an offline Godbolt but within a terminal) and the out of order declarations.

What architectures will you support?

I'll be starting with x64 but I plan on having Aarch64 support soon enough, it's mostly a matter of user-demand what other platforms I add though I probably won't be supporting anything with a segmented address space because I don't want to implement it.

What OSes will you support?

Ideally the essentials like Windows, Linux and MacOS but currently MacOS isn't setup and Linux has basic support (no live compiler)

Will it have optimizations?

It will eventually have a smart but non-aggressive optimizer but that's still a work in progress

What C extensions will you have?

I'll be supporting all the normal extensions such as:

  • pragma once
  • builtin bitmath (popcount, ffs, clz, ctz, etc)
  • __builtin_trap, __builtin_expect
  • x86 SIMD intrinsics
  • typeof
  • case ranges
  • computed goto

And some possibly novel extensions such as:

What's left?

It can currently compile programs using the subset of C it currently supports but it's still missing some essential details before it compiles any basic C program such as:

  • More tests
  • Bug fixes
  • Self hosting
  • Thread local
  • Atomics (halfway there)
  • MSVC extensions
  • GNU extensions
  • Proper Mac/Linux support

PS

If you're wondering about the tinybackend static library, it's essentially a project of mine that's not ready for everyone's precious eyes so i've been sharing it just enough to actually let people play with the compiler but not play with the backend (it'll be open source eventually).

Comments
  • How to compile successfully on windows

    How to compile successfully on windows

    fatal error: too many errors emitted, stopping now [-ferror-limit=] 20 errors generated. 20 errors generated. 20 errors generated. 20 errors generated. lld-link: error: build\arena.obj: machine type x86 conflicts with x64 lld-link: error: build\atoms.obj: machine type x86 conflicts with x64 lld-link: error: build\big_array.obj: machine type x86 conflicts with x64 lld-link: error: build\crash_handler.obj: machine type x86 conflicts with x64 lld-link: error: build\diagnostic.obj: machine type x86 conflicts with x64 lld-link: error: build\lexer.obj: machine type x86 conflicts with x64 lld-link: error: build\linker.obj: machine type x86 conflicts with x64 lld-link: error: build\microsoft_craziness.obj: machine type x86 conflicts with x64 lld-link: error: build\tblink.obj: machine type x86 conflicts with x64 lld-link: error: build\threads_msvc.obj: machine type x86 conflicts with x64 lld-link: error: build\tls.obj: machine type x86 conflicts with x64 lld-link: error: could not open 'ole32.lib': no such file or directory lld-link: error: could not open 'Advapi32.lib': no such file or directory lld-link: error: could not open 'OleAut32.lib': no such file or directory lld-link: error: could not open 'DbgHelp.lib': no such file or directory lld-link: error: could not open 'libcmt.lib': no such file or directory

    opened by icyfox168168 3
  • Fix some bugs, add small improvements

    Fix some bugs, add small improvements

    Changes:

    1. If the user who is compiling Cuik already has vcvars set, vcvars won't need to be initialized again. Helps with extra error message like "vcvars not found" in case of Visual Studio Developer Prompt that doesn't keep vcvars in it's PATH by default.
    2. If vcvars weren't found in PATH a nice error message is displayed telling the user to either add it to PATH or use the Visual Studio Develeoper Command Prompt.
    3. /Z7 doesn't emit an extra pdb (that's not essential for normal debugging) also fuck visual studio
    4. Fixed a case of UB on calling strcmp with NULL argument that would trigger a crash on Windows if the argument to an option is not specified.
    opened by flysand7 1
  • Simple Fix to Allow Compilation On MSVC

    Simple Fix to Allow Compilation On MSVC

    When compiling with MSVC, cc_command doesn't isn't declared. This PR adds a declaration with a default value of 0. This function isn't called when compiling with MSVC, but it still blocks compiling compile.c

    image

    opened by Ne0nWinds 1
  • Nested macros expansion bug

    Nested macros expansion bug

    Test case:

    struct Expr typedef Expr;
    struct Expr {
        Expr *car;
        Expr *cdr;
    };
    
    #define      car(expr) expr->car
    #define      cdr(expr) expr->cdr
    
    void x(Expr *args)
    {
        car(cdr(cdr(args)));
    }
    

    MSVC and Cland expand macro, as expected, to expr->cdr->cdr->car. Cuik however prints the following error message:

    $ cuik build code\test.c
    error: code\test.c:13:0: could not resolve symbol: cdr
        13| cdr(args) -> cdr
          | ^~~
    exited with 1 error
    
    opened by flysand7 0
  • Could not parse expression

    Could not parse expression "_Pragma ..."

    When I try to compile my project with cuik I get an error on the following line:

        return make_bool(isinf(f1));
    

    Note the isinf function, which is a standard library function. The error says:

    error: C:/programs/blisp/code/wrap.c:261:0: Could not parse expression!
       261| _Pragma ( "warning ( suppress : 6334 )" )
          | ^~~~~~~
    
    opened by flysand7 0
  • Unkown command

    Unkown command "help"

    The help message for cuik lists "help" as one of the valid commands, however when I try to run cuik it says "help" is an unkown command ("I have never seen this man before")

    $ cuik help
    Unknown command: help
    

    As a side not i'd like for a way to look up information about various flags and options available in the compiler

    opened by flysand7 0
Owner
Yasser Arguelles
Human
Yasser Arguelles
This project contains information on the PC-Link hardware interface for some early 2000 Sony HiFi decks

pclink-i2c This project contains information on the PC-Link hardware interface for some early 2000 Sony HiFi decks, such as the CMT-DC500MD (also know

Sir68k 1 Jan 21, 2022
Collection of cross-platform single-header C libraries for doing a lot of stuff! (Still WIP)

ice_libs Collection of cross-platform single-header C libraries for doing a lot of stuff! (Still WIP) Brief ice_libs is collection of Single-Header C

Rabia Alhaffar 115 Sep 27, 2022
CVE-2021-24084 Windows Local Privilege Escalation Left officially unpatched since 2020. Hence, its still a zero day

WindowsMDM-LPE-0Day Works best on Windows 11 CVE-2021-24084 Windows Local Privilege Escalation Left officially unpatched since 2020. Hence, its still

Exploit Blizzard 36 Aug 31, 2022
Orca - Advanced Malware with multifeatures written in ASM/C/C++ , work on all windows versions ! (some features still under developing and not stable)

About Orca Orca is an Advanced Malware with multifeatures written in ASM/C/C++ features Run in Background (Hidden Mode) Records keystrokes and saves t

anas 176 Oct 4, 2022
Faster neofetch alternative, written in C. Still improving :)

albafetch ~by alba4k albafetch is a simple, fast system fetching program. It prints many info about the system in way less than a second. I decided to

alba4k 16 Aug 25, 2022
CHIP-8 interpreter in C11

shoganai | しょうがない It means accepting what happens beyond our control and cannot be avoided. It is used to encourage people to move forward without bei

Gioele 2 Sep 28, 2021
Single-header C11 port of abseil.io's Swiss Table

cwisstable.h cwisstable is a single-header C11 port of the Abseil project's Swiss Tables. This project is intended to bring the proven performance and

Google 25 Sep 12, 2022
Macro magic for declaring/calling Objective-C APIs from C11 or C++. Preloads selectors, chooses the correct objc_msgSend to call per method/platform.

OC - Easily Declare/Invoke Objective-C APIs from C11 or C++11 Usage // Call class and instance methods: NSWindow* const nswindow = oc_cls(NSWindow,new

Garett Bass 45 Sep 9, 2022
Compiler Optimizations Playground

This is (hopefully) the simplest implementation of the classic register-machine intermediate representation (IR) to undertake data and control flow analysis in a compiler middle-end.

null 27 May 31, 2022
PL/0 Compiler Extension(including repeat, for, case, function, real, record and so on)

EX-PL0 PL/0 Compiler Extension(including repeat, for, case, function, real, record and so on) Structure src/PL source code of PL compiler; src/interpr

Chunshuo Qiu 16 Jul 21, 2022
A simple assembler, made primarily for assembling output from my compiler.

Assembler This assembler is not currently meant for general use. It supports only the instructions and features emitted (and used) in my C compiler. I

null 2 Nov 14, 2021
Pure Data patch export to lv2 plugin using heavy compiler + dpf example

Pure Data patch export to lv2 plugin using heavy compiler + dpf example Work in progress - Takes an audio input and writes to a 0.5 seconds buffers. 4

Qwrtst 2 Jun 13, 2022
Set of examples how to use CLion with various unsupported compilers using Custom Defined Compiler feature

About This repository contains: Set of examples how to use CLion with various unsupported compilers using Custom Defined Compiler feature Public set o

JetBrains 37 Sep 30, 2022
A PL/I compiler for Windows NT

PLI-2000 A PL/I compiler for Windows NT This project began as an academic exercise while learning the 'C' language during the summer of 1990, I wanted

null 6 Jun 10, 2022
Practical assignments for the XDU compiler course: The interpreter of function drawing language.

drawing-lang-interpreter Practical assignments for the XDU compiler course: The toy interpreter of function drawing language, written by XDU Zhang Yi(

null 4 Sep 30, 2022
The C source code was RESTORED by disassembling the original executable file OPTIM.COM from the Hi-Tech v3.09 compiler.

The C source code was RESTORED by disassembling the original executable file OPTIM.COM from the Hi-Tech v3.09 compiler. This file is compiled by Hi-Te

null 9 May 23, 2022
A skeleton C compiler in C++

cppc C compiler in C++ Background This is a learning project for Crafting interpreters. Most part of C is supported. Support for pointer is hacky. For

Yujia Qiao 8 Jul 23, 2022
Skyline's fork of yuzu's shader compiler

Skyline Shader Compiler (SSC) A fork of yuzu's shader compiler modified for Skyline's needs with all other changes being upstreamed and changes from y

Skyline 15 Aug 30, 2022