Sarek_ir_codegenShared code-generation helpers used across GPU backends (CUDA, OpenCL, Metal, Vulkan/GLSL). Extracted to avoid duplication of identical variant/struct generation logic.
Mangle an OCaml type name into a valid C/GLSL identifier (e.g. "Module.point" -> "Module_point"). Replaces '.' with '_'.
val gen_variant_def :
type_of_elttype:(Sarek_ir_types.elttype -> string) ->
constructor_prefix:string ->
Stdlib.Buffer.t ->
(string * (string * Sarek_ir_types.elttype list) list) ->
unitEmit a C/MSL tagged-union variant type: an enum of constructor tags, a typedef struct with a tag field and a union of payloads, and one inline constructor function per case.
type_of_elttype maps IR element types to backend C type strings. constructor_prefix is the qualifier emitted before each constructor function (e.g. "__device__ __host__ inline" for CUDA, "static inline" for OpenCL/Metal).
Used by the CUDA, OpenCL, and Metal backends.
val gen_variant_def_glsl :
type_of_elttype:(Sarek_ir_types.elttype -> string) ->
Stdlib.Buffer.t ->
(string * (string * Sarek_ir_types.elttype list) list) ->
unitEmit a GLSL variant type. GLSL has no enum, typedef, or union, so tags are const int declarations, the type is a bare struct, payloads are flat fields, and constructor functions have no qualifier prefix.
type_of_elttype maps IR element types to GLSL type strings.
Used by the Vulkan backend.