Repository files navigation

Col6Forge

A Fortran Frontend and Compiler Driver Written in Zig

Starting from .f/.for/.f77/.f90/.f95/.f03 inputs, going through lexical/parsing/semantic analysis and LLVM IR generation, and finally utilizing zig cc to build object files or executables.

Project Overview

Col6Forge is currently not a "wrapper script for gfortran", but a genuine, standalone frontend pipeline:

  1. Reads Fortran source files.
  2. Automatically detects fixed form / free form.
  3. Normalizes logical lines while preserving source location mappings.
  4. Executes lexical, parsing, and semantic analysis.
  5. Generates LLVM IR.
  6. In cc mode, passes the generated IR along with the runtime to zig cc for compilation/linking.

There are two main entry points:

  • col6forge Directly runs the frontend pipeline and outputs LLVM IR.
  • col6forge cc / col6forge-cc Processes Fortran inputs in a manner similar to cc, and passes non-Fortran inputs and additional arguments transparently to zig cc.

The repository also includes multiple built-in development toolsets for golden testing, NIST F78 validation, GCC gfortran.dg compilation validation, BLAS/LAPACK validation, performance regression comparison, error code documentation generation, and architecture auditing.

Current Implementation Scope

Language Frontend

  • Supports fixed form and free form inputs, with heuristic auto-detection based on extensions and content.
  • Fixed form normalization covers classic column rules, and is compatible with tab-format as well as continuation variants shifted right by one or two columns.
  • Diagnostics for both free form and fixed form attempt to fall back to the original source row and column, rather than solely reporting the normalized logical line position.

Language Support Status

Stable (Production Ready)

  • F77 Core: Fixed-form source, basic types (INTEGER, REAL, DOUBLE PRECISION, COMPLEX, LOGICAL, CHARACTER), COMMON, DO/IF, SUBROUTINE/FUNCTION, ENTRY, alternate returns
  • F90 Arrays: ALLOCATABLE, array constructors [...], basic array operations
  • F2003 OOP Basics: Derived types, EXTENDS (type inheritance), member access

Experimental (Parsed but Incomplete Codegen)

  • F90 Modules: MODULE syntax parsed, but procedures inside modules may fail to link
  • F2003 C Interop: BIND(C) and iso_c_binding parsed, but symbol generation incomplete
  • SUBMODULE: Syntax recognized, but codegen not fully implemented
  • Advanced Features: INTERFACE, generic interfaces, type-bound procedures, ABSTRACT, deferred bindings

Not Supported

  • F2008+ Concurrency: DO CONCURRENT, Coarrays, SYNC statements
  • F2008+ Parallel: No parallel runtime features
  • Advanced F2003: Procedure pointers, abstract interfaces with complex signatures

Additional Coverage

  • CONTAINS internal procedures
  • USE, ONLY, rename, and module prelude propagation
  • EQUIVALENCE consistency checks
  • Implicit typing rules
  • Intrinsic resolution and arity checks for calls

Code Generation and Runtime

  • The currently exposed EmitKind is only llvm, representing LLVM IR.
  • The cc mode automatically links the col6forge_rt runtime when Fortran inputs are present.
  • The runtime source tree already includes modules for formatted I/O, list-directed I/O, binary/direct/unformatted I/O, dynamic formats, PAUSE, and complex/integer helpers.
  • Optional runtime array bounds checking and PAUSE behavior control have been integrated into the command line.

Toolchain and Validation

  • zig build check for fast compilation-level regression checks.
  • zig build test to run Zig unit tests.
  • zig build golden / diagnostic-golden / cc-diagnostic-golden for golden validation.
  • zig build verify for NIST F78 execution validation.
  • zig build gcc-dg-verify for GCC gfortran.dg compilation validation.
  • zig build blas-verify / lapack-verify for numerical library validation.
  • zig build perf-bench / perf-compare / perf-dashboard for performance profiling, comparison, and historical dashboard generation.

Overall Architecture

flowchart LR
A[Fortran Source] --> B[Source Form Detection]
B --> C[Normalization]
C --> D[Lexer / Parser]
D --> E[Semantic Analysis]
E --> F[LLVM IR Generation]
F --> G[col6forge Output .ll]
F --> H[col6forge-cc / zig cc]
H --> I[Object / Executable]
H --> J[col6forge_rt]
Loading

The pipeline stages have explicit profile sampling points in the source code:

  • read
  • normalize
  • parse
  • semantic
  • codegen
  • pipeline

When -ftime-report or --time-report is enabled, the CLI will output a total/read/normalize/parse/sema/codegen elapsed time summary to standard error.

Repository Structure

PathPurpose
src/main.zigMain CLI entry point, handles both IR mode and cc driver mode
src/root.zigExported library API, exposing frontend, semantics, codegen, and pipeline capabilities
src/frontend/Fixed/free form normalization, lexical and syntax analysis
src/semantic/Semantic analysis, symbols/scopes, constraint checking
src/codegen/LLVM IR generation
src/runtime/col6forge_rt runtime implementation
src/driver/Pipeline and cc driver
src/tools/Tools for golden/verify/gcc-dg/BLAS/LAPACK/perf/docgen/audit, etc.
tests/Test assets including NIST F78, GCC, BLAS, LAPACK, MINPACK, diagnostic golden, etc.
docs/Supplementary documentation; may lag behind except for error code docs
scratch/Experimental examples and mixed-language experiments

Environment Requirements

  • Zig: 0.16.0 or higher
  • It is recommended to execute all commands in the root directory of the repository.
  • To run NIST / BLAS / LAPACK baseline verification, gfortran is typically required on the machine.

The repository's build.zig.zon explicitly declares:

minimum_zig_version = 0.16.0

Quick Start

1. Perform a Quick Compilation Check First

zig build check

2. Output LLVM IR

The repository includes a minimal example hello.f:

PROGRAM HELLO
WRITE (*,*) 'HELLO, COL6FORGE'
END

Compile it into LLVM IR. Note: IR mode does not automatically create parent directories for the output file, so output directly to the current directory here:

zig build run -- hello.f -emit-llvm -o hello.ll

3. Compile and Link Directly into an Executable

zig build cc -- hello.f -o zig-out/hello.exe

Execution result:

HELLO, COL6FORGE

4. Install to zig-out/

zig build

By default, it will install:

  • zig-out/bin/col6forge
  • zig-out/bin/col6forge-cc
  • The col6forge_rt static library under zig-out/lib/

Command Reference

CLI Mode

col6forge: IR Mode

zig build run -- <input.f> -emit-llvm -o <out.ll>

Common flags:

FlagPurpose
-emit-llvmOutputs LLVM IR, currently the default and only publicly exposed output type
-o <path>Specifies the output path; parent directories must pre-exist in IR mode
-fbounds-checkEnables runtime array bounds checking
`-fpause-mode <autocontinue
-ftime-report / --time-reportOutputs the total/read/normalize/parse/sema/codegen time summary
-h / --helpDisplays help

Examples:

zig build run -- hello.f -emit-llvm -o hello.ll
zig build run -- hello.f -fbounds-check -fpause-mode=continue -o hello.ll

col6forge cc / col6forge-cc / col6cc: Driver Mode

zig build cc -- <inputs...> [options] [-- <zig-cc-flags...>]

Driver Rules:

  • Fortran inputs will first go through Col6Forge's LLVM IR pipeline.
  • Other inputs will be forwarded directly to zig cc.
  • -flag options not consumed by col6forge cc itself are usually forwarded directly to zig cc; if necessary, they can be explicitly appended after -- <zig-cc-flags...>.
  • In non--c modes, the col6forge_rt runtime will be automatically linked as long as Fortran inputs are present.
  • In -c mode, if -o is explicitly provided, there must be exactly one compilable input unit.
  • The -c mode does not accept pure linker inputs (e.g., .o/.obj/.a/.lib/.so/.dll).
  • The driver extracts -target / --target, -mcpu, and -ofmt from transparently passed arguments to build/reuse a runtime object cache matching the target configuration.
  • Every run of the cc driver generates temporary translation artifacts under zig-cache/cc-driver/<timestamp>/ and reuses the runtime object cache under zig-cache/cc-driver/cache/.

Common Examples:

zig build cc -- hello.f -o zig-out/hello.exe
zig build cc -- a.f b.f90 helper.c -O2 -o zig-out/app.exe
zig build cc -- a.f -c
zig build cc -- a.f -- -target x86_64-windows-gnu
zig build cc -- a.f -- --target=x86_64-linux-gnu

Notes:

  • Fortran source file extensions are currently recognized as .f/.for/.f77/.f90/.f95/.f03.
  • For non-Fortran files, .c/.cc/.cpp/.cxx/.m/.mm/.s/.S/.ll are currently treated as compilable inputs, and other paths are treated as standard linking/transparent inputs.

Top-level zig build Steps

CommandPurpose
zig buildInstalls main artifacts to zig-out/
zig build run -- ...Runs col6forge
zig build cc -- ...Runs the col6forge-cc driver
zig build testRuns Zig unit tests
zig build checkPerforms compilation only, without running tests
zig build toolsInstalls all development tools
zig build tools-checkPerforms compilation only for all development tools
zig build architecture-auditRuns the architectural constraint auditor
zig build errors-docs-checkVerifies if docs/errors.md matches the source code
zig build errors-docsRegenerates docs/errors.md
zig build goldenRuns golden file tests
zig build diagnostic-goldenRuns diagnostic golden tests
zig build cc-diagnostic-goldenRuns cc translation diagnostic golden tests
zig build verifyRuns NIST F78 validation
zig build verify-strictStrict fallback gating for NIST F78
zig build gcc-dg-verifyRuns GCC gfortran.dg compilation validation
zig build blas-verifyRuns BLAS 3.12.0 validation
zig build lapack-verifyRuns LAPACK-lite 3.1.1 validation
zig build lapack-verify-strictStrict fallback gating for LAPACK
zig build test-allRuns the unified test harness
zig build perf-benchProfiles performance and outputs JSON
zig build perf-compareCompares two performance JSONs and reports regressions based on thresholds
zig build perf-regressCI alias for perf-compare
zig build perf-dashboardUpdates performance history and generates a Markdown dashboard

Validation and Testing Ecosystem

Test Assets Overview

The numbers below represent the recursive file counts in the current repository directories. They are provided to help understand the scale of the test assets, which does not equal the "actual runnable case count".

DirectoryFile CountPrimary Purpose
tests/NIST_F78_test_suite630Classic NIST F78 validation assets
tests/gcc-tests/gfortran.dg8717GCC gfortran.dg compilation validation assets
tests/BLAS-3.12.0365BLAS 3.12.0 validation assets
tests/LAPACK-lite-3.1.12555LAPACK-lite 3.1.1 validation assets
tests/MINPACK457MINPACK related assets
tests/diagnostic_golden10Pipeline diagnostic golden
tests/diagnostic_golden_cc10cc translation diagnostic golden
tests/adv_crowther10Supplementary historical test assets

Recommended Daily Regression Sequence

Quick regression:

zig build check
zig build architecture-audit
zig build errors-docs-check

Language and diagnostics regression:

zig build test
zig build golden
zig build diagnostic-golden
zig build cc-diagnostic-golden

Compatibility and external baseline regression:

zig build verify -- --filter FM715
zig build gcc-dg-verify -- --filter array_constructor_14
zig build blas-verify -- --filter xblat3d
zig build lapack-verify -- --filter xlintstds

Default Suites for test-all

The unified test harness currently has these suites built-in:

  • golden
  • diagnostic-golden
  • cc-diagnostic-golden
  • nist
  • gcc-dg

Note that gcc-dg is not enabled by default, while the other four suites are enabled by default.

To view the suite list:

zig build test-all -- --list-suites

Fallback Gating

Validation tools support fallback statistics and gating strategies:

  • disabled
  • report
  • budget
  • strict

Common usage:

zig build verify-strict
zig build verify -Dverify_max_fallbacks=3
zig build lapack-verify-strict
zig build lapack-verify -Dlapack_max_fallbacks=5

Diagnostics and Documentation Synchronization

Stable Error Codes

The project's error directory is derived from the error catalog in the source code and uses stable CFxxxx encoding.

Diagnostic format illustration:

path/to/file.f90:12:7: error[CFxxxx]: ...

docs/errors.md is Not Hand-Written

It is automatically generated from the source code:

zig build errors-docs
zig build errors-docs-check

Therefore:

  • If you want to add or modify error codes, please edit the error catalog in the source code.
  • Do not manually edit docs/errors.md directly.

Architecture Audit

The repository contains an explicit architectural constraint auditor that checks for several forbidden dependencies and forbidden patterns, such as:

  • Forbidding reverse dependencies on docs/errors.md from the source code logic.
  • Forbidding several legacy formatted entry paths from flowing back.
  • Forbidding partial semantic/codegen layers from reading compatibility mirror fields.
  • Checking whether the error code directory is complete, unique, and ordered.

Execution method:

zig build architecture-audit

Using as a Zig Dependency

build.zig has already exposed reusable artifacts:

  • module: Col6Forge
  • artifact: col6forge_rt
  • named lazy path: col6forge_rt_src
  • named lazy path: col6forge_rt_dir
  • named lazy path: col6forge_src_dir

A minimal Zig-side invocation example:

conststd=@import("std");
constCol6Forge=@import("Col6Forge");
pubfnmain() !void {
vargpa=std.heap.GeneralPurposeAllocator(.{}){};
defer_=gpa.deinit();
constresult=tryCol6Forge.runPipelineWithOptions(
gpa.allocator(),
"hello.f",
.llvm,
.{},
);
defergpa.allocator().free(result.output);
trystd.io.getStdOut().writeAll(result.output);
}

The library interface provides direct access to:

  • Frontend normalization and parsing
  • Semantic analysis
  • Pipeline execution
  • Diagnostic output
  • Profile sample capturing

License

This project is licensed under the Apache License 2.0.

See the LICENSE file in the root directory for details.

About

A modern Fortran frontend and compiler driver written in Zig. It parses legacy and free-form Fortran, emits LLVM IR, and leverages zig cc for seamless cross-platform compilation.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

Repository files navigation

Col6Forge

A Fortran Frontend and Compiler Driver Written in Zig

Starting from .f/.for/.f77/.f90/.f95/.f03 inputs, going through lexical/parsing/semantic analysis and LLVM IR generation, and finally utilizing zig cc to build object files or executables.

Project Overview

Col6Forge is currently not a "wrapper script for gfortran", but a genuine, standalone frontend pipeline:

  1. Reads Fortran source files.
  2. Automatically detects fixed form / free form.
  3. Normalizes logical lines while preserving source location mappings.
  4. Executes lexical, parsing, and semantic analysis.
  5. Generates LLVM IR.
  6. In cc mode, passes the generated IR along with the runtime to zig cc for compilation/linking.

There are two main entry points:

  • col6forge Directly runs the frontend pipeline and outputs LLVM IR.
  • col6forge cc / col6forge-cc Processes Fortran inputs in a manner similar to cc, and passes non-Fortran inputs and additional arguments transparently to zig cc.

The repository also includes multiple built-in development toolsets for golden testing, NIST F78 validation, GCC gfortran.dg compilation validation, BLAS/LAPACK validation, performance regression comparison, error code documentation generation, and architecture auditing.

Current Implementation Scope

Language Frontend

  • Supports fixed form and free form inputs, with heuristic auto-detection based on extensions and content.
  • Fixed form normalization covers classic column rules, and is compatible with tab-format as well as continuation variants shifted right by one or two columns.
  • Diagnostics for both free form and fixed form attempt to fall back to the original source row and column, rather than solely reporting the normalized logical line position.

Language Support Status

Stable (Production Ready)

  • F77 Core: Fixed-form source, basic types (INTEGER, REAL, DOUBLE PRECISION, COMPLEX, LOGICAL, CHARACTER), COMMON, DO/IF, SUBROUTINE/FUNCTION, ENTRY, alternate returns
  • F90 Arrays: ALLOCATABLE, array constructors [...], basic array operations
  • F2003 OOP Basics: Derived types, EXTENDS (type inheritance), member access

Experimental (Parsed but Incomplete Codegen)

  • F90 Modules: MODULE syntax parsed, but procedures inside modules may fail to link
  • F2003 C Interop: BIND(C) and iso_c_binding parsed, but symbol generation incomplete
  • SUBMODULE: Syntax recognized, but codegen not fully implemented
  • Advanced Features: INTERFACE, generic interfaces, type-bound procedures, ABSTRACT, deferred bindings

Not Supported

  • F2008+ Concurrency: DO CONCURRENT, Coarrays, SYNC statements
  • F2008+ Parallel: No parallel runtime features
  • Advanced F2003: Procedure pointers, abstract interfaces with complex signatures

Additional Coverage

  • CONTAINS internal procedures
  • USE, ONLY, rename, and module prelude propagation
  • EQUIVALENCE consistency checks
  • Implicit typing rules
  • Intrinsic resolution and arity checks for calls

Code Generation and Runtime

  • The currently exposed EmitKind is only llvm, representing LLVM IR.
  • The cc mode automatically links the col6forge_rt runtime when Fortran inputs are present.
  • The runtime source tree already includes modules for formatted I/O, list-directed I/O, binary/direct/unformatted I/O, dynamic formats, PAUSE, and complex/integer helpers.
  • Optional runtime array bounds checking and PAUSE behavior control have been integrated into the command line.

Toolchain and Validation

  • zig build check for fast compilation-level regression checks.
  • zig build test to run Zig unit tests.
  • zig build golden / diagnostic-golden / cc-diagnostic-golden for golden validation.
  • zig build verify for NIST F78 execution validation.
  • zig build gcc-dg-verify for GCC gfortran.dg compilation validation.
  • zig build blas-verify / lapack-verify for numerical library validation.
  • zig build perf-bench / perf-compare / perf-dashboard for performance profiling, comparison, and historical dashboard generation.

Overall Architecture

flowchart LR
A[Fortran Source] --> B[Source Form Detection]
B --> C[Normalization]
C --> D[Lexer / Parser]
D --> E[Semantic Analysis]
E --> F[LLVM IR Generation]
F --> G[col6forge Output .ll]
F --> H[col6forge-cc / zig cc]
H --> I[Object / Executable]
H --> J[col6forge_rt]
Loading

The pipeline stages have explicit profile sampling points in the source code:

  • read
  • normalize
  • parse
  • semantic
  • codegen
  • pipeline

When -ftime-report or --time-report is enabled, the CLI will output a total/read/normalize/parse/sema/codegen elapsed time summary to standard error.

Repository Structure

PathPurpose
src/main.zigMain CLI entry point, handles both IR mode and cc driver mode
src/root.zigExported library API, exposing frontend, semantics, codegen, and pipeline capabilities
src/frontend/Fixed/free form normalization, lexical and syntax analysis
src/semantic/Semantic analysis, symbols/scopes, constraint checking
src/codegen/LLVM IR generation
src/runtime/col6forge_rt runtime implementation
src/driver/Pipeline and cc driver
src/tools/Tools for golden/verify/gcc-dg/BLAS/LAPACK/perf/docgen/audit, etc.
tests/Test assets including NIST F78, GCC, BLAS, LAPACK, MINPACK, diagnostic golden, etc.
docs/Supplementary documentation; may lag behind except for error code docs
scratch/Experimental examples and mixed-language experiments

Environment Requirements

  • Zig: 0.16.0 or higher
  • It is recommended to execute all commands in the root directory of the repository.
  • To run NIST / BLAS / LAPACK baseline verification, gfortran is typically required on the machine.

The repository's build.zig.zon explicitly declares:

minimum_zig_version = 0.16.0

Quick Start

1. Perform a Quick Compilation Check First

zig build check

2. Output LLVM IR

The repository includes a minimal example hello.f:

PROGRAM HELLO
WRITE (*,*) 'HELLO, COL6FORGE'
END

Compile it into LLVM IR. Note: IR mode does not automatically create parent directories for the output file, so output directly to the current directory here:

zig build run -- hello.f -emit-llvm -o hello.ll

3. Compile and Link Directly into an Executable

zig build cc -- hello.f -o zig-out/hello.exe

Execution result:

HELLO, COL6FORGE

4. Install to zig-out/

zig build

By default, it will install:

  • zig-out/bin/col6forge
  • zig-out/bin/col6forge-cc
  • The col6forge_rt static library under zig-out/lib/

Command Reference

CLI Mode

col6forge: IR Mode

zig build run -- <input.f> -emit-llvm -o <out.ll>

Common flags:

FlagPurpose
-emit-llvmOutputs LLVM IR, currently the default and only publicly exposed output type
-o <path>Specifies the output path; parent directories must pre-exist in IR mode
-fbounds-checkEnables runtime array bounds checking
`-fpause-mode <autocontinue
-ftime-report / --time-reportOutputs the total/read/normalize/parse/sema/codegen time summary
-h / --helpDisplays help

Examples:

zig build run -- hello.f -emit-llvm -o hello.ll
zig build run -- hello.f -fbounds-check -fpause-mode=continue -o hello.ll

col6forge cc / col6forge-cc / col6cc: Driver Mode

zig build cc -- <inputs...> [options] [-- <zig-cc-flags...>]

Driver Rules:

  • Fortran inputs will first go through Col6Forge's LLVM IR pipeline.
  • Other inputs will be forwarded directly to zig cc.
  • -flag options not consumed by col6forge cc itself are usually forwarded directly to zig cc; if necessary, they can be explicitly appended after -- <zig-cc-flags...>.
  • In non--c modes, the col6forge_rt runtime will be automatically linked as long as Fortran inputs are present.
  • In -c mode, if -o is explicitly provided, there must be exactly one compilable input unit.
  • The -c mode does not accept pure linker inputs (e.g., .o/.obj/.a/.lib/.so/.dll).
  • The driver extracts -target / --target, -mcpu, and -ofmt from transparently passed arguments to build/reuse a runtime object cache matching the target configuration.
  • Every run of the cc driver generates temporary translation artifacts under zig-cache/cc-driver/<timestamp>/ and reuses the runtime object cache under zig-cache/cc-driver/cache/.

Common Examples:

zig build cc -- hello.f -o zig-out/hello.exe
zig build cc -- a.f b.f90 helper.c -O2 -o zig-out/app.exe
zig build cc -- a.f -c
zig build cc -- a.f -- -target x86_64-windows-gnu
zig build cc -- a.f -- --target=x86_64-linux-gnu

Notes:

  • Fortran source file extensions are currently recognized as .f/.for/.f77/.f90/.f95/.f03.
  • For non-Fortran files, .c/.cc/.cpp/.cxx/.m/.mm/.s/.S/.ll are currently treated as compilable inputs, and other paths are treated as standard linking/transparent inputs.

Top-level zig build Steps

CommandPurpose
zig buildInstalls main artifacts to zig-out/
zig build run -- ...Runs col6forge
zig build cc -- ...Runs the col6forge-cc driver
zig build testRuns Zig unit tests
zig build checkPerforms compilation only, without running tests
zig build toolsInstalls all development tools
zig build tools-checkPerforms compilation only for all development tools
zig build architecture-auditRuns the architectural constraint auditor
zig build errors-docs-checkVerifies if docs/errors.md matches the source code
zig build errors-docsRegenerates docs/errors.md
zig build goldenRuns golden file tests
zig build diagnostic-goldenRuns diagnostic golden tests
zig build cc-diagnostic-goldenRuns cc translation diagnostic golden tests
zig build verifyRuns NIST F78 validation
zig build verify-strictStrict fallback gating for NIST F78
zig build gcc-dg-verifyRuns GCC gfortran.dg compilation validation
zig build blas-verifyRuns BLAS 3.12.0 validation
zig build lapack-verifyRuns LAPACK-lite 3.1.1 validation
zig build lapack-verify-strictStrict fallback gating for LAPACK
zig build test-allRuns the unified test harness
zig build perf-benchProfiles performance and outputs JSON
zig build perf-compareCompares two performance JSONs and reports regressions based on thresholds
zig build perf-regressCI alias for perf-compare
zig build perf-dashboardUpdates performance history and generates a Markdown dashboard

Validation and Testing Ecosystem

Test Assets Overview

The numbers below represent the recursive file counts in the current repository directories. They are provided to help understand the scale of the test assets, which does not equal the "actual runnable case count".

DirectoryFile CountPrimary Purpose
tests/NIST_F78_test_suite630Classic NIST F78 validation assets
tests/gcc-tests/gfortran.dg8717GCC gfortran.dg compilation validation assets
tests/BLAS-3.12.0365BLAS 3.12.0 validation assets
tests/LAPACK-lite-3.1.12555LAPACK-lite 3.1.1 validation assets
tests/MINPACK457MINPACK related assets
tests/diagnostic_golden10Pipeline diagnostic golden
tests/diagnostic_golden_cc10cc translation diagnostic golden
tests/adv_crowther10Supplementary historical test assets

Recommended Daily Regression Sequence

Quick regression:

zig build check
zig build architecture-audit
zig build errors-docs-check

Language and diagnostics regression:

zig build test
zig build golden
zig build diagnostic-golden
zig build cc-diagnostic-golden

Compatibility and external baseline regression:

zig build verify -- --filter FM715
zig build gcc-dg-verify -- --filter array_constructor_14
zig build blas-verify -- --filter xblat3d
zig build lapack-verify -- --filter xlintstds

Default Suites for test-all

The unified test harness currently has these suites built-in:

  • golden
  • diagnostic-golden
  • cc-diagnostic-golden
  • nist
  • gcc-dg

Note that gcc-dg is not enabled by default, while the other four suites are enabled by default.

To view the suite list:

zig build test-all -- --list-suites

Fallback Gating

Validation tools support fallback statistics and gating strategies:

  • disabled
  • report
  • budget
  • strict

Common usage:

zig build verify-strict
zig build verify -Dverify_max_fallbacks=3
zig build lapack-verify-strict
zig build lapack-verify -Dlapack_max_fallbacks=5

Diagnostics and Documentation Synchronization

Stable Error Codes

The project's error directory is derived from the error catalog in the source code and uses stable CFxxxx encoding.

Diagnostic format illustration:

path/to/file.f90:12:7: error[CFxxxx]: ...

docs/errors.md is Not Hand-Written

It is automatically generated from the source code:

zig build errors-docs
zig build errors-docs-check

Therefore:

  • If you want to add or modify error codes, please edit the error catalog in the source code.
  • Do not manually edit docs/errors.md directly.

Architecture Audit

The repository contains an explicit architectural constraint auditor that checks for several forbidden dependencies and forbidden patterns, such as:

  • Forbidding reverse dependencies on docs/errors.md from the source code logic.
  • Forbidding several legacy formatted entry paths from flowing back.
  • Forbidding partial semantic/codegen layers from reading compatibility mirror fields.
  • Checking whether the error code directory is complete, unique, and ordered.

Execution method:

zig build architecture-audit

Using as a Zig Dependency

build.zig has already exposed reusable artifacts:

  • module: Col6Forge
  • artifact: col6forge_rt
  • named lazy path: col6forge_rt_src
  • named lazy path: col6forge_rt_dir
  • named lazy path: col6forge_src_dir

A minimal Zig-side invocation example:

conststd=@import("std");
constCol6Forge=@import("Col6Forge");
pubfnmain() !void {
vargpa=std.heap.GeneralPurposeAllocator(.{}){};
defer_=gpa.deinit();
constresult=tryCol6Forge.runPipelineWithOptions(
gpa.allocator(),
"hello.f",
.llvm,
.{},
);
defergpa.allocator().free(result.output);
trystd.io.getStdOut().writeAll(result.output);
}

The library interface provides direct access to:

  • Frontend normalization and parsing
  • Semantic analysis
  • Pipeline execution
  • Diagnostic output
  • Profile sample capturing

License

This project is licensed under the Apache License 2.0.

See the LICENSE file in the root directory for details.

About

A modern Fortran frontend and compiler driver written in Zig. It parses legacy and free-form Fortran, emits LLVM IR, and leverages zig cc for seamless cross-platform compilation.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

Col6Forge

A Fortran Frontend and Compiler Driver Written in Zig

Starting from .f/.for/.f77/.f90/.f95/.f03 inputs, going through lexical/parsing/semantic analysis and LLVM IR generation, and finally utilizing zig cc to build object files or executables.

Project Overview

Col6Forge is currently not a "wrapper script for gfortran", but a genuine, standalone frontend pipeline:

  1. Reads Fortran source files.
  2. Automatically detects fixed form / free form.
  3. Normalizes logical lines while preserving source location mappings.
  4. Executes lexical, parsing, and semantic analysis.
  5. Generates LLVM IR.
  6. In cc mode, passes the generated IR along with the runtime to zig cc for compilation/linking.

There are two main entry points:

  • col6forge Directly runs the frontend pipeline and outputs LLVM IR.
  • col6forge cc / col6forge-cc Processes Fortran inputs in a manner similar to cc, and passes non-Fortran inputs and additional arguments transparently to zig cc.

The repository also includes multiple built-in development toolsets for golden testing, NIST F78 validation, GCC gfortran.dg compilation validation, BLAS/LAPACK validation, performance regression comparison, error code documentation generation, and architecture auditing.

Current Implementation Scope

Language Frontend

  • Supports fixed form and free form inputs, with heuristic auto-detection based on extensions and content.
  • Fixed form normalization covers classic column rules, and is compatible with tab-format as well as continuation variants shifted right by one or two columns.
  • Diagnostics for both free form and fixed form attempt to fall back to the original source row and column, rather than solely reporting the normalized logical line position.

Language Support Status

Stable (Production Ready)

  • F77 Core: Fixed-form source, basic types (INTEGER, REAL, DOUBLE PRECISION, COMPLEX, LOGICAL, CHARACTER), COMMON, DO/IF, SUBROUTINE/FUNCTION, ENTRY, alternate returns
  • F90 Arrays: ALLOCATABLE, array constructors [...], basic array operations
  • F2003 OOP Basics: Derived types, EXTENDS (type inheritance), member access

Experimental (Parsed but Incomplete Codegen)

  • F90 Modules: MODULE syntax parsed, but procedures inside modules may fail to link
  • F2003 C Interop: BIND(C) and iso_c_binding parsed, but symbol generation incomplete
  • SUBMODULE: Syntax recognized, but codegen not fully implemented
  • Advanced Features: INTERFACE, generic interfaces, type-bound procedures, ABSTRACT, deferred bindings

Not Supported

  • F2008+ Concurrency: DO CONCURRENT, Coarrays, SYNC statements
  • F2008+ Parallel: No parallel runtime features
  • Advanced F2003: Procedure pointers, abstract interfaces with complex signatures

Additional Coverage

  • CONTAINS internal procedures
  • USE, ONLY, rename, and module prelude propagation
  • EQUIVALENCE consistency checks
  • Implicit typing rules
  • Intrinsic resolution and arity checks for calls

Code Generation and Runtime

  • The currently exposed EmitKind is only llvm, representing LLVM IR.
  • The cc mode automatically links the col6forge_rt runtime when Fortran inputs are present.
  • The runtime source tree already includes modules for formatted I/O, list-directed I/O, binary/direct/unformatted I/O, dynamic formats, PAUSE, and complex/integer helpers.
  • Optional runtime array bounds checking and PAUSE behavior control have been integrated into the command line.

Toolchain and Validation

  • zig build check for fast compilation-level regression checks.
  • zig build test to run Zig unit tests.
  • zig build golden / diagnostic-golden / cc-diagnostic-golden for golden validation.
  • zig build verify for NIST F78 execution validation.
  • zig build gcc-dg-verify for GCC gfortran.dg compilation validation.
  • zig build blas-verify / lapack-verify for numerical library validation.
  • zig build perf-bench / perf-compare / perf-dashboard for performance profiling, comparison, and historical dashboard generation.

Overall Architecture

flowchart LR
A[Fortran Source] --> B[Source Form Detection]
B --> C[Normalization]
C --> D[Lexer / Parser]
D --> E[Semantic Analysis]
E --> F[LLVM IR Generation]
F --> G[col6forge Output .ll]
F --> H[col6forge-cc / zig cc]
H --> I[Object / Executable]
H --> J[col6forge_rt]
Loading

The pipeline stages have explicit profile sampling points in the source code:

  • read
  • normalize
  • parse
  • semantic
  • codegen
  • pipeline

When -ftime-report or --time-report is enabled, the CLI will output a total/read/normalize/parse/sema/codegen elapsed time summary to standard error.

Repository Structure

PathPurpose
src/main.zigMain CLI entry point, handles both IR mode and cc driver mode
src/root.zigExported library API, exposing frontend, semantics, codegen, and pipeline capabilities
src/frontend/Fixed/free form normalization, lexical and syntax analysis
src/semantic/Semantic analysis, symbols/scopes, constraint checking
src/codegen/LLVM IR generation
src/runtime/col6forge_rt runtime implementation
src/driver/Pipeline and cc driver
src/tools/Tools for golden/verify/gcc-dg/BLAS/LAPACK/perf/docgen/audit, etc.
tests/Test assets including NIST F78, GCC, BLAS, LAPACK, MINPACK, diagnostic golden, etc.
docs/Supplementary documentation; may lag behind except for error code docs
scratch/Experimental examples and mixed-language experiments

Environment Requirements

  • Zig: 0.16.0 or higher
  • It is recommended to execute all commands in the root directory of the repository.
  • To run NIST / BLAS / LAPACK baseline verification, gfortran is typically required on the machine.

The repository's build.zig.zon explicitly declares:

minimum_zig_version = 0.16.0

Quick Start

1. Perform a Quick Compilation Check First

zig build check

2. Output LLVM IR

The repository includes a minimal example hello.f:

PROGRAM HELLO
WRITE (*,*) 'HELLO, COL6FORGE'
END

Compile it into LLVM IR. Note: IR mode does not automatically create parent directories for the output file, so output directly to the current directory here:

zig build run -- hello.f -emit-llvm -o hello.ll

3. Compile and Link Directly into an Executable

zig build cc -- hello.f -o zig-out/hello.exe

Execution result:

HELLO, COL6FORGE

4. Install to zig-out/

zig build

By default, it will install:

  • zig-out/bin/col6forge
  • zig-out/bin/col6forge-cc
  • The col6forge_rt static library under zig-out/lib/

Command Reference

CLI Mode

col6forge: IR Mode

zig build run -- <input.f> -emit-llvm -o <out.ll>

Common flags:

FlagPurpose
-emit-llvmOutputs LLVM IR, currently the default and only publicly exposed output type
-o <path>Specifies the output path; parent directories must pre-exist in IR mode
-fbounds-checkEnables runtime array bounds checking
`-fpause-mode <autocontinue
-ftime-report / --time-reportOutputs the total/read/normalize/parse/sema/codegen time summary
-h / --helpDisplays help

Examples:

zig build run -- hello.f -emit-llvm -o hello.ll
zig build run -- hello.f -fbounds-check -fpause-mode=continue -o hello.ll

col6forge cc / col6forge-cc / col6cc: Driver Mode

zig build cc -- <inputs...> [options] [-- <zig-cc-flags...>]

Driver Rules:

  • Fortran inputs will first go through Col6Forge's LLVM IR pipeline.
  • Other inputs will be forwarded directly to zig cc.
  • -flag options not consumed by col6forge cc itself are usually forwarded directly to zig cc; if necessary, they can be explicitly appended after -- <zig-cc-flags...>.
  • In non--c modes, the col6forge_rt runtime will be automatically linked as long as Fortran inputs are present.
  • In -c mode, if -o is explicitly provided, there must be exactly one compilable input unit.
  • The -c mode does not accept pure linker inputs (e.g., .o/.obj/.a/.lib/.so/.dll).
  • The driver extracts -target / --target, -mcpu, and -ofmt from transparently passed arguments to build/reuse a runtime object cache matching the target configuration.
  • Every run of the cc driver generates temporary translation artifacts under zig-cache/cc-driver/<timestamp>/ and reuses the runtime object cache under zig-cache/cc-driver/cache/.

Common Examples:

zig build cc -- hello.f -o zig-out/hello.exe
zig build cc -- a.f b.f90 helper.c -O2 -o zig-out/app.exe
zig build cc -- a.f -c
zig build cc -- a.f -- -target x86_64-windows-gnu
zig build cc -- a.f -- --target=x86_64-linux-gnu

Notes:

  • Fortran source file extensions are currently recognized as .f/.for/.f77/.f90/.f95/.f03.
  • For non-Fortran files, .c/.cc/.cpp/.cxx/.m/.mm/.s/.S/.ll are currently treated as compilable inputs, and other paths are treated as standard linking/transparent inputs.

Top-level zig build Steps

CommandPurpose
zig buildInstalls main artifacts to zig-out/
zig build run -- ...Runs col6forge
zig build cc -- ...Runs the col6forge-cc driver
zig build testRuns Zig unit tests
zig build checkPerforms compilation only, without running tests
zig build toolsInstalls all development tools
zig build tools-checkPerforms compilation only for all development tools
zig build architecture-auditRuns the architectural constraint auditor
zig build errors-docs-checkVerifies if docs/errors.md matches the source code
zig build errors-docsRegenerates docs/errors.md
zig build goldenRuns golden file tests
zig build diagnostic-goldenRuns diagnostic golden tests
zig build cc-diagnostic-goldenRuns cc translation diagnostic golden tests
zig build verifyRuns NIST F78 validation
zig build verify-strictStrict fallback gating for NIST F78
zig build gcc-dg-verifyRuns GCC gfortran.dg compilation validation
zig build blas-verifyRuns BLAS 3.12.0 validation
zig build lapack-verifyRuns LAPACK-lite 3.1.1 validation
zig build lapack-verify-strictStrict fallback gating for LAPACK
zig build test-allRuns the unified test harness
zig build perf-benchProfiles performance and outputs JSON
zig build perf-compareCompares two performance JSONs and reports regressions based on thresholds
zig build perf-regressCI alias for perf-compare
zig build perf-dashboardUpdates performance history and generates a Markdown dashboard

Validation and Testing Ecosystem

Test Assets Overview

The numbers below represent the recursive file counts in the current repository directories. They are provided to help understand the scale of the test assets, which does not equal the "actual runnable case count".

DirectoryFile CountPrimary Purpose
tests/NIST_F78_test_suite630Classic NIST F78 validation assets
tests/gcc-tests/gfortran.dg8717GCC gfortran.dg compilation validation assets
tests/BLAS-3.12.0365BLAS 3.12.0 validation assets
tests/LAPACK-lite-3.1.12555LAPACK-lite 3.1.1 validation assets
tests/MINPACK457MINPACK related assets
tests/diagnostic_golden10Pipeline diagnostic golden
tests/diagnostic_golden_cc10cc translation diagnostic golden
tests/adv_crowther10Supplementary historical test assets

Recommended Daily Regression Sequence

Quick regression:

zig build check
zig build architecture-audit
zig build errors-docs-check

Language and diagnostics regression:

zig build test
zig build golden
zig build diagnostic-golden
zig build cc-diagnostic-golden

Compatibility and external baseline regression:

zig build verify -- --filter FM715
zig build gcc-dg-verify -- --filter array_constructor_14
zig build blas-verify -- --filter xblat3d
zig build lapack-verify -- --filter xlintstds

Default Suites for test-all

The unified test harness currently has these suites built-in:

  • golden
  • diagnostic-golden
  • cc-diagnostic-golden
  • nist
  • gcc-dg

Note that gcc-dg is not enabled by default, while the other four suites are enabled by default.

To view the suite list:

zig build test-all -- --list-suites

Fallback Gating

Validation tools support fallback statistics and gating strategies:

  • disabled
  • report
  • budget
  • strict

Common usage:

zig build verify-strict
zig build verify -Dverify_max_fallbacks=3
zig build lapack-verify-strict
zig build lapack-verify -Dlapack_max_fallbacks=5

Diagnostics and Documentation Synchronization

Stable Error Codes

The project's error directory is derived from the error catalog in the source code and uses stable CFxxxx encoding.

Diagnostic format illustration:

path/to/file.f90:12:7: error[CFxxxx]: ...

docs/errors.md is Not Hand-Written

It is automatically generated from the source code:

zig build errors-docs
zig build errors-docs-check

Therefore:

  • If you want to add or modify error codes, please edit the error catalog in the source code.
  • Do not manually edit docs/errors.md directly.

Architecture Audit

The repository contains an explicit architectural constraint auditor that checks for several forbidden dependencies and forbidden patterns, such as:

  • Forbidding reverse dependencies on docs/errors.md from the source code logic.
  • Forbidding several legacy formatted entry paths from flowing back.
  • Forbidding partial semantic/codegen layers from reading compatibility mirror fields.
  • Checking whether the error code directory is complete, unique, and ordered.

Execution method:

zig build architecture-audit

Using as a Zig Dependency

build.zig has already exposed reusable artifacts:

  • module: Col6Forge
  • artifact: col6forge_rt
  • named lazy path: col6forge_rt_src
  • named lazy path: col6forge_rt_dir
  • named lazy path: col6forge_src_dir

A minimal Zig-side invocation example:

conststd=@import("std");
constCol6Forge=@import("Col6Forge");
pubfnmain() !void {
vargpa=std.heap.GeneralPurposeAllocator(.{}){};
defer_=gpa.deinit();
constresult=tryCol6Forge.runPipelineWithOptions(
gpa.allocator(),
"hello.f",
.llvm,
.{},
);
defergpa.allocator().free(result.output);
trystd.io.getStdOut().writeAll(result.output);
}

The library interface provides direct access to:

  • Frontend normalization and parsing
  • Semantic analysis
  • Pipeline execution
  • Diagnostic output
  • Profile sample capturing

License

This project is licensed under the Apache License 2.0.

See the LICENSE file in the root directory for details.

About

A modern Fortran frontend and compiler driver written in Zig. It parses legacy and free-form Fortran, emits LLVM IR, and leverages zig cc for seamless cross-platform compilation.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

Col6Forge

A Fortran Frontend and Compiler Driver Written in Zig

Starting from .f/.for/.f77/.f90/.f95/.f03 inputs, going through lexical/parsing/semantic analysis and LLVM IR generation, and finally utilizing zig cc to build object files or executables.

Project Overview

Col6Forge is currently not a "wrapper script for gfortran", but a genuine, standalone frontend pipeline:

  1. Reads Fortran source files.
  2. Automatically detects fixed form / free form.
  3. Normalizes logical lines while preserving source location mappings.
  4. Executes lexical, parsing, and semantic analysis.
  5. Generates LLVM IR.
  6. In cc mode, passes the generated IR along with the runtime to zig cc for compilation/linking.

There are two main entry points:

  • col6forge Directly runs the frontend pipeline and outputs LLVM IR.
  • col6forge cc / col6forge-cc Processes Fortran inputs in a manner similar to cc, and passes non-Fortran inputs and additional arguments transparently to zig cc.

The repository also includes multiple built-in development toolsets for golden testing, NIST F78 validation, GCC gfortran.dg compilation validation, BLAS/LAPACK validation, performance regression comparison, error code documentation generation, and architecture auditing.

Current Implementation Scope

Language Frontend

  • Supports fixed form and free form inputs, with heuristic auto-detection based on extensions and content.
  • Fixed form normalization covers classic column rules, and is compatible with tab-format as well as continuation variants shifted right by one or two columns.
  • Diagnostics for both free form and fixed form attempt to fall back to the original source row and column, rather than solely reporting the normalized logical line position.

Language Support Status

Stable (Production Ready)

  • F77 Core: Fixed-form source, basic types (INTEGER, REAL, DOUBLE PRECISION, COMPLEX, LOGICAL, CHARACTER), COMMON, DO/IF, SUBROUTINE/FUNCTION, ENTRY, alternate returns
  • F90 Arrays: ALLOCATABLE, array constructors [...], basic array operations
  • F2003 OOP Basics: Derived types, EXTENDS (type inheritance), member access

Experimental (Parsed but Incomplete Codegen)

  • F90 Modules: MODULE syntax parsed, but procedures inside modules may fail to link
  • F2003 C Interop: BIND(C) and iso_c_binding parsed, but symbol generation incomplete
  • SUBMODULE: Syntax recognized, but codegen not fully implemented
  • Advanced Features: INTERFACE, generic interfaces, type-bound procedures, ABSTRACT, deferred bindings

Not Supported

  • F2008+ Concurrency: DO CONCURRENT, Coarrays, SYNC statements
  • F2008+ Parallel: No parallel runtime features
  • Advanced F2003: Procedure pointers, abstract interfaces with complex signatures

Additional Coverage

  • CONTAINS internal procedures
  • USE, ONLY, rename, and module prelude propagation
  • EQUIVALENCE consistency checks
  • Implicit typing rules
  • Intrinsic resolution and arity checks for calls

Code Generation and Runtime

  • The currently exposed EmitKind is only llvm, representing LLVM IR.
  • The cc mode automatically links the col6forge_rt runtime when Fortran inputs are present.
  • The runtime source tree already includes modules for formatted I/O, list-directed I/O, binary/direct/unformatted I/O, dynamic formats, PAUSE, and complex/integer helpers.
  • Optional runtime array bounds checking and PAUSE behavior control have been integrated into the command line.

Toolchain and Validation

  • zig build check for fast compilation-level regression checks.
  • zig build test to run Zig unit tests.
  • zig build golden / diagnostic-golden / cc-diagnostic-golden for golden validation.
  • zig build verify for NIST F78 execution validation.
  • zig build gcc-dg-verify for GCC gfortran.dg compilation validation.
  • zig build blas-verify / lapack-verify for numerical library validation.
  • zig build perf-bench / perf-compare / perf-dashboard for performance profiling, comparison, and historical dashboard generation.

Overall Architecture

flowchart LR
A[Fortran Source] --> B[Source Form Detection]
B --> C[Normalization]
C --> D[Lexer / Parser]
D --> E[Semantic Analysis]
E --> F[LLVM IR Generation]
F --> G[col6forge Output .ll]
F --> H[col6forge-cc / zig cc]
H --> I[Object / Executable]
H --> J[col6forge_rt]
Loading

The pipeline stages have explicit profile sampling points in the source code:

  • read
  • normalize
  • parse
  • semantic
  • codegen
  • pipeline

When -ftime-report or --time-report is enabled, the CLI will output a total/read/normalize/parse/sema/codegen elapsed time summary to standard error.

Repository Structure

PathPurpose
src/main.zigMain CLI entry point, handles both IR mode and cc driver mode
src/root.zigExported library API, exposing frontend, semantics, codegen, and pipeline capabilities
src/frontend/Fixed/free form normalization, lexical and syntax analysis
src/semantic/Semantic analysis, symbols/scopes, constraint checking
src/codegen/LLVM IR generation
src/runtime/col6forge_rt runtime implementation
src/driver/Pipeline and cc driver
src/tools/Tools for golden/verify/gcc-dg/BLAS/LAPACK/perf/docgen/audit, etc.
tests/Test assets including NIST F78, GCC, BLAS, LAPACK, MINPACK, diagnostic golden, etc.
docs/Supplementary documentation; may lag behind except for error code docs
scratch/Experimental examples and mixed-language experiments

Environment Requirements

  • Zig: 0.16.0 or higher
  • It is recommended to execute all commands in the root directory of the repository.
  • To run NIST / BLAS / LAPACK baseline verification, gfortran is typically required on the machine.

The repository's build.zig.zon explicitly declares:

minimum_zig_version = 0.16.0

Quick Start

1. Perform a Quick Compilation Check First

zig build check

2. Output LLVM IR

The repository includes a minimal example hello.f:

PROGRAM HELLO
WRITE (*,*) 'HELLO, COL6FORGE'
END

Compile it into LLVM IR. Note: IR mode does not automatically create parent directories for the output file, so output directly to the current directory here:

zig build run -- hello.f -emit-llvm -o hello.ll

3. Compile and Link Directly into an Executable

zig build cc -- hello.f -o zig-out/hello.exe

Execution result:

HELLO, COL6FORGE

4. Install to zig-out/

zig build

By default, it will install:

  • zig-out/bin/col6forge
  • zig-out/bin/col6forge-cc
  • The col6forge_rt static library under zig-out/lib/

Command Reference

CLI Mode

col6forge: IR Mode

zig build run -- <input.f> -emit-llvm -o <out.ll>

Common flags:

FlagPurpose
-emit-llvmOutputs LLVM IR, currently the default and only publicly exposed output type
-o <path>Specifies the output path; parent directories must pre-exist in IR mode
-fbounds-checkEnables runtime array bounds checking
`-fpause-mode <autocontinue
-ftime-report / --time-reportOutputs the total/read/normalize/parse/sema/codegen time summary
-h / --helpDisplays help

Examples:

zig build run -- hello.f -emit-llvm -o hello.ll
zig build run -- hello.f -fbounds-check -fpause-mode=continue -o hello.ll

col6forge cc / col6forge-cc / col6cc: Driver Mode

zig build cc -- <inputs...> [options] [-- <zig-cc-flags...>]

Driver Rules:

  • Fortran inputs will first go through Col6Forge's LLVM IR pipeline.
  • Other inputs will be forwarded directly to zig cc.
  • -flag options not consumed by col6forge cc itself are usually forwarded directly to zig cc; if necessary, they can be explicitly appended after -- <zig-cc-flags...>.
  • In non--c modes, the col6forge_rt runtime will be automatically linked as long as Fortran inputs are present.
  • In -c mode, if -o is explicitly provided, there must be exactly one compilable input unit.
  • The -c mode does not accept pure linker inputs (e.g., .o/.obj/.a/.lib/.so/.dll).
  • The driver extracts -target / --target, -mcpu, and -ofmt from transparently passed arguments to build/reuse a runtime object cache matching the target configuration.
  • Every run of the cc driver generates temporary translation artifacts under zig-cache/cc-driver/<timestamp>/ and reuses the runtime object cache under zig-cache/cc-driver/cache/.

Common Examples:

zig build cc -- hello.f -o zig-out/hello.exe
zig build cc -- a.f b.f90 helper.c -O2 -o zig-out/app.exe
zig build cc -- a.f -c
zig build cc -- a.f -- -target x86_64-windows-gnu
zig build cc -- a.f -- --target=x86_64-linux-gnu

Notes:

  • Fortran source file extensions are currently recognized as .f/.for/.f77/.f90/.f95/.f03.
  • For non-Fortran files, .c/.cc/.cpp/.cxx/.m/.mm/.s/.S/.ll are currently treated as compilable inputs, and other paths are treated as standard linking/transparent inputs.

Top-level zig build Steps

CommandPurpose
zig buildInstalls main artifacts to zig-out/
zig build run -- ...Runs col6forge
zig build cc -- ...Runs the col6forge-cc driver
zig build testRuns Zig unit tests
zig build checkPerforms compilation only, without running tests
zig build toolsInstalls all development tools
zig build tools-checkPerforms compilation only for all development tools
zig build architecture-auditRuns the architectural constraint auditor
zig build errors-docs-checkVerifies if docs/errors.md matches the source code
zig build errors-docsRegenerates docs/errors.md
zig build goldenRuns golden file tests
zig build diagnostic-goldenRuns diagnostic golden tests
zig build cc-diagnostic-goldenRuns cc translation diagnostic golden tests
zig build verifyRuns NIST F78 validation
zig build verify-strictStrict fallback gating for NIST F78
zig build gcc-dg-verifyRuns GCC gfortran.dg compilation validation
zig build blas-verifyRuns BLAS 3.12.0 validation
zig build lapack-verifyRuns LAPACK-lite 3.1.1 validation
zig build lapack-verify-strictStrict fallback gating for LAPACK
zig build test-allRuns the unified test harness
zig build perf-benchProfiles performance and outputs JSON
zig build perf-compareCompares two performance JSONs and reports regressions based on thresholds
zig build perf-regressCI alias for perf-compare
zig build perf-dashboardUpdates performance history and generates a Markdown dashboard

Validation and Testing Ecosystem

Test Assets Overview

The numbers below represent the recursive file counts in the current repository directories. They are provided to help understand the scale of the test assets, which does not equal the "actual runnable case count".

DirectoryFile CountPrimary Purpose
tests/NIST_F78_test_suite630Classic NIST F78 validation assets
tests/gcc-tests/gfortran.dg8717GCC gfortran.dg compilation validation assets
tests/BLAS-3.12.0365BLAS 3.12.0 validation assets
tests/LAPACK-lite-3.1.12555LAPACK-lite 3.1.1 validation assets
tests/MINPACK457MINPACK related assets
tests/diagnostic_golden10Pipeline diagnostic golden
tests/diagnostic_golden_cc10cc translation diagnostic golden
tests/adv_crowther10Supplementary historical test assets

Recommended Daily Regression Sequence

Quick regression:

zig build check
zig build architecture-audit
zig build errors-docs-check

Language and diagnostics regression:

zig build test
zig build golden
zig build diagnostic-golden
zig build cc-diagnostic-golden

Compatibility and external baseline regression:

zig build verify -- --filter FM715
zig build gcc-dg-verify -- --filter array_constructor_14
zig build blas-verify -- --filter xblat3d
zig build lapack-verify -- --filter xlintstds

Default Suites for test-all

The unified test harness currently has these suites built-in:

  • golden
  • diagnostic-golden
  • cc-diagnostic-golden
  • nist
  • gcc-dg

Note that gcc-dg is not enabled by default, while the other four suites are enabled by default.

To view the suite list:

zig build test-all -- --list-suites

Fallback Gating

Validation tools support fallback statistics and gating strategies:

  • disabled
  • report
  • budget
  • strict

Common usage:

zig build verify-strict
zig build verify -Dverify_max_fallbacks=3
zig build lapack-verify-strict
zig build lapack-verify -Dlapack_max_fallbacks=5

Diagnostics and Documentation Synchronization

Stable Error Codes

The project's error directory is derived from the error catalog in the source code and uses stable CFxxxx encoding.

Diagnostic format illustration:

path/to/file.f90:12:7: error[CFxxxx]: ...

docs/errors.md is Not Hand-Written

It is automatically generated from the source code:

zig build errors-docs
zig build errors-docs-check

Therefore:

  • If you want to add or modify error codes, please edit the error catalog in the source code.
  • Do not manually edit docs/errors.md directly.

Architecture Audit

The repository contains an explicit architectural constraint auditor that checks for several forbidden dependencies and forbidden patterns, such as:

  • Forbidding reverse dependencies on docs/errors.md from the source code logic.
  • Forbidding several legacy formatted entry paths from flowing back.
  • Forbidding partial semantic/codegen layers from reading compatibility mirror fields.
  • Checking whether the error code directory is complete, unique, and ordered.

Execution method:

zig build architecture-audit

Using as a Zig Dependency

build.zig has already exposed reusable artifacts:

  • module: Col6Forge
  • artifact: col6forge_rt
  • named lazy path: col6forge_rt_src
  • named lazy path: col6forge_rt_dir
  • named lazy path: col6forge_src_dir

A minimal Zig-side invocation example:

conststd=@import("std");
constCol6Forge=@import("Col6Forge");
pubfnmain() !void {
vargpa=std.heap.GeneralPurposeAllocator(.{}){};
defer_=gpa.deinit();
constresult=tryCol6Forge.runPipelineWithOptions(
gpa.allocator(),
"hello.f",
.llvm,
.{},
);
defergpa.allocator().free(result.output);
trystd.io.getStdOut().writeAll(result.output);
}

The library interface provides direct access to:

  • Frontend normalization and parsing
  • Semantic analysis
  • Pipeline execution
  • Diagnostic output
  • Profile sample capturing

License

This project is licensed under the Apache License 2.0.

See the LICENSE file in the root directory for details.

About

A modern Fortran frontend and compiler driver written in Zig. It parses legacy and free-form Fortran, emits LLVM IR, and leverages zig cc for seamless cross-platform compilation.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

Repository files navigation

Col6Forge

A Fortran Frontend and Compiler Driver Written in Zig

Starting from .f/.for/.f77/.f90/.f95/.f03 inputs, going through lexical/parsing/semantic analysis and LLVM IR generation, and finally utilizing zig cc to build object files or executables.

Project Overview

Col6Forge is currently not a "wrapper script for gfortran", but a genuine, standalone frontend pipeline:

  1. Reads Fortran source files.
  2. Automatically detects fixed form / free form.
  3. Normalizes logical lines while preserving source location mappings.
  4. Executes lexical, parsing, and semantic analysis.
  5. Generates LLVM IR.
  6. In cc mode, passes the generated IR along with the runtime to zig cc for compilation/linking.

There are two main entry points:

  • col6forge Directly runs the frontend pipeline and outputs LLVM IR.
  • col6forge cc / col6forge-cc Processes Fortran inputs in a manner similar to cc, and passes non-Fortran inputs and additional arguments transparently to zig cc.

The repository also includes multiple built-in development toolsets for golden testing, NIST F78 validation, GCC gfortran.dg compilation validation, BLAS/LAPACK validation, performance regression comparison, error code documentation generation, and architecture auditing.

Current Implementation Scope

Language Frontend

  • Supports fixed form and free form inputs, with heuristic auto-detection based on extensions and content.
  • Fixed form normalization covers classic column rules, and is compatible with tab-format as well as continuation variants shifted right by one or two columns.
  • Diagnostics for both free form and fixed form attempt to fall back to the original source row and column, rather than solely reporting the normalized logical line position.

Language Support Status

Stable (Production Ready)

  • F77 Core: Fixed-form source, basic types (INTEGER, REAL, DOUBLE PRECISION, COMPLEX, LOGICAL, CHARACTER), COMMON, DO/IF, SUBROUTINE/FUNCTION, ENTRY, alternate returns
  • F90 Arrays: ALLOCATABLE, array constructors [...], basic array operations
  • F2003 OOP Basics: Derived types, EXTENDS (type inheritance), member access

Experimental (Parsed but Incomplete Codegen)

  • F90 Modules: MODULE syntax parsed, but procedures inside modules may fail to link
  • F2003 C Interop: BIND(C) and iso_c_binding parsed, but symbol generation incomplete
  • SUBMODULE: Syntax recognized, but codegen not fully implemented
  • Advanced Features: INTERFACE, generic interfaces, type-bound procedures, ABSTRACT, deferred bindings

Not Supported

  • F2008+ Concurrency: DO CONCURRENT, Coarrays, SYNC statements
  • F2008+ Parallel: No parallel runtime features
  • Advanced F2003: Procedure pointers, abstract interfaces with complex signatures

Additional Coverage

  • CONTAINS internal procedures
  • USE, ONLY, rename, and module prelude propagation
  • EQUIVALENCE consistency checks
  • Implicit typing rules
  • Intrinsic resolution and arity checks for calls

Code Generation and Runtime

  • The currently exposed EmitKind is only llvm, representing LLVM IR.
  • The cc mode automatically links the col6forge_rt runtime when Fortran inputs are present.
  • The runtime source tree already includes modules for formatted I/O, list-directed I/O, binary/direct/unformatted I/O, dynamic formats, PAUSE, and complex/integer helpers.
  • Optional runtime array bounds checking and PAUSE behavior control have been integrated into the command line.

Toolchain and Validation

  • zig build check for fast compilation-level regression checks.
  • zig build test to run Zig unit tests.
  • zig build golden / diagnostic-golden / cc-diagnostic-golden for golden validation.
  • zig build verify for NIST F78 execution validation.
  • zig build gcc-dg-verify for GCC gfortran.dg compilation validation.
  • zig build blas-verify / lapack-verify for numerical library validation.
  • zig build perf-bench / perf-compare / perf-dashboard for performance profiling, comparison, and historical dashboard generation.

Overall Architecture

flowchart LR
A[Fortran Source] --> B[Source Form Detection]
B --> C[Normalization]
C --> D[Lexer / Parser]
D --> E[Semantic Analysis]
E --> F[LLVM IR Generation]
F --> G[col6forge Output .ll]
F --> H[col6forge-cc / zig cc]
H --> I[Object / Executable]
H --> J[col6forge_rt]
Loading

The pipeline stages have explicit profile sampling points in the source code:

  • read
  • normalize
  • parse
  • semantic
  • codegen
  • pipeline

When -ftime-report or --time-report is enabled, the CLI will output a total/read/normalize/parse/sema/codegen elapsed time summary to standard error.

Repository Structure

PathPurpose
src/main.zigMain CLI entry point, handles both IR mode and cc driver mode
src/root.zigExported library API, exposing frontend, semantics, codegen, and pipeline capabilities
src/frontend/Fixed/free form normalization, lexical and syntax analysis
src/semantic/Semantic analysis, symbols/scopes, constraint checking
src/codegen/LLVM IR generation
src/runtime/col6forge_rt runtime implementation
src/driver/Pipeline and cc driver
src/tools/Tools for golden/verify/gcc-dg/BLAS/LAPACK/perf/docgen/audit, etc.
tests/Test assets including NIST F78, GCC, BLAS, LAPACK, MINPACK, diagnostic golden, etc.
docs/Supplementary documentation; may lag behind except for error code docs
scratch/Experimental examples and mixed-language experiments

Environment Requirements

  • Zig: 0.16.0 or higher
  • It is recommended to execute all commands in the root directory of the repository.
  • To run NIST / BLAS / LAPACK baseline verification, gfortran is typically required on the machine.

The repository's build.zig.zon explicitly declares:

minimum_zig_version = 0.16.0

Quick Start

1. Perform a Quick Compilation Check First

zig build check

2. Output LLVM IR

The repository includes a minimal example hello.f:

PROGRAM HELLO
WRITE (*,*) 'HELLO, COL6FORGE'
END

Compile it into LLVM IR. Note: IR mode does not automatically create parent directories for the output file, so output directly to the current directory here:

zig build run -- hello.f -emit-llvm -o hello.ll

3. Compile and Link Directly into an Executable

zig build cc -- hello.f -o zig-out/hello.exe

Execution result:

HELLO, COL6FORGE

4. Install to zig-out/

zig build

By default, it will install:

  • zig-out/bin/col6forge
  • zig-out/bin/col6forge-cc
  • The col6forge_rt static library under zig-out/lib/

Command Reference

CLI Mode

col6forge: IR Mode

zig build run -- <input.f> -emit-llvm -o <out.ll>

Common flags:

FlagPurpose
-emit-llvmOutputs LLVM IR, currently the default and only publicly exposed output type
-o <path>Specifies the output path; parent directories must pre-exist in IR mode
-fbounds-checkEnables runtime array bounds checking
`-fpause-mode <autocontinue
-ftime-report / --time-reportOutputs the total/read/normalize/parse/sema/codegen time summary
-h / --helpDisplays help

Examples:

zig build run -- hello.f -emit-llvm -o hello.ll
zig build run -- hello.f -fbounds-check -fpause-mode=continue -o hello.ll

col6forge cc / col6forge-cc / col6cc: Driver Mode

zig build cc -- <inputs...> [options] [-- <zig-cc-flags...>]

Driver Rules:

  • Fortran inputs will first go through Col6Forge's LLVM IR pipeline.
  • Other inputs will be forwarded directly to zig cc.
  • -flag options not consumed by col6forge cc itself are usually forwarded directly to zig cc; if necessary, they can be explicitly appended after -- <zig-cc-flags...>.
  • In non--c modes, the col6forge_rt runtime will be automatically linked as long as Fortran inputs are present.
  • In -c mode, if -o is explicitly provided, there must be exactly one compilable input unit.
  • The -c mode does not accept pure linker inputs (e.g., .o/.obj/.a/.lib/.so/.dll).
  • The driver extracts -target / --target, -mcpu, and -ofmt from transparently passed arguments to build/reuse a runtime object cache matching the target configuration.
  • Every run of the cc driver generates temporary translation artifacts under zig-cache/cc-driver/<timestamp>/ and reuses the runtime object cache under zig-cache/cc-driver/cache/.

Common Examples:

zig build cc -- hello.f -o zig-out/hello.exe
zig build cc -- a.f b.f90 helper.c -O2 -o zig-out/app.exe
zig build cc -- a.f -c
zig build cc -- a.f -- -target x86_64-windows-gnu
zig build cc -- a.f -- --target=x86_64-linux-gnu

Notes:

  • Fortran source file extensions are currently recognized as .f/.for/.f77/.f90/.f95/.f03.
  • For non-Fortran files, .c/.cc/.cpp/.cxx/.m/.mm/.s/.S/.ll are currently treated as compilable inputs, and other paths are treated as standard linking/transparent inputs.

Top-level zig build Steps

CommandPurpose
zig buildInstalls main artifacts to zig-out/
zig build run -- ...Runs col6forge
zig build cc -- ...Runs the col6forge-cc driver
zig build testRuns Zig unit tests
zig build checkPerforms compilation only, without running tests
zig build toolsInstalls all development tools
zig build tools-checkPerforms compilation only for all development tools
zig build architecture-auditRuns the architectural constraint auditor
zig build errors-docs-checkVerifies if docs/errors.md matches the source code
zig build errors-docsRegenerates docs/errors.md
zig build goldenRuns golden file tests
zig build diagnostic-goldenRuns diagnostic golden tests
zig build cc-diagnostic-goldenRuns cc translation diagnostic golden tests
zig build verifyRuns NIST F78 validation
zig build verify-strictStrict fallback gating for NIST F78
zig build gcc-dg-verifyRuns GCC gfortran.dg compilation validation
zig build blas-verifyRuns BLAS 3.12.0 validation
zig build lapack-verifyRuns LAPACK-lite 3.1.1 validation
zig build lapack-verify-strictStrict fallback gating for LAPACK
zig build test-allRuns the unified test harness
zig build perf-benchProfiles performance and outputs JSON
zig build perf-compareCompares two performance JSONs and reports regressions based on thresholds
zig build perf-regressCI alias for perf-compare
zig build perf-dashboardUpdates performance history and generates a Markdown dashboard

Validation and Testing Ecosystem

Test Assets Overview

The numbers below represent the recursive file counts in the current repository directories. They are provided to help understand the scale of the test assets, which does not equal the "actual runnable case count".

DirectoryFile CountPrimary Purpose
tests/NIST_F78_test_suite630Classic NIST F78 validation assets
tests/gcc-tests/gfortran.dg8717GCC gfortran.dg compilation validation assets
tests/BLAS-3.12.0365BLAS 3.12.0 validation assets
tests/LAPACK-lite-3.1.12555LAPACK-lite 3.1.1 validation assets
tests/MINPACK457MINPACK related assets
tests/diagnostic_golden10Pipeline diagnostic golden
tests/diagnostic_golden_cc10cc translation diagnostic golden
tests/adv_crowther10Supplementary historical test assets

Recommended Daily Regression Sequence

Quick regression:

zig build check
zig build architecture-audit
zig build errors-docs-check

Language and diagnostics regression:

zig build test
zig build golden
zig build diagnostic-golden
zig build cc-diagnostic-golden

Compatibility and external baseline regression:

zig build verify -- --filter FM715
zig build gcc-dg-verify -- --filter array_constructor_14
zig build blas-verify -- --filter xblat3d
zig build lapack-verify -- --filter xlintstds

Default Suites for test-all

The unified test harness currently has these suites built-in:

  • golden
  • diagnostic-golden
  • cc-diagnostic-golden
  • nist
  • gcc-dg

Note that gcc-dg is not enabled by default, while the other four suites are enabled by default.

To view the suite list:

zig build test-all -- --list-suites

Fallback Gating

Validation tools support fallback statistics and gating strategies:

  • disabled
  • report
  • budget
  • strict

Common usage:

zig build verify-strict
zig build verify -Dverify_max_fallbacks=3
zig build lapack-verify-strict
zig build lapack-verify -Dlapack_max_fallbacks=5

Diagnostics and Documentation Synchronization

Stable Error Codes

The project's error directory is derived from the error catalog in the source code and uses stable CFxxxx encoding.

Diagnostic format illustration:

path/to/file.f90:12:7: error[CFxxxx]: ...

docs/errors.md is Not Hand-Written

It is automatically generated from the source code:

zig build errors-docs
zig build errors-docs-check

Therefore:

  • If you want to add or modify error codes, please edit the error catalog in the source code.
  • Do not manually edit docs/errors.md directly.

Architecture Audit

The repository contains an explicit architectural constraint auditor that checks for several forbidden dependencies and forbidden patterns, such as:

  • Forbidding reverse dependencies on docs/errors.md from the source code logic.
  • Forbidding several legacy formatted entry paths from flowing back.
  • Forbidding partial semantic/codegen layers from reading compatibility mirror fields.
  • Checking whether the error code directory is complete, unique, and ordered.

Execution method:

zig build architecture-audit

Using as a Zig Dependency

build.zig has already exposed reusable artifacts:

  • module: Col6Forge
  • artifact: col6forge_rt
  • named lazy path: col6forge_rt_src
  • named lazy path: col6forge_rt_dir
  • named lazy path: col6forge_src_dir

A minimal Zig-side invocation example:

conststd=@import("std");
constCol6Forge=@import("Col6Forge");
pubfnmain() !void {
vargpa=std.heap.GeneralPurposeAllocator(.{}){};
defer_=gpa.deinit();
constresult=tryCol6Forge.runPipelineWithOptions(
gpa.allocator(),
"hello.f",
.llvm,
.{},
);
defergpa.allocator().free(result.output);
trystd.io.getStdOut().writeAll(result.output);
}

The library interface provides direct access to:

  • Frontend normalization and parsing
  • Semantic analysis
  • Pipeline execution
  • Diagnostic output
  • Profile sample capturing

License

This project is licensed under the Apache License 2.0.

See the LICENSE file in the root directory for details.

About

A modern Fortran frontend and compiler driver written in Zig. It parses legacy and free-form Fortran, emits LLVM IR, and leverages zig cc for seamless cross-platform compilation.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

Col6Forge

A Fortran Frontend and Compiler Driver Written in Zig

Starting from .f/.for/.f77/.f90/.f95/.f03 inputs, going through lexical/parsing/semantic analysis and LLVM IR generation, and finally utilizing zig cc to build object files or executables.

Project Overview

Col6Forge is currently not a "wrapper script for gfortran", but a genuine, standalone frontend pipeline:

  1. Reads Fortran source files.
  2. Automatically detects fixed form / free form.
  3. Normalizes logical lines while preserving source location mappings.
  4. Executes lexical, parsing, and semantic analysis.
  5. Generates LLVM IR.
  6. In cc mode, passes the generated IR along with the runtime to zig cc for compilation/linking.

There are two main entry points:

  • col6forge Directly runs the frontend pipeline and outputs LLVM IR.
  • col6forge cc / col6forge-cc Processes Fortran inputs in a manner similar to cc, and passes non-Fortran inputs and additional arguments transparently to zig cc.

The repository also includes multiple built-in development toolsets for golden testing, NIST F78 validation, GCC gfortran.dg compilation validation, BLAS/LAPACK validation, performance regression comparison, error code documentation generation, and architecture auditing.

Current Implementation Scope

Language Frontend

  • Supports fixed form and free form inputs, with heuristic auto-detection based on extensions and content.
  • Fixed form normalization covers classic column rules, and is compatible with tab-format as well as continuation variants shifted right by one or two columns.
  • Diagnostics for both free form and fixed form attempt to fall back to the original source row and column, rather than solely reporting the normalized logical line position.

Language Support Status

Stable (Production Ready)

  • F77 Core: Fixed-form source, basic types (INTEGER, REAL, DOUBLE PRECISION, COMPLEX, LOGICAL, CHARACTER), COMMON, DO/IF, SUBROUTINE/FUNCTION, ENTRY, alternate returns
  • F90 Arrays: ALLOCATABLE, array constructors [...], basic array operations
  • F2003 OOP Basics: Derived types, EXTENDS (type inheritance), member access

Experimental (Parsed but Incomplete Codegen)

  • F90 Modules: MODULE syntax parsed, but procedures inside modules may fail to link
  • F2003 C Interop: BIND(C) and iso_c_binding parsed, but symbol generation incomplete
  • SUBMODULE: Syntax recognized, but codegen not fully implemented
  • Advanced Features: INTERFACE, generic interfaces, type-bound procedures, ABSTRACT, deferred bindings

Not Supported

  • F2008+ Concurrency: DO CONCURRENT, Coarrays, SYNC statements
  • F2008+ Parallel: No parallel runtime features
  • Advanced F2003: Procedure pointers, abstract interfaces with complex signatures

Additional Coverage

  • CONTAINS internal procedures
  • USE, ONLY, rename, and module prelude propagation
  • EQUIVALENCE consistency checks
  • Implicit typing rules
  • Intrinsic resolution and arity checks for calls

Code Generation and Runtime

  • The currently exposed EmitKind is only llvm, representing LLVM IR.
  • The cc mode automatically links the col6forge_rt runtime when Fortran inputs are present.
  • The runtime source tree already includes modules for formatted I/O, list-directed I/O, binary/direct/unformatted I/O, dynamic formats, PAUSE, and complex/integer helpers.
  • Optional runtime array bounds checking and PAUSE behavior control have been integrated into the command line.

Toolchain and Validation

  • zig build check for fast compilation-level regression checks.
  • zig build test to run Zig unit tests.
  • zig build golden / diagnostic-golden / cc-diagnostic-golden for golden validation.
  • zig build verify for NIST F78 execution validation.
  • zig build gcc-dg-verify for GCC gfortran.dg compilation validation.
  • zig build blas-verify / lapack-verify for numerical library validation.
  • zig build perf-bench / perf-compare / perf-dashboard for performance profiling, comparison, and historical dashboard generation.

Overall Architecture

flowchart LR
A[Fortran Source] --> B[Source Form Detection]
B --> C[Normalization]
C --> D[Lexer / Parser]
D --> E[Semantic Analysis]
E --> F[LLVM IR Generation]
F --> G[col6forge Output .ll]
F --> H[col6forge-cc / zig cc]
H --> I[Object / Executable]
H --> J[col6forge_rt]
Loading

The pipeline stages have explicit profile sampling points in the source code:

  • read
  • normalize
  • parse
  • semantic
  • codegen
  • pipeline

When -ftime-report or --time-report is enabled, the CLI will output a total/read/normalize/parse/sema/codegen elapsed time summary to standard error.

Repository Structure

PathPurpose
src/main.zigMain CLI entry point, handles both IR mode and cc driver mode
src/root.zigExported library API, exposing frontend, semantics, codegen, and pipeline capabilities
src/frontend/Fixed/free form normalization, lexical and syntax analysis
src/semantic/Semantic analysis, symbols/scopes, constraint checking
src/codegen/LLVM IR generation
src/runtime/col6forge_rt runtime implementation
src/driver/Pipeline and cc driver
src/tools/Tools for golden/verify/gcc-dg/BLAS/LAPACK/perf/docgen/audit, etc.
tests/Test assets including NIST F78, GCC, BLAS, LAPACK, MINPACK, diagnostic golden, etc.
docs/Supplementary documentation; may lag behind except for error code docs
scratch/Experimental examples and mixed-language experiments

Environment Requirements

  • Zig: 0.16.0 or higher
  • It is recommended to execute all commands in the root directory of the repository.
  • To run NIST / BLAS / LAPACK baseline verification, gfortran is typically required on the machine.

The repository's build.zig.zon explicitly declares:

minimum_zig_version = 0.16.0

Quick Start

1. Perform a Quick Compilation Check First

zig build check

2. Output LLVM IR

The repository includes a minimal example hello.f:

PROGRAM HELLO
WRITE (*,*) 'HELLO, COL6FORGE'
END

Compile it into LLVM IR. Note: IR mode does not automatically create parent directories for the output file, so output directly to the current directory here:

zig build run -- hello.f -emit-llvm -o hello.ll

3. Compile and Link Directly into an Executable

zig build cc -- hello.f -o zig-out/hello.exe

Execution result:

HELLO, COL6FORGE

4. Install to zig-out/

zig build

By default, it will install:

  • zig-out/bin/col6forge
  • zig-out/bin/col6forge-cc
  • The col6forge_rt static library under zig-out/lib/

Command Reference

CLI Mode

col6forge: IR Mode

zig build run -- <input.f> -emit-llvm -o <out.ll>

Common flags:

FlagPurpose
-emit-llvmOutputs LLVM IR, currently the default and only publicly exposed output type
-o <path>Specifies the output path; parent directories must pre-exist in IR mode
-fbounds-checkEnables runtime array bounds checking
`-fpause-mode <autocontinue
-ftime-report / --time-reportOutputs the total/read/normalize/parse/sema/codegen time summary
-h / --helpDisplays help

Examples:

zig build run -- hello.f -emit-llvm -o hello.ll
zig build run -- hello.f -fbounds-check -fpause-mode=continue -o hello.ll

col6forge cc / col6forge-cc / col6cc: Driver Mode

zig build cc -- <inputs...> [options] [-- <zig-cc-flags...>]

Driver Rules:

  • Fortran inputs will first go through Col6Forge's LLVM IR pipeline.
  • Other inputs will be forwarded directly to zig cc.
  • -flag options not consumed by col6forge cc itself are usually forwarded directly to zig cc; if necessary, they can be explicitly appended after -- <zig-cc-flags...>.
  • In non--c modes, the col6forge_rt runtime will be automatically linked as long as Fortran inputs are present.
  • In -c mode, if -o is explicitly provided, there must be exactly one compilable input unit.
  • The -c mode does not accept pure linker inputs (e.g., .o/.obj/.a/.lib/.so/.dll).
  • The driver extracts -target / --target, -mcpu, and -ofmt from transparently passed arguments to build/reuse a runtime object cache matching the target configuration.
  • Every run of the cc driver generates temporary translation artifacts under zig-cache/cc-driver/<timestamp>/ and reuses the runtime object cache under zig-cache/cc-driver/cache/.

Common Examples:

zig build cc -- hello.f -o zig-out/hello.exe
zig build cc -- a.f b.f90 helper.c -O2 -o zig-out/app.exe
zig build cc -- a.f -c
zig build cc -- a.f -- -target x86_64-windows-gnu
zig build cc -- a.f -- --target=x86_64-linux-gnu

Notes:

  • Fortran source file extensions are currently recognized as .f/.for/.f77/.f90/.f95/.f03.
  • For non-Fortran files, .c/.cc/.cpp/.cxx/.m/.mm/.s/.S/.ll are currently treated as compilable inputs, and other paths are treated as standard linking/transparent inputs.

Top-level zig build Steps

CommandPurpose
zig buildInstalls main artifacts to zig-out/
zig build run -- ...Runs col6forge
zig build cc -- ...Runs the col6forge-cc driver
zig build testRuns Zig unit tests
zig build checkPerforms compilation only, without running tests
zig build toolsInstalls all development tools
zig build tools-checkPerforms compilation only for all development tools
zig build architecture-auditRuns the architectural constraint auditor
zig build errors-docs-checkVerifies if docs/errors.md matches the source code
zig build errors-docsRegenerates docs/errors.md
zig build goldenRuns golden file tests
zig build diagnostic-goldenRuns diagnostic golden tests
zig build cc-diagnostic-goldenRuns cc translation diagnostic golden tests
zig build verifyRuns NIST F78 validation
zig build verify-strictStrict fallback gating for NIST F78
zig build gcc-dg-verifyRuns GCC gfortran.dg compilation validation
zig build blas-verifyRuns BLAS 3.12.0 validation
zig build lapack-verifyRuns LAPACK-lite 3.1.1 validation
zig build lapack-verify-strictStrict fallback gating for LAPACK
zig build test-allRuns the unified test harness
zig build perf-benchProfiles performance and outputs JSON
zig build perf-compareCompares two performance JSONs and reports regressions based on thresholds
zig build perf-regressCI alias for perf-compare
zig build perf-dashboardUpdates performance history and generates a Markdown dashboard

Validation and Testing Ecosystem

Test Assets Overview

The numbers below represent the recursive file counts in the current repository directories. They are provided to help understand the scale of the test assets, which does not equal the "actual runnable case count".

DirectoryFile CountPrimary Purpose
tests/NIST_F78_test_suite630Classic NIST F78 validation assets
tests/gcc-tests/gfortran.dg8717GCC gfortran.dg compilation validation assets
tests/BLAS-3.12.0365BLAS 3.12.0 validation assets
tests/LAPACK-lite-3.1.12555LAPACK-lite 3.1.1 validation assets
tests/MINPACK457MINPACK related assets
tests/diagnostic_golden10Pipeline diagnostic golden
tests/diagnostic_golden_cc10cc translation diagnostic golden
tests/adv_crowther10Supplementary historical test assets

Recommended Daily Regression Sequence

Quick regression:

zig build check
zig build architecture-audit
zig build errors-docs-check

Language and diagnostics regression:

zig build test
zig build golden
zig build diagnostic-golden
zig build cc-diagnostic-golden

Compatibility and external baseline regression:

zig build verify -- --filter FM715
zig build gcc-dg-verify -- --filter array_constructor_14
zig build blas-verify -- --filter xblat3d
zig build lapack-verify -- --filter xlintstds

Default Suites for test-all

The unified test harness currently has these suites built-in:

  • golden
  • diagnostic-golden
  • cc-diagnostic-golden
  • nist
  • gcc-dg

Note that gcc-dg is not enabled by default, while the other four suites are enabled by default.

To view the suite list:

zig build test-all -- --list-suites

Fallback Gating

Validation tools support fallback statistics and gating strategies:

  • disabled
  • report
  • budget
  • strict

Common usage:

zig build verify-strict
zig build verify -Dverify_max_fallbacks=3
zig build lapack-verify-strict
zig build lapack-verify -Dlapack_max_fallbacks=5

Diagnostics and Documentation Synchronization

Stable Error Codes

The project's error directory is derived from the error catalog in the source code and uses stable CFxxxx encoding.

Diagnostic format illustration:

path/to/file.f90:12:7: error[CFxxxx]: ...

docs/errors.md is Not Hand-Written

It is automatically generated from the source code:

zig build errors-docs
zig build errors-docs-check

Therefore:

  • If you want to add or modify error codes, please edit the error catalog in the source code.
  • Do not manually edit docs/errors.md directly.

Architecture Audit

The repository contains an explicit architectural constraint auditor that checks for several forbidden dependencies and forbidden patterns, such as:

  • Forbidding reverse dependencies on docs/errors.md from the source code logic.
  • Forbidding several legacy formatted entry paths from flowing back.
  • Forbidding partial semantic/codegen layers from reading compatibility mirror fields.
  • Checking whether the error code directory is complete, unique, and ordered.

Execution method:

zig build architecture-audit

Using as a Zig Dependency

build.zig has already exposed reusable artifacts:

  • module: Col6Forge
  • artifact: col6forge_rt
  • named lazy path: col6forge_rt_src
  • named lazy path: col6forge_rt_dir
  • named lazy path: col6forge_src_dir

A minimal Zig-side invocation example:

conststd=@import("std");
constCol6Forge=@import("Col6Forge");
pubfnmain() !void {
vargpa=std.heap.GeneralPurposeAllocator(.{}){};
defer_=gpa.deinit();
constresult=tryCol6Forge.runPipelineWithOptions(
gpa.allocator(),
"hello.f",
.llvm,
.{},
);
defergpa.allocator().free(result.output);
trystd.io.getStdOut().writeAll(result.output);
}

The library interface provides direct access to:

  • Frontend normalization and parsing
  • Semantic analysis
  • Pipeline execution
  • Diagnostic output
  • Profile sample capturing

License

This project is licensed under the Apache License 2.0.

See the LICENSE file in the root directory for details.

About

A modern Fortran frontend and compiler driver written in Zig. It parses legacy and free-form Fortran, emits LLVM IR, and leverages zig cc for seamless cross-platform compilation.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

Col6Forge

A Fortran Frontend and Compiler Driver Written in Zig

Starting from .f/.for/.f77/.f90/.f95/.f03 inputs, going through lexical/parsing/semantic analysis and LLVM IR generation, and finally utilizing zig cc to build object files or executables.

Project Overview

Col6Forge is currently not a "wrapper script for gfortran", but a genuine, standalone frontend pipeline:

  1. Reads Fortran source files.
  2. Automatically detects fixed form / free form.
  3. Normalizes logical lines while preserving source location mappings.
  4. Executes lexical, parsing, and semantic analysis.
  5. Generates LLVM IR.
  6. In cc mode, passes the generated IR along with the runtime to zig cc for compilation/linking.

There are two main entry points:

  • col6forge Directly runs the frontend pipeline and outputs LLVM IR.
  • col6forge cc / col6forge-cc Processes Fortran inputs in a manner similar to cc, and passes non-Fortran inputs and additional arguments transparently to zig cc.

The repository also includes multiple built-in development toolsets for golden testing, NIST F78 validation, GCC gfortran.dg compilation validation, BLAS/LAPACK validation, performance regression comparison, error code documentation generation, and architecture auditing.

Current Implementation Scope

Language Frontend

  • Supports fixed form and free form inputs, with heuristic auto-detection based on extensions and content.
  • Fixed form normalization covers classic column rules, and is compatible with tab-format as well as continuation variants shifted right by one or two columns.
  • Diagnostics for both free form and fixed form attempt to fall back to the original source row and column, rather than solely reporting the normalized logical line position.

Language Support Status

Stable (Production Ready)

  • F77 Core: Fixed-form source, basic types (INTEGER, REAL, DOUBLE PRECISION, COMPLEX, LOGICAL, CHARACTER), COMMON, DO/IF, SUBROUTINE/FUNCTION, ENTRY, alternate returns
  • F90 Arrays: ALLOCATABLE, array constructors [...], basic array operations
  • F2003 OOP Basics: Derived types, EXTENDS (type inheritance), member access

Experimental (Parsed but Incomplete Codegen)

  • F90 Modules: MODULE syntax parsed, but procedures inside modules may fail to link
  • F2003 C Interop: BIND(C) and iso_c_binding parsed, but symbol generation incomplete
  • SUBMODULE: Syntax recognized, but codegen not fully implemented
  • Advanced Features: INTERFACE, generic interfaces, type-bound procedures, ABSTRACT, deferred bindings

Not Supported

  • F2008+ Concurrency: DO CONCURRENT, Coarrays, SYNC statements
  • F2008+ Parallel: No parallel runtime features
  • Advanced F2003: Procedure pointers, abstract interfaces with complex signatures

Additional Coverage

  • CONTAINS internal procedures
  • USE, ONLY, rename, and module prelude propagation
  • EQUIVALENCE consistency checks
  • Implicit typing rules
  • Intrinsic resolution and arity checks for calls

Code Generation and Runtime

  • The currently exposed EmitKind is only llvm, representing LLVM IR.
  • The cc mode automatically links the col6forge_rt runtime when Fortran inputs are present.
  • The runtime source tree already includes modules for formatted I/O, list-directed I/O, binary/direct/unformatted I/O, dynamic formats, PAUSE, and complex/integer helpers.
  • Optional runtime array bounds checking and PAUSE behavior control have been integrated into the command line.

Toolchain and Validation

  • zig build check for fast compilation-level regression checks.
  • zig build test to run Zig unit tests.
  • zig build golden / diagnostic-golden / cc-diagnostic-golden for golden validation.
  • zig build verify for NIST F78 execution validation.
  • zig build gcc-dg-verify for GCC gfortran.dg compilation validation.
  • zig build blas-verify / lapack-verify for numerical library validation.
  • zig build perf-bench / perf-compare / perf-dashboard for performance profiling, comparison, and historical dashboard generation.

Overall Architecture

flowchart LR
A[Fortran Source] --> B[Source Form Detection]
B --> C[Normalization]
C --> D[Lexer / Parser]
D --> E[Semantic Analysis]
E --> F[LLVM IR Generation]
F --> G[col6forge Output .ll]
F --> H[col6forge-cc / zig cc]
H --> I[Object / Executable]
H --> J[col6forge_rt]
Loading

The pipeline stages have explicit profile sampling points in the source code:

  • read
  • normalize
  • parse
  • semantic
  • codegen
  • pipeline

When -ftime-report or --time-report is enabled, the CLI will output a total/read/normalize/parse/sema/codegen elapsed time summary to standard error.

Repository Structure

PathPurpose
src/main.zigMain CLI entry point, handles both IR mode and cc driver mode
src/root.zigExported library API, exposing frontend, semantics, codegen, and pipeline capabilities
src/frontend/Fixed/free form normalization, lexical and syntax analysis
src/semantic/Semantic analysis, symbols/scopes, constraint checking
src/codegen/LLVM IR generation
src/runtime/col6forge_rt runtime implementation
src/driver/Pipeline and cc driver
src/tools/Tools for golden/verify/gcc-dg/BLAS/LAPACK/perf/docgen/audit, etc.
tests/Test assets including NIST F78, GCC, BLAS, LAPACK, MINPACK, diagnostic golden, etc.
docs/Supplementary documentation; may lag behind except for error code docs
scratch/Experimental examples and mixed-language experiments

Environment Requirements

  • Zig: 0.16.0 or higher
  • It is recommended to execute all commands in the root directory of the repository.
  • To run NIST / BLAS / LAPACK baseline verification, gfortran is typically required on the machine.

The repository's build.zig.zon explicitly declares:

minimum_zig_version = 0.16.0

Quick Start

1. Perform a Quick Compilation Check First

zig build check

2. Output LLVM IR

The repository includes a minimal example hello.f:

PROGRAM HELLO
WRITE (*,*) 'HELLO, COL6FORGE'
END

Compile it into LLVM IR. Note: IR mode does not automatically create parent directories for the output file, so output directly to the current directory here:

zig build run -- hello.f -emit-llvm -o hello.ll

3. Compile and Link Directly into an Executable

zig build cc -- hello.f -o zig-out/hello.exe

Execution result:

HELLO, COL6FORGE

4. Install to zig-out/

zig build

By default, it will install:

  • zig-out/bin/col6forge
  • zig-out/bin/col6forge-cc
  • The col6forge_rt static library under zig-out/lib/

Command Reference

CLI Mode

col6forge: IR Mode

zig build run -- <input.f> -emit-llvm -o <out.ll>

Common flags:

FlagPurpose
-emit-llvmOutputs LLVM IR, currently the default and only publicly exposed output type
-o <path>Specifies the output path; parent directories must pre-exist in IR mode
-fbounds-checkEnables runtime array bounds checking
`-fpause-mode <autocontinue
-ftime-report / --time-reportOutputs the total/read/normalize/parse/sema/codegen time summary
-h / --helpDisplays help

Examples:

zig build run -- hello.f -emit-llvm -o hello.ll
zig build run -- hello.f -fbounds-check -fpause-mode=continue -o hello.ll

col6forge cc / col6forge-cc / col6cc: Driver Mode

zig build cc -- <inputs...> [options] [-- <zig-cc-flags...>]

Driver Rules:

  • Fortran inputs will first go through Col6Forge's LLVM IR pipeline.
  • Other inputs will be forwarded directly to zig cc.
  • -flag options not consumed by col6forge cc itself are usually forwarded directly to zig cc; if necessary, they can be explicitly appended after -- <zig-cc-flags...>.
  • In non--c modes, the col6forge_rt runtime will be automatically linked as long as Fortran inputs are present.
  • In -c mode, if -o is explicitly provided, there must be exactly one compilable input unit.
  • The -c mode does not accept pure linker inputs (e.g., .o/.obj/.a/.lib/.so/.dll).
  • The driver extracts -target / --target, -mcpu, and -ofmt from transparently passed arguments to build/reuse a runtime object cache matching the target configuration.
  • Every run of the cc driver generates temporary translation artifacts under zig-cache/cc-driver/<timestamp>/ and reuses the runtime object cache under zig-cache/cc-driver/cache/.

Common Examples:

zig build cc -- hello.f -o zig-out/hello.exe
zig build cc -- a.f b.f90 helper.c -O2 -o zig-out/app.exe
zig build cc -- a.f -c
zig build cc -- a.f -- -target x86_64-windows-gnu
zig build cc -- a.f -- --target=x86_64-linux-gnu

Notes:

  • Fortran source file extensions are currently recognized as .f/.for/.f77/.f90/.f95/.f03.
  • For non-Fortran files, .c/.cc/.cpp/.cxx/.m/.mm/.s/.S/.ll are currently treated as compilable inputs, and other paths are treated as standard linking/transparent inputs.

Top-level zig build Steps

CommandPurpose
zig buildInstalls main artifacts to zig-out/
zig build run -- ...Runs col6forge
zig build cc -- ...Runs the col6forge-cc driver
zig build testRuns Zig unit tests
zig build checkPerforms compilation only, without running tests
zig build toolsInstalls all development tools
zig build tools-checkPerforms compilation only for all development tools
zig build architecture-auditRuns the architectural constraint auditor
zig build errors-docs-checkVerifies if docs/errors.md matches the source code
zig build errors-docsRegenerates docs/errors.md
zig build goldenRuns golden file tests
zig build diagnostic-goldenRuns diagnostic golden tests
zig build cc-diagnostic-goldenRuns cc translation diagnostic golden tests
zig build verifyRuns NIST F78 validation
zig build verify-strictStrict fallback gating for NIST F78
zig build gcc-dg-verifyRuns GCC gfortran.dg compilation validation
zig build blas-verifyRuns BLAS 3.12.0 validation
zig build lapack-verifyRuns LAPACK-lite 3.1.1 validation
zig build lapack-verify-strictStrict fallback gating for LAPACK
zig build test-allRuns the unified test harness
zig build perf-benchProfiles performance and outputs JSON
zig build perf-compareCompares two performance JSONs and reports regressions based on thresholds
zig build perf-regressCI alias for perf-compare
zig build perf-dashboardUpdates performance history and generates a Markdown dashboard

Validation and Testing Ecosystem

Test Assets Overview

The numbers below represent the recursive file counts in the current repository directories. They are provided to help understand the scale of the test assets, which does not equal the "actual runnable case count".

DirectoryFile CountPrimary Purpose
tests/NIST_F78_test_suite630Classic NIST F78 validation assets
tests/gcc-tests/gfortran.dg8717GCC gfortran.dg compilation validation assets
tests/BLAS-3.12.0365BLAS 3.12.0 validation assets
tests/LAPACK-lite-3.1.12555LAPACK-lite 3.1.1 validation assets
tests/MINPACK457MINPACK related assets
tests/diagnostic_golden10Pipeline diagnostic golden
tests/diagnostic_golden_cc10cc translation diagnostic golden
tests/adv_crowther10Supplementary historical test assets

Recommended Daily Regression Sequence

Quick regression:

zig build check
zig build architecture-audit
zig build errors-docs-check

Language and diagnostics regression:

zig build test
zig build golden
zig build diagnostic-golden
zig build cc-diagnostic-golden

Compatibility and external baseline regression:

zig build verify -- --filter FM715
zig build gcc-dg-verify -- --filter array_constructor_14
zig build blas-verify -- --filter xblat3d
zig build lapack-verify -- --filter xlintstds

Default Suites for test-all

The unified test harness currently has these suites built-in:

  • golden
  • diagnostic-golden
  • cc-diagnostic-golden
  • nist
  • gcc-dg

Note that gcc-dg is not enabled by default, while the other four suites are enabled by default.

To view the suite list:

zig build test-all -- --list-suites

Fallback Gating

Validation tools support fallback statistics and gating strategies:

  • disabled
  • report
  • budget
  • strict

Common usage:

zig build verify-strict
zig build verify -Dverify_max_fallbacks=3
zig build lapack-verify-strict
zig build lapack-verify -Dlapack_max_fallbacks=5

Diagnostics and Documentation Synchronization

Stable Error Codes

The project's error directory is derived from the error catalog in the source code and uses stable CFxxxx encoding.

Diagnostic format illustration:

path/to/file.f90:12:7: error[CFxxxx]: ...

docs/errors.md is Not Hand-Written

It is automatically generated from the source code:

zig build errors-docs
zig build errors-docs-check

Therefore:

  • If you want to add or modify error codes, please edit the error catalog in the source code.
  • Do not manually edit docs/errors.md directly.

Architecture Audit

The repository contains an explicit architectural constraint auditor that checks for several forbidden dependencies and forbidden patterns, such as:

  • Forbidding reverse dependencies on docs/errors.md from the source code logic.
  • Forbidding several legacy formatted entry paths from flowing back.
  • Forbidding partial semantic/codegen layers from reading compatibility mirror fields.
  • Checking whether the error code directory is complete, unique, and ordered.

Execution method:

zig build architecture-audit

Using as a Zig Dependency

build.zig has already exposed reusable artifacts:

  • module: Col6Forge
  • artifact: col6forge_rt
  • named lazy path: col6forge_rt_src
  • named lazy path: col6forge_rt_dir
  • named lazy path: col6forge_src_dir

A minimal Zig-side invocation example:

conststd=@import("std");
constCol6Forge=@import("Col6Forge");
pubfnmain() !void {
vargpa=std.heap.GeneralPurposeAllocator(.{}){};
defer_=gpa.deinit();
constresult=tryCol6Forge.runPipelineWithOptions(
gpa.allocator(),
"hello.f",
.llvm,
.{},
);
defergpa.allocator().free(result.output);
trystd.io.getStdOut().writeAll(result.output);
}

The library interface provides direct access to:

  • Frontend normalization and parsing
  • Semantic analysis
  • Pipeline execution
  • Diagnostic output
  • Profile sample capturing

License

This project is licensed under the Apache License 2.0.

See the LICENSE file in the root directory for details.

About

A modern Fortran frontend and compiler driver written in Zig. It parses legacy and free-form Fortran, emits LLVM IR, and leverages zig cc for seamless cross-platform compilation.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

Repository files navigation

Col6Forge

A Fortran Frontend and Compiler Driver Written in Zig

Starting from .f/.for/.f77/.f90/.f95/.f03 inputs, going through lexical/parsing/semantic analysis and LLVM IR generation, and finally utilizing zig cc to build object files or executables.

Project Overview

Col6Forge is currently not a "wrapper script for gfortran", but a genuine, standalone frontend pipeline:

  1. Reads Fortran source files.
  2. Automatically detects fixed form / free form.
  3. Normalizes logical lines while preserving source location mappings.
  4. Executes lexical, parsing, and semantic analysis.
  5. Generates LLVM IR.
  6. In cc mode, passes the generated IR along with the runtime to zig cc for compilation/linking.

There are two main entry points:

  • col6forge Directly runs the frontend pipeline and outputs LLVM IR.
  • col6forge cc / col6forge-cc Processes Fortran inputs in a manner similar to cc, and passes non-Fortran inputs and additional arguments transparently to zig cc.

The repository also includes multiple built-in development toolsets for golden testing, NIST F78 validation, GCC gfortran.dg compilation validation, BLAS/LAPACK validation, performance regression comparison, error code documentation generation, and architecture auditing.

Current Implementation Scope

Language Frontend

  • Supports fixed form and free form inputs, with heuristic auto-detection based on extensions and content.
  • Fixed form normalization covers classic column rules, and is compatible with tab-format as well as continuation variants shifted right by one or two columns.
  • Diagnostics for both free form and fixed form attempt to fall back to the original source row and column, rather than solely reporting the normalized logical line position.

Language Support Status

Stable (Production Ready)

  • F77 Core: Fixed-form source, basic types (INTEGER, REAL, DOUBLE PRECISION, COMPLEX, LOGICAL, CHARACTER), COMMON, DO/IF, SUBROUTINE/FUNCTION, ENTRY, alternate returns
  • F90 Arrays: ALLOCATABLE, array constructors [...], basic array operations
  • F2003 OOP Basics: Derived types, EXTENDS (type inheritance), member access

Experimental (Parsed but Incomplete Codegen)

  • F90 Modules: MODULE syntax parsed, but procedures inside modules may fail to link
  • F2003 C Interop: BIND(C) and iso_c_binding parsed, but symbol generation incomplete
  • SUBMODULE: Syntax recognized, but codegen not fully implemented
  • Advanced Features: INTERFACE, generic interfaces, type-bound procedures, ABSTRACT, deferred bindings

Not Supported

  • F2008+ Concurrency: DO CONCURRENT, Coarrays, SYNC statements
  • F2008+ Parallel: No parallel runtime features
  • Advanced F2003: Procedure pointers, abstract interfaces with complex signatures

Additional Coverage

  • CONTAINS internal procedures
  • USE, ONLY, rename, and module prelude propagation
  • EQUIVALENCE consistency checks
  • Implicit typing rules
  • Intrinsic resolution and arity checks for calls

Code Generation and Runtime

  • The currently exposed EmitKind is only llvm, representing LLVM IR.
  • The cc mode automatically links the col6forge_rt runtime when Fortran inputs are present.
  • The runtime source tree already includes modules for formatted I/O, list-directed I/O, binary/direct/unformatted I/O, dynamic formats, PAUSE, and complex/integer helpers.
  • Optional runtime array bounds checking and PAUSE behavior control have been integrated into the command line.

Toolchain and Validation

  • zig build check for fast compilation-level regression checks.
  • zig build test to run Zig unit tests.
  • zig build golden / diagnostic-golden / cc-diagnostic-golden for golden validation.
  • zig build verify for NIST F78 execution validation.
  • zig build gcc-dg-verify for GCC gfortran.dg compilation validation.
  • zig build blas-verify / lapack-verify for numerical library validation.
  • zig build perf-bench / perf-compare / perf-dashboard for performance profiling, comparison, and historical dashboard generation.

Overall Architecture

flowchart LR
A[Fortran Source] --> B[Source Form Detection]
B --> C[Normalization]
C --> D[Lexer / Parser]
D --> E[Semantic Analysis]
E --> F[LLVM IR Generation]
F --> G[col6forge Output .ll]
F --> H[col6forge-cc / zig cc]
H --> I[Object / Executable]
H --> J[col6forge_rt]
Loading

The pipeline stages have explicit profile sampling points in the source code:

  • read
  • normalize
  • parse
  • semantic
  • codegen
  • pipeline

When -ftime-report or --time-report is enabled, the CLI will output a total/read/normalize/parse/sema/codegen elapsed time summary to standard error.

Repository Structure

PathPurpose
src/main.zigMain CLI entry point, handles both IR mode and cc driver mode
src/root.zigExported library API, exposing frontend, semantics, codegen, and pipeline capabilities
src/frontend/Fixed/free form normalization, lexical and syntax analysis
src/semantic/Semantic analysis, symbols/scopes, constraint checking
src/codegen/LLVM IR generation
src/runtime/col6forge_rt runtime implementation
src/driver/Pipeline and cc driver
src/tools/Tools for golden/verify/gcc-dg/BLAS/LAPACK/perf/docgen/audit, etc.
tests/Test assets including NIST F78, GCC, BLAS, LAPACK, MINPACK, diagnostic golden, etc.
docs/Supplementary documentation; may lag behind except for error code docs
scratch/Experimental examples and mixed-language experiments

Environment Requirements

  • Zig: 0.16.0 or higher
  • It is recommended to execute all commands in the root directory of the repository.
  • To run NIST / BLAS / LAPACK baseline verification, gfortran is typically required on the machine.

The repository's build.zig.zon explicitly declares:

minimum_zig_version = 0.16.0

Quick Start

1. Perform a Quick Compilation Check First

zig build check

2. Output LLVM IR

The repository includes a minimal example hello.f:

PROGRAM HELLO
WRITE (*,*) 'HELLO, COL6FORGE'
END

Compile it into LLVM IR. Note: IR mode does not automatically create parent directories for the output file, so output directly to the current directory here:

zig build run -- hello.f -emit-llvm -o hello.ll

3. Compile and Link Directly into an Executable

zig build cc -- hello.f -o zig-out/hello.exe

Execution result:

HELLO, COL6FORGE

4. Install to zig-out/

zig build

By default, it will install:

  • zig-out/bin/col6forge
  • zig-out/bin/col6forge-cc
  • The col6forge_rt static library under zig-out/lib/

Command Reference

CLI Mode

col6forge: IR Mode

zig build run -- <input.f> -emit-llvm -o <out.ll>

Common flags:

FlagPurpose
-emit-llvmOutputs LLVM IR, currently the default and only publicly exposed output type
-o <path>Specifies the output path; parent directories must pre-exist in IR mode
-fbounds-checkEnables runtime array bounds checking
`-fpause-mode <autocontinue
-ftime-report / --time-reportOutputs the total/read/normalize/parse/sema/codegen time summary
-h / --helpDisplays help

Examples:

zig build run -- hello.f -emit-llvm -o hello.ll
zig build run -- hello.f -fbounds-check -fpause-mode=continue -o hello.ll

col6forge cc / col6forge-cc / col6cc: Driver Mode

zig build cc -- <inputs...> [options] [-- <zig-cc-flags...>]

Driver Rules:

  • Fortran inputs will first go through Col6Forge's LLVM IR pipeline.
  • Other inputs will be forwarded directly to zig cc.
  • -flag options not consumed by col6forge cc itself are usually forwarded directly to zig cc; if necessary, they can be explicitly appended after -- <zig-cc-flags...>.
  • In non--c modes, the col6forge_rt runtime will be automatically linked as long as Fortran inputs are present.
  • In -c mode, if -o is explicitly provided, there must be exactly one compilable input unit.
  • The -c mode does not accept pure linker inputs (e.g., .o/.obj/.a/.lib/.so/.dll).
  • The driver extracts -target / --target, -mcpu, and -ofmt from transparently passed arguments to build/reuse a runtime object cache matching the target configuration.
  • Every run of the cc driver generates temporary translation artifacts under zig-cache/cc-driver/<timestamp>/ and reuses the runtime object cache under zig-cache/cc-driver/cache/.

Common Examples:

zig build cc -- hello.f -o zig-out/hello.exe
zig build cc -- a.f b.f90 helper.c -O2 -o zig-out/app.exe
zig build cc -- a.f -c
zig build cc -- a.f -- -target x86_64-windows-gnu
zig build cc -- a.f -- --target=x86_64-linux-gnu

Notes:

  • Fortran source file extensions are currently recognized as .f/.for/.f77/.f90/.f95/.f03.
  • For non-Fortran files, .c/.cc/.cpp/.cxx/.m/.mm/.s/.S/.ll are currently treated as compilable inputs, and other paths are treated as standard linking/transparent inputs.

Top-level zig build Steps

CommandPurpose
zig buildInstalls main artifacts to zig-out/
zig build run -- ...Runs col6forge
zig build cc -- ...Runs the col6forge-cc driver
zig build testRuns Zig unit tests
zig build checkPerforms compilation only, without running tests
zig build toolsInstalls all development tools
zig build tools-checkPerforms compilation only for all development tools
zig build architecture-auditRuns the architectural constraint auditor
zig build errors-docs-checkVerifies if docs/errors.md matches the source code
zig build errors-docsRegenerates docs/errors.md
zig build goldenRuns golden file tests
zig build diagnostic-goldenRuns diagnostic golden tests
zig build cc-diagnostic-goldenRuns cc translation diagnostic golden tests
zig build verifyRuns NIST F78 validation
zig build verify-strictStrict fallback gating for NIST F78
zig build gcc-dg-verifyRuns GCC gfortran.dg compilation validation
zig build blas-verifyRuns BLAS 3.12.0 validation
zig build lapack-verifyRuns LAPACK-lite 3.1.1 validation
zig build lapack-verify-strictStrict fallback gating for LAPACK
zig build test-allRuns the unified test harness
zig build perf-benchProfiles performance and outputs JSON
zig build perf-compareCompares two performance JSONs and reports regressions based on thresholds
zig build perf-regressCI alias for perf-compare
zig build perf-dashboardUpdates performance history and generates a Markdown dashboard

Validation and Testing Ecosystem

Test Assets Overview

The numbers below represent the recursive file counts in the current repository directories. They are provided to help understand the scale of the test assets, which does not equal the "actual runnable case count".

DirectoryFile CountPrimary Purpose
tests/NIST_F78_test_suite630Classic NIST F78 validation assets
tests/gcc-tests/gfortran.dg8717GCC gfortran.dg compilation validation assets
tests/BLAS-3.12.0365BLAS 3.12.0 validation assets
tests/LAPACK-lite-3.1.12555LAPACK-lite 3.1.1 validation assets
tests/MINPACK457MINPACK related assets
tests/diagnostic_golden10Pipeline diagnostic golden
tests/diagnostic_golden_cc10cc translation diagnostic golden
tests/adv_crowther10Supplementary historical test assets

Recommended Daily Regression Sequence

Quick regression:

zig build check
zig build architecture-audit
zig build errors-docs-check

Language and diagnostics regression:

zig build test
zig build golden
zig build diagnostic-golden
zig build cc-diagnostic-golden

Compatibility and external baseline regression:

zig build verify -- --filter FM715
zig build gcc-dg-verify -- --filter array_constructor_14
zig build blas-verify -- --filter xblat3d
zig build lapack-verify -- --filter xlintstds

Default Suites for test-all

The unified test harness currently has these suites built-in:

  • golden
  • diagnostic-golden
  • cc-diagnostic-golden
  • nist
  • gcc-dg

Note that gcc-dg is not enabled by default, while the other four suites are enabled by default.

To view the suite list:

zig build test-all -- --list-suites

Fallback Gating

Validation tools support fallback statistics and gating strategies:

  • disabled
  • report
  • budget
  • strict

Common usage:

zig build verify-strict
zig build verify -Dverify_max_fallbacks=3
zig build lapack-verify-strict
zig build lapack-verify -Dlapack_max_fallbacks=5

Diagnostics and Documentation Synchronization

Stable Error Codes

The project's error directory is derived from the error catalog in the source code and uses stable CFxxxx encoding.

Diagnostic format illustration:

path/to/file.f90:12:7: error[CFxxxx]: ...

docs/errors.md is Not Hand-Written

It is automatically generated from the source code:

zig build errors-docs
zig build errors-docs-check

Therefore:

  • If you want to add or modify error codes, please edit the error catalog in the source code.
  • Do not manually edit docs/errors.md directly.

Architecture Audit

The repository contains an explicit architectural constraint auditor that checks for several forbidden dependencies and forbidden patterns, such as:

  • Forbidding reverse dependencies on docs/errors.md from the source code logic.
  • Forbidding several legacy formatted entry paths from flowing back.
  • Forbidding partial semantic/codegen layers from reading compatibility mirror fields.
  • Checking whether the error code directory is complete, unique, and ordered.

Execution method:

zig build architecture-audit

Using as a Zig Dependency

build.zig has already exposed reusable artifacts:

  • module: Col6Forge
  • artifact: col6forge_rt
  • named lazy path: col6forge_rt_src
  • named lazy path: col6forge_rt_dir
  • named lazy path: col6forge_src_dir

A minimal Zig-side invocation example:

conststd=@import("std");
constCol6Forge=@import("Col6Forge");
pubfnmain() !void {
vargpa=std.heap.GeneralPurposeAllocator(.{}){};
defer_=gpa.deinit();
constresult=tryCol6Forge.runPipelineWithOptions(
gpa.allocator(),
"hello.f",
.llvm,
.{},
);
defergpa.allocator().free(result.output);
trystd.io.getStdOut().writeAll(result.output);
}

The library interface provides direct access to:

  • Frontend normalization and parsing
  • Semantic analysis
  • Pipeline execution
  • Diagnostic output
  • Profile sample capturing

License

This project is licensed under the Apache License 2.0.

See the LICENSE file in the root directory for details.

About

A modern Fortran frontend and compiler driver written in Zig. It parses legacy and free-form Fortran, emits LLVM IR, and leverages zig cc for seamless cross-platform compilation.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages