How chigraph/chigraph works
Project Type and Purpose
• Chigraph is a compiler‐style language project (systems programming language) made up of:
• A CLI tool (“chi”)
• A core library (libchigraph) for parsing, graph representation, codegen (to LLVM IR)
• A debugger support library (libchigraphdebugger)
• It fetches remote modules (via libgit2), constructs an in‐memory graph representation, compiles to LLVM IR, links in a small C runtime, and can run or JIT modules.
File‐Structure Analysis
• Top‐level CMakeLists.txt orchestrates build of subprojects:
• chi/ : CLI front end (compile.cpp, run.cpp, get.cpp, interpret.cpp, etc.)
• lib/
– core/ : core APIs (Context, ChiModule, GraphFunction, FunctionCompiler…)
– debugger/ : Debugger API & implementation
– fetcher/ : Module fetching & caching (libgit2)
– runtime/ : C runtime to support generated code
– support/ : utility helpers (ExecutablePath, Subprocess, UUID, JSON)
• examples/ : sample code using libchigraph
• test/ : unit tests (Catch)
• third_party/ : vendored Catch
• doc/ : Doxygen, build instructions, screenshots
README Insights
• Describes three high‐level components: chi CLI, libchigraph, libchigraphdebugger
• Lists tech stack: LLVM/Clang for codegen, libgit2 for fetch, Boost for filesystem/args/UUID, Catch for tests
– chi CLI
– libchigraph core library
• Context & ModuleLoader
• Graph representation
• Codegen (FunctionCompiler, NodeCompiler)
– libchigraphdebugger
– fetcher module (libgit2 + ModuleCache)
– support utilities (filesystem, JSON, subprocess)
– runtime (C‐based arc.c / main.c)
– LLVM/Clang backend
– External: remote Git servers, local filesystem
1. chi CLI → Context.loadModule() → fetcher
2. fetcher → Git remote over HTTPS → local ModuleCache
3. Context parses module files → builds GraphModule → GraphFunction
4. Codegen components → generate LLVM IR
5. LLVM API → optimize & compile to machine code
6. Link in runtime C objects → final executable or JIT
7. Debugger lib hooks into Context & Graph to provide breakpoints
c. Architectural Patterns
– Layered: CLI layer, library API layer, codegen layer, backend layer
– Plugin‐like: modules fetched dynamically, cached
– Separation of concerns: fetching vs parsing vs codegen vs runtime vs debugging
d. Key Technologies/Frameworks
– CMake for build orchestration
– LLVM/Clang libraries (llvm::Module)
– libgit2 for remote module fetching
– Boost (filesystem, program_options, uuid, etc.)
– Catch for unit tests