Skip to content

Commit b5e012b

Browse files
committed
Write the TransformEnums section and add note about ClangScraper platform differences
1 parent 7c4ddee commit b5e012b

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

docs/for-contributors/Generator/generator-mods.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,12 @@ This is a critical mod used to generate the initial set of raw C# bindings for C
146146
to using `ClangSharpPInvokeGenerator`. The C# source code generated by this mod is typically the starting point for all
147147
of the transformations done by the rest of the SilkTouch mods.
148148

149+
Note that this mod is platform specific and will have different outputs depending on the platform. This is because
150+
`ClangScraper` makes use of system headers. Any platform specific differences in the API for which bindings are being
151+
generated will also affect the output.
152+
153+
(TODO: Document platform specific differences and how they are handled by Silk)
154+
149155
Usage recommendations:
150156

151157
This mod is configured differently from the rest of the mods. The JSON mod configuration follows the same pattern as the
@@ -545,8 +551,28 @@ attributes can also be helpful for this or other purposes.
545551

546552
Mod categories: Transformation
547553

554+
This mod focuses on the transformation of enum types.
555+
548556
Usage recommendations:
549557

558+
This mod can be used to reduce the platform specific differences in the generated bindings. For example, enums use
559+
signed backing types by default on Windows while enums default to unsigned backing types on Unix. This is controlled by
560+
the `CoerceBackingTypes` configuration option.
561+
562+
This mod can also be used to transform `[Flags]` enums in various ways. A `None = 0` member can be added for `[Flags]`
563+
enums that do not have an equivalent. Member values can also be rewritten to use hexadecimal for `[Flags]` enums and
564+
decimal values for normal enums.
565+
566+
Finally, the last feature is that member can be according to a filter. This filter can filter the type name and the
567+
member name by regex. The filter can also filter by member value. One common use case is for removing the "max value"
568+
enum members used by native libraries to ensure that enum backing types are a specific width. For example, in Vulkan,
569+
the value used is `0x7FFFFFFF`, equivalent to the maximum value of a 32-bit signed integer.
570+
571+
Note: Currently, `TransformEnums` requires the `[Flags]` attribute on enum types to be added by another mod.
572+
`TransformEnums` does not yet have the functionality to identify enums on its own. This is a relatively high priority
573+
task. However, also note that identification will be done using a heuristic and may not be perfectly accurate. If other
574+
metadata is available for identifying `[Flags]` enums, consider using that instead for better results.
575+
550576
### TransformFunctions
551577

552578
Mod categories: Transformation

0 commit comments

Comments
 (0)