Port Kaleidoscope chapter 9 (debug info) and document chapter 10#262
Merged
tannergooding merged 1 commit intoJul 15, 2026
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
SourceLocationis threaded through the shared lexer, parser, and AST, and translated to DWARF viaLLVMDIBuilderRef. The plumbing is deliberately central so the earlier chapters stay untouched:Kaleidoscope.Common: newSourceLocation, aLocationonExprAST, aLineonPrototypeAST, line/column tracking in theLexer, node stamping in the baseParser, and an inertEmitLocationhook on the baseCodeGenVisitor(a no-op for Ch3–8).Chapter9layers the debug info over Ch7's frontend and Ch8's object-file driver: aDICompileUnit, aDISubprogramper function, aDILocalVariable+#dbg_declareper parameter, and a!dbglocation on every instruction. The emitted object verifies cleanly afterDIBuilderFinalize.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!DILocationwith 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
Chapter9intoKaleidoscopeTutorial.slnxand the rootLLVMSharp.slnx, and added aChapter9_EmitsDebugInfotest toLLVMSharp.KaleidoscopeTests. Whole solution builds with 0 warnings (TreatWarningsAsErrors+Nullableon); 2587 unit + 7 chapter tests pass.