# wanderer1500/riscv_cpu architecture

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

- Interactive diagram: https://gitdiagram.com/wanderer1500/riscv_cpu
- Repository: https://github.com/wanderer1500/riscv_cpu

## Overview

##### Project Type and Purpose
- The project is an implementation of a RISC-V CPU, likely targeting simulation or an educational lab environment.
- It focuses on the behavior and functionality of a RISC-V based processor, possibly emphasizing CPU modifications or experimental features (as hinted by “CpuModified.cpp”).

##### Analyzing the File Structure
- Since we only have two major C++ source files, it is clear that the project does not follow a multi-layer or multi-tier setup like a full-stack application.
- The file names suggest separation by purpose:
- cpu_lab.cpp might serve as the main driver or testing harness for running the CPU simulation.
- CpuModified.cpp may encapsulate modifications or extended functionalities to the basic CPU design.
- There isn’t a conventional separation into frontend/backend or MVC components; instead, we need to focus on internal components of the CPU simulation.

a. CPU Core:
- Central processing unit as the “RiscV CPU Core.”
- Instruction Fetch Unit
- Instruction Decode Unit
- Execution/ALU Unit
- Memory Access Unit (if applicable)
- Write Back Unit
- These divisions might not directly match file boundaries but will capture the conceptual architecture.

b. Simulation/Test Harness:
- “CPU Lab/Simulation Driver” which is likely implemented in cpu_lab.cpp.
- How this component initializes the CPU, feeds in instructions, and possibly checks outputs or performance.

c. Extended/Modified Components:
- Since there is a file called CpuModified.cpp, highlight any modifications or extended functionalities.

##### Highlighting Architectural Patterns and Technologies
- Design principles such as modularity in the CPU design, the separation of concerns (simulation driver vs. CPU core), and the potential pipeline flow inherent in RISC-V processor designs.

- A section for the “RiscV CPU Core” broken down further into sub-modules (Fetch, Decode, Execute/ALU, Memory Access, Write Back).
- A section for the “Lab/Simulation Driver” component (likely from cpu_lab.cpp) that interacts with the CPU.
- An annotation or highlighted area representing “Modified CPU functionalities” from CpuModified.cpp.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% RiscV CPU Core Subgraph
    subgraph "RiscV CPU Core"
        RF["Instruction Fetch Unit"]:::cpu
        RD["Instruction Decode Unit"]:::cpu
        EX["Execution/ALU Unit"]:::cpu
        MEM["Memory Access Unit"]:::cpu
        WB["Write Back Unit"]:::cpu
        Modified["Modified CPU functionalities"]:::cpuModification
        %% Pipeline flow within the CPU Core
        RF -->|"fetched"| RD
        RD -->|"decoded"| EX
        EX -->|"processed"| MEM
        MEM -->|"data"| WB
        %% Feedback loop from Write Back to Instruction Fetch
        WB -->|"feedback"| RF
        %% Link the modified functionalities to the Execution unit
        EX --->|"modified_by"| Modified
    end

    %% Simulation/Test Harness Subgraph
    subgraph "Simulation/Test Harness"
        CPULab["CPU Lab Driver"]:::simulation
    end

    %% Project Documentation Node
    Doc["Project Documentation"]:::doc

    %% Relationship: Simulation driver initializes the CPU Core
    CPULab -->|"initializes"| RF

    %% Click Events
    click Modified "https://github.com/wanderer1500/riscv_cpu/blob/main/CpuModified.cpp"
    click CPULab "https://github.com/wanderer1500/riscv_cpu/blob/main/cpu_lab.cpp"
    click Doc "https://github.com/wanderer1500/riscv_cpu/blob/main/README.md"

    %% Styles for nodes
    classDef cpu fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef simulation fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef doc fill:#ABEBC6,stroke:#1D8348,stroke-width:2px;
    classDef cpuModification fill:#F5B7B1,stroke:#C0392B,stroke-width:2px;
```
