Skip to content

Rewrite and complete the Kaleidoscope tutorial samples (Ch3-8, ORC LLJIT) - #260

Merged
tannergooding merged 4 commits into
dotnet:mainfrom
tannergooding:tannergooding-kaleidoscope-samples-triage
Jul 15, 2026
Merged

Rewrite and complete the Kaleidoscope tutorial samples (Ch3-8, ORC LLJIT)#260
tannergooding merged 4 commits into
dotnet:mainfrom
tannergooding:tannergooding-kaleidoscope-samples-triage

Conversation

@tannergooding

Copy link
Copy Markdown
Member

The Kaleidoscope samples were built against the abandoned LLVMSharp 5.0.0 NuGet package (LLVM 5, 2017), not the in-repo library, so the API they called (LLVM.BuildCall, the legacy LLVMAdd*Pass function pass manager, MCJIT) was gone or reshaped in 21.x -- and the projects were OutputType=Library with a Main, so they didn''t even run.

Rather than patch the three dead chapters, this rewrites samples/KaleidoscopeTutorial on the in-repo LLVMSharp.Interop, ports the tutorial through Chapter 8, moves the JIT to ORC LLJIT, and restructures so the invariant frontend lives in a shared Kaleidoscope.Common library and each chapter contains only its delta over the previous one. Builds with 0 warnings (TreatWarningsAsErrors/Nullable on) and every chapter is smoke-tested end to end.


Structure

  • Kaleidoscope.Common -- lexer, token, full AST, base Parser + base CodeGenVisitor, the ORC LLJIT wrapper, the REPL loop, host functions, support helpers.
  • Chapter3 emit IR (dump only); Chapter4 ORC LLJIT + new pass manager; Chapter5 if/for; Chapter6 user-defined operators; Chapter7 mutable variables (alloca + mem2reg); Chapter8 native object-file emission.

Each chapter''s Parser/CodeGenVisitor derive from the previous chapter''s and override only the new productions; Chapter{N} references Chapter{N-1}, so the incremental steps are visible instead of copied.


What it fixes


Verified (Release): Ch4 foo(2,3)=25/foo(4,5)=81, extern sin resolves, 4+5 folds; Ch5 printstar(5) prints *****, if 1<2 then 10 else 20 -> 10; Ch6 !0=1/!1=0; Ch7 test(3)=8, iterative mutable fibi(10)=55; Ch8 emits a valid COFF x64 object exporting double average(double, double).

Out of scope: tutorial Chapter 9 (debug info / DWARF via DIBuilder) and Chapter 10. The samples are intentionally not part of the root LLVMSharp.slnx; a KaleidoscopeTutorial.slnx and a README.md describing the structure and chapter mapping are included.

tannergooding and others added 4 commits July 15, 2026 11:37
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
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