You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
Raphael Roberts b5d3f222c6 Bumped version 5 years ago
c2logic Added UnaryOp constant folding 4 years ago
examples Update drawing example to at least compile 5 years ago
include Changed index to order 5 years ago
.clang-format initial commit 5 years ago
.clang-tidy initial commit 5 years ago
.flake8 Added template, new instructions, and dev stuff. 5 years ago
.gitignore Added all special_vars 5 years ago
.pylintrc bugfixes 5 years ago
.style.yapf initial commit 5 years ago
LICENSE added installation 5 years ago
MANIFEST.in Added instruction_definition.c to package 5 years ago
README.md Added int constant folding 4 years ago
mypy.ini cleanup 5 years ago
parser.py Record of added instructions in new.masm and parser/templates for 5 years ago
requirements.txt cleanup 5 years ago
setup.py Bumped version 4 years ago
skeleton.j2 Record of added instructions in new.masm and parser/templates for 5 years ago

README.md

c2logic

Compiles C code to Mindustry logic. Still in beta, so compiled output may not be fully optimized. Requirements are the pycparser package and the C preprocessor (cpp).

Installation

pip install git+https://github.com/SuperStormer/c2logic

Documentation

Run the command line tool using:

c2logic filename -O optimization_level

where filename is a string and optimization_level is an optional integer.

Optimization Level:

  1. completely unoptimized.
  2. the default
    • modify variables without using a temporary
  3. more optimizations
    • remove uncalled functions
    • constant folding
  4. turns on some potentially unsafe optimizations
    • augmented assignment and pre/postincrement/decrement don't modify __rax
    • returning from main becomes equivalent to end

Locals are rewritten as _<varname>_<func_name>. Globals are unchanged.

Special Variables:

  • __rax: similar to x86 rax
  • __rbx: stores left hand side of binary ops to avoid clobbering by the right side
  • __retaddr__<func_name>: stores return address of func call

When writing your code, you must include c2logic/builtins.h, which is located in the python include directory (location depends on system, mine is at ~/.local/include/python3.8/). A quick way to find this is python3 -c "from c2logic.compiler import get_include_path; print(get_include_path())" (use python if you are using windows).

See include/builtins.h for API definitions and examples for API sample usage.

Supported Features

  • all Mindustry instructions as of BE 20879 with single data returns (nothing that sets both outx and outy for example)
  • all C control flow structures except switch
  • functions
  • local/global variables

Unsupported Features

  • defining global variables outside of functions - define it in main
  • recursive calls - use iteration
  • structs - split it into multiple variables
  • enums - use an int plus macros
  • block scoped variables - just use locals
  • typedefs - use macros
  • pointers - don't use them
  • switch - use if-else chains