# rohinthan/cco-lang architecture

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

- Interactive diagram: https://gitdiagram.com/rohinthan/cco-lang
- Repository: https://github.com/rohinthan/cco-lang

## Overview

Cco is a statically typed compiled language whose compiler takes source through lexical and syntactic analysis, module and semantic resolution, then IR lowering and optimization before selecting a C11 or native x86-64 output path. The native path includes instruction selection, encoding, ELF generation and linking; the C11 path emits portable C for a host compiler. The README documents additional language capabilities represented as frontend/semantic subsystems. Some subsystem paths are directories because their detailed implementation was not excerpted; edges reflect README statements or visible source-index references.

Main entry points: [`src/main.c`](https://github.com/rohinthan/cco-lang/blob/main/src/main.c) (Compiler driver), [`src/backend/x86_64/x86_64_codegen.c`](https://github.com/rohinthan/cco-lang/blob/main/src/backend/x86_64/x86_64_codegen.c) (x86-64 codegen), [`src/frontend/parser.c`](https://github.com/rohinthan/cco-lang/blob/main/src/frontend/parser.c) (Parser and AST), [`src/ir/ir_lower.c`](https://github.com/rohinthan/cco-lang/blob/main/src/ir/ir_lower.c) (IR lowering)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_lexer["Lexer<br/>[lexer.c]"]
  node_parser["Parser and AST<br/>[parser.c]"]
  node_modules["Module resolver<br/>[module_resolver.c]"]
  node_scope["Scope analysis<br/>[scope_analysis.c]"]
  node_classes["Class declarations<br/>[class_decl.c]"]
  node_traits["Trait resolution<br/>[trait_resolver.c]"]
end

subgraph group_ir["IR and Optimization"]
  node_lower["IR lowering<br/>[ir_lower.c]"]
  node_ircore["IR representation<br/>[ir.c]"]
  node_verify["IR verification<br/>[ir_verify.c]"]
  node_ssa["SSA construction<br/>[ir_ssa.c]"]
  node_ssaopt["SSA optimization<br/>[ir_ssa_opt.c]"]
  node_iropt["IR optimization<br/>[ir_opt.c]"]
  node_ipa["Interprocedural analysis<br/>[ir_ipa.c]"]
end

subgraph group_c11["C11 Backend"]
  node_cgen["C code generation<br/>[codegen.c]"]
end

subgraph group_native["Native Backend"]
  node_nativegen["x86-64 codegen<br/>[x86_64_codegen.c]"]
  node_regalloc["Register allocation<br/>[x86_64_regalloc.c]"]
  node_instr["Instruction representation<br/>[x86_64_instr.c]"]
  node_encode["Machine encoding<br/>[x86_64_encode.c]"]
  node_elf["ELF object writer<br/>[x86_64_elf.c]"]
  node_linker["Native linker<br/>[x86_64_link.c]"]
  node_runtime["Freestanding runtime"]
end

node_user(("Cco programmer"))
node_driver["Compiler driver<br/>[main.c]"]
node_ccompiler["Host C compiler"]

node_user -->|"provides source"| node_driver
node_driver -->|"starts lexing"| node_lexer
node_driver -->|"parses tokens"| node_parser
node_driver -->|"resolves imports"| node_modules
node_driver -->|"checks scopes"| node_scope
node_driver -->|"resolves traits"| node_traits
node_parser -->|"builds declarations"| node_classes
node_driver -->|"lowers AST"| node_lower
node_lower -->|"creates IR"| node_ircore
node_driver -->|"verifies IR"| node_verify
node_driver -->|"builds SSA"| node_ssa
node_driver -->|"optimizes SSA"| node_ssaopt
node_driver -->|"optimizes IR"| node_iropt
node_driver -->|"runs IPA"| node_ipa
node_driver -->|"selects C11 path"| node_cgen
node_cgen -->|"emits C for"| node_ccompiler
node_driver -->|"selects native path"| node_nativegen
node_nativegen -->|"uses allocation"| node_regalloc
node_nativegen -->|"emits instructions"| node_instr
node_nativegen -->|"encodes instructions"| node_encode
node_nativegen -->|"writes object"| node_elf
node_driver -->|"invokes linking"| node_linker
node_linker -->|"embeds startup"| node_runtime

click node_driver "https://github.com/rohinthan/cco-lang/blob/main/src/main.c"
click node_lexer "https://github.com/rohinthan/cco-lang/blob/main/src/frontend/lexer.c"
click node_parser "https://github.com/rohinthan/cco-lang/blob/main/src/frontend/parser.c"
click node_modules "https://github.com/rohinthan/cco-lang/blob/main/src/frontend/module_resolver.c"
click node_scope "https://github.com/rohinthan/cco-lang/blob/main/src/frontend/scope_analysis.c"
click node_classes "https://github.com/rohinthan/cco-lang/blob/main/src/frontend/class_decl.c"
click node_traits "https://github.com/rohinthan/cco-lang/blob/main/src/frontend/trait_resolver.c"
click node_lower "https://github.com/rohinthan/cco-lang/blob/main/src/ir/ir_lower.c"
click node_ircore "https://github.com/rohinthan/cco-lang/blob/main/src/ir/ir.c"
click node_verify "https://github.com/rohinthan/cco-lang/blob/main/src/ir/ir_verify.c"
click node_ssa "https://github.com/rohinthan/cco-lang/blob/main/src/ir/ir_ssa.c"
click node_ssaopt "https://github.com/rohinthan/cco-lang/blob/main/src/ir/ir_ssa_opt.c"
click node_iropt "https://github.com/rohinthan/cco-lang/blob/main/src/ir/ir_opt.c"
click node_ipa "https://github.com/rohinthan/cco-lang/blob/main/src/ir/ir_ipa.c"
click node_cgen "https://github.com/rohinthan/cco-lang/blob/main/src/backend/c11/codegen.c"
click node_nativegen "https://github.com/rohinthan/cco-lang/blob/main/src/backend/x86_64/x86_64_codegen.c"
click node_regalloc "https://github.com/rohinthan/cco-lang/blob/main/src/backend/x86_64/x86_64_regalloc.c"
click node_instr "https://github.com/rohinthan/cco-lang/blob/main/src/backend/x86_64/x86_64_instr.c"
click node_encode "https://github.com/rohinthan/cco-lang/blob/main/src/backend/x86_64/x86_64_encode.c"
click node_elf "https://github.com/rohinthan/cco-lang/blob/main/src/backend/x86_64/x86_64_elf.c"
click node_linker "https://github.com/rohinthan/cco-lang/blob/main/src/backend/x86_64/x86_64_link.c"
click node_runtime "https://github.com/rohinthan/cco-lang/blob/main/src/runtime/runtime_start_data.h"

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_lexer,node_parser,node_modules,node_scope,node_classes,node_traits toneBlue
class node_lower,node_ircore,node_verify,node_ssa,node_ssaopt,node_iropt,node_ipa toneAmber
class node_cgen toneMint
class node_nativegen,node_regalloc,node_instr,node_encode,node_elf,node_linker,node_runtime toneRose
class node_user,node_ccompiler toneIndigo
class node_driver toneTeal
```

## Components

### Frontend

- [Lexer](https://github.com/rohinthan/cco-lang/blob/main/src/frontend/lexer.c): `src/frontend/lexer.c`
- [Parser and AST](https://github.com/rohinthan/cco-lang/blob/main/src/frontend/parser.c): `src/frontend/parser.c`
- [Module resolver](https://github.com/rohinthan/cco-lang/blob/main/src/frontend/module_resolver.c): `src/frontend/module_resolver.c`
- [Scope analysis](https://github.com/rohinthan/cco-lang/blob/main/src/frontend/scope_analysis.c): `src/frontend/scope_analysis.c`
- [Class declarations](https://github.com/rohinthan/cco-lang/blob/main/src/frontend/class_decl.c): `src/frontend/class_decl.c`
- [Trait resolution](https://github.com/rohinthan/cco-lang/blob/main/src/frontend/trait_resolver.c): `src/frontend/trait_resolver.c`

### IR and Optimization

- [IR lowering](https://github.com/rohinthan/cco-lang/blob/main/src/ir/ir_lower.c): `src/ir/ir_lower.c`
- [IR representation](https://github.com/rohinthan/cco-lang/blob/main/src/ir/ir.c): `src/ir/ir.c`
- [IR verification](https://github.com/rohinthan/cco-lang/blob/main/src/ir/ir_verify.c): `src/ir/ir_verify.c`
- [SSA construction](https://github.com/rohinthan/cco-lang/blob/main/src/ir/ir_ssa.c): `src/ir/ir_ssa.c`
- [SSA optimization](https://github.com/rohinthan/cco-lang/blob/main/src/ir/ir_ssa_opt.c): `src/ir/ir_ssa_opt.c`
- [IR optimization](https://github.com/rohinthan/cco-lang/blob/main/src/ir/ir_opt.c): `src/ir/ir_opt.c`
- [Interprocedural analysis](https://github.com/rohinthan/cco-lang/blob/main/src/ir/ir_ipa.c): `src/ir/ir_ipa.c`

### C11 Backend

- [C code generation](https://github.com/rohinthan/cco-lang/blob/main/src/backend/c11/codegen.c): `src/backend/c11/codegen.c`

### Native Backend

- [x86-64 codegen](https://github.com/rohinthan/cco-lang/blob/main/src/backend/x86_64/x86_64_codegen.c): `src/backend/x86_64/x86_64_codegen.c`
- [Register allocation](https://github.com/rohinthan/cco-lang/blob/main/src/backend/x86_64/x86_64_regalloc.c): `src/backend/x86_64/x86_64_regalloc.c`
- [Instruction representation](https://github.com/rohinthan/cco-lang/blob/main/src/backend/x86_64/x86_64_instr.c): `src/backend/x86_64/x86_64_instr.c`
- [Machine encoding](https://github.com/rohinthan/cco-lang/blob/main/src/backend/x86_64/x86_64_encode.c): `src/backend/x86_64/x86_64_encode.c`
- [ELF object writer](https://github.com/rohinthan/cco-lang/blob/main/src/backend/x86_64/x86_64_elf.c): `src/backend/x86_64/x86_64_elf.c`
- [Native linker](https://github.com/rohinthan/cco-lang/blob/main/src/backend/x86_64/x86_64_link.c): `src/backend/x86_64/x86_64_link.c`
- [Freestanding runtime](https://github.com/rohinthan/cco-lang/blob/main/src/runtime/runtime_start_data.h): `src/runtime/runtime_start_data.h`

### Other components

- **Cco programmer**
- [Compiler driver](https://github.com/rohinthan/cco-lang/blob/main/src/main.c): `src/main.c`
- **Host C compiler**

## Connections

- Cco programmer → Compiler driver: provides source
- Compiler driver → Lexer: starts lexing (evidence: `src/main.c`)
- Compiler driver → Parser and AST: parses tokens (evidence: `src/main.c`)
- Compiler driver → Module resolver: resolves imports (evidence: `src/main.c`)
- Compiler driver → Scope analysis: checks scopes (evidence: `src/main.c`)
- Compiler driver → Trait resolution: resolves traits (evidence: `src/main.c`)
- Parser and AST → Class declarations: builds declarations
- Compiler driver → IR lowering: lowers AST (evidence: `src/main.c`)
- IR lowering → IR representation: creates IR
- Compiler driver → IR verification: verifies IR (evidence: `src/main.c`)
- Compiler driver → SSA construction: builds SSA
- Compiler driver → SSA optimization: optimizes SSA (evidence: `src/main.c`)
- Compiler driver → IR optimization: optimizes IR
- Compiler driver → Interprocedural analysis: runs IPA
- Compiler driver → C code generation: selects C11 path (evidence: `src/main.c`)
- C code generation → Host C compiler: emits C for
- Compiler driver → x86-64 codegen: selects native path (evidence: `src/main.c`)
- x86-64 codegen → Register allocation: uses allocation (evidence: `src/backend/x86_64/x86_64_codegen.c`)
- x86-64 codegen → Instruction representation: emits instructions (evidence: `src/backend/x86_64/x86_64_codegen.c`)
- x86-64 codegen → Machine encoding: encodes instructions (evidence: `src/backend/x86_64/x86_64_codegen.c`)
- x86-64 codegen → ELF object writer: writes object (evidence: `src/backend/x86_64/x86_64_codegen.c`)
- Compiler driver → Native linker: invokes linking (evidence: `src/main.c`)
- Native linker → Freestanding runtime: embeds startup (evidence: `src/backend/x86_64/x86_64_link.c`)
