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.

53 lines
1.8 KiB

5 years ago
  1. # c2logic
  2. 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`).
  3. # Installation
  4. `pip install git+https://github.com/SuperStormer/c2logic`
  5. # Documentation
  6. Run the command line tool using:
  7. `c2logic filename -O optimization_level`
  8. where `filename` is a string and `optimization_level` is an optional integer.
  9. Optimization Level:
  10. 0. completely unoptimized.
  11. 1. the default
  12. - modify variables without using a temporary
  13. 2. turns on some potentially unsafe optimizations
  14. - augmented assignment and pre/postincrement/decrement don't modify `__rax`
  15. - returning from main becomes equivalent to `end`
  16. Locals are rewritten as `_<varname>_<func_name>`. Globals are unchanged.
  17. Special Variables:
  18. - `__rax`: similar to x86 rax
  19. - `__rbx`: stores left hand side of binary ops to avoid clobbering by the right side
  20. - `__retaddr__<func_name>`: stores return address of func call
  21. 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/`).
  22. 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).
  23. See [include/builtins.h](./include/builtins.h) for API definitions and [examples](./examples) for API sample usage.
  24. # Supported Features
  25. - all Mindustry instructions as of BE
  26. - all control flow structures except goto
  27. - functions
  28. - local/global variables
  29. # Unsupported Features
  30. - structs - split it into multiple variables
  31. - enums - use an int plus macros
  32. - block scoped variables - just use locals
  33. - typedefs - use macros
  34. - pointers - don't use them
  35. - goto - don't use it