# kaist-cp/kecc-public architecture

> Architecture diagram of the GitHub repository kaist-cp/kecc-public, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kaist-cp/kecc-public
- Repository: https://github.com/kaist-cp/kecc-public

## Overview

##### Main Components (Top Level)
- Rectangle (Blue): Frontend (C Parser)
- Rectangle (Green): IR Generation & Optimization Pipeline
- Rectangle (Orange): Backend (Assembly Generation)
- Rectangle (Gray): Support Systems (Testing/Fuzzing)

##### Pipeline Stages (Left to Right Flow)

- [C Source] -> [Parser] -> [IR Gen] -> [Optimization Passes] -> [ASM Gen] -> [RISC-V Binary]

##### IR Transformation Stages (Detail View)
Different IR levels (IR0 through IR4) as intermediate steps:
- IR0 -> IR1 -> IR2 -> IR3 -> IR4

##### Optimization Components (Subcomponents)
- Dead Code Elimination
- Global Value Numbering (GVN)
- Memory to Register Promotion (mem2reg)
- CFG Simplification

##### Testing/Support Infrastructure
Parallel systems that support the main pipeline:
- Fuzzing Framework
- Test Suite
- Benchmark System

Key Elements to Include:

##### Special Features
- IR Interpreter
- IR Visualizer
- Debug Information Flow

**□ Processing Stage**
**○ Data Format**
**◇ Optimization Pass**
**∆ Testing Component**

**Lines:**
**→ Direct Data Flow**
**⟶ Control Flow**
**⟵⟶ Bidirectional Interaction**

**🔵 Core Components**
**🟢 Optimization**
**🟡 Input/Output**
**⚪ Support Tools**

Level of Detail:
- Keep the top-level view focused on the main compilation pipeline
1. IR Transformation Pipeline
2. Optimization Framework
3. Testing Infrastructure
4. Build System

##### The separation between core compiler components and support infrastructure

This structure reflects the project's organization as seen in the src/ directory and matches the compilation stages described in the README's usage instructions.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Input
        source[C Source Code]:::input
    end

    subgraph "Frontend Layer"
        parser["C Parser"]:::frontend
    end

    subgraph "IR Generation & Pipeline"
        irgen["IR Generator"]:::irgen
        
        subgraph "IR Stages"
            ir0["IR0"]:::ir
            ir1["IR1"]:::ir
            ir2["IR2"]:::ir
            ir3["IR3"]:::ir
            ir4["IR4"]:::ir
        end
        
        subgraph "Optimization Framework"
            direction TB
            opt["Optimization Controller"]:::opt
            dce["Dead Code Elimination"]:::opt
            gvn["Global Value Numbering"]:::opt
            m2r["Memory to Register"]:::opt
            cfg["CFG Simplification"]:::opt
        end
    end

    subgraph "Backend Layer"
        asmgen["Assembly Generator"]:::backend
        asmwrite["Assembly Writer"]:::backend
    end

    subgraph "Support Infrastructure"
        irinterp["IR Interpreter"]:::support
        irvis["IR Visualizer"]:::support
        fuzz["Fuzzing Framework"]:::support
        tests["Test Suite"]:::support
        bench["Benchmarking"]:::support
    end

    source --> parser
    parser --> irgen
    irgen --> ir0
    ir0 --> ir1
    ir1 --> ir2
    ir2 --> ir3
    ir3 --> ir4
    
    ir4 --> opt
    opt --> dce
    opt --> gvn
    opt --> m2r
    opt --> cfg
    
    cfg --> asmgen
    asmgen --> asmwrite
    
    irinterp -.-> ir0
    irinterp -.-> ir1
    irinterp -.-> ir2
    irinterp -.-> ir3
    irinterp -.-> ir4
    
    irvis -.-> ir0
    irvis -.-> ir1
    irvis -.-> ir2
    irvis -.-> ir3
    irvis -.-> ir4
    
    fuzz -.-> parser
    tests -.-> asmwrite
    bench -.-> asmwrite

    %% Styling
    classDef input fill:#FFE873
    classDef frontend fill:#4B8BBE
    classDef irgen fill:#306998
    classDef ir fill:#646464
    classDef opt fill:#4B8F8C
    classDef backend fill:#FFB836
    classDef support fill:#9DC3E6

    %% Click events
    click parser "https://github.com/kaist-cp/kecc-public/blob/main/src/c/parse.rs"
    click irgen "https://github.com/kaist-cp/kecc-public/blob/main/src/irgen/mod.rs"
    click ir0 "https://github.com/kaist-cp/kecc-public/tree/main/examples/ir0/"
    click ir1 "https://github.com/kaist-cp/kecc-public/tree/main/examples/ir1/"
    click ir2 "https://github.com/kaist-cp/kecc-public/tree/main/examples/ir2/"
    click ir3 "https://github.com/kaist-cp/kecc-public/tree/main/examples/ir3/"
    click ir4 "https://github.com/kaist-cp/kecc-public/tree/main/examples/ir4/"
    click opt "https://github.com/kaist-cp/kecc-public/blob/main/src/opt/mod.rs"
    click dce "https://github.com/kaist-cp/kecc-public/blob/main/src/opt/deadcode.rs"
    click gvn "https://github.com/kaist-cp/kecc-public/blob/main/src/opt/gvn.rs"
    click m2r "https://github.com/kaist-cp/kecc-public/blob/main/src/opt/mem2reg.rs"
    click cfg "https://github.com/kaist-cp/kecc-public/blob/main/src/opt/simplify_cfg.rs"
    click asmgen "https://github.com/kaist-cp/kecc-public/blob/main/src/asmgen/mod.rs"
    click asmwrite "https://github.com/kaist-cp/kecc-public/blob/main/src/asm/write_asm.rs"
    click irinterp "https://github.com/kaist-cp/kecc-public/blob/main/src/ir/interp.rs"
    click irvis "https://github.com/kaist-cp/kecc-public/blob/main/src/ir/visualize.rs"
    click fuzz "https://github.com/kaist-cp/kecc-public/blob/main/bin/fuzz.rs"
    click tests "https://github.com/kaist-cp/kecc-public/blob/main/tests/test_examples.rs"
    click bench "https://github.com/kaist-cp/kecc-public/tree/main/bench/"
```
