Code Monkey home page Code Monkey logo

c2v's Introduction

C2V

C => V source code translator.

Demo Video: Translating DOOM from C to V, building and running it.

https://www.youtube.com/watch?v=6oXrz3oRoEg

Building

v .

... or if you want to debug c2v behaviour:

v -d trace_verbose .

No dependencies other than a clang binary.

Usage

c2v accepts the following arguments:

-keep_ast           keep ast files
-print_tree         print the entire tree
c2v file.c

This will generate file.v.

c2v project

This will translate each C file in the project directory.

project/   ==>  project/
  a.c              a.c
  foo.c            a.v
                   foo.c
		   foo.v

You may need to run translated code with v -translated file.v until early 2023.

Wrapper generation

C2V can also generate V wrappers on top of C libraries.

c2v wrapper file.c

Notes

C2V is using Clang's AST to generate V. This allowed us to avoid writing a C parser.

In order to avoid LLVM dependencies/C++ complexity, C2V parses AST generated by the clang binary.

Configuration

C2V supports reading from a project configuration file named c2v.toml, located in one of these places, in this order:

  1. if C2V_CONFIG is set, it should contain the c2v.toml path.
  2. the project folder (the last folder passed to c2v) + /c2v.toml
  3. the project folder (the folder of the file that is last passed to c2v) + /c2v.toml

That file has the following format:

[project]
uses_sdl = true
output_dirname = "c2v_out.dir"
additional_flags = "-I. -I.. -I../.."

["info.c"]
additional_flags = "-I/some/folder/used/only/for/that/specific/file"

In the above: uses_sdl is a boolean, that defaults to false. When it is true, c2v will append the result of sdl2-config --cflags to additional_flags . output_dirname is a string, that defaults to c2v_output. c2v will create that folder, if it does not exist, and it will put all the translated .v files there. additional_flags is a string, that will be passed verbatim to the clang parser for each .c file. It can be used to pass additional -I flags, that are specific to your project, so that clang can find all the headers needed by that project.

Note: all these are global to the project.

The c2v.toml configuration file also supports file specific overrides, for the additional_flags option, just put them in their own sections, titled as the file name.

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.