The Fortran programming language continues to dominate the scientific computing community, with many production codes written in the outdated Fortran-77 dialect, yet with many non-standard extensions such as Cray poiters. This creates significant maintenance burden within the community, with tremendous efforts devoted to modernization. However, despite the modern age of advanced compiler frameworks, processing and transforming old Fortran codes remains challenging. In this paper, we present StmtTree, a new Fortran code transformation toolkit to address this issue. StmtTree abstracts the Fortran grammar into statement tree, offering both a low-level representation manipulation API and a high-level, easy-to-use query and manipulation mini-language. StmtTree simplifies the creation of customized Fortran transformation tools. Experiments show that StmtTree adapts well to legacy Fortran-77 codes, and complex tools such as removing unused statements can be developed with fewer than 100 lines of python code.
翻译:Fortran编程语言在科学计算领域仍占据主导地位,大量生产代码使用过时的Fortran-77方言编写,且包含许多非标准扩展(如Cray指针)。这给相关社区带来了沉重的维护负担,现代化改造工作耗费巨大。然而,尽管当前已进入先进的编译器框架时代,处理和转换传统Fortran代码仍面临挑战。本文提出StmtTree——一种新型Fortran代码转换工具包以解决该问题。StmtTree将Fortran语法抽象为语句树结构,同时提供底层表示操作API和高级易用的查询操作微型语言。该工具包显著简化了定制化Fortran转换工具的创建流程。实验表明,StmtTree能良好适配遗留的Fortran-77代码,开发复杂工具(如删除无用语句)仅需不足100行Python代码。