Time0o / cdd-c

Frontend for C, concentrating on: generation from code; single-file analysis; modification; and emission (prettyprinting).

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

c-cdd

License Linux, Windows, macOS

Frontend for C, concentrating on: generation from code; single-file analysis; modification; and emission (to C code).

Use-cases this is designed to support:

  • Generate/update free calling int cleanup_StructName(struct StructName*) functions, e.g.:
    • struct Foo { struct Bar *bar;}; struct Bar { int a; }; will generate:
    • int cleanup_Bar(struct Bar*); &
    • int cleanup_Foo(struct Foo*); (which internally will call cleanup_Bar)
  • With fmt of JSON, INI, YAML, TOML, &etc.:
    • Generate/update parsers from const char* to struct: const int StructName_<fmt>_parse(struct StructName*, const char*) function;
    • Generate/update emitters from struct to char*: const int StructName_<fmt>_emit(const struct StructName*, char*) function;
  • Generate Google Cloud client library for C (with Google Cloud API Discovery Service as input);
  • Generate arbitrary C client libraries (with OpenAPI as input);
  • Generating #pragma for every function to expose them for calling from, e.g., assembly

Design

This C compiler has a very unusual design, the macro and C language are treated as one. The foci are:

  • location start/end of function, struct, and feature macros (e.g., #ifdef JSON_EMIT then #endif /* JSON_EMIT */);
  • struct fields.

…which enable a number of use-cases to be simply developed, e.g., see the list above.

Drawbacks

  • Macros aren't evaluated, which means a simple #define LBRACE { will break cdd-c.
  • Like m4, CMake, and other tools; cdd-c must be run before your code is built.

Development guide

Install: CMake ; C compiler toolchain ; git. Then:

$ git clone "https://github.com/offscale/vcpkg" -b "project0"
# Windows:
$ vcpkg\bootstrap-vcpkg.bat
# Non-Windows:
$ ./vcpkg/bootstrap-vcpkg.sh
# Both Windows and non-Windows:
$ git clone "https://github.com/SamuelMarks/cdd-c" && cd "cdd-c"  # Or your fork of this repo
# Windows
$ cmake -DCMAKE_BUILD_TYPE="Debug" -DCMAKE_TOOLCHAIN_FILE="..\vcpkg\scripts\buildsystems\vcpkg.cmake" -S . -B "build"
# Non-Windows
$ cmake -DCMAKE_BUILD_TYPE='Debug' -DCMAKE_TOOLCHAIN_FILE='../vcpkg/scripts/buildsystems/vcpkg.cmake' -S . -B 'build'
# Both Windows and non-Windows:
$ cmake --build "build"
# Test
$ cd "build" && ctest -C "Debug" --verbose

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

About

Frontend for C, concentrating on: generation from code; single-file analysis; modification; and emission (prettyprinting).

License:Apache License 2.0


Languages

Language:C 67.8%Language:CMake 12.5%Language:C++ 9.7%Language:Yacc 6.9%Language:Lex 3.2%