# compilemylife/mips-lite architecture

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

- Interactive diagram: https://gitdiagram.com/compilemylife/mips-lite
- Repository: https://github.com/compilemylife/mips-lite

## Overview

##### Project type and purpose
- This is a command-line educational simulator (“MIPS Lite Simulator”) that models an in-order 5-stage MIPS pipeline.
- It reads an assembly or memory image file, decodes instructions, and simulates IF, ID, EX, MEM, and WB stages in separate threads.

##### File structure
- Top‐level:
- Makefile & README.md – build and usage instructions
- hazardTest*.txt – sample input and explanation files for verifying pipeline hazards
- noHazardTest.txt – control test case
- / – public headers for each pipeline stage thread (IF_thread.h, ID_thread.h, …), TSqueue (thread-safe FIFO), decoder, masterHelpers, and sys_core
- src/ – implementation files for each component mirror the headers, plus main.cpp to launch the simulation
- Key configuration: Makefile defines compile/link steps; no external deployment descriptors

##### README
- Confirms purpose and build/run commands

##### Detail
- Thread-safe queue pattern and highlight that each queue enforces FIFO between producer and consumer threads

## Diagram (Mermaid)

```mermaid
flowchart TB
    A["CLI Frontend\n(src/main.cpp)"]:::orchestrator
    B["System Core\n(sys_core.cpp/h)"]:::orchestrator
    C[/"Input Files\n(memory image & hazard tests)"/]:::input

    A -->|"initializes"| B
    C -->|"feeds"| A

    subgraph "5-Stage Pipeline"
        direction TB
        IF["IF Stage\n(IF_thread.cpp/h)"]:::stage
        Q1["IF→ID TSqueue<T>"]:::queue
        ID["ID Stage\n(ID_thread.cpp/h)"]:::stage
        Q2["ID→EX TSqueue<T>"]:::queue
        EX["EX Stage\n(EX_thread.cpp/h)"]:::stage
        Q3["EX→MEM TSqueue<T>"]:::queue
        MEM["MEM Stage\n(MEM_thread.cpp/h)"]:::stage
        Q4["MEM→WB TSqueue<T>"]:::queue
        WB["WB Stage\n(WB_thread.cpp/h)"]:::stage
    end

    B -->|"spawns thread"| IF
    IF -->|"pushes instruction"| Q1
    Q1 -->|"pops for decode"| ID
    ID -->|"pushes decoded"| Q2
    Q2 --> EX
    EX --> Q3
    Q3 --> MEM
    MEM --> Q4
    Q4 --> WB

    subgraph "Utilities"
        direction TB
        D["Decoder\n(decoder.cpp/h)"]:::util
        M["masterHelpers\n(masterHelpers.cpp/h)"]:::util
    end

    ID -.uses.-> D
    IF -.uses.-> M
    ID -.uses.-> M
    EX -.uses.-> M
    MEM -.uses.-> M
    WB -.uses.-> M

    subgraph "Build Artifacts"
        MF["Makefile"]:::build
        RD["README.md"]:::build
    end

    MF -.builds.-> A
    RD -.docs.-> A

    click A "https://github.com/compilemylife/mips-lite/blob/main/src/main.cpp"
    click B "https://github.com/compilemylife/mips-lite/blob/main/include/sys_core.h"
    click IF "https://github.com/compilemylife/mips-lite/blob/main/include/IF_thread.h"
    click ID "https://github.com/compilemylife/mips-lite/blob/main/include/ID_thread.h"
    click EX "https://github.com/compilemylife/mips-lite/blob/main/include/EX_thread.h"
    click MEM "https://github.com/compilemylife/mips-lite/blob/main/include/MEM_thread.h"
    click WB "https://github.com/compilemylife/mips-lite/blob/main/include/WB_thread.h"
    click Q1 "https://github.com/compilemylife/mips-lite/blob/main/include/TSqueue.h"
    click D "https://github.com/compilemylife/mips-lite/blob/main/include/decoder.h"
    click M "https://github.com/compilemylife/mips-lite/blob/main/include/masterHelpers.h"
    click MF "https://github.com/compilemylife/mips-lite/tree/main/Makefile"
    click RD "https://github.com/compilemylife/mips-lite/blob/main/README.md"

    classDef orchestrator fill:#FFD700,stroke:#333,stroke-width:1px
    classDef stage fill:#87CEFA,stroke:#333,stroke-width:1px
    classDef queue fill:#FFB6C1,stroke:#333,stroke-width:1px,stroke-dasharray:5 5
    classDef util fill:#90EE90,stroke:#333,stroke-width:1px,stroke-dasharray:5 5
    classDef input fill:#D3D3D3,stroke:#333,stroke-width:1px,stroke-dasharray:2 2
    classDef build fill:#F0E68C,stroke:#333,stroke-width:1px,stroke-dasharray:5 5
```
