# fubukimaru/asmsx architecture

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

- Interactive diagram: https://gitdiagram.com/fubukimaru/asmsx
- Repository: https://github.com/fubukimaru/asmsx

## Overview

##### Project type and purpose
- asMSX is a command‐line, Z80 cross‐assembler targeting the MSX home‐computer platform. It reads assembly source, runs a compile‐time pipeline (lexing, parsing, semantic analysis, code generation), and emits binary images or ROMs for MSX.

##### File structure
- Top‐level:
- src/            ← core assembler implementation in C, Flex and Bison grammar files
- Headers mixed in src/ (.h) and inc folders under code/wrally (example game)
- code/           ← example MSX assembly projects demonstrating assembler output
- doc/            ← manuals, coding style, testing guidelines
- ref/            ← reference docs for Z80 and MSX internals
- test/           ← Python‐based integration tests and Gherkin features
- Dockerfile & .github/workflows ← container image build and CI pipelines
- Makefile        ← local build orchestrator using GCC/Flex/Bison

##### README for additional insights
- Confirms technology stack: GCC, Flex, Bison
- Describes project as GPLv3 Z80 cross‐assembler, usage via CLI or Docker
- Points to testing guide and coding style

##### Main components
a. Frontend (Source Processing)
– Command‐line Interface (main)
– Flex Lexer (lex.l)
– Bison Parser (dura.y + parser*.l)
– AST/Symbol Table modules (labels.c/.h, types.h)
b. Semantic Analyzer & Intermediate Representation
– labels.c/.h (symbol resolution)
– types.h (operand/type management)
c. Backend & Code Generator
– src/*.c modules that emit Z80 opcodes, handling MSX paging (projects in code/wrally/inc)
– output formatter producing .bin, .rom, or tape images
d. Build & DevOps
– Makefile / Dockerfile orchestrating GCC/Flex/Bison → asmsx binary
– GitHub Actions/workflows for CI, Docker‐build, release drafting
e. Test Harness
– Python environment (test/environment.py)
– Gherkin feature tests (test/features/*.feature)
– Step definitions (test/steps/*.py) invoking the CLI and verifying outputs

##### Relationships & data flow
– User supplies `.asm` files → CLI passes them to Flex Lexer → tokens to Bison Parser → build AST → semantic analysis & symbol resolution → code generator emits binary → post‐processing (e.g., UPX compression, packing into .rom) → final MSX image
– Build tools (Make/Docker) orchestrate compilation of C/lexer/parser code → produce asmsx executable
– CI jobs pull source → build container → run tests → publish Docker image & GitHub release

##### Architectural patterns & principles
– Compiler pipeline (lexer → parser → semantic → codegen)
– Modular C architecture: separate translation units for lexing, parsing, symbol management, and output
– Assembler extensibility: grammar in Bison, Z80 instructions data‐driven where possible
– CI/CD flow decoupled via container images

## Diagram (Mermaid)

```mermaid
flowchart TB
  %% Compiler Pipeline
  subgraph "Compiler Pipeline"
    direction TB
    CLI["CLI Frontend\n(src/asmsx.c)"]:::frontend
    Lexer["Flex Lexer\n(src/lex.l)"]:::frontend
    Parser["Bison Parser\n(src/dura.y)"]:::frontend
    Parser1["Parser Def 1\n(src/parser1.l)"]:::frontend
    Parser2["Parser Def 2\n(src/parser2.l)"]:::frontend
    Parser3["Parser Def 3\n(src/parser3.l)"]:::frontend
    Parser4["Parser Def 4\n(src/parser4.l)"]:::frontend
    Semantic["Symbol Table & Semantic Analysis\n(src/labels.c)"]:::backend
    Types["Type/Operand Management\n(src/types.h)"]:::backend
    Codegen["Code Generator & Output Formatter\n(src/asmsx.c)"]:::backend
    Output["Binary/ROM Image"]:::backend

    CLI -->|"source .asm"| Lexer
    Lexer -->|"tokens"| Parser
    Parser -->|"AST"| Semantic
    Parser1 --> Parser
    Parser2 --> Parser
    Parser3 --> Parser
    Parser4 --> Parser
    Semantic --> Types
    Types --> Codegen
    Codegen -->|"binary"| Output
  end

  %% Example Projects
  subgraph "Example Projects"
    direction TB
    ASMExamples["Assembly Projects\n(code/*.asm)"]:::example
    MSXGame["MSX Game Project\n(code/wrally/)"]:::example
  end

  Output --> ASMExamples
  ASMExamples --> MSXGame

  %% DevOps & Build
  subgraph "Build & CI/CD"
    direction TB
    Make["Makefile"]:::devops
    Docker["Dockerfile"]:::devops
    CI["GitHub Actions\n(.github/workflows)"]:::devops
  end

  Make -->|"build C/Flex/Bison"| CLI
  Docker --> Make
  CI --> Docker
  CI --> Make

  %% Documentation & References
  subgraph "Documentation"
    direction TB
    Doc1["User Manual\n(doc/asmsx.md)"]:::docs
    Doc2["Coding Style\n(doc/coding-style.md)"]:::docs
    Doc3["Testing Guide\n(doc/testing.md)"]:::docs
  end

  subgraph "Reference Manuals"
    direction TB
    Ref1["RedBook-Konamiman\n(ref/RedBook-Konamiman.txt)"]:::docs
    Ref2["A Red Book\n(ref/aredbook.txt)"]:::docs
    Ref3["Grammar Slides\n(ref/slides-GrammarDisambiguation.pdf)"]:::docs
    Ref4["Z80 Docs\n(ref/Undocumented Z80 Documented, The (Sean Young).pdf)"]:::docs
  end

  %% Test Harness
  subgraph "Test Harness"
    direction TB
    Env["Environment Setup\n(test/environment.py)"]:::test
    Features["Feature Specs\n(test/features/*.feature)"]:::test
    Steps["Step Definitions\n(test/steps/*.py)"]:::test
  end

  CI --> Env
  Env --> Features
  Features --> Steps
  Steps --> CLI

  %% Click Events
  click CLI "https://github.com/fubukimaru/asmsx/blob/master/src/asmsx.c"
  click Lexer "https://github.com/fubukimaru/asmsx/blob/master/src/lex.l"
  click Parser "https://github.com/fubukimaru/asmsx/blob/master/src/dura.y"
  click Parser1 "https://github.com/fubukimaru/asmsx/blob/master/src/parser1.l"
  click Parser2 "https://github.com/fubukimaru/asmsx/blob/master/src/parser2.l"
  click Parser3 "https://github.com/fubukimaru/asmsx/blob/master/src/parser3.l"
  click Parser4 "https://github.com/fubukimaru/asmsx/blob/master/src/parser4.l"
  click Semantic "https://github.com/fubukimaru/asmsx/blob/master/src/labels.c"
  click Types "https://github.com/fubukimaru/asmsx/blob/master/src/types.h"
  click Codegen "https://github.com/fubukimaru/asmsx/blob/master/src/asmsx.c"
  click ASMExamples "https://github.com/fubukimaru/asmsx/blob/master/code/*.asm"
  click MSXGame "https://github.com/fubukimaru/asmsx/tree/master/code/wrally/"
  click Make "https://github.com/fubukimaru/asmsx/tree/master/Makefile"
  click Docker "https://github.com/fubukimaru/asmsx/tree/master/Dockerfile"
  click CI "https://github.com/fubukimaru/asmsx/blob/master/.github/workflows/build.yml"
  %% note: mapping had multiple workflows, linking to primary
  click Doc1 "https://github.com/fubukimaru/asmsx/blob/master/doc/asmsx.md"
  click Doc2 "https://github.com/fubukimaru/asmsx/blob/master/doc/coding-style.md"
  click Doc3 "https://github.com/fubukimaru/asmsx/blob/master/doc/testing.md"
  click Ref1 "https://github.com/fubukimaru/asmsx/blob/master/ref/RedBook-Konamiman.txt"
  click Ref2 "https://github.com/fubukimaru/asmsx/blob/master/ref/aredbook.txt"
  click Ref3 "https://github.com/fubukimaru/asmsx/blob/master/ref/slides-GrammarDisambiguation.pdf"
  click Ref4 "https://github.com/fubukimaru/asmsx/blob/master/ref/Undocumented Z80 Documented, The (Sean Young).pdf"
  click Env "https://github.com/fubukimaru/asmsx/blob/master/test/environment.py"
  click Features "https://github.com/fubukimaru/asmsx/blob/master/test/features/bugs.feature"
  click Steps "https://github.com/fubukimaru/asmsx/blob/master/test/steps/build.py"

  %% Styles
  classDef frontend fill:#D0E8FF,stroke:#0066CC
  classDef backend fill:#DFFFD0,stroke:#339900
  classDef devops fill:#F2E2C4,stroke:#CC9900
  classDef test fill:#E8D0FF,stroke:#6600CC
  classDef docs fill:#FFF2CC,stroke:#CCCC00
  classDef example fill:#FFE0E0,stroke:#CC0000
```
