Giter Site home page Giter Site logo

c-chads / tinycc Goto Github PK

View Code? Open in Web Editor NEW
77.0 7.0 8.0 5.69 MB

C-Chads Maintained fork of Tiny C Compiler, regularly pulled from https://repo.or.cz/w/tinycc.git

License: GNU Lesser General Public License v2.1

Makefile 0.98% C 96.75% C++ 0.53% Assembly 1.02% Shell 0.29% Perl 0.29% Batchfile 0.15%
tinycc fabrice-bellard tcc-compiler tcc

tinycc's Introduction

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.


2) 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.

3) 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'.

4) 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.

tinycc's People

Contributors

akimd avatar avih avatar c-jullien avatar cosmo-ray avatar daym avatar egrimley avatar ghostmansd avatar hermantb avatar jsoroka avatar ldoolitt avatar mgttt avatar mingodad avatar minux avatar navytux avatar pipcet avatar pskocik avatar robotux avatar s09bq5 avatar sdaoden avatar seyko2 avatar shinh avatar susematz avatar tylov avatar vinc17fr avatar waddlesplash avatar winspool avatar wqweto avatar xppxppgh avatar zde avatar ziyao233 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

tinycc's Issues

Linking static libraries

Hello,
I've been trying our your fork and I'm trying to link with a static library but TCC is saying that the symbols aren't found. I'm having this issue both with the tcc executable and when using libtcc.h and tcc_add_file, any ideas on how I can get this to work?

VFS support

We need it so that we can build TCC to make it run on WASM, or make it possible so that we can run TCC on Compiler Explorer.

I personally uses libtcc mainly for experimental headers and libraries embedding, so I can just compile libtcc.c and leverage the ONE_SOURCE feature. And then I instruct the C compiler to override the necessary functions.

    if cfg!(feature = "vfs") {
        cc.define("open", "vfs_open");
        cc.define("read", "vfs_read");
        cc.define("lseek", "vfs_lseek");
        cc.define("close", "vfs_close");
    }

And then I implemented a tiny VFS wrapper:

extern "C" {
    fn open(path: *const c_char, oflag: c_int, ap: VaList) -> c_int;
}


#[no_mangle]
pub unsafe extern "C" fn vfs_open(path: *const c_char, oflag: c_int, mut args: ...) -> c_int {
    fn insert_vfs(vfs: Box<impl VFS + Send + Sync + Clone + 'static>) -> c_int {
        loop {
            let vfs = vfs.clone();
            let key: c_int = unsafe { RNG.gen_range(0..c_int::MAX) };
            if let Ok(_) = unsafe { FILES.try_insert(key, vfs) } {
                return key;
            }
        }
    }

    if let Ok(path) = CStr::from_ptr(path).to_str() {
        let prefix = "memory:///headers/";

        if path.starts_with(prefix) {
            let path = path.strip_prefix(prefix).unwrap();

            if let Some(file) = crate::headers::ASSET_MAP.get(path) {
                return insert_vfs(Box::new(MemoryVFS::from_static(file.contents_bytes)));
            }
        }

        let prefix = "memory:///libraries/";

        if path.starts_with(prefix) {
            let path = path.strip_prefix(prefix).unwrap();
            if let Some(file) = crate::LIBRARIES.get_file(path) {
                return insert_vfs(Box::new(MemoryVFS::from_static(file.contents())));
            }
        }
    }

    let fd = open(path, oflag, args.as_va_list());
    if fd >= 0 {
        insert_vfs(Box::new(PosixVFS::new(fd)))
    } else {
        fd
    }
}

This one worked out pretty well, but I think this is very hacky, and there is a lack of write support. Specifically, if we want to run this on Godbolt, we need to capture the output executable, but the current implementation of TCC writes directly to a file descriptor. Instead, we should have a dynamic stream API that supports byte stream or file stream.

Windows build issues

so running the build-tcc.bat under win32 produces the below error, but still builds and the version is still 0.9.27 (tcc -v).

Changelog says it should be 0.9.28?

fatal: Not a git repository (or any of the parent directories): .git
fatal: Not a git repository (or any of the parent directories): .git
Not a git repository
To compare two paths outside a working tree:
usage: git diff [--no-index] <path> <path>

C:\tcc\tinycc-mob\win32>echo #define TCC_VERSION "0.9.27" 1>..\config.h

C:\tcc\tinycc-mob\win32>echo #ifdef TCC_TARGET_X86_64 1>>..\config.h

C:\tcc\tinycc-mob\win32>echo #define TCC_LIBTCC1 "libtcc1-64.a" 1>>..\config.h

C:\tcc\tinycc-mob\win32>echo #else 1>>..\config.h

C:\tcc\tinycc-mob\win32>echo #define TCC_LIBTCC1 "libtcc1-32.a" 1>>..\config.h

C:\tcc\tinycc-mob\win32>echo #endif 1>>..\config.h

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.