-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cbuilder: second half of cgen (#24432)
Follows up #24423, needed more refactoring than I expected, sorry for ugly diff. With this pretty much all of the raw C code generating parts of the codegen are abstracted into the cbuilder API (to my knowledge at least). The current design of NIFC does not implement everything the codegen generates, such things have mostly not been adapted, they are the following along with how I'm guessing they could be implemented: * C++ specific codegen: Maybe a dialect of NIFC for generating C++? * `codegenDecl` pragma: Could be passed as a pragma to NIFC * C macros, currently only used for line info IIRC i.e. `nimln_(123)`: Just inline them when generating NIFC * Other C defines & `#line`: Maybe as NIFC directives or line infos? * There is also [this `#ifndef`](https://github.com/nim-lang/Nim/blob/21420d8b0976dc034feb90ab2878ae0dd63121ae/compiler/cgen.nim#L2249) when generating headers but NIFC shouldn't need it * `alignof`/`offsetof`: Is in `cbuilder` but not implemented in NIFC, should be easy For now we can disable C++ and the `codegenDecl` pragma when generating NIFC but since cbuilder is mostly designed to generate NIFC as a flag when booting the compiler, this hinders the ability to run the CI against NIFC. Maybe we could also make cbuilder able to generate both C and NIFC at runtime, this would be a large refactor but wouldn't be too difficult. Other missing abstractions before being able to generate NIFC are: * Primitive types and symbols i.e. `int`, `void*`, `NI`, `NIM_NULL` are currently still constant string literals, `NU8`, `NU16` etc are also sometimes generated like `"NU" & $bits`. * NIFC identifiers, i.e. adding `.c` to imported symbols and properly mangling generated ones. Not sure how difficult this is going to be.
- Loading branch information
Showing
7 changed files
with
485 additions
and
294 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.