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.
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 |
Example
Section titled “Example”# Generate the C source and kbuild fragmentkdalc -o build/ my_sensor_driver.kdc
# The same, with the kernel directory and an aarch64 prefix# written into Makefile.kbuildkdalc -o build/ -K /lib/modules/$(uname -r)/build \ -x aarch64-linux-gnu- my_sensor_driver.kdcThe 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 formake -C $KDIR M=$PWD
Compiler Pipeline
Section titled “Compiler Pipeline”kdalc implements a four-stage pipeline with zero external dependencies -
no lex/yacc, no LLVM, just portable C99.
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).
Stage 1 - Lexer
Section titled “Stage 1 - Lexer”Hand-written tokeniser, single-pass, O(n) in source length.
- Produces a flat array of
kdal_token_tstructs - 62 keyword entries covering both
.kdhand.kdcvocabularies - Supports line comments (
//) and block comments (/* */) - No external tool dependency (no flex/lex)
Stage 2 - Parser
Section titled “Stage 2 - Parser”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
Stage 3 - Semantic Analysis
Section titled “Stage 3 - Semantic Analysis”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.
Stage 4 - Code Generation
Section titled “Stage 4 - Code Generation”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 |
Public API
Section titled “Public API”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.
Source Files
Section titled “Source Files”| 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 |