Repository navigation
7 1 tc command line driver
Source: https://deepwiki.com/PonvasanthPon/TransCompilator/7-1-tc-command-line-driver
Relevant source files
The following files were used as context for generating this wiki page:
The tc command-line driver serves as the primary user-facing interface for the tc_r1 compiler workspace crates/tc-cli/src/main.rs:1-5. Located in crates/tc-cli, it orchestrates the compilation pipeline from structured English source files (.eng or .tc) through syntax segmentation, semantic analysis, type checking, intermediate representation (Core-7 IR), and downstream execution, interpretation, or native x86-64 code generation.
The driver entry point resides in main crates/tc-cli/src/main.rs:22-47, which parses command-line arguments using standard library iterators and dispatches execution to dedicated subcommand handlers or system flags (--version, --audit, --selftest).
The CommandLine configuration struct captures parsed parameters, including source paths, output binaries, include search directories, program arguments, paraphrase modes, and interpreter working directories crates/tc-cli/src/main.rs:55-63.
graph TD
A["main"] --> B{"Argument Match"}
B -->|"--version / -V"| C["Report Version"]
B -->|"--audit"| D["run_audit"]
B -->|"--selftest"| E["run_selftest"]
B -->|"build"| F["run_build"]
B -->|"run"| G["run_run"]
B -->|"interp"| H["run_interp"]
B -->|"trace"| I["run_trace"]
B -->|"paraphrase"| J["run_paraphrase"]
B -->|"Unrecognized / None"| K["usage & ExitCode::from(2)"]
style A fill:#fff,stroke:#000,stroke-width:1px
style B fill:#fff,stroke:#000,stroke-width:1px
style C fill:#fff,stroke:#000,stroke-width:1px
style D fill:#fff,stroke:#000,stroke-width:1px
style E fill:#fff,stroke:#000,stroke-width:1px
style F fill:#fff,stroke:#000,stroke-width:1px
style G fill:#fff,stroke:#000,stroke-width:1px
style H fill:#fff,stroke:#000,stroke-width:1px
style I fill:#fff,stroke:#000,stroke-width:1px
style J fill:#fff,stroke:#000,stroke-width:1px
style K fill:#fff,stroke:#000,stroke-width:1px
Figure 1: CLI Dispatch and Argument Routing.
Sources: [crates/tc-cli/src/main.rs:22-126]()
The driver exposes five core execution modes corresponding to developer workflows:
-
build: Parses, type-checks, lowers to Core-7 IR, and invokes the x86-64 backend (tc-codegen-x86) and system linker to produce a static ELF64 binary. Supports custom output paths via-o. -
run: Compiles the English source to a temporary native executable and immediately executes it with optional command-line arguments passed after--. -
interp: Executes the program directly using the Core-7 reference interpreter (tc_ir::interpret/interpret_in_dir), supporting custom execution working directories via--cwd. -
trace: Runs the program under the interpreter while emitting step-by-step evaluation traces for debugging semantic flow. -
paraphrase: Performs syntactic and semantic parsing, echoing back the normalized canonical English representation of the source program.
Sources: [crates/tc-cli/src/main.rs:32-36], [crates/tc-cli/src/main.rs:55-126]()
Import resolution scans source documents for Use or Import statements crates/tc-cli/src/main.rs:128-152. The function module_imports segments the source text, tokenizes sentences, and extracts imported module names (ignoring noise words such as and, module, or as) crates/tc-cli/src/main.rs:128-152.
The find_import function resolves module names to physical files by searching through a prioritized sequence of directories crates/tc-cli/src/main.rs:154-185:
- The current working directory of the referencing file.
- The parent directory of the entry point.
- User-supplied include paths passed via
-i. - The standard library directory (
std_dir) discovered viafind_std_dir.
graph TD
A["module_imports"] --> B["tc_syntax::segment_source"]
B --> C["tc_syntax::tokenize"]
C --> D{"Token is import/use?"}
D -->|Yes| E["Extract Module Identifiers"]
D -->|No| C
E --> F["find_import"]
F --> G["Current Directory"]
F --> H["Entry Point Parent"]
F --> I["User Include Paths -I"]
F --> J["Standard Library Directory std_dir"]
style A fill:#fff,stroke:#000,stroke-width:1px
style B fill:#fff,stroke:#000,stroke-width:1px
style C fill:#fff,stroke:#000,stroke-width:1px
style D fill:#fff,stroke:#000,stroke-width:1px
style E fill:#fff,stroke:#000,stroke-width:1px
style F fill:#fff,stroke:#000,stroke-width:1px
style G fill:#fff,stroke:#000,stroke-width:1px
style H fill:#fff,stroke:#000,stroke-width:1px
style I fill:#fff,stroke:#000,stroke-width:1px
style J fill:#fff,stroke:#000,stroke-width:1px
Figure 2: Import Resolution and Module Search Path Flow.
Sources: [crates/tc-cli/src/main.rs:128-185], [crates/tc-semantics/src/lib.rs:1-17]()
The driver implements two system-level diagnostic routines invoked without subcommands:
-
--audit: Executes strict workspace validation checks. It verifies that no machine learning model files (.onnx,.pt,.binlm, etc.) exist, checks that all dependencies are strictly local path-based (Cargo.toml), enforces thatCargo.lockcontains exclusively the nine localtc-*packages with zero external registry sources or checksums, and scans for forbidden network, HTML, or path references Makefile:35-64. -
--selftest: Executes internal compiler verification tests, regression suites, and differential parity checks between the reference interpreter and the native x86-64 backend Makefile:26-27.
Sources: [crates/tc-cli/src/main.rs:30-31], [Makefile:26-64]()
The TransCompilator Project