How geekforalgorithm/legacy-cc works
Project Type and Purpose
• Clearly, this is a compiler for the C language from the early days of the language’s evolution. Its purpose is to translate (a subset of) C into assembly code (targeting a PDP‑11 environment, as indicated by the links to a PDP‑11/unix emulator).
• The README highlights its historical significance and provides links for experimenting in an emulated environment.
File Structure
• There are two main directories: “last1120c” and “prestruct”. Each contains a set of C source files (with names like c00.c, c01.c, …, c11.c) and several assembly (’.s’) files.
• The naming convention (e.g., “c00”, “c01”, “c10”, “c11”, etc.) suggests that the compiler’s logic was divided into multiple phases or modules. For instance, modules under “c00- c03” might cover the initial phases (like lexical analysis and parsing) while “c10” and “c11” may handle later phases (such as code generation). Files like “cvopt.c” indicate a dedicated optimization module.
• The .s files (such as c0t.s, c1t.s, cctab.s, efftab.s, regtab.s, and sptab.s) serve as pre-defined tables or ancillary data needed by the compiler – likely used for token tables, optimization decision data, register allocation data, and so on.
• The “prestruct” directory appears to be an earlier or alternative implementation design (“prestruct” could refer to a non-structured, or “pre-structured” version) that might have its own variation of the compiler phases.
• Source Input Module: Representing the initial input phase of the compiler where C code is read.
• Lexical Analysis / Tokenization: Likely contained in modules such as the early “c00.c” files (parsing characters and converting them into tokens).
• Syntax/Parsing Phase: Possibly spread over files like “c01.c” and “c02.c”, handling the formation of the abstract syntax tree.
• Semantic Analysis: Although not explicitly labeled, later stages may incorporate semantic checks.
• Optimization Component: Highlight “cvopt.c” to show that some basic optimization strategies were implemented.
• Code Generation: Modules such as “c10.c” and “c11.c” are suggestive of the translation of the abstract syntax tree into assembly code.
• Assembly/Table Definitions: The .s files (c0t.s, c1t.s, cctab.s, etc.) that provide necessary static data and templates for code generation.
• Alternative/Legacy Structures: Separate the “prestruct” set as an alternative design variant of the compiler’s architecture.
b. Relationships and Interactions:
• From the Lexical Analyzer, show the flow into the Parsing/Syntax Analysis module.
• The output from parsing flows into semantic analysis (if applicable) and then onto the Code Generation phase.
• For the “prestruct” variant, you may set up a parallel flow that resembles the main system but highlights differences (if any) in design philosophy.
c. Architectural Patterns and Technologies:
• Each “cXX” module represents a specific point in the processing pipeline.
• That the project relies on plain C and assembly, targeting very early Unix/PDP‑11 environments.
• That historical design principles such as minimal separation of concerns and close integration between compilation phases are present.
d. Tailoring Guidelines:
• Since this is a compiler (a language processing tool), clarify each compilation stage: Lexical Analysis, Parsing, Optional Semantic Analysis, Optimization, and Code Generation.
• Be sure to capture the ancillary role of assembly templates/tables as separate yet connected components.