Coder Social home page Coder Social logo

cxgo's Introduction

C to Go translator

GitHub license Gitter GoDoc

CxGo is a tool for translating C source code to Go (aka transpiler, source-to-source compiler).

It uses cc for preprocessing and parsing C (no clang/gcc dependencies!) and a custom type-checker and AST translation layer to make the best output possible.

The only requirement is: C code must compile with cxgo, including headers.

Having said that, cxgo uses a few tricks to make this process easier.

TL;DR for the project goals:

  1. Implement a practical C to Go translator (no C++ for now).
  2. Keep the output program code correct.
  3. Make the generated code human-readable and as idiomatic as possible.
  4. Make it easy to use and customize.

Check the FAQ for more common question about the project.

Status

The project is experimental! Do not rely on it in production and other sensitive environments!

Although it was successfully tested on multiple projects, it might change the behavior of the code due to yet unknown bugs.

Compiler test results:

  • TCC: 62/89 (70%)
  • GCC: 783/1236 (63%)

Transpiled projects:

Installation

go get -u github.com/gotranspile/cxgo/cmd/cxgo

or download the latest release from Github.

How to use

The fastest way to try it is:

cxgo file main.c

For more details, check our examples section.

It will guide you through basic usage patterns as well as a more advanced ones (on real-world projects).

You may also check FAQ if you have any issues.

Caveats

The following C features are currently accepted by cxgo, but may be implemented partially or not implemented at all:

  • preserving comments from C code (#2)
  • static (#4)
  • auto (#5)
  • bitfields (#6)
  • union with C-identical data layout (#7)
  • packed structs (#8)
  • asm
  • case in weird places (#9)
  • goto forbidden by Go (there is a workaround, though, see #10)
  • label variables (#11)
  • thread local storage (#12)
  • setjmp (will compile, but panics at runtime)
  • some stdlib functions and types are missing (good first issue!)
  • deep type inference (when converting to Go string/slices)
  • considering multiple #ifdef paths for different OS/envs

Community

Join our community! We'd like to hear back from you!

Contributing

See CONTRIBUTING.

License

MIT

cxgo's People

Contributors

dennwc avatar totallygamerjet avatar g41797 avatar chenrui333 avatar nemith avatar redbow-kimee avatar koteyur avatar

Stargazers

Prof Syd Xu avatar

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.