# iamzhz/ababiu architecture

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

- Interactive diagram: https://gitdiagram.com/iamzhz/ababiu
- Repository: https://github.com/iamzhz/ababiu

## Overview

##### Project type and purpose
- This is a compiler for a toy programming language called “Ababiu.”
- It reads `.abb` source files, lexes them, parses into an AST/IR, performs semantic analysis and transformations, generates x86-64 assembly, then relies on `nasm`/`gcc` plus a small runtime library (`libababiu`) to produce a native executable.

##### File structure
- Top-level:
- build scripts: `makefile`, `CMakeLists.txt`, `xmake.lua`
- runtime library: `libababiu/`
- sources: `src/` with one subdirectory per compiler phase or helper
- tests: `src/main_test.cc`, `test.abb`
- Phase modules under `src/`:
- CmdLineParser – handles CLI flags and input/output filenames
- FileManager – reads/writes source and generated files
- Lexer – tokenizes the input text
- Parser – builds AST (including control, loop, function, unit nodes)
- IR – intermediate representation container
- Symbol – symbol table & scope management
- PointerManager, AutoAssign, StackEraser – semantic/optimization passes
- CodeGen – emits raw x86-64 assembly
- SayError – centralized error reporting
- debug – debugging utilities
- env_config – compile‐time configuration
- main.cc – orchestrates whole pipeline

##### README for additional insights
- It sketches the build and compile flow:
- compile `ababiu` executable → transform `.abb` to `assembly.asm` → assemble + link with `libababiu.o` → run.

##### Elements
- Labels: use clear, concise names (“Lexer Module,” “Parser Module,” “CodeGen Module,” etc.)
- External tools/runtime in neutral tones

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Driver/CLI Module
    subgraph "Driver / CLI Module"
        direction TB
        CMD["CmdLineParser"]:::driver
        FM["FileManager"]:::driver
        EC["env_config"]:::driver
        MAIN["main.cc"]:::driver
    end

    %% Frontend
    subgraph "Frontend (Lexing & Parsing)"
        direction TB
        LEX["Lexer"]:::frontend
        PAR["Parser"]:::frontend
        ERR["SayError"]:::frontend
    end

    %% Semantic & IR Passes
    subgraph "Semantic & IR Passes"
        direction TB
        IRMOD["IR"]:::semantic
        SYM["Symbol"]:::semantic
        AA["AutoAssign"]:::semantic
        PM["PointerManager"]:::semantic
        SE["StackEraser"]:::semantic
    end

    %% Backend
    subgraph "Backend / Code Generation"
        direction TB
        CG["CodeGen"]:::backend
    end

    %% Runtime Library
    subgraph "Runtime Library"
        direction TB
        LIB["libababiu.c"]:::library
    end

    %% External Tools
    subgraph "External Tools"
        direction TB
        NASM["nasm"]:::ext
        GCC["gcc / linker"]:::ext
    end

    %% Data Flow
    MAIN -->|"loads config & parses CLI"| EC
    MAIN -->|"reads source"| FM
    FM -->|"source text"| LEX
    LEX -->|"tokens"| PAR
    PAR -->|"AST/IR"| ERR
    PAR -->|"AST/IR"| IRMOD
    ERR -->|handles errors| PAR
    IRMOD -->|"IR"| SYM
    SYM -->|"validated IR"| AA
    AA -->|"transformed IR"| PM
    PM -->|"transformed IR"| SE
    SE -->|"final IR"| CG
    CG -->|"assembly.asm"| FM
    FM -->|"assembly.asm"| NASM
    LIB -->|"libababiu.o"| GCC
    NASM -->|"object file"| GCC
    GCC -->|"executable"| MAIN

    %% Click Events
    click CMD "https://github.com/iamzhz/ababiu/blob/main/src/CmdLineParser/CmdLineParser.cc"
    click FM "https://github.com/iamzhz/ababiu/blob/main/src/FileManager/FileManager.cc"
    click EC "https://github.com/iamzhz/ababiu/blob/main/src/env_config/config.h"
    click MAIN "https://github.com/iamzhz/ababiu/blob/main/src/main.cc"
    click LEX "https://github.com/iamzhz/ababiu/blob/main/src/Lexer/Lexer.cc"
    click PAR "https://github.com/iamzhz/ababiu/blob/main/src/Parser/Parser.cc"
    click ERR "https://github.com/iamzhz/ababiu/blob/main/src/SayError/SayError.cc"
    click IRMOD "https://github.com/iamzhz/ababiu/blob/main/src/IR/IR.cc"
    click SYM "https://github.com/iamzhz/ababiu/blob/main/src/Symbol/Symbol.cc"
    click AA "https://github.com/iamzhz/ababiu/blob/main/src/AutoAssign/AutoAssign.cc"
    click PM "https://github.com/iamzhz/ababiu/blob/main/src/PointerManager/PointerManager.cc"
    click SE "https://github.com/iamzhz/ababiu/blob/main/src/StackEraser/StackEraser.cc"
    click CG "https://github.com/iamzhz/ababiu/blob/main/src/CodeGen/CodeGen.cc"
    click LIB "https://github.com/iamzhz/ababiu/blob/main/libababiu/libababiu.c"

    %% Styles
    classDef driver fill:#E3F2FD,stroke:#90CAF9,color:#0D47A1
    classDef frontend fill:#FFEBEE,stroke:#EF9A9A,color:#B71C1C
    classDef semantic fill:#E8F5E9,stroke:#A5D6A7,color:#1B5E20
    classDef backend fill:#FFF3E0,stroke:#FFCC80,color:#E65100
    classDef library fill:#EDE7F6,stroke:#B39DDB,color:#4A148C
    classDef ext fill:#CFD8DC,stroke:#90A4AE,color:#263238
```
