Skip to content

Commit

Permalink
Frontend: Final removal of OFP frontend
Browse files Browse the repository at this point in the history
o7
  • Loading branch information
mlange05 committed Jan 8, 2025
1 parent ad1e2bc commit ec41880
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 2,107 deletions.
1 change: 0 additions & 1 deletion loki/frontend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

from loki.frontend.preprocessing import * # noqa
from loki.frontend.source import * # noqa
from loki.frontend.ofp import * # noqa
from loki.frontend.omni import * # noqa
from loki.frontend.fparser import * # noqa
from loki.frontend.util import * # noqa
Expand Down
1,973 changes: 0 additions & 1,973 deletions loki/frontend/ofp.py

This file was deleted.

14 changes: 0 additions & 14 deletions loki/frontend/preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
__all__ = ['preprocess_cpp', 'sanitize_input', 'sanitize_registry', 'PPRule']


OFP = Frontend.OFP


def preprocess_cpp(source, filepath=None, includes=None, defines=None):
"""
Invoke an external C-preprocessor to sanitize input files.
Expand Down Expand Up @@ -233,17 +230,6 @@ def postprocess(self, ir, info):
'FYPP ANNOTATIONS': PPRule(match=re.compile(r'(# [1-9].*\".*\.fypp\"\n)'), replace=''),
},
OMNI: {},
OFP: {
# Remove various IBM directives
'IBM_DIRECTIVES': PPRule(match=re.compile(r'(@PROCESS.*\n)'), replace='\n'),

# Despite F2008 compatability, OFP does not recognise the CONTIGUOUS keyword :(
'CONTIGUOUS': PPRule(
match=re.compile(r', CONTIGUOUS', re.I), replace='', postprocess=reinsert_contiguous),

# Strip line annotations from Fypp preprocessor
'FYPP ANNOTATIONS': PPRule(match=re.compile(r'(# [1-9].*\".*\.fypp\"\n)'), replace=''),
},
FP: {
# Remove various IBM directives
'IBM_DIRECTIVES': PPRule(match=re.compile(r'(@PROCESS.*\n)'), replace='\n'),
Expand Down
11 changes: 3 additions & 8 deletions loki/frontend/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ class Frontend(IntEnum):
"""
#: The OMNI compiler frontend
OMNI = 1
#: The Open Fortran Parser
OFP = 2
#: Fparser 2 from STFC
FP = 3
#: Reduced functionality parsing using regular expressions
Expand Down Expand Up @@ -68,7 +66,7 @@ def available_frontends(xfail=None, skip=None, include_regex=False):
Use as
..code-block::
@pytest.mark.parametrize('frontend', available_frontends(xfail=[OMNI, (OFP, 'Because...')]))
@pytest.mark.parametrize('frontend', available_frontends(xfail=[OMNI, (FP, 'Because...')]))
def my_test(frontend):
source = Sourcefile.from_file('some.F90', frontend=frontend)
# ...
Expand Down Expand Up @@ -112,8 +110,6 @@ def my_test(frontend):
# Build the list of parameters
params = []
for f in Frontend:
if f == Frontend.OFP:
continue # OFP is now deprecated!
if f in skip:
params += [pytest.param(f, marks=pytest.mark.skip(reason=skip[f]))]
elif f in xfail:
Expand Down Expand Up @@ -201,7 +197,7 @@ def inline_labels(ir):
"""
Find labels and merge them onto the following node.
Note: This is currently only required for OMNI and OFP frontends which
Note: This is currently only required for the OMNI frontend which
has labels as nodes next to the corresponding statement without
any connection between both.
"""
Expand Down Expand Up @@ -382,10 +378,9 @@ def sanitize_ir(_ir, frontend, pp_registry=None, pp_info=None):
# Revert OMNI's array dimension expansion from `a(n)` => `arr(1:n)`
_ir = RangeIndexTransformer(invalidate_source=False).visit(_ir)

if frontend in (OMNI, Frontend.OFP):
_ir = inline_labels(_ir)

if frontend in (FP, Frontend.OFP):
if frontend == FP:
_ir = CombineMultilinePragmasTransformer(inplace=True, invalidate_source=False).visit(_ir)
_ir = RemoveDuplicateVariableDeclarationsForExternalProcedures(inplace=True, invalidate_source=False).visit(_ir)

Expand Down
27 changes: 1 addition & 26 deletions loki/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
Contains the declaration of :any:`Module` to represent Fortran modules.
"""
from loki.frontend import (
get_fparser_node, parse_omni_ast, parse_ofp_ast, parse_fparser_ast,
get_fparser_node, parse_omni_ast, parse_fparser_ast,
parse_regex_source
)
from loki.ir import (
Expand Down Expand Up @@ -143,31 +143,6 @@ def from_omni(cls, ast, raw_source, definitions=None, parent=None, type_map=None
type_map=type_map, scope=parent
)

@classmethod
def from_ofp(cls, ast, raw_source, definitions=None, pp_info=None, parent=None):
"""
Create :any:`Module` from :any:`OFP` parse tree
Parameters
----------
ast :
The OFP parse tree
raw_source : str
Fortran source string
definitions : list
List of external :any:`Module` to provide derived-type and procedure declarations
pp_info :
Preprocessing info as obtained by :any:`sanitize_input`
parent : :any:`Scope`, optional
The enclosing parent scope of the module.
"""
if ast.tag != 'module':
ast = ast.find('file/module')
return parse_ofp_ast(
ast=ast, pp_info=pp_info, raw_source=raw_source,
definitions=definitions, scope=parent
)

@classmethod
def from_fparser(cls, ast, raw_source, definitions=None, pp_info=None, parent=None):
"""
Expand Down
7 changes: 1 addition & 6 deletions loki/program_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from loki.expression import Variable, parse_expr
from loki.frontend import (
Frontend, parse_omni_source, parse_ofp_source, parse_fparser_source,
Frontend, parse_omni_source, parse_fparser_source,
RegexParserClass, preprocess_cpp, sanitize_input
)
from loki.ir import (
Expand Down Expand Up @@ -163,11 +163,6 @@ def from_source(cls, source, definitions=None, preprocess=False,
return cls.from_omni(ast=ast, raw_source=source, definitions=definitions,
type_map=type_map, parent=parent)

if frontend == Frontend.OFP:
ast = parse_ofp_source(source)
return cls.from_ofp(ast=ast, raw_source=source, definitions=definitions,
pp_info=pp_info, parent=parent) # pylint: disable=possibly-used-before-assignment

if frontend == Frontend.FP:
ast = parse_fparser_source(source)
return cls.from_fparser(ast=ast, raw_source=source, definitions=definitions,
Expand Down
57 changes: 4 additions & 53 deletions loki/sourcefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
from loki.backend.fgen import fgen
from loki.backend.cufgen import cufgen
from loki.frontend import (
Frontend, OMNI, FP, REGEX, sanitize_input, Source, read_file, preprocess_cpp,
parse_omni_source, parse_ofp_source, parse_fparser_source,
parse_omni_ast, parse_ofp_ast, parse_fparser_ast, parse_regex_source,
Frontend, OMNI, FP, REGEX, sanitize_input, Source, read_file,
preprocess_cpp, parse_omni_source, parse_fparser_source,
parse_omni_ast, parse_fparser_ast, parse_regex_source,
RegexParserClass

)
Expand All @@ -32,9 +32,6 @@
__all__ = ['Sourcefile']


OFP = Frontend.OFP


class Sourcefile:
"""
Class to handle and manipulate source files, storing :any:`Module` and
Expand Down Expand Up @@ -136,9 +133,6 @@ def from_file(cls, filename, definitions=None, preprocess=False,
includes=includes, defines=defines,
xmods=xmods, omni_includes=omni_includes)

if frontend == OFP:
return cls.from_ofp(source, filepath, definitions=definitions)

if frontend == FP:
return cls.from_fparser(source, filepath, definitions=definitions)

Expand Down Expand Up @@ -205,42 +199,6 @@ def _from_omni_ast(cls, ast, path=None, raw_source=None, definitions=None, typet
source = Source(lines, string=raw_source, file=path)
return cls(path=path, ir=ir, ast=ast, source=source)

@classmethod
def from_ofp(cls, raw_source, filepath, definitions=None):
"""
Parse a given source string using the Open Fortran Parser (OFP) frontend
Parameters
----------
raw_source : str
Fortran source string
filepath : str or :any:`pathlib.Path`
The filepath of this source file
definitions : list
List of external :any:`Module` to provide derived-type and procedure declarations
"""
# Preprocess using internal frontend-specific PP rules
# to sanitize input and work around known frontend problems.
source, pp_info = sanitize_input(source=raw_source, frontend=OFP)

# Parse the file content into a Fortran AST
ast = parse_ofp_source(source, filepath=filepath)

return cls._from_ofp_ast(path=filepath, ast=ast, definitions=definitions,
pp_info=pp_info, raw_source=raw_source)

@classmethod
def _from_ofp_ast(cls, ast, path=None, raw_source=None, definitions=None, pp_info=None):
"""
Generate the full set of :any:`Subroutine` and :any:`Module` members
in the :any:`Sourcefile`.
"""
ir = parse_ofp_ast(ast.find('file'), pp_info=pp_info, definitions=definitions, raw_source=raw_source)

lines = (1, raw_source.count('\n') + 1)
source = Source(lines, string=raw_source, file=path)
return cls(path=path, ir=ir, ast=ast, source=source)

@classmethod
def from_fparser(cls, raw_source, filepath, definitions=None):
"""
Expand Down Expand Up @@ -343,9 +301,6 @@ def from_source(cls, source, definitions=None, preprocess=False,
return cls.from_omni(source, filepath=None, definitions=definitions, includes=includes,
defines=defines, xmods=xmods, omni_includes=omni_includes)

if frontend == OFP:
return cls.from_ofp(source, filepath=None, definitions=definitions)

if frontend == FP:
return cls.from_fparser(source, filepath=None, definitions=definitions)

Expand Down Expand Up @@ -378,7 +333,7 @@ def make_complete(self, **frontend_args):
elif frontend == OMNI:
frontend_argnames = ['definitions', 'type_map', 'symbol_map', 'scope']
xmods = frontend_args.get('xmods')
elif frontend in (OFP, FP):
elif frontend == FP:
frontend_argnames = ['definitions', 'scope']
else:
raise NotImplementedError(f'Unknown frontend: {frontend}')
Expand All @@ -402,10 +357,6 @@ def make_complete(self, **frontend_args):
elif frontend == OMNI:
ast = parse_omni_source(source=source, xmods=xmods)
ir_ = parse_omni_ast(ast=ast, raw_source=raw_source, **sanitized_frontend_args)
elif frontend == OFP:
ast = parse_ofp_source(source=source)
ir_ = parse_ofp_ast(ast, raw_source=raw_source, pp_info=pp_info,
**sanitized_frontend_args)
elif frontend == FP:
# Fparser is unable to parse comment-only source files/strings,
# so we see if this is only comments and convert them ourselves
Expand Down
27 changes: 1 addition & 26 deletions loki/subroutine.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from loki.expression import symbols as sym
from loki.frontend import (
parse_omni_ast, parse_ofp_ast, parse_fparser_ast, get_fparser_node,
parse_omni_ast, parse_fparser_ast, get_fparser_node,
parse_regex_source
)
from loki.ir import (
Expand Down Expand Up @@ -180,31 +180,6 @@ def from_omni(cls, ast, raw_source, definitions=None, parent=None, type_map=None
type_map=type_map, scope=parent
)

@classmethod
def from_ofp(cls, ast, raw_source, definitions=None, pp_info=None, parent=None):
"""
Create :any:`Subroutine` from :any:`OFP` parse tree
Parameters
----------
ast :
The OFP parse tree
raw_source : str
Fortran source string
definitions : list
List of external :any:`Module` to provide derived-type and procedure declarations
pp_info :
Preprocessing info as obtained by :any:`sanitize_input`
parent : :any:`Scope`, optional
The enclosing parent scope of the subroutine, typically a :any:`Module`.
"""
if ast.tag not in ('subroutine', 'function'):
ast = [r for r in as_tuple(ast.find('file')) if r.tag in ('subroutine', 'function')].pop()
return parse_ofp_ast(
ast=ast, pp_info=pp_info, raw_source=raw_source,
definitions=definitions, scope=parent
)

@classmethod
def from_fparser(cls, ast, raw_source, definitions=None, pp_info=None, parent=None):
"""
Expand Down

0 comments on commit ec41880

Please sign in to comment.