# airbus5717/rotate architecture

> Architecture diagram of the GitHub repository airbus5717/rotate, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/airbus5717/rotate
- Repository: https://github.com/airbus5717/rotate

## Overview

##### Project Overview & Main Components
- Project Type: This is a compiler written in C++ with a largely C-style approach using only standard C libraries (apart from language-specific syntax sugar).
- High-Level Pipeline:
- Main Entrypoint (main.cpp) that initializes the compiler.
- Lexical Analysis (Lexer in src/fe): Tokenization of the source code.
- Parsing (planned): Construction of an Abstract Syntax Tree (AST) based on token stream.
- Type Checking, Semantic Analysis, and further phases like Optimization and Code Generation (planned).
- Test Suite: Files under the test directory indicate that the compiler will be tested against various source files (with a .vr extension).

##### Breaking Down the File Structure
- Top-Level Files:
- Build and configuration files (CMakeLists.txt, Makefile, .clang-format, .clang-tidy, etc.) show how the project is assembled.
- LICENSE, README, and docs provide documentation and project context.
- src Directory:
- main.cpp: Entry point to the application.
- src/fe: Contains components for the front-end (currently the lexer is implemented).
- src/include: Contains header files for shared definitions and functionality (e.g., defines, arrays, logging).
- Utility functions and common code are in src/utl.
- Test Directory:
- Contains sample .vr source files, suggesting that these files are used to validate different language constructs.

##### Relationships and Interactions
- Flow of Data:
- Begin at the Compiler Driver, which reads a source file.
- Data flows to the Lexer (which converts characters into tokens).
- The supposed parser will then consume these tokens to build syntax trees.
- Subsequent compiler phases (type checking, semantic analysis, optimization, and code generation) use these trees.
- Utility and header libraries as supporting each core component.
- Tests as providing input and verification of the outputs from each stage.

##### Architectural Patterns & Design Principles
- Pipeline Architecture: Use a sequential pipeline approach to show compilation phases.
- Modularity / Separation of Concerns: Each component (lexer, parser, type checker, etc.) should be visually separated, with clear interfaces (e.g., token streams, ASTs) between them.

##### Practical Steps
1. Lexical Analysis (source: src/fe)
2. Parsing (planned)
3. Type Checking (planned)
4. Semantic Analysis / Analyzer (planned)
5. (Optional) Optimizer (possible future work)
6. Code Generation (planned for a custom architecture)
- At the bottom or as a parallel component: outline the testing infrastructure (test directory).
- Supporting components like build configurations (Makefile, CMakeLists.txt) and documentation (docs folder).

##### Final Recommendations
- Clarity: Each component should be clearly defined with proper annotations regarding status (implemented vs. planned).

## Diagram (Mermaid)

```mermaid
graph TD
    %% Compiler Driver
    CompilerDriver["Compiler Driver (main.cpp)"]:::implemented

    %% Front End Components
    subgraph "Front End"
        L1["lexer.cpp"]:::implemented
        L2["lexer.hpp"]:::implemented
        T1["token.cpp"]:::implemented
        T2["token.hpp"]:::implemented
        %% Grouping Lexical Analyzer Files
        L1 --> L2
        L2 --> T1
        T1 --> T2
        %% Pipeline continues with planned components
        T2 --> P["Parser (Planned)"]:::planned
        P --> TC["Type_Checking (Planned)"]:::planned
        TC --> SA["Semantic_Analysis (Planned)"]:::planned
        SA --> OPT["Optimizer (Planned)"]:::planned
        OPT --> CG["Code_Generation (Planned)"]:::planned
    end

    %% Link Compiler Driver to Front End (start with lexer.cpp)
    CompilerDriver --> L1

    %% Dependencies: Shared Headers & Utilities
    subgraph "Dependencies"
        Headers["Headers (src/include)"]:::utility
        Utils["Utilities (src/utl)"]:::utility
        Headers --> Utils
    end
    %% Dependency to Front End (for instance, headers used by lexer)
    Headers --> L2

    %% Build & Configuration
    subgraph "Build_&_Config"
        B1["CMakeLists.txt"]:::build
        B2["Makefile"]:::build
        B3[".clang-format"]:::build
        B4[".clang-tidy"]:::build
        B5[".editorconfig"]:::build
        B6[".gitattributes"]:::build
        B1 --> B2
        B2 --> B3
        B3 --> B4
        B4 --> B5
        B5 --> B6
    end
    %% Connect build configuration to Compiler Driver
    B1 --- CompilerDriver

    %% Documentation
    subgraph "Documentation"
        D1["docs/index.html"]:::doc
        D2["docs/index.org"]:::doc
        D3["docs/solarized-min.css"]:::doc
        D4["docs/style.css"]:::doc
        D1 --> D2
        D2 --> D3
        D3 --> D4
    end
    %% Documentation linked to Compiler Driver for context
    D1 --- CompilerDriver

    %% Testing Framework
    subgraph "Testing"
        Tst1["test/000_empty.vr"]:::test
        Tst2["test/001_hello.vr"]:::test
        Tst1 --> Tst2
    end
    %% Testing providing sample inputs to Compiler Driver
    Tst1 --- CompilerDriver

    %% Click Events
    click CompilerDriver "https://github.com/airbus5717/rotate/blob/master/src/main.cpp"
    click L1 "https://github.com/airbus5717/rotate/blob/master/src/fe/lexer.cpp"
    click L2 "https://github.com/airbus5717/rotate/blob/master/src/fe/lexer.hpp"
    click T1 "https://github.com/airbus5717/rotate/blob/master/src/fe/token.cpp"
    click T2 "https://github.com/airbus5717/rotate/blob/master/src/fe/token.hpp"
    click Headers "https://github.com/airbus5717/rotate/tree/master/src/include"
    click Utils "https://github.com/airbus5717/rotate/tree/master/src/utl"
    click B1 "https://github.com/airbus5717/rotate/blob/master/CMakeLists.txt"
    click B2 "https://github.com/airbus5717/rotate/tree/master/Makefile"
    click B3 "https://github.com/airbus5717/rotate/blob/master/.clang-format"
    click B4 "https://github.com/airbus5717/rotate/blob/master/.clang-tidy"
    click B5 "https://github.com/airbus5717/rotate/blob/master/.editorconfig"
    click B6 "https://github.com/airbus5717/rotate/blob/master/.gitattributes"
    click D1 "https://github.com/airbus5717/rotate/blob/master/docs/index.html"
    click D2 "https://github.com/airbus5717/rotate/blob/master/docs/index.org"
    click D3 "https://github.com/airbus5717/rotate/blob/master/docs/solarized-min.css"
    click D4 "https://github.com/airbus5717/rotate/blob/master/docs/style.css"
    click Tst1 "https://github.com/airbus5717/rotate/blob/master/test/000_empty.vr"
    click Tst2 "https://github.com/airbus5717/rotate/blob/master/test/001_hello.vr"

    %% Styles
    classDef implemented fill:#c2f0c2,stroke:#333,stroke-width:2px;
    classDef planned fill:#fff2a8,stroke:#333,stroke-width:2px;
    classDef utility fill:#cce5ff,stroke:#333,stroke-width:2px;
    classDef build fill:#f7d1ba,stroke:#333,stroke-width:2px;
    classDef doc fill:#d1c4e9,stroke:#333,stroke-width:2px;
    classDef test fill:#f3c5f5,stroke:#333,stroke-width:2px;
```
