Skip to content

Port Kaleidoscope chapter 9 (debug info) and document chapter 10#262

Merged
tannergooding merged 1 commit into
dotnet:mainfrom
tannergooding:tannergooding-kaleidoscope-samples-triage
Jul 15, 2026
Merged

Port Kaleidoscope chapter 9 (debug info) and document chapter 10#262
tannergooding merged 1 commit into
dotnet:mainfrom
tannergooding:tannergooding-kaleidoscope-samples-triage

Conversation

@tannergooding

@tannergooding tannergooding commented Jul 15, 2026

Copy link
Copy Markdown
Member

Follow-up to #260 (the Ch3–8 rewrite), which is now merged. This stacks the last two tutorial chapters on top of it.

Chapter 9 — DWARF debug information. A SourceLocation is threaded through the shared lexer, parser, and AST, and translated to DWARF via LLVMDIBuilderRef. The plumbing is deliberately central so the earlier chapters stay untouched:

  • Kaleidoscope.Common: new SourceLocation, a Location on ExprAST, a Line on PrototypeAST, line/column tracking in the Lexer, node stamping in the base Parser, and an inert EmitLocation hook on the base CodeGenVisitor (a no-op for Ch3–8).
  • Chapter9 layers the debug info over Ch7's frontend and Ch8's object-file driver: a DICompileUnit, a DISubprogram per function, a DILocalVariable + #dbg_declare per parameter, and a !dbg location on every instruction. The emitted object verifies cleanly after DIBuilderFinalize.

def fib(n) if n < 3 then 1 else fib(n-1) + fib(n-2); now emits IR carrying !DICompileUnit, !DISubprogram(name: "fib"), !DILocalVariable(name: "n"), and !DILocation with accurate line/column.

Chapter 10. Upstream Chapter 10 is a prose conclusion with no accompanying code, so it's documented as a README "Where to go from here" section (aggregates/types, GC, exception handling, debugger integration — all expressible via LLVMSharp interop) rather than invented as a project.


Wired Chapter9 into KaleidoscopeTutorial.slnx and the root LLVMSharp.slnx, and added a Chapter9_EmitsDebugInfo test to LLVMSharp.KaleidoscopeTests. Whole solution builds with 0 warnings (TreatWarningsAsErrors + Nullable on); 2587 unit + 7 chapter tests pass.

Thread a SourceLocation through the shared lexer, parser, and AST and add an
inert EmitLocation hook to the base CodeGenVisitor, so chapters 3-8 are
unaffected. Chapter 9 layers DWARF debug info over chapter 7's frontend and
chapter 8's object-file driver: a compile unit, a subprogram per function,
a parameter DILocalVariable, and a !dbg location on every instruction. Document
the prose-only chapter 10 as a README conclusion.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@tannergooding tannergooding changed the title Rewrite the Kaleidoscope tutorial (Ch3-9) on the in-repo interop with shared code Port Kaleidoscope chapter 9 (debug info) and document chapter 10 Jul 15, 2026
@tannergooding
tannergooding merged commit a0a39f8 into dotnet:main Jul 15, 2026
12 checks passed
@tannergooding
tannergooding deleted the tannergooding-kaleidoscope-samples-triage branch July 15, 2026 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant