# deviant-liang/deviant architecture

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

- Interactive diagram: https://gitdiagram.com/deviant-liang/deviant
- Repository: https://github.com/deviant-liang/deviant

## Overview

##### Project type and purpose
- This is a compiler front-end for a simple educational language (“Deviant”) that parses source code and emits LLVM IR.
- It reads `.dv` test files or user input, lexes and parses them into an AST, then uses LLVM APIs to generate `out.ll`.

##### File structure
- Top-level files:
- CMakeLists.txt – build configuration
- main.cpp – orchestration of the compile pipeline
- out.ll – generated LLVM IR
- test.dv – sample Deviant source file
- / – public interfaces for each phase:
- lexer.h / token.h
- parser.h / ast.h
- user_input.h
- deviant_llvm.h (LLVM codegen)
- src/ – implementation of each interface:
- lexer.cpp
- parser.cpp
- ast.cpp
- user_input.cpp
- deviant_llvm.cpp

##### README for additional insights
- Use cases: compile simple Deviant programs to LLVM IR for educational purposes.

## Diagram (Mermaid)

```mermaid
flowchart TD
    CMake["CMakeLists.txt"]:::config
    main["main.cpp"]:::internal
    test[/test.dv/]:::docs
    out[/out.ll/]:::docs

    subgraph "Compile Pipeline"
        direction TB
        Input["Input Reader Module"]:::internal
        Lexer["Lexer Module"]:::internal
        Parser["Parser Module"]:::internal
        AST["AST Module"]:::internal
        Codegen["Codegen Module"]:::internal
    end

    LLVM(("LLVM C++ API")):::external

    CMake --> main
    main --> Input
    main --> Lexer
    main --> Parser
    main --> AST
    main --> Codegen
    main --> out

    test -->|reads| Input
    Input -->|tokenizes| Lexer
    Lexer -->|parses| Parser
    Parser -->|builds AST| AST
    AST -->|generates IR| Codegen
    Codegen -->|writes IR| out

    Codegen --> LLVM

    click CMake "https://github.com/deviant-liang/deviant/blob/main/CMakeLists.txt"
    click main "https://github.com/deviant-liang/deviant/blob/main/main.cpp"
    click test "https://github.com/deviant-liang/deviant/blob/main/test.dv"
    click out "https://github.com/deviant-liang/deviant/blob/main/out.ll"
    click Input "https://github.com/deviant-liang/deviant/blob/main/include/user_input.h"
    click Lexer "https://github.com/deviant-liang/deviant/blob/main/include/lexer.h"
    click Parser "https://github.com/deviant-liang/deviant/blob/main/include/parser.h"
    click AST "https://github.com/deviant-liang/deviant/blob/main/include/ast.h"
    click Codegen "https://github.com/deviant-liang/deviant/blob/main/include/deviant_llvm.h"

    classDef internal fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef external fill:#90EE90,stroke:#000,stroke-width:1px
    classDef config fill:#FFFACD,stroke:#000,stroke-width:1px
    classDef docs fill:#D3D3D3,stroke:#000,stroke-width:1px
```
