Sarek_codegen.Sarek_ir_wgslmodule Codegen_error : sig ... endLocal error module — tagged as "WebGPU" in error messages.
val current_variants :
(string * (string * Sarek_ir_types.elttype list) list) list Stdlib.refCurrent kernel's variant definitions (set during generate)
Current framework name — mirrors the other generators so set_framework in Sarek_transpile can set it, and the pure registry resolves Float32 math with framework="WGSL" (falls through to the generic sin spelling).
val wgsl_type_of_elttype : Sarek_ir_types.elttype -> stringMap Sarek IR element type to WGSL type string. Float64 (f64) is not supported in WebGPU — callers must check for TFloat64 before reaching this function and raise Codegen_error.unsupported_construct.
val has_float64 : Sarek_ir_types.elttype -> boolCheck whether an elttype (recursively) uses Float64.
Thread Intrinsics
WGSL uses three distinct builtins:
local_invocation_id (sarek_lid) — thread within workgroupworkgroup_id (sarek_wid) — workgroup index in the dispatch gridglobal_invocation_id (sarek_gid) — globally unique thread indexAll are vec3<u32>; we cast to i32 to match the IR's i32 type for thread ids. The entry point declares all three builtins; unused ones are harmless (WGSL permits unused builtin params).
Names of scalar kernel params — accessed as params.<name> in WGSL.
val gen_expr : Stdlib.Buffer.t -> Sarek_ir_types.expr -> unitval gen_binop : Sarek_ir_types.binop -> stringval gen_unop : Sarek_ir_types.unop -> stringval gen_intrinsic :
Stdlib.Buffer.t ->
string list ->
string ->
Sarek_ir_types.expr list ->
unitval gen_lvalue : Stdlib.Buffer.t -> Sarek_ir_types.lvalue -> unitval gen_match_pattern :
Stdlib.Buffer.t ->
string ->
string ->
string ->
string list ->
(string -> Sarek_ir_types.elttype list option) ->
unitval gen_var_decl :
Stdlib.Buffer.t ->
string ->
mutable_:bool ->
string ->
Sarek_ir_types.elttype ->
Sarek_ir_types.expr ->
unitval gen_stmt : Stdlib.Buffer.t -> string -> Sarek_ir_types.stmt -> unitval gen_helper_func : Stdlib.Buffer.t -> Sarek_ir_types.helper_func -> unitval gen_record_def :
Stdlib.Buffer.t ->
(string * (string * Sarek_ir_types.elttype) list) ->
unitval gen_variant_def :
Stdlib.Buffer.t ->
(string * (string * Sarek_ir_types.elttype list) list) ->
unitEmit a WGSL variant type. WGSL has no enums or unions. We emit:
const <CNAME> : i32 = N; for each constructor tagtag : i32 and flat payload fieldsfn make_<Type>_<Constr>(...) -> <Type> constructorsval collect_workgroup_decls :
Sarek_ir_types.stmt ->
(string * Sarek_ir_types.elttype * Sarek_ir_types.expr) listCollect workgroup shared array declarations from a statement tree.
val gen_workgroup_module_decls :
Stdlib.Buffer.t ->
(string * Sarek_ir_types.elttype * Sarek_ir_types.expr) list ->
unitval split_params :
Sarek_ir_types.decl list ->
Sarek_ir_types.var list * Sarek_ir_types.var listSeparate kernel params into vectors (storage buffers) and scalars (uniform).
val gen_bindings : Stdlib.Buffer.t -> Sarek_ir_types.decl list -> string listEmit storage buffer bindings and the Params uniform struct. Returns the list of scalar param names (for scalar_param_names ref).
val params_have_float64 : Sarek_ir_types.decl list -> boolCheck if any kernel param uses Float64.
val generate :
?block:(int * int * int) ->
?log:(string -> unit) ->
Sarek_ir_types.kernel ->
stringGenerate complete WGSL source for a kernel.
val generate_with_types :
?block:(int * int * int) ->
?log:(string -> unit) ->
types:(string * (string * Sarek_ir_types.elttype) list) list ->
Sarek_ir_types.kernel ->
stringGenerate WGSL source with custom type definitions.
val abi : ?block:(int * int * int) -> Sarek_ir_types.kernel -> Sarek_wgsl_abi.tBuild the ABI descriptor for a kernel. Reuses split_params and escape_wgsl_name / wgsl_type_of_elttype so the descriptor cannot drift from gen_bindings.
Raises Codegen_error.unsupported_construct for f64 parameters (same error as generate).