Repository navigation
1 2 compilation pipeline end to end
Source: https://deepwiki.com/PonvasanthPon/TransCompilator/1-2-compilation-pipeline-end-to-end
Relevant source files
The following files were used as context for generating this wiki page:
This document details the deterministic, zero-ML compilation pipeline of tc_r1 from structured English source files (.eng) to verified Core-7 intermediate representation (crates/tc-ir/src/lib.rs), and subsequently to executable x86-64 machine code via crates/tc-codegen-x86/ or execution via the reference interpreter. It covers module import resolution, syntactic segmentation, semantic lowering, type checking, and backend generation.
Sources: crates/tc-semantics/src/lib.rs:1-152, crates/tc-cli/src/main.rs:1-47
When the command-line driver processes an entry point file (e.g., via tc build or tc run), it scans the source files for module imports and resolves them against local directories, include paths, and the standard library.
The import resolution mechanism parses sentences starting with import or use using module_imports crates/tc-cli/src/main.rs:128-152. It extracts dependent module names and resolves their physical file paths using find_import crates/tc-cli/src/main.rs:154-185, checking the current working directory, the entry file's parent directory, explicit -I include paths (parsed.includes), and the standard library directory (std_dir).
graph TD
sub5["Natural Language Space: Import Statement (.eng)"]
sub5 -->|"(e.g., 'import core')"| N1
subgraph CodeEntitySpace ["Code Entity Space"]
N1["tc_cli::main"] --> N2["tc_cli::load_sources"]
N2 --> N3["tc_cli::module_imports"]
N3 --> N4["tc_cli::find_import"]
N4 -->|"(Resolves to path/*.eng)"| N5["tc_semantics::SourceFile"]
end
style sub5 fill:none,stroke:none
style CodeEntitySpace fill:none,stroke:none
Sources: crates/tc-cli/src/main.rs:128-185
The compilation process moves through five distinct sequential phases: Syntax Analysis, Semantic Lowering, Type Checking / Monomorphization, Core-7 IR Generation, and Backend Generation or Interpretation.
graph TD
sub1["Natural Language Space: Source Code (.eng)"]
sub1 -->|"(Raw English Text)"| S1
subgraph CodeEntitySpace ["Code Entity Space"]
S1["tc_syntax::segment_source & tokenize"] --> S2["tc_semantics::lower_project"]
S2 -->|"(LoweredProject)"| S3["tc_typeck::type_check_project"]
S3 -->|"(Program & AstModule)"| S4["tc_ir::Module & verify_module"]
S4 -->|"(CompiledProject)"| S5["tc_codegen_x86::emit_x86 OR tc_ir::interpret"]
end
style sub1 fill:none,stroke:none
style CodeEntitySpace fill:none,stroke:none
Sources: crates/tc-semantics/src/lib.rs:165-211, crates/tc-cli/src/main.rs:13-18
Source files (SourceFile) are ingested and segmented into raw blocks, items, and sentences via segment_source crates/tc-semantics/src/lib.rs:45-49. Each sentence is tokenized into a vector of Token structures containing lexical kinds (TokenKind) and lowercase lexemes.
Link Grammar 5.13.2 bindings (LinkGrammarParser) are invoked to produce complete linkages (LgParse), normalize active, passive, and imperative structures, and construct structured clause trees (ClauseTree) containing verb heads (VerbHead) and prepositional phrases (PrepPhrase).
Sources: crates/tc-semantics/src/lib.rs:44-49
The semantics front end consumes the syntactic clause trees and applies a strict three-way intent gate (IntentVerdict classifying sentences into EXEC, COMMENT_OMITTED, or UNSUPPORTED) crates/tc-semantics/src/lib.rs:38-118.
The lower_project and lower_project_outcome functions crates/tc-semantics/src/lib.rs:196-211 orchestrate sentence lowering, anaphora resolution, phrase matching (match_phrase), and semantic frame construction (SemanticFrame). The output is a LoweredProject containing a high-level typed AST program alongside per-sentence provenance traces (SentenceTrace) and deterministic paraphrase documents (ParaphraseDoc) crates/tc-semantics/src/lib.rs:142-151.
Sources: crates/tc-semantics/src/lib.rs:38-211
The typed AST produced by tc-semantics is passed to tc-typeck. This stage manages scoped symbol resolution, strict type checking against primitive and user-defined records, and demand-driven monomorphization of generic phrase declarations. Errors during type checking are mapped back to source spans via type_error crates/tc-semantics/src/lib.rs:178-186.
Sources: crates/tc-semantics/src/lib.rs:165-186, Cargo.lock:76-81
Following type checking, the AST is lowered into Core-7 intermediate representation (tc_ir::Module) crates/tc-semantics/src/lib.rs:165-176. A tc_ir::Module contains functions (Function), local variable definitions (LocalDef), basic blocks, read-only data (RodataDef), and typed instructions (Stmt, Expr).
The verify_module function validates SSA integrity and type correctness across the IR. For development, parity checks, and direct execution without native compilation, tc_ir::interpret or interpret_in_dir executes the IR via the reference interpreter crates/tc-cli/src/main.rs:13-18.
Sources: crates/tc-semantics/src/lib.rs:165-176, crates/tc-cli/src/main.rs:13-18
For native compilation (tc build or tc run), the validated tc_ir::Module is passed to tc-codegen-x86. This backend emits x86-64 machine instructions, constructs zero-libc static ELF64 binaries, and invokes system assemblers and linkers to generate standalone executable artifacts.
Sources: Cargo.lock:6-16, crates/tc-cli/src/main.rs:13-18
The TransCompilator Project