# morilhat-paul/preprocessor architecture

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

- Interactive diagram: https://gitdiagram.com/morilhat-paul/preprocessor
- Repository: https://github.com/morilhat-paul/preprocessor

## Overview

##### Main Components
a. Source Modules
- main.c: the entry point, contains your core logic and uses macros.
- main.h: declarations for functions or types used by main.c.
- log.h: header defining logging macros (operators, directives) you’re experimenting with.
b. Build System
- Makefile: orchestrates preprocessing, compilation, and linking.
c. Build Stages (Processes)
- Preprocessor: expands all #includes, macros, conditional directives.
- Compiler (cc/gcc): parses the expanded source into object code.
- Linker: resolves symbols, produces final executable.
d. Artifacts
- .o object files (intermediate).
- final executable (e.g., a.out or named binary).

##### Relationships & Data Flow
- main.c “includes” main.h and log.h → send these into the preprocessor.
- Preprocessor outputs a single translation unit (fully expanded C code).
- Compiler consumes that translation unit → produces main.o.
- Linker takes main.o → spits out the executable.
- Makefile triggers each stage in sequence (with proper flags).

##### Architectural/Design Principles
- Modularity via headers: separate declarations (main.h) vs macro definitions (log.h).
- Preprocessor exploration: illustrate how macros in log.h affect the expanded code.
- Single compilation unit: all inclusion happens before compilation, no dynamic linking or plugins.

##### Relevant Technologies & Tools
- GNU Make (Makefile).
- C Preprocessor (cpp).
- GCC or equivalent C compiler.
- Standard C build pipeline.

##### Detail Without Overthinking
- Even though it’s small, capture each distinct step.
- How log.h’s macros inject code during preprocessing.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Source Code
    mainC["main.c"]:::source
    mainH["main.h"]:::source
    logH["log.h"]:::source

    %% Build Orchestrator
    Makefile["Makefile"]:::process

    %% Build Processes
    Preprocessor["Preprocessor\n(#include + Macro Expansion)"]:::process
    Compiler["Compiler\n(Compile)"]:::process
    Linker["Linker\n(Link)"]:::process

    %% Artifacts
    TU[".i (Expanded Translation Unit)"]:::artifact
    OBJ["main.o"]:::artifact
    Exe["executable"]:::artifact

    %% Relationships
    Makefile -->|"trigger Preprocessing"| Preprocessor
    Makefile -->|"trigger Compilation"| Compiler
    Makefile -->|"trigger Linking"| Linker

    mainC -->|"includes"| Preprocessor
    mainH -->|"includes"| Preprocessor
    logH -->|"includes"| Preprocessor

    Preprocessor -->|"expands to"| TU
    TU -->|"compile"| Compiler
    Compiler -->|"produces"| OBJ
    OBJ -->|"link"| Linker
    Linker -->|"produce"| Exe

    %% Click Events
    click mainC "https://github.com/morilhat-paul/preprocessor/blob/master/./main.c"
    click mainH "https://github.com/morilhat-paul/preprocessor/blob/master/./main.h"
    click logH "https://github.com/morilhat-paul/preprocessor/blob/master/./log.h"
    click Makefile "https://github.com/morilhat-paul/preprocessor/tree/master/./Makefile"

    %% Styles
    classDef source fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef process fill:#90EE90,stroke:#333,stroke-width:1px
    classDef artifact fill:#FFA500,stroke:#333,stroke-width:1px
```
