Skip to content

kdalc Compiler

kdalc is the core compiler that translates .kdc driver implementations (together with their .kdh device headers) into kernel-module C source and a kbuild fragment. The generated module does not build yet (open finding O7, below). The language and compiler are frozen since 2026-11-01.

Terminal window
kdalc [options] <file.kdc>
Flag Argument Description
-o <dir> Output directory (default: .)
-K <dir> Kernel build directory (KDIR)
-x <pfx> CROSS_COMPILE prefix (e.g. aarch64-linux-gnu-)
-v - Verbose output
-h - Show help
Terminal window
# Generate the C source and kbuild fragment
kdalc -o build/ my_sensor_driver.kdc
# The same, with the kernel directory and an aarch64 prefix
# written into Makefile.kbuild
kdalc -o build/ -K /lib/modules/$(uname -r)/build \
-x aarch64-linux-gnu- my_sensor_driver.kdc

The compiler produces two files in the output directory:

  • <driver>.c - the kernel module source; it includes <linux/kdal.h>, which does not exist yet (O7)
  • Makefile.kbuild - A kbuild Makefile fragment for make -C $KDIR M=$PWD

kdalc implements a four-stage pipeline with zero external dependencies - no lex/yacc, no LLVM, just portable C99.

flowchart LR SRC[/".kdc driver<br/>importing .kdh headers"/] READ["Read<br/>source.c"] LEX["Lexer<br/>lexer.c<br/>characters to tokens"] PARSE["Parser<br/>parser.c<br/>recursive descent, tokens to AST"] SEMA["Semantic analysis<br/>sema.c<br/>types, register access,<br/>scopes, backends"] GEN["Codegen<br/>codegen.c<br/>AST to C"] OUT[/".c and Makefile.kbuild"/] KO[/"kbuild: .ko<br/>fails today: open finding O7"/] SRC --> READ --> LEX --> PARSE --> SEMA --> GEN --> OUT --> KO classDef observed stroke:#0ca30c,stroke-width:2px class READ,LEX,PARSE,SEMA,GEN observed

The same diagram as KDAL’s lang/DESIGN.md: the five phases run (kdality compile succeeds on every example); the generated module does not build yet (finding O7 in KDAL’s docs/open-findings-20261121.md).

Hand-written tokeniser, single-pass, O(n) in source length.

  • Produces a flat array of kdal_token_t structs
  • 62 keyword entries covering both .kdh and .kdc vocabularies
  • Supports line comments (//) and block comments (/* */)
  • No external tool dependency (no flex/lex)

Recursive-descent parser, LL(1) with up to 2-token lookahead.

  • All nodes allocated from kdal_arena_t (a block-based arena: no heap allocation after the parse, pointers remain stable)
  • No external parser generator dependency (no bison/yacc)
  • AST node hierarchy:
    KDAL_NODE_FILE → device classes → registers / signals / capabilities / power / config
    KDAL_NODE_FILE → drivers → handlers / statements / expressions
  • Expression parser handles: literals, register paths, read(), binary/unary operators

Two-scope symbol table: globals (device namespace) + locals (handler block).

Check Kind Description
Register access error writing a ro register, reading a wo register
Duplicates error the same register, signal or config field name twice
Duplicates warning the same capability twice
Register overlap warning two registers whose offset ranges overlap
Bitfields error a bitfield with an invalid range
Bounded loops warning a for bound that may not be a compile-time constant
IRQ safety warning wait() inside an on_write handler (may block in IRQ context)

There is no check that an MMIO backend’s registers all have an @ offset.

Symbol kinds: SYM_REGISTER, SYM_SIGNAL, SYM_CAPABILITY, SYM_CONFIG, SYM_LOCAL_VAR.

Emits a Linux kernel module source in the platform_driver model (module_platform_driver).

Input construct Generated output
Driver context struct <Name>_ctx with struct kdal_driver kdal and void __iomem *base
probe block static int <Name>_probe(struct platform_device *pdev): maps the first memory resource, registers with kdal_driver_register
remove block static int <Name>_remove(struct platform_device *pdev)
on read/on write <Name>_read/<Name>_write in a struct kdal_driver_ops
on signal static irqreturn_t <Name>_irq(int irq, void *dev_id); nothing requests the IRQ
on power static int <Name>_pm_notify(struct kdal_driver *kdal, int state)
on timeout static void <Name>_timeout(struct kdal_driver *kdal)
Diagnostics kdal_error(), kdal_warn(), kdal_note() with filename:line:col: prefix

The compiler is also built as a C library (libkdalc.a); its header is compiler/include/codegen.h, installed as include/kdalc/codegen.h. The signatures and options are on the API Reference page.

File Purpose
compiler/main.c Standalone kdalc entry point
compiler/source.c Reading the source file
compiler/lexer.c Hand-written tokeniser
compiler/parser.c Recursive-descent parser
compiler/sema.c Semantic analysis
compiler/codegen.c AST → kernel C + Kbuild
compiler/include/token.h Token type enum
compiler/include/ast.h AST node definitions (tagged-union, arena-allocated)
compiler/include/codegen.h Public API header