Research Article

SPOT: A DSL for Extending Fortran Programs with Metaprogramming

Table 1

Overview of SPOT syntax and semantic.

Language constructs

Scope constructsProjectProject-wide transformation
FileFile-wide transformation
ModuleIndicate module definition
ClassIndicate class definition
FunctionIndicate function definition

User defined typeIntegerDefine an integer variable
StringDefine a string variable

Basic constructsFunctionCallIndicate expression of function call
VariableReadIndicate expression of variable read
VariableWriteIndicate expression of variable write
VariableDeclIndicate expression of variable declaration
StatementIndicate statement of any type
StatementType*Indicate statement of a particular type

Keywords for scope clock

Within(construct <name>) Get the scope of transformation. Supported scopes include a project, a file, a module, a function, and statements implying a scope (e.g., condition or loop statement)

Before(<para>*)/Before Perform transformation before an entity

After(<para>)/After Perform transformation after an entity

Keywords for control flow

IF(<expr>*) ELSE Proceed based on the value of expr

FORALL(construct<name>/<Pattern>) List all constructs specified with name

Primary actions

FunctionRenameFunction(<oldName>, <newName>)
FindFunctionCall(<funName>)

VariableAddVariable(<type>, <name>, <intialValue>)
AddVariables(<type>, <name1>, <name2>,…) //with the same type
DeleteVariable(<name>)
RenameVariable(<oldName>, <newName>)
FindVariableRead/Write(<name>)

StatementAddStatement(<“stmt*”>)/ AddStatement(<loc>, <targetStmt>, <“stmt”>)
AddCallStatement(<loc>, <targetStmt>, <funName>, <parameterList>)
DeleteStatement(<“stmt”>)/ DeleteStatement(<loc>, <targetStmt>,<“stmt”>)
ReplaceStatement(<“oldStmt”>, <“newStmt”>)

Auxiliary functionality

Retrieve functionsFunction <fun> = getFunctionDef(<name>)
Module <md> = getModuleDef(<name>)
StatementType %<stList> = getStatementType( )
Statement %<stList> = getStatementAll(<“stmt”>/<pattern>)
Statement  <st>  = getStatement(lineNumber) 
Statement  <st>  = getStatement(<“stmt”>/<pattern>)
Statement  <st>  = getStatementIndex*(<“stmt”>/<pattern>)
VariableWrite  %<vw>=getVariableWrite(<varName>)
VariableRead  %<vr>=getVariableRead(<varName>)
VariableDecl  <vd> = getVariableDecl(<name>)

Include blockIncludeCode  {source code in Fortran}
IncludeCode  {source code in Fortran}  into  <filename>

(1) Fortran syntax needs to be included within double quotes “”.
(2) para can be a construct variable or an expression (expr) or statement (stmt); stmt indicates a Fortran statement (within double quotes) or a pattern described with %var substituting for real expressions within a statement; expr indicates an actual Fortran expression or a pattern described with %var.
(3) %var is a user-defined variable representing a collection of entities, using $var to access an element in the collection.
(4) statementType indicates statement of a particular type (e.g., StatementFOR and StatementIF).
(5) statementIndex indicates the index-th statement with the same stmt or pattern.