# jallib/jalv2compiler architecture

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

- Interactive diagram: https://gitdiagram.com/jallib/jalv2compiler
- Repository: https://github.com/jallib/jalv2compiler

## Overview

JALV2 compiles a Pascal-like JAL program for Microchip PIC devices. The principal workflow is source tokenization and JAL parsing, construction and optimization of compiler state/commands, then PIC-specific code generation and output. The tree and README establish the compiler’s purpose and device-file requirement; sampled excerpts confirm parts of the intermediate representation and backend, but not the complete driver or all output wiring.

Main entry points: [`src/libcore/pfile.c`](https://github.com/jallib/jalv2compiler/blob/master/src/libcore/pfile.c) (Compiler state), [`src/jal/jal_tokn.c`](https://github.com/jallib/jalv2compiler/blob/master/src/jal/jal_tokn.c) (Tokenization), [`src/libpic12/pic.c`](https://github.com/jallib/jalv2compiler/blob/master/src/libpic12/pic.c) (PIC code generation), [`src/jal/jal_main.c`](https://github.com/jallib/jalv2compiler/blob/master/src/jal/jal_main.c) (Compiler entry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_front["JAL frontend"]
  node_driver["Compiler entry<br/>[jal_main.c]"]
  node_tokens["Tokenization<br/>[jal_tokn.c]"]
  node_expressions["Expression parsing<br/>[jal_expr.c]"]
  node_declarations["Declarations<br/>[jal_vdef.c]"]
  node_procedures["Procedure parsing<br/>[jal_proc.c]"]
  node_control["Control parsing<br/>[jal_ctrl.c]"]
  node_includes["Includes and pragmas<br/>[jal_incl.c]"]
end

subgraph group_core["Compiler core"]
  node_state["Compiler state<br/>[pfile.c]"]
  node_values["Values and variables<br/>[variable.c]"]
  node_commands["Command IR<br/>[cmd.c]"]
  node_optimization["Command optimization<br/>[cmd_optm.c]"]
end

subgraph group_backend["PIC backend"]
  node_pic["PIC code generation<br/>[pic.c]"]
  node_operators["PIC operators<br/>[pic_op.c]"]
  node_builtins["PIC built-ins<br/>[pic_opfn.c]"]
  node_devices["PIC device families<br/>[pic12.c]"]
end

subgraph group_output["Compiler output"]
  node_assembly["Assembly output<br/>[jal_asm.c]"]
  node_cod["COD metadata<br/>[cod_file.c]"]
end

node_user(("Programmer"))
node_source["JAL source"]

node_user -->|"writes"| node_source
node_user -->|"invokes"| node_driver
node_driver -->|"parses input"| node_tokens
node_tokens -->|"supplies tokens"| node_expressions
node_tokens -->|"supplies tokens"| node_declarations
node_tokens -->|"supplies tokens"| node_procedures
node_tokens -->|"supplies tokens"| node_control
node_tokens -->|"supplies tokens"| node_includes
node_expressions -->|"builds expressions"| node_state
node_declarations -->|"records declarations"| node_state
node_procedures -->|"records procedures"| node_state
node_control -->|"records blocks"| node_state
node_includes -->|"updates settings"| node_state
node_state -->|"manages values"| node_values
node_state -->|"records commands"| node_commands
node_commands -->|"optimizes"| node_optimization
node_pic -->|"generates operations"| node_operators
node_pic -->|"generates built-ins"| node_builtins
node_pic -->|"targets families"| node_devices
node_optimization -->|"provides commands"| node_pic
node_pic -->|"emits assembly"| node_assembly
node_pic -.->|"writes metadata"| node_cod

click node_driver "https://github.com/jallib/jalv2compiler/blob/master/src/jal/jal_main.c"
click node_tokens "https://github.com/jallib/jalv2compiler/blob/master/src/jal/jal_tokn.c"
click node_expressions "https://github.com/jallib/jalv2compiler/blob/master/src/jal/jal_expr.c"
click node_declarations "https://github.com/jallib/jalv2compiler/blob/master/src/jal/jal_vdef.c"
click node_procedures "https://github.com/jallib/jalv2compiler/blob/master/src/jal/jal_proc.c"
click node_control "https://github.com/jallib/jalv2compiler/blob/master/src/jal/jal_ctrl.c"
click node_includes "https://github.com/jallib/jalv2compiler/blob/master/src/jal/jal_incl.c"
click node_state "https://github.com/jallib/jalv2compiler/blob/master/src/libcore/pfile.c"
click node_values "https://github.com/jallib/jalv2compiler/blob/master/src/libcore/variable.c"
click node_commands "https://github.com/jallib/jalv2compiler/blob/master/src/libcore/cmd.c"
click node_optimization "https://github.com/jallib/jalv2compiler/blob/master/src/libcore/cmd_optm.c"
click node_pic "https://github.com/jallib/jalv2compiler/blob/master/src/libpic12/pic.c"
click node_operators "https://github.com/jallib/jalv2compiler/blob/master/src/libpic12/pic_op.c"
click node_builtins "https://github.com/jallib/jalv2compiler/blob/master/src/libpic12/pic_opfn.c"
click node_devices "https://github.com/jallib/jalv2compiler/blob/master/src/libpic12/pic12.c"
click node_assembly "https://github.com/jallib/jalv2compiler/blob/master/src/jal/jal_asm.c"
click node_cod "https://github.com/jallib/jalv2compiler/blob/master/src/libutils/cod_file.c"

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_driver,node_tokens,node_expressions,node_declarations,node_procedures,node_control,node_includes toneBlue
class node_state,node_values,node_commands,node_optimization toneAmber
class node_pic,node_operators,node_builtins,node_devices toneMint
class node_assembly,node_cod toneRose
class node_user,node_source toneIndigo
```

## Components

### JAL frontend

- [Compiler entry](https://github.com/jallib/jalv2compiler/blob/master/src/jal/jal_main.c): `src/jal/jal_main.c`
- [Tokenization](https://github.com/jallib/jalv2compiler/blob/master/src/jal/jal_tokn.c): `src/jal/jal_tokn.c`
- [Expression parsing](https://github.com/jallib/jalv2compiler/blob/master/src/jal/jal_expr.c): `src/jal/jal_expr.c`
- [Declarations](https://github.com/jallib/jalv2compiler/blob/master/src/jal/jal_vdef.c): `src/jal/jal_vdef.c`
- [Procedure parsing](https://github.com/jallib/jalv2compiler/blob/master/src/jal/jal_proc.c): `src/jal/jal_proc.c`
- [Control parsing](https://github.com/jallib/jalv2compiler/blob/master/src/jal/jal_ctrl.c): `src/jal/jal_ctrl.c`
- [Includes and pragmas](https://github.com/jallib/jalv2compiler/blob/master/src/jal/jal_incl.c): `src/jal/jal_incl.c`

### Compiler core

- [Compiler state](https://github.com/jallib/jalv2compiler/blob/master/src/libcore/pfile.c): `src/libcore/pfile.c`
- [Values and variables](https://github.com/jallib/jalv2compiler/blob/master/src/libcore/variable.c): `src/libcore/variable.c`
- [Command IR](https://github.com/jallib/jalv2compiler/blob/master/src/libcore/cmd.c): `src/libcore/cmd.c`
- [Command optimization](https://github.com/jallib/jalv2compiler/blob/master/src/libcore/cmd_optm.c): `src/libcore/cmd_optm.c`

### PIC backend

- [PIC code generation](https://github.com/jallib/jalv2compiler/blob/master/src/libpic12/pic.c): `src/libpic12/pic.c`
- [PIC operators](https://github.com/jallib/jalv2compiler/blob/master/src/libpic12/pic_op.c): `src/libpic12/pic_op.c`
- [PIC built-ins](https://github.com/jallib/jalv2compiler/blob/master/src/libpic12/pic_opfn.c): `src/libpic12/pic_opfn.c`
- [PIC device families](https://github.com/jallib/jalv2compiler/blob/master/src/libpic12/pic12.c): `src/libpic12/pic12.c`

### Compiler output

- [Assembly output](https://github.com/jallib/jalv2compiler/blob/master/src/jal/jal_asm.c): `src/jal/jal_asm.c`
- [COD metadata](https://github.com/jallib/jalv2compiler/blob/master/src/libutils/cod_file.c): `src/libutils/cod_file.c`

### Other components

- **Programmer**
- **JAL source**

## Connections

- Programmer → JAL source: writes
- Programmer → Compiler entry: invokes
- Compiler entry → Tokenization: parses input
- Tokenization → Expression parsing: supplies tokens
- Tokenization → Declarations: supplies tokens
- Tokenization → Procedure parsing: supplies tokens
- Tokenization → Control parsing: supplies tokens
- Tokenization → Includes and pragmas: supplies tokens
- Expression parsing → Compiler state: builds expressions
- Declarations → Compiler state: records declarations
- Procedure parsing → Compiler state: records procedures
- Control parsing → Compiler state: records blocks
- Includes and pragmas → Compiler state: updates settings
- Compiler state → Values and variables: manages values
- Compiler state → Command IR: records commands
- Command IR → Command optimization: optimizes
- PIC code generation → PIC operators: generates operations
- PIC code generation → PIC built-ins: generates built-ins
- PIC code generation → PIC device families: targets families
- Command optimization → PIC code generation: provides commands
- PIC code generation → Assembly output: emits assembly
- PIC code generation → COD metadata: writes metadata
