Skip to content
Snippets Groups Projects
Commit 072372c3 authored by Andreas Klöckner's avatar Andreas Klöckner
Browse files

Optionally allow running a C preprocessor on Fortran source

parent 468bc9c2
No related branches found
No related tags found
No related merge requests found
......@@ -116,7 +116,7 @@ def main():
kernels = [kernel]
elif args.lang in ["fortran", "floopy"]:
elif args.lang in ["fortran", "floopy", "fpp"]:
pre_transform_code = None
if args.transform:
with open(args.transform, "r") as xform_fd:
......@@ -132,7 +132,8 @@ def main():
+ pre_transform_code)
from loopy.frontend.fortran import f2loopy
kernels = f2loopy(infile_content, pre_transform_code=pre_transform_code)
kernels = f2loopy(infile_content, pre_transform_code=pre_transform_code,
use_c_preprocessor=(args.lang == "fpp"))
if args.name is not None:
kernels = [kernel for kernel in kernels
......
......@@ -3,4 +3,4 @@
NAME="$1"
shift
python $(which loopy) --lang=floopy "$NAME" - "$@"
python $(which loopy) --lang=fpp "$NAME" - "$@"
......@@ -22,9 +22,39 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
"""
from loopy.diagnostic import LoopyError
def f2loopy(source, free_form=True, strict=True,
pre_transform_code=None):
pre_transform_code=None, use_c_preprocessor=False,
file_name="<floopy code>"):
if use_c_preprocessor:
try:
import ply.lex as lex
import ply.cpp as cpp
except ImportError:
raise LoopyError("Using the C preprocessor requires PLY to be installed")
lexer = lex.lex(cpp)
from ply.cpp import Preprocessor
p = Preprocessor(lexer)
p.parse(source, file_name)
tokens = []
while True:
tok = p.token()
if not tok:
break
if tok.type == "CPP_COMMENT":
continue
tokens.append(tok.value)
source = "".join(tokens)
from fparser import api
tree = api.parse(source, isfree=free_form, isstrict=strict,
analyze=False, ignore_comments=False)
......
......@@ -6,3 +6,6 @@ git+git://github.com/pyopencl/pyopencl
git+git://github.com/inducer/pymbolic
hg+https://bitbucket.org/inducer/f2py
# Optional, needed for using the C preprocessor on Fortran
ply>=3.6
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment