# berkeley-abc/abc architecture

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

- Interactive diagram: https://gitdiagram.com/berkeley-abc/abc
- Repository: https://github.com/berkeley-abc/abc

## Overview

##### Project Type and Purpose
- ABC is a monolithic, performance‐oriented C/C++ system for sequential logic synthesis and formal verification.
- It exposes both a command‐line interface (“abc” binary) and a static/shared library API (`Abc_Start()`, `Abc_Stop()`).
- It ingests hardware description formats (AIGER, BLIF, Verilog, SMT, etc.), applies synthesis/optimization/verification passes, and emits reports or transformed netlists.

##### Top-Level Components
a. Front-End Interfaces
- Command-Line Client (src/base/main, starter.c)
- Demo Application (src/demo.c)
- Static Library API (`Abc_Start()`, `Abc_Stop()`)
b. Core Engine
- Main Dispatcher (`main.c`, cmd.c)
- Data Structures & Managers (AIG, BDD, PLA, Verilog representations in src/aig, src/bdd, src/base/pla, src/base/ver)
c. Algorithm Modules
- Logic Rewriting & Optimization (src/aig/*, src/opt/*)
- Technology Mapping (src/map/*)
- Verification & Proof (src/proof/*, src/sat/*)
- Timing, Placement & Routing Helpers (src/phys/*)
d. I/O & Utilities
- File Readers/Writers (src/base/io, ioRead*/ioWrite*)
- Parsing & Formats (BLIF, AIGER, SMT, Verilog modules)
- Miscellaneous Libraries (src/misc/*: zlib, bzip2, hash tables, vectors, parse utilities)
e. External Dependencies
- pthreads (lib/pthread*), readline, math (`-lm`), dynamic loader (`-ldl`)

##### Relationships & Data Flow
- User issues a command or calls the API → Front-End
- Front-End invokes Core Dispatcher → loads input via I/O module → builds in-memory network (AIG/BDD)
- Core Dispatcher schedules passes in Algorithm Modules
- Each pass reads/modifies the in-memory model, possibly invoking SAT/BMC in src/sat or proof engines in src/proof
- Results fed back to Core Dispatcher → written out by I/O module or reported to user

##### Architectural Patterns & Principles
- Plugin-like module.make system: each module registers its commands and callbacks at init time
- Separation of concerns: I/O layer, core data structures, algorithmic modules, external solver interfaces
- Incremental extension: new passes can be dropped into src/opt or src/map and hooked via module.make

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User
    U["User"]:::user

    %% Front-End Interfaces
    subgraph "Front-End Interfaces"
        direction TB
        CLI["CLI Client"]:::frontend
        Demo["Demo Application"]:::frontend
        API["Static Library API"]:::frontend
    end

    %% Core Engine
    subgraph "Core Engine"
        direction TB
        Dispatcher["Dispatcher & Pass Manager"]:::core
    end

    %% I/O Layer
    subgraph "I/O Layer"
        direction TB
        IO["File Readers/Writers"]:::core
    end

    %% Core Data Structures
    subgraph "Core Data Structures"
        direction TB
        AIG["AIG Manager"]:::core
        BDD["BDD Manager"]:::core
        PLA["PLA Manager"]:::core
        Verilog["Verilog Parser"]:::core
    end

    %% Algorithm Modules
    subgraph "Algorithm Modules"
        direction TB
        subgraph "Optimization" 
            RWR["Rewriting (rwr)"]:::plugin
            RWT["Rewriting (rwt)"]:::plugin
        end
        subgraph "Mapping"
            MAP["Tech Mapper"]:::plugin
        end
        subgraph "Verification"
            PROOF["Proof Engines"]:::plugin
            SATIF["SAT Solver Interfaces"]:::plugin
        end
        subgraph "Physical"
            PHYS["Placement & Routing"]:::plugin
        end
    end

    %% External Dependencies
    subgraph "External Dependencies"
        direction TB
        PTHREAD["pthreads"]:::external
    end

    %% Build & Test
    subgraph "Build & Test"
        direction TB
        BUILD["Build System"]:::external
        TEST["Test Harness"]:::external
    end

    %% Connections
    U -->|"issues command or API call"| CLI
    U -->|"issues command or API call"| Demo
    U -->|"calls Abc_Start()/Stop()"| API
    CLI -->|invokes| Dispatcher
    Demo -->|invokes| Dispatcher
    API -->|invokes| Dispatcher

    Dispatcher -->|reads input| IO
    IO -->|builds network| AIG
    IO -->|builds network| BDD
    IO -->|builds network| PLA
    IO -->|parses input| Verilog

    Dispatcher -->|schedules| RWR
    Dispatcher -->|schedules| RWT
    Dispatcher -->|schedules| MAP
    Dispatcher -->|schedules| PROOF
    Dispatcher -->|schedules| SATIF
    Dispatcher -->|schedules| PHYS

    RWR <-->|reads/modifies| AIG
    RWT <-->|reads/modifies| AIG
    MAP <-->|reads/modifies| AIG
    PROOF <-->|invokes| BDD
    SATIF <-->|invokes| externalSAT[/"External SAT Solvers"/]:::external
    PHYS <-->|reads/modifies| AIG

    Dispatcher -->|writes output| IO
    IO -->|returns results| CLI
    IO -->|returns results| Demo
    IO -->|returns results| API

    %% Click Events
    click CLI "https://github.com/berkeley-abc/abc/blob/master/src/base/main/main.c"
    click Demo "https://github.com/berkeley-abc/abc/blob/master/src/demo.c"
    click API "https://github.com/berkeley-abc/abc/blob/master/src/base/main/abcapis.h"
    click API "https://github.com/berkeley-abc/abc/blob/master/src/base/main/libSupport.c"
    click Dispatcher "https://github.com/berkeley-abc/abc/blob/master/src/base/cmd/cmd.c"
    click AIG "https://github.com/berkeley-abc/abc/tree/master/src/aig/aig"
    click BDD "https://github.com/berkeley-abc/abc/tree/master/src/bdd/cudd"
    click PLA "https://github.com/berkeley-abc/abc/blob/master/src/base/pla/pla.c"
    click Verilog "https://github.com/berkeley-abc/abc/blob/master/src/base/ver/verParse.c"
    click RWR "https://github.com/berkeley-abc/abc/blob/master/src/opt/rwr/rwrDec.c"
    click RWT "https://github.com/berkeley-abc/abc/blob/master/src/opt/rwt/rwtDec.c"
    click MAP "https://github.com/berkeley-abc/abc/blob/master/src/map/mapper/mapperCore.c"
    click PROOF "https://github.com/berkeley-abc/abc/tree/master/src/proof"
    click SATIF "https://github.com/berkeley-abc/abc/blob/master/src/sat/bsat/satSolver.c"
    click PHYS "https://github.com/berkeley-abc/abc/blob/master/src/phys/place/place_base.c"
    click IO "https://github.com/berkeley-abc/abc/blob/master/src/base/io/ioReadBlif.c"
    click PTHREAD "https://github.com/berkeley-abc/abc/blob/master/lib/pthread.h"
    click BUILD "https://github.com/berkeley-abc/abc/blob/master/CMakeLists.txt"
    click BUILD "https://github.com/berkeley-abc/abc/tree/master/Makefile"
    click TEST "https://github.com/berkeley-abc/abc/blob/master/test/CMakeLists.txt"
    click TEST "https://github.com/berkeley-abc/abc/blob/master/test/gia/gia_test.cc"

    %% Styles
    classDef user fill:#D0E8FF,stroke:#0050A0,color:#003060;
    classDef frontend fill:#E0F7FA,stroke:#007C91,color:#004B59;
    classDef core fill:#C5CAE9,stroke:#3F51B5,color:#1A237E;
    classDef plugin fill:#C8E6C9,stroke:#388E3C,color:#1B5E20;
    classDef external fill:#FFE0B2,stroke:#FB8C00,color:#E65100;
```
