# vectorpikachu/transpiler-from-c-to-dafny architecture

> Architecture diagram of the GitHub repository vectorpikachu/transpiler-from-c-to-dafny, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/vectorpikachu/transpiler-from-c-to-dafny
- Repository: https://github.com/vectorpikachu/transpiler-from-c-to-dafny

## Overview

##### Main Components

a) Input/Output Layer:
- Input: C source files (.c)
- Output: Dafny files (.dfy)

b) Core Processing Components (based on the src/ directory):
- Preprocessing Module (preprocess.rs)
- Context Management (context.rs)
- AST Conversion System (converter.rs)
- Dafny AST Representation (dafny_ast.rs)
- Tree Traversal Engine (traverse.rs)
- Code Generation/Printing (printer.rs)

##### External Dependencies Layer
- Tree-sitter (C parser)
- Tree-sitter-c

##### Flow and Relationships

**[C Source Code] → [Tree-sitter Parser] → [AST Processing Pipeline] → [Dafny Output]**

Where the AST Processing Pipeline should be expanded to show:
**[Preprocessor] → [Context Manager] → [AST Converter] → [Tree Traversal] → [Dafny Printer]**

##### Additional Details

- Version/dependency information for tree-sitter
- Configuration or intermediate file generation points
- Where error handling occurs in the pipeline

##### Key Relationships to Highlight

- The relationship between converter.rs and dafny_ast.rs
- How traverse.rs interacts with the AST structures
- The role of context.rs in managing state during conversion
- The final printing phase using printer.rs

## Diagram (Mermaid)

```mermaid
flowchart TB
    classDef input fill:#b3d9ff,stroke:#333,stroke-width:2px
    classDef output fill:#b3d9ff,stroke:#333,stroke-width:2px
    classDef process fill:#90EE90,stroke:#333,stroke-width:2px
    classDef external fill:#ffeb99,stroke:#333,stroke-width:2px
    classDef support fill:#d9d9d9,stroke:#333,stroke-width:2px

    subgraph Input
        CSource[".c Source Files"]:::input
        click CSource "https://github.com/vectorpikachu/Transpiler-from-C-to-Dafny/blob/master/hello.c"
    end

    subgraph "External Dependencies"
        TreeSitter["Tree-sitter Parser"]:::external
        TreeSitterC["Tree-sitter-c Grammar"]:::external
    end

    subgraph "Processing Pipeline"
        Main["Main Entry Point"]:::process
        click Main "https://github.com/vectorpikachu/Transpiler-from-C-to-Dafny/blob/master/src/main.rs"
        
        Preprocess["Preprocessing Module"]:::process
        click Preprocess "https://github.com/vectorpikachu/Transpiler-from-C-to-Dafny/blob/master/src/preprocess.rs"
        
        Context["Context Management"]:::process
        click Context "https://github.com/vectorpikachu/Transpiler-from-C-to-Dafny/blob/master/src/context.rs"
        
        Converter["AST Conversion System"]:::process
        click Converter "https://github.com/vectorpikachu/Transpiler-from-C-to-Dafny/blob/master/src/converter.rs"
        
        DafnyAST["Dafny AST Representation"]:::process
        click DafnyAST "https://github.com/vectorpikachu/Transpiler-from-C-to-Dafny/blob/master/src/dafny_ast.rs"
        
        Traverse["Tree Traversal Engine"]:::process
        click Traverse "https://github.com/vectorpikachu/Transpiler-from-C-to-Dafny/blob/master/src/traverse.rs"
        
        Printer["Code Generation/Printing"]:::process
        click Printer "https://github.com/vectorpikachu/Transpiler-from-C-to-Dafny/blob/master/src/printer.rs"
    end

    subgraph Output
        DafnyOut[".dfy Output Files"]:::output
        click DafnyOut "https://github.com/vectorpikachu/Transpiler-from-C-to-Dafny/blob/master/hello.dfy"
        
        DebugAST["AST Debug Output"]:::support
        click DebugAST "https://github.com/vectorpikachu/Transpiler-from-C-to-Dafny/blob/master/syntax_tree.txt"
        
        Documentation["System Documentation"]:::support
        click Documentation "https://github.com/vectorpikachu/Transpiler-from-C-to-Dafny/blob/master/docs/doc.pdf"
    end

    %% Flow connections
    CSource --> TreeSitter
    TreeSitter --> TreeSitterC
    TreeSitterC --> Main
    Main --> Preprocess
    Preprocess --> Context
    Context --> Converter
    Converter --> DafnyAST
    DafnyAST --> Traverse
    Traverse --> Printer
    Printer --> DafnyOut
    Traverse -.-> DebugAST
    
    %% Support connections
    Context -.-> DafnyAST
    Converter -.-> Context
    
    %% Legend
    subgraph Legend
        L1[" Input/Output"]:::input
        L2[" Processing"]:::process
        L3[" External Dependencies"]:::external
        L4[" Support/Debug"]:::support
    end
```
