Convert Figma logo to code with AI

TinyCC logotinycc

Unofficial mirror of mob development branch

1,947
363
1,947
15

Top Related Projects

6,127

A Small C Compiler

9,633

C in four functions

1,728

Online OR1K Emulator running Linux

Quick Overview

TinyCC (Tiny C Compiler) is a small, fast, and efficient C compiler. It aims to be simple, small, and fast while still supporting most of ANSI C99 and many GNU C extensions. TinyCC can be used as a backend for JIT libraries or to compile and run C code directly.

Pros

  • Extremely fast compilation speed
  • Small size (about 100KB for x86 TinyCC executable)
  • Supports most of C99 and many GNU C extensions
  • Can be used for generating code at runtime (JIT compilation)

Cons

  • Limited optimization capabilities compared to more advanced compilers
  • Not as widely used or tested as GCC or Clang
  • May not support some advanced C11 or C17 features
  • Documentation could be more comprehensive

Code Examples

  1. Basic compilation and execution:
#include <stdio.h>

int main() {
    printf("Hello, TinyCC!\n");
    return 0;
}

Save this as hello.c and compile/run with: tcc -run hello.c

  1. Using TinyCC as a JIT compiler:
#include <stdio.h>
#include <libtcc.h>

int main() {
    TCCState *s;
    int (*func)(int);

    s = tcc_new();
    tcc_set_output_type(s, TCC_OUTPUT_MEMORY);

    tcc_compile_string(s, "int add(int a, int b) { return a + b; }");
    
    func = tcc_get_symbol(s, "add");
    printf("Result: %d\n", func(2, 3));

    tcc_delete(s);
    return 0;
}

This example demonstrates using TinyCC as a JIT compiler to compile and execute C code at runtime.

  1. Compiling with custom include paths and libraries:
#include <tcclib.h>

int main(int argc, char **argv) {
    TCCState *s;
    
    s = tcc_new();
    tcc_set_output_type(s, TCC_OUTPUT_EXE);
    tcc_add_include_path(s, "/custom/include/path");
    tcc_add_library_path(s, "/custom/lib/path");
    tcc_add_library(s, "customlib");
    
    if (tcc_compile_file(s, "myprogram.c") == -1)
        return 1;
    
    tcc_output_file(s, "myprogram");
    tcc_delete(s);
    return 0;
}

This example shows how to use TinyCC to compile a file with custom include paths and libraries.

Getting Started

  1. Clone the repository:

    git clone https://github.com/TinyCC/tinycc.git
    cd tinycc
    
  2. Configure and build:

    ./configure
    make
    
  3. Install (optional):

    sudo make install
    
  4. Use TinyCC to compile and run a C file:

    ./tcc -run example.c
    

Competitor Comparisons

6,127

A Small C Compiler

Pros of 8cc

  • Designed as a learning tool, with clear and well-commented code
  • Implements a full C11 compiler in a single file
  • Includes a comprehensive test suite for self-hosting

Cons of 8cc

  • Less mature and feature-complete compared to TinyCC
  • Limited platform support (primarily targets x86-64)
  • Not actively maintained (last commit in 2016)

Code Comparison

TinyCC:

static void gen_opf(TCCState *s1, int op)
{
    int r;
    SValue sv;
    GFuncContext gf;
    int func_call = op & FUNC_CALL;
    int invert = op & INVERT;
    op &= ~(FUNC_CALL | INVERT);

8cc:

static void emit_binop(Node *node) {
    if (node->ty->kind == KIND_PTR) {
        emit_pointer_arith(node);
        return;
    }
    emit_expr(node->left);
    push("rax");
    emit_expr(node->right);

Both projects aim to provide compact C compilers, but TinyCC is more feature-rich and actively maintained, while 8cc focuses on simplicity and educational value. TinyCC offers broader platform support and is suitable for production use, whereas 8cc is primarily a learning tool for compiler construction.

9,633

C in four functions

Pros of c4

  • Extremely compact codebase (less than 1000 lines)
  • Designed for educational purposes, making it easier to understand compiler internals
  • Implements a self-hosting C compiler, demonstrating the concept of bootstrapping

Cons of c4

  • Limited feature set compared to tinycc
  • Less actively maintained and developed
  • Not suitable for production use or compiling complex C programs

Code Comparison

c4:

int *e, *le, *text, *stack;
char *p, *lp, *data;
int *id, *sym, tk, val, ty, poolsz, *idmain;

tinycc:

struct TCCState {
    int output_type;
    int char_is_unsigned;
    int leading_underscore;
    int ms_extensions;
    int dollars_in_identifiers;
    int gnu_extensions;

Summary

c4 is a minimalist C compiler designed for educational purposes, offering a compact codebase that's easy to understand. However, it lacks the features and active development of tinycc. tinycc, on the other hand, provides a more comprehensive C compiler with broader language support and ongoing maintenance, making it more suitable for practical use cases beyond educational purposes.

1,728

Online OR1K Emulator running Linux

Pros of jor1k

  • Provides a complete emulation of an OpenRISC 1000 architecture system, allowing for a full Linux environment in the browser
  • Includes a graphical terminal and filesystem support, offering a more interactive user experience
  • Supports networking and audio capabilities, enabling a wider range of applications

Cons of jor1k

  • More complex and resource-intensive due to its full system emulation approach
  • Less suitable for lightweight or embedded use cases where a minimal compiler is needed
  • May have a steeper learning curve for users unfamiliar with system emulation concepts

Code Comparison

While a direct code comparison is not particularly relevant due to the different nature of these projects, we can highlight some key differences in their implementation:

tinycc:

static void parse_btype(CType *type, AttributeDef *ad)
{
    int t, u, type_found;
    Sym *s;
    CType type1;

jor1k:

jor1kgui.prototype.Start = function() {
    this.Stop(true);
    this.term.Init(this.jor1kbasename, this.termid);
    this.worker = new Worker(this.jor1kbasename + "/js/worker/worker.js");

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Tiny C Compiler - C Scripting Everywhere - The Smallest ANSI C compiler

Features:

  • SMALL! You can compile and execute C code everywhere, for example on rescue disks.

  • FAST! tcc generates optimized x86 code. No byte code overhead. Compile, assemble and link about 7 times faster than 'gcc -O0'.

  • UNLIMITED! Any C dynamic library can be used directly. TCC is heading toward full ISOC99 compliance. TCC can of course compile itself.

  • SAFE! tcc includes an optional memory and bound checker. Bound checked code can be mixed freely with standard code.

  • Compile and execute C source directly. No linking or assembly necessary. Full C preprocessor included.

  • C script supported : just add '#!/usr/local/bin/tcc -run' at the first line of your C source, and execute it directly from the command line.

Documentation:

  1. Installation on a i386/x86_64/arm/aarch64/riscv64 Linux/macOS/FreeBSD/NetBSD/OpenBSD hosts.

    ./configure make make test make install

    Notes: For FreeBSD, NetBSD and OpenBSD, gmake should be used instead of make. For Windows read tcc-win32.txt.

makeinfo must be installed to compile the doc. By default, tcc is installed in /usr/local/bin. ./configure --help shows configuration options.

  1. Introduction

We assume here that you know ANSI C. Look at the example ex1.c to know what the programs look like.

The include file <tcclib.h> can be used if you want a small basic libc include support (especially useful for floppy disks). Of course, you can also use standard headers, although they are slower to compile.

You can begin your C script with '#!/usr/local/bin/tcc -run' on the first line and set its execute bits (chmod a+x your_script). Then, you can launch the C code as a shell or perl script :-) The command line arguments are put in 'argc' and 'argv' of the main functions, as in ANSI C.

  1. Examples

ex1.c: simplest example (hello world). Can also be launched directly as a script: './ex1.c'.

ex2.c: more complicated example: find a number with the four operations given a list of numbers (benchmark).

ex3.c: compute fibonacci numbers (benchmark).

ex4.c: more complicated: X11 program. Very complicated test in fact because standard headers are being used ! As for ex1.c, can also be launched directly as a script: './ex4.c'.

ex5.c: 'hello world' with standard glibc headers.

tcc.c: TCC can of course compile itself. Used to check the code generator.

tcctest.c: auto test for TCC which tests many subtle possible bugs. Used when doing 'make test'.

  1. Full Documentation

Please read tcc-doc.html to have all the features of TCC.

Additional information is available for the Windows port in tcc-win32.txt.

License:

TCC is distributed under the GNU Lesser General Public License (see COPYING file).

Fabrice Bellard.