# mshockwave/sqlgen architecture

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

- Interactive diagram: https://gitdiagram.com/mshockwave/sqlgen
- Repository: https://github.com/mshockwave/sqlgen

## Overview

##### Flow and Relationships

- TableGen Input -> Parser -> Appropriate Emitter -> SQL Output
- ↕            ↕
- Error Handler   ↕
- ↕
- Base SQLEmitter

##### Key Technical Elements to Highlight

- Input/Output components (green)
- Processing components (blue)
- Error handling (red)
- Base classes (yellow)

- Inheritance hierarchy:
- SQLEmitter as the base class
- SQLQueryEmitter, SQLInsertEmitter, and SQLTableEmitter inheriting from it

##### Testing Infrastructure (Secondary Layer)

A separate section showing:
- LIT Testing Framework
- Test Files (.td)
- FileCheck Verification
- CMake Build System

##### Important Details

- Command flow from input to output
- Test verification paths

##### Specific Implementation Notes

- Notes about the Query class structure
- Transformation process from TableGen to SQL
- Where configuration happens (CMake)

Remember to:
- Keep the LLVM integration visible but not overwhelming
- Emitter hierarchy as it's central to the design
- Clear boundaries between test infrastructure and core functionality

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Legend
        style Legend fill:#f5f5f5,stroke:#333
        input[Input Files]:::input
        process[Processing Components]:::process
        error[Error Handling]:::error
        base[Base Components]:::base
        output[Output Files]:::output
        test[Testing Components]:::test
    end

    subgraph Input
        TD["TableGen Input (.td)"]:::input
        click TD "https://github.com/mshockwave/SQLGen/blob/main/test/CreateTables.td"
        TD_INSERT["Insert Definitions (.td)"]:::input
        click TD_INSERT "https://github.com/mshockwave/SQLGen/blob/main/test/InsertRows.td"
        TD_QUERY["Query Definitions (.td)"]:::input
        click TD_QUERY "https://github.com/mshockwave/SQLGen/blob/main/test/MakeQueries.td"
    end

    subgraph "Core Processing"
        PARSER["LLVM TableGen Parser"]:::process
        
        subgraph "Emitter Hierarchy"
            BASE["SQLEmitter (Base)"]:::base
            click BASE "https://github.com/mshockwave/SQLGen/blob/main/SQLEmitter.cpp"
            
            QUERY["SQLQueryEmitter"]:::process
            click QUERY "https://github.com/mshockwave/SQLGen/blob/main/SQLQueryEmitter.cpp"
            
            INSERT["SQLInsertEmitter"]:::process
            click INSERT "https://github.com/mshockwave/SQLGen/blob/main/SQLInsertEmitter.cpp"
            
            TABLE["SQLTableEmitter"]:::process
            click TABLE "https://github.com/mshockwave/SQLGen/blob/main/SQLTableEmitter.cpp"
        end
    end

    subgraph "Error System"
        ERROR["Error Handler"]:::error
        click ERROR "https://github.com/mshockwave/SQLGen/blob/main/Error.cpp"
    end

    subgraph "Output Layer"
        SQL["SQL Output (.sql)"]:::output
    end

    subgraph "Testing Infrastructure"
        LIT["LIT Framework"]:::test
        click LIT "https://github.com/mshockwave/SQLGen/blob/main/test/lit.cfg.py"
        FILECHECK["FileCheck Verification"]:::test
        CMAKE["CMake Build System"]:::test
        click CMAKE "https://github.com/mshockwave/SQLGen/blob/main/CMakeLists.txt"
    end

    %% Relationships
    TD --> PARSER
    TD_INSERT --> PARSER
    TD_QUERY --> PARSER
    
    PARSER --> BASE
    PARSER <--> ERROR
    
    BASE --> QUERY
    BASE --> INSERT
    BASE --> TABLE
    
    QUERY --> SQL
    INSERT --> SQL
    TABLE --> SQL
    
    SQL --> FILECHECK
    FILECHECK --> LIT
    
    classDef input fill:#90EE90,stroke:#333
    classDef process fill:#87CEEB,stroke:#333
    classDef error fill:#FFB6C6,stroke:#333
    classDef base fill:#FFE4B5,stroke:#333
    classDef output fill:#98FB98,stroke:#333
    classDef test fill:#DDA0DD,stroke:#333
```
