# deepf2c **Repository Path**: lurkerwzc/deepf2c ## Basic Information - **Project Name**: deepf2c - **Description**: No description available - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-06-08 - **Last Updated**: 2026-09-16 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # DeepF2C β€” Fortran to C++ Transpiler [![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE) [![Python](https://img.shields.io/badge/python-3.8%2B-blue.svg)](https://www.python.org/) **DeepF2C** is an automated tool that converts Fortran code (F77/F90) into C++ code with **ABI-level binary compatibility** β€” the generated C++ functions can be called directly by unconverted Fortran callers, and vice versa, at the assembly level without recompilation. --- ## ✨ Key Features - **πŸ”— ABI-Level Compatibility** β€” Generated C++ functions are fully binary-compatible with the original Fortran at the calling convention level, enabling seamless cross-language calls - **πŸ“¦ Incremental Migration** β€” Convert individual files or partial directories; no need for an all-or-nothing migration - **🧩 COMMON Block Sharing** β€” Fortran and C++ share COMMON block memory layout transparently - **πŸ”§ ifort-Friendly** β€” Supports ifort-specific behaviors (argument mismatch, Cray Pointers, and other non-standard patterns) - **πŸ“ Fixed & Free Format** β€” Supports both F77 fixed-format and F90 free-format source code - **πŸ§ͺ Rich Test Suite** β€” 1000+ minimal test cases covering common Fortran syntax features - **⚑ Incremental Pipeline** β€” 7-step conversion pipeline supports resume from any step and step control --- ## πŸ”§ Comparison with Similar Tools | Tool | Method | ABI Compat | ifort Support | Partial Convert | |------|--------|:---:|:---:|:---:| | f2c | Fortranβ†’C | ❌ | ❌ | ❌ | | fable | Fortranβ†’C++ | ❌ | ❌ | ❌ | | OpenFortranParser | Parse+Analysis | β€” | Partial | β€” | | **DeepF2C** | Fortranβ†’C++ + ABI Adapt | βœ… | βœ… | βœ… | --- ## πŸ“‹ Quick Start ### Requirements - **Python** 3.8+ - **C++ compiler**: g++ 8+ (for compiling generated C++) - **Fortran compiler**: gfortran or ifort (for verification testing) - **CMake** 3.14+ ### Basic Usage > **Python runner**: Prefer `pypy3` (faster). If `pypy3` is not available, replace with `python3` or `python`. ```bash # Convert a single Fortran file pypy3 scripts_v2/run_pipeline.py path/to/source.f # Convert an entire directory pypy3 scripts_v2/run_pipeline.py src/fortran/ # Step control β€” parse only, don't generate pypy3 scripts_v2/run_pipeline.py src/ --to-step parse # Resume from a specific step pypy3 scripts_v2/run_pipeline.py --from-step analyze # Specify integer/real width for C++ generation pypy3 scripts_v2/run_pipeline.py src/ --int8 --real8 # Check pipeline status python3 scripts_v2/run_pipeline.py --status ``` ### Running Tests ```bash # Run all tests (default: gfortran + ifort Γ— i4 + i8) python3 scripts_v2/test.py run # Run specific tests python3 scripts_v2/test.py run add_reals array_ops # Filter tests by name substring python3 scripts_v2/test.py run --filter common # Parallel build python3 scripts_v2/test.py run -j 16 # Compiler selection: python3 scripts_v2/test.py run --fc ifort python3 scripts_v2/test.py run --fc gfortran # Integer-width selection: python3 scripts_v2/test.py run -i 8 # List tests / summarize saved results: python3 scripts_v2/test.py list python3 scripts_v2/test.py report # Run all configs and update todo_v2.yml python3 scripts_v2/test.py update ``` --- ## πŸ—οΈ Project Architecture ``` src/ β”œβ”€β”€ ast_nodes.py # Typed AST nodes / NodeType enum β”œβ”€β”€ hir/ # Typed HIR nodes β”œβ”€β”€ cpp_ir/ # CppIR nodes, expressions, types, emitter β”œβ”€β”€ passes/ # Analysis/lowering pass pipeline β”œβ”€β”€ lowering/ # HIR β†’ CppIR lowering β”œβ”€β”€ abi/ # ABI adaptation layer β”œβ”€β”€ runtime/ # Header-only C++ runtime β”œβ”€β”€ steps/ # Pipeline step scripts β”œβ”€β”€ pipeline.py # Pipeline scheduler └── pipeline_utils.py # Shared utilities tests/ # πŸ§ͺ End-to-end test suite β”œβ”€β”€ e2e_single/ # Single-file tests β”œβ”€β”€ e2e_multi/ # Multi-file test directories β”œβ”€β”€ unit/ # Python unit tests β”œβ”€β”€ cmake/ # CMake modules + diff scripts └── blacklist.json # Known failure classifications (user-controlled) scripts_v2/ β”œβ”€β”€ run_pipeline.py # Pipeline entry point β”œβ”€β”€ test.py # Test runner v2 β”œβ”€β”€ tdd_loop.py # TDD repair loop └── edd_loop.py # Production-driven incremental replacement build_test_v2_* # Generated build artifacts ``` ### Pipeline Stages `discover β†’ survey β†’ preproc β†’ parse β†’ fallback β†’ analyze β†’ transform β†’ generate β†’ package` The transform stage runs the canonical pass pipeline defined in `src/passes/pipeline_def.py` (`Fortran AST β†’ HIR β†’ CppIR β†’ C++ text`). --- ## πŸ“¦ Runtime Library Generated C++ code depends on a lightweight set of header-only runtime files: | Header | Purpose | |--------|---------| | `common.h` | Type aliases (`f2c_integer`, `f2c_real`, ...), platform export macros | | `fortran_string.h` | Fixed-length Fortran strings `f2c_string`, space padding, 1-based slicing | | `intrinsics.h` | Intrinsic function wrappers: SIGN, DIM, MOD, MODULO, NINT, AINT, etc. | | `array.h` | Multi-dimensional arrays, column-major storage, 1-based indexing | | `array_intrinsics.h` | Array intrinsics: SIZE, SHAPE, LBOUND, UBOUND, etc. | | `common_manager.h` | COMMON block memory management | | `unit_manager.h` | I/O unit number management | | `write.h` / `stop.h` | WRITE / STOP statement implementations | --- ## πŸ§ͺ Testing Strategy The test framework uses a **dual-compilation comparison** strategy to verify ABI compatibility: 1. **Fortran side**: compile the original `.f` file β†’ run β†’ capture stdout 2. **C++ side**: DeepF2C converts β†’ g++ compiles β†’ run β†’ capture stdout 3. **Comparison**: both outputs must match **character-for-character** Fortran output is cached under `tests/cache/` (git-managed). The v2 runner stores structured results in `tests/cache/results/` and can regenerate `todo_v2.yml` with `python3 scripts_v2/test.py update`. ### Test Naming Tests are single `.f`/`.f90` files in `tests/e2e_single/`. Multi-file tests are subdirectories with their own `CMakeLists.txt` and `f2c_convert.txt`. Each test must produce stdout output (PRINT/WRITE). ### Blacklist System `tests/blacklist.json` categorizes known failures by compiler: - `gfortran` / `ifort` β€” Compiler cannot compile the source - `convert` β€” Pipeline conversion failure - `build` β€” C++ compilation failure - `diff` β€” Output mismatch --- ## πŸ“– Documentation Detailed specification documents live in [`docs/spec/`](docs/spec/). Recommended reading order: 1. [Project Overview](docs/spec/01-overview.md) 2. [IR & Symbol Table Design Specification](docs/spec/02-ir-symbol-table.md) 3. [Technical Architecture](docs/spec/04-architecture.md) 4. [ABI Equivalence Specification](docs/spec/05-abi-spec.md) 5. [Syntax Coverage Matrix](docs/spec/08-syntax-matrix.md) 6. [CLI / API Reference](docs/spec/09-cli-api.md) Fix documents follow the pattern `NN-.md` with sections: problem description (Chinese), fix approach, changed files, and test results. --- ## πŸ“„ License MIT License β€” see [LICENSE](LICENSE) for details.