From 7ea5aeedfd0a864d47331194f3a101deaa34b4be Mon Sep 17 00:00:00 2001 From: Araq Date: Sat, 13 Jun 2026 21:03:55 +0200 Subject: [PATCH] IC: add inert --icBackendStage/--icBackendModule switches (Phase 2b scaffold) Config plumbing for the per-module backend: icBackendStage (cg|merge|emit, empty = today's whole-program backend) and icBackendModule (the NIF suffix the cg/emit stage operates on). No behavior yet -- the nifbackend stages and deps.nim rules that consume these land next. Whole-program backend, koch boot, and a 2-module IC build are unchanged. Co-Authored-By: Claude Opus 4.8 --- compiler/commands.nim | 13 +++++++++++++ compiler/options.nim | 12 ++++++++++++ 2 files changed, 25 insertions(+) diff --git a/compiler/commands.nim b/compiler/commands.nim index 3a8ae18559..f5434fb621 100644 --- a/compiler/commands.nim +++ b/compiler/commands.nim @@ -960,6 +960,19 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo; # config loading can replay it instead of re-parsing the `nim.cfg` chain. expectArg(conf, switch, arg, pass, info) conf.icPreparsedConfig = arg + of "icbackendstage": + # `nim nifc` only: per-module backend stage, one of cg|merge|emit (see + # options.icBackendStage). Empty (switch unused) keeps the whole-program + # backend. Emitted by `deps.nim`'s backend build file. + expectArg(conf, switch, arg, pass, info) + if pass in {passCmd2, passPP}: + conf.icBackendStage = arg + of "icbackendmodule": + # `nim nifc` only: the NIF module suffix the cg/emit stage operates on (see + # options.icBackendModule). + expectArg(conf, switch, arg, pass, info) + if pass in {passCmd2, passPP}: + conf.icBackendModule = arg of "import": expectArg(conf, switch, arg, pass, info) if pass in {passCmd2, passPP}: diff --git a/compiler/options.nim b/compiler/options.nim index 1c78a77181..fd194e0b23 100644 --- a/compiler/options.nim +++ b/compiler/options.nim @@ -418,6 +418,18 @@ type # process; only the `ic` driver serialises them. # Path-search switches are excluded — the driver # forwards the resolved `searchPaths` as `--path`. + icBackendStage*: string # under `nim nifc`: which stage of the per-module + # backend this invocation runs — "cg" (codegen one + # module to its `.c.nif`), "merge" (global liveness + # + owner assignment across all `.c.nif`), "emit" + # (render one module's `.c` from its `.c.nif` + the + # merge decision). Empty = today's whole-program + # backend (load all, codegen+DCE+cc+link in one + # process). See `compiler/nifbackend.nim`. + icBackendModule*: string # under `nim nifc` with icBackendStage in {cg,emit}: + # the NIF module suffix this invocation codegens or + # emits. The other modules are loaded only so types + # resolve; their definitions are referenced extern. spellSuggestMax*: int # max number of spelling suggestions for typos cppDefines*: HashSet[string] # (*)