# oceanosdev/mycc architecture

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

- Interactive diagram: https://gitdiagram.com/oceanosdev/mycc
- Repository: https://github.com/oceanosdev/mycc

## Overview

This repository implements the Com S 440 compiler project: it reads C-like source, parses and type-checks the documented language features, and includes a JVM bytecode generation backend. The principal workflow is source input through parsing, binding/type checking, and code generation; command-line modes also expose token, syntax-tree, and bound-tree output. The tree shows distinct flow-analysis and bound-tree-rewriting subsystems, but sampled excerpts do not establish their exact connection to code generation, so that wiring is omitted.

Main entry points: [`main.cpp`](https://github.com/oceanosdev/mycc/blob/master/main.cpp) (Mode Dispatcher), [`binding/binder.cpp`](https://github.com/oceanosdev/mycc/blob/master/binding/binder.cpp) (Binder and Type Checker), [`driver.cpp`](https://github.com/oceanosdev/mycc/blob/master/driver.cpp) (Lexer and Parser), [`jvm_processor/j_asm_builder.cpp`](https://github.com/oceanosdev/mycc/blob/master/jvm_processor/j_asm_builder.cpp) (JVM Assembler)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_front["Front End"]
  node_main["Mode Dispatcher<br/>[main.cpp]"]
  node_args["Argument Parser<br/>[arg_parser.cpp]"]
  node_driver["Lexer and Parser<br/>[driver.cpp]"]
  node_lexer["Lexical Analysis<br/>[lexer.h]"]
  node_syntax["Syntax Trees"]
  node_syntaxout["Syntax Tree Output"]
end

subgraph group_semantic["Semantic Analysis"]
  node_binder["Binder and Type Checker<br/>[binder.cpp]"]
  node_bound["Bound Trees<br/>[bound_program.cpp]"]
  node_symbols["Symbols and Types<br/>[type_symbol.cpp]"]
  node_boundout["Bound Tree Output"]
  node_rewriter["Bound Tree Rewriter<br/>[tree_rewriter.cpp]"]
end

subgraph group_backend["JVM Backend"]
  node_codegen["Code Generator<br/>[code_generator.cpp]"]
  node_emitter["Statement and Expression Emission"]
  node_assembler["JVM Assembler<br/>[j_asm_builder.cpp]"]
  node_instructions["JVM Instructions<br/>[instruction.cpp]"]
  node_output["Generated JVM Body<br/>[finalized_body.h]"]
end

subgraph group_support["Diagnostics and Analysis"]
  node_flow["Control Flow Analysis"]
  node_diagnostics["Diagnostics<br/>[diagnostics.cpp]"]
  node_logger["Output Logger<br/>[logger.cpp]"]
end

node_user(("Compiler User"))

node_user -->|"selects mode"| node_main
node_main -->|"parses options"| node_args
node_main -->|"runs parsing"| node_driver
node_driver -->|"scans source"| node_lexer
node_driver -->|"builds units"| node_syntax
node_main -.->|"prints syntax tree"| node_syntaxout
node_main -->|"binds program"| node_binder
node_binder -->|"produces bound tree"| node_bound
node_binder -->|"resolves types"| node_symbols
node_binder -->|"reports errors"| node_diagnostics
node_main -.->|"prints bound tree"| node_boundout
node_main -->|"starts generation"| node_codegen
node_codegen -->|"emits statements"| node_emitter
node_emitter -->|"builds instructions"| node_assembler
node_assembler -->|"records instructions"| node_instructions
node_assembler -->|"finalizes body"| node_output
node_main -->|"selects output"| node_logger
node_diagnostics -->|"logs diagnostics"| node_logger

click node_main "https://github.com/oceanosdev/mycc/blob/master/main.cpp"
click node_args "https://github.com/oceanosdev/mycc/blob/master/arg_parser.cpp"
click node_driver "https://github.com/oceanosdev/mycc/blob/master/driver.cpp"
click node_lexer "https://github.com/oceanosdev/mycc/blob/master/lexer.h"
click node_syntax "https://github.com/oceanosdev/mycc/blob/master/syntax/translation_unit_node.cpp"
click node_syntaxout "https://github.com/oceanosdev/mycc/blob/master/syntax_tree_printer.cpp"
click node_binder "https://github.com/oceanosdev/mycc/blob/master/binding/binder.cpp"
click node_bound "https://github.com/oceanosdev/mycc/blob/master/binding/bound_program.cpp"
click node_symbols "https://github.com/oceanosdev/mycc/blob/master/symbols/type_symbol.cpp"
click node_boundout "https://github.com/oceanosdev/mycc/blob/master/bound_tree_printer.cpp"
click node_rewriter "https://github.com/oceanosdev/mycc/blob/master/binding/tree_rewriter.cpp"
click node_flow "https://github.com/oceanosdev/mycc/blob/master/flow_analysis/control_flow_graph_factory.cpp"
click node_diagnostics "https://github.com/oceanosdev/mycc/blob/master/logging/diagnostics.cpp"
click node_codegen "https://github.com/oceanosdev/mycc/blob/master/codegen/code_generator.cpp"
click node_emitter "https://github.com/oceanosdev/mycc/blob/master/codegen/code_gen_emit_stmt.cpp"
click node_assembler "https://github.com/oceanosdev/mycc/blob/master/jvm_processor/j_asm_builder.cpp"
click node_instructions "https://github.com/oceanosdev/mycc/blob/master/jvm_processor/instruction.cpp"
click node_output "https://github.com/oceanosdev/mycc/blob/master/jvm_processor/finalized_body.h"
click node_logger "https://github.com/oceanosdev/mycc/blob/master/logging/logger.cpp"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_args,node_driver,node_lexer,node_syntax,node_syntaxout,node_user toneBlue
class node_binder,node_bound,node_symbols,node_boundout,node_rewriter toneAmber
class node_codegen,node_emitter,node_assembler,node_instructions,node_output toneMint
class node_flow,node_diagnostics,node_logger toneRose
```

## Components

### Front End

- [Mode Dispatcher](https://github.com/oceanosdev/mycc/blob/master/main.cpp): `main.cpp`
- [Argument Parser](https://github.com/oceanosdev/mycc/blob/master/arg_parser.cpp): `arg_parser.cpp`
- [Lexer and Parser](https://github.com/oceanosdev/mycc/blob/master/driver.cpp): `driver.cpp`
- [Lexical Analysis](https://github.com/oceanosdev/mycc/blob/master/lexer.h): `lexer.h`
- [Syntax Trees](https://github.com/oceanosdev/mycc/blob/master/syntax/translation_unit_node.cpp): `syntax/translation_unit_node.cpp`
- [Syntax Tree Output](https://github.com/oceanosdev/mycc/blob/master/syntax_tree_printer.cpp): `syntax_tree_printer.cpp`

### Semantic Analysis

- [Binder and Type Checker](https://github.com/oceanosdev/mycc/blob/master/binding/binder.cpp): `binding/binder.cpp`
- [Bound Trees](https://github.com/oceanosdev/mycc/blob/master/binding/bound_program.cpp): `binding/bound_program.cpp`
- [Symbols and Types](https://github.com/oceanosdev/mycc/blob/master/symbols/type_symbol.cpp): `symbols/type_symbol.cpp`
- [Bound Tree Output](https://github.com/oceanosdev/mycc/blob/master/bound_tree_printer.cpp): `bound_tree_printer.cpp`
- [Bound Tree Rewriter](https://github.com/oceanosdev/mycc/blob/master/binding/tree_rewriter.cpp): `binding/tree_rewriter.cpp`

### JVM Backend

- [Code Generator](https://github.com/oceanosdev/mycc/blob/master/codegen/code_generator.cpp): `codegen/code_generator.cpp`
- [Statement and Expression Emission](https://github.com/oceanosdev/mycc/blob/master/codegen/code_gen_emit_stmt.cpp): `codegen/code_gen_emit_stmt.cpp`
- [JVM Assembler](https://github.com/oceanosdev/mycc/blob/master/jvm_processor/j_asm_builder.cpp): `jvm_processor/j_asm_builder.cpp`
- [JVM Instructions](https://github.com/oceanosdev/mycc/blob/master/jvm_processor/instruction.cpp): `jvm_processor/instruction.cpp`
- [Generated JVM Body](https://github.com/oceanosdev/mycc/blob/master/jvm_processor/finalized_body.h): `jvm_processor/finalized_body.h`

### Diagnostics and Analysis

- [Control Flow Analysis](https://github.com/oceanosdev/mycc/blob/master/flow_analysis/control_flow_graph_factory.cpp): `flow_analysis/control_flow_graph_factory.cpp`
- [Diagnostics](https://github.com/oceanosdev/mycc/blob/master/logging/diagnostics.cpp): `logging/diagnostics.cpp`
- [Output Logger](https://github.com/oceanosdev/mycc/blob/master/logging/logger.cpp): `logging/logger.cpp`

### Other components

- **Compiler User**

## Connections

- Compiler User → Mode Dispatcher: selects mode
- Mode Dispatcher → Argument Parser: parses options
- Mode Dispatcher → Lexer and Parser: runs parsing
- Lexer and Parser → Lexical Analysis: scans source
- Lexer and Parser → Syntax Trees: builds units
- Mode Dispatcher → Syntax Tree Output: prints syntax tree
- Mode Dispatcher → Binder and Type Checker: binds program
- Binder and Type Checker → Bound Trees: produces bound tree
- Binder and Type Checker → Symbols and Types: resolves types
- Binder and Type Checker → Diagnostics: reports errors
- Mode Dispatcher → Bound Tree Output: prints bound tree
- Mode Dispatcher → Code Generator: starts generation
- Code Generator → Statement and Expression Emission: emits statements
- Statement and Expression Emission → JVM Assembler: builds instructions
- JVM Assembler → JVM Instructions: records instructions
- JVM Assembler → Generated JVM Body: finalizes body
- Mode Dispatcher → Output Logger: selects output
- Diagnostics → Output Logger: logs diagnostics
