{"id":15398495,"url":"https://github.com/zero9178/cld","last_synced_at":"2025-04-15T22:31:08.340Z","repository":{"id":188026281,"uuid":"171492773","full_name":"zero9178/cld","owner":"zero9178","description":"A C99 compliant compiler","archived":false,"fork":false,"pushed_at":"2021-05-09T21:01:15.000Z","size":5099,"stargazers_count":18,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-29T03:42:00.619Z","etag":null,"topics":["c","c-plus-plus-17","c99","llvm"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zero9178.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2019-02-19T14:54:58.000Z","updated_at":"2025-02-19T01:16:39.000Z","dependencies_parsed_at":"2023-08-13T11:26:03.318Z","dependency_job_id":null,"html_url":"https://github.com/zero9178/cld","commit_stats":null,"previous_names":["zero9178/cld"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zero9178%2Fcld","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zero9178%2Fcld/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zero9178%2Fcld/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zero9178%2Fcld/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zero9178","download_url":"https://codeload.github.com/zero9178/cld/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249165984,"owners_count":21223360,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","c-plus-plus-17","c99","llvm"],"created_at":"2024-10-01T15:44:18.297Z","updated_at":"2025-04-15T22:31:06.956Z","avatar_url":"https://github.com/zero9178.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cld - A C99 Compiler\n\ncld is a fully C99 compliant (minus bugs) Compiler written in C++. The frontend was written from scratch and LLVM is\ncurrently used as a backend for code generation. The command line interface is designed to match the one of GCC but is\ncurrently still under work.\n\nCurrently supported targets for code generation are x64 on Windows and Linux (although ABI wise other x64 Operating\nSystems should work).\n\nThe compilers source code is designed to be usable as a library. Each phase of the compiler is cleanly separated from\neach other but builds on top of the previous phase.\n\nAs an example, checking if C source code is valid and emit errors to stderr is simply:\n\n```cpp\nauto options = cld::LanguageOptions::native();\nbool errors = false;\nauto pptokens = cld::Lexer::tokenize(std::move(input),\u0026options,\u0026llvm::errs(),\u0026errors);\nif (errors)\n{\n    return -1;    \n}\npptokens = cld::PP::preprocess(std::move(pptokens),\u0026llvm::errs(),\u0026errors);\nif (errors)\n{\n    return -1;\n}\nauto ctokens = cld::Lexer::toCTokens(pptokens,\u0026llvm::errs(),\u0026errors);\nif (errors)\n{\n    return -1;\n}\nauto tree = cld::Parser::buildTree(ctokens,\u0026llvm::errs(),\u0026errors);\nif (errors)\n{\n    return -1;\n}\ncld::Semantics::analyse(tree,std::move(ctokens),\u0026llvm::errs(),\u0026errors);\n```\n\nCompiling C source code can be done just like with GCC:\n`cld -c test.c` which will then produce a `test.o` object file.\n\nProjects that have already successfully been compiled include zlib and sqlite3 using both glibc and MinGW as libc.\n\n## WIP\n\nThings that are currently still Work in Progress are:\n\n* More commandline compatibility with GCC\n* Ability to link\n* Find sysroots for the target similar to clang\n* Improve kind of broken preprocessor tokens to text conversion\n* Implement more and more GCC Extensions and builtins\n* Generating complete debug info\n\n## Building\n\nTo build cld and it's libraries do enter following commands from the project root:\n\n```shell\nmkdir build\ncd build\ncmake .. -G\u003cGENERATOR\u003e -DCMAKE_INSTALL_PREFIX=\u003cDIRECTORY\u003e\n```\n\nwith the generators, install directory, C++ compilers and more of your choice.\n\nThen use the install target with the generator of your choice (`make install`,`ninja install`,etc...).\n\nAdditional options are:\n\n* `CLD_BUILD_TESTS` (default ON): Also build tests and enable the `test` target\n* `CLD_FUZZER` (default OFF): Enable fuzzer instrumentation and also build fuzzers\n* `CLD_ENABLE_ASSERTS` (default OFF): Enable asserts in release mode as well (always active in debug mode)\n* `CLD_USE_EXCEPTIONS` (default ON): Compile with exceptions\n* `CLD_COVERAGE` (default OFF): Compile with Coverage\n* `CLD_DEFAULT_TARGET` (default empty): String of the default target\n\nAdditionally cld currently unconditionally depends on LLVM 12. If your LLVM installation is not in a default location\nfor cmake to find you might need to append the path to CMAKE_PREFIX_PATH.\n\nSupported Compilers are newer versions of Clang, GCC and MSVC. The compiler needs C++17 supports and good constexpr\nsupport. The source code was tested and written using Clang 9 to 11, GCC 9 to 11 and MSVC 19.24 to 19.27 on Windows and\nLinux. It should theoretically also compile on Mac OS\n\n## Using cld with your own projects\n\nSimply add the following to your CMakeLists.txt:\n\n```cmake\nfind_package(Threads::Threads REQUIRED)\nfind_package(LLVM REQUIRED 12)\nfind_package(cld REQUIRED)\n```\n\nMake sure to use and append to CMAKE_PREFIX_PATH the same LLVM installation you used when building cld. You may list\nmultiple paths to CMAKE_PREFIX_PATH by separating them with `;`.\n\nFollowing CMake targets are then available and must simply be linked against. The targets are:\n\n* `cld::Frontend`. This includes all code related to the compiler frontend. All headers within cld/Frontend/* may be\n  used without linking issues\n* `cld::LLVMBackend`, has a dependency on `cld::Frontend`. This includes the LLVMBackend and allows LLVM IR to be\n  generated from the Frontends AST. All headers within cld/LLVMBackend may be used without linker errors\n* `cld::cldMain`, has a dependency on `cld::LLVMBackend`. This includes the main program used by the compiler. Linking\n  against this target allows the usage of all headers in cld/cldmain.\n\nAdditionally all of the above targets depend on `cld::Support`, allowing all headers in cld/Support to be used.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzero9178%2Fcld","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzero9178%2Fcld","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzero9178%2Fcld/lists"}