Skip to content

C/WASM Generation

Controlled pseudo-code can be transformed into a deterministic C subset, then compiled to WebAssembly.

sigMAX uses that toolchain as a deterministic compiler step. The safety model does not come from Clang alone: it comes from contracts, the restricted C subset, explicit WASM imports, runtime primitives and Binary Agreements.

LLVM logo

LLVM: compiler infrastructure

LLVM provides reusable compiler libraries: intermediate representation, optimizer passes, target backends, object emission and toolchain foundations. In this chain, LLVM is the machinery that makes wasm32 code generation possible.

Official site · logo assets

Clang frontend logo

Clang: C-family frontend

Clang reads C, C++, Objective-C and related languages, validates syntax and semantics, then feeds LLVM. In sigMAX, Clang only sees generated C subset code, not arbitrary application source.

Official site · LLVM logo used by Clang

WebAssembly logo

WebAssembly: portable binary target

WebAssembly is the compact executable format loaded by the runtime. A WASM module has linear memory, explicit imports and exports, and no ambient access to the host unless the embedder provides it.

Official site

WASI logo

WASI: standard host interface

WASI defines standards-track host APIs for WASM applications. sigMAX business handlers do not rely on WASI by default; they use sigMAX runtime primitives instead. WASI remains the reference when a WASI-style host interface is intentionally introduced.

Official site

LLVM is a compiler platform made of reusable pieces. A frontend such as Clang is one entry point into that platform.

LayerGeneral roleIn this page
Source languageHuman or generated source before compilation.Deterministic C subset generated from controlled pseudo-code.
Clang frontendParses C/C++/Objective-C and produces LLVM-level compiler input.Parses the generated C subset.
LLVM middle endPerforms target-independent analysis and optimization.Keeps the compiled path deterministic and inspectable.
LLVM backendEmits machine code or another target format.Emits WebAssembly for wasm32.
Link stepResolves exports, imports and runtime assumptions.Exports memory and the handler, leaves sigMAX primitives as host imports.

Clang can compile C toward many targets. With --target=wasm32, the target is a 32-bit WebAssembly environment, not a Linux process. That distinction matters: C code that expects files, sockets, libc, POSIX calls or a process environment needs a matching runtime model.

In a general WebAssembly build, Clang parses C, LLVM lowers it to wasm32, and the final module depends on the selected environment.

  • A freestanding build may avoid libc and provide only explicit imports.
  • A WASI build uses a WASI sysroot and host APIs.
  • A browser or embedder build exposes imports chosen by that embedder.

sigMAX uses the freestanding shape. Generated C includes the runtime header, avoids ambient OS behavior and calls only declared primitives.

  • Generated handlers include /runtime/sigma.h.
  • Undefined primitive calls become WASM imports.
  • Imports are emitted under the sigmax namespace.
  • The runtime checks capabilities before host work happens.
  • The Binary Agreement records what was actually compiled and accepted.

The component skeleton compiles each generated C file into a WASM module with a compact Clang invocation.

Terminal window
clang \
--target=wasm32 \
-nostdlib \
-fvisibility=hidden \
-Wl,--no-entry \
-Wl,--export=memory \
-Wl,--allow-undefined \
-Wl,--export=handle_<name> \
-o <name>.wasm \
<name>.c
FlagWhy it matters
--target=wasm32Selects the WebAssembly 32-bit target.
-nostdlibPrevents accidental dependency on a host C runtime.
-fvisibility=hiddenKeeps generated symbols private unless explicitly exported.
--no-entryBuilds a module with callable exports rather than a process entrypoint.
--export=memoryExposes WASM linear memory to the runtime.
--allow-undefinedAllows sigMAX primitives to remain host imports.
--export=handle_<name>Exposes the handler function expected by the route contract.

Contract

Pseudo-code

C subset

Clang + LLVM

WASM

Validate ABI

Runtime

Agreement

The result is a small executable boundary: the WASM module exports a handler and memory, imports only declared sigMAX primitives, and runs behind the Rust runtime.

The runtime header marks host primitives so Clang/LLVM emits imports in the sigmax module namespace instead of the default env namespace.

ConcernsigMAX rule
Host accessNo direct Linux calls, filesystem, raw sockets or process APIs.
Runtime APIUse declared primitives such as input, response, ObjectIR, storage invocation, HTTP, JSON, regex, crypto and time.
Memory exchangeUse WASM linear memory and C-compatible c_repr layouts where typed buffers cross the boundary.
ErrorsReturn compact status codes, with handled business errors emitted through response primitives.
EvidenceStore imports, exports, hashes, ABI expectations and validation results in the Binary Agreement.
Avoided pathReason
Arbitrary generated CToo much surface for undefined behavior and hidden dependencies.
Direct libc or POSIX assumptionsThe WASM module is not a normal Linux process.
Direct SQL or socketsStorage and networking must go through declared runtime primitives.
Raw JSON response stringsPublic output should be produced through response and ObjectIR primitives.
Trusting a binary only because it compiledThe compiled artifact still needs contract and agreement validation.