Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

F frontend #1275

Merged
merged 16 commits into from
Jun 27, 2023
62 changes: 62 additions & 0 deletions dace/cli/fcdc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Copyright 2019-2023 ETH Zurich and the DaCe authors. All rights reserved.
""" Simple Fortran SDFG command-line compiler. """

import dace
import os
import sys
import argparse
import shutil
from dace.frontend.fortran import fortran_parser

def main():
# Command line options parser
parser = argparse.ArgumentParser(description='Fortran to SDFG command-line transpiler.')

# Required argument for Fortran file path
parser.add_argument('filepath', help='<PATH TO FORTRAN FILE>', type=str)

# Optional argument for output location
parser.add_argument('-o',
'--out',
type=str,
help='If provided, saves library as the given file or in the specified path, '
'together with a header file.')

parser.add_argument('-O',
'--optimize',
dest='optimize',
action='store_true',
help="If set, invokes the command-line optimization"
" interface",
default=False)

args = parser.parse_args()

filepath = args.filepath
if not os.path.isfile(filepath):
print('Fortran file', filepath, 'not found')
exit(1)

outpath = args.out

# Load SDFG
sdfg = fortran_parser.create_sdfg_from_fortran_file(filepath)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit sad that fcdc has to live separate from sdfgcc, since they seem functionally and programatically identical in all but one (or two, if you count the import) line.

What do you think about just using sdfgcc and detecting whether something is an SDFG or Fortran file? The name sdfgcc may be sub-optimal in that case, maybe it makes sense to have a dace-cc that autodetects (or is told explicitly what it is with --source-lang, and have sdfgcc alias dace-cc --source-lang=sdfg and fcdc alias dace-cc --source-lang=fortran.

Not a crucial point, but the code duplication is a bit sad.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed - this was done by request of @tbennun . What do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about this. We can discuss

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seconding the idea of dace-cc with autodetection and additional parameters.


if args.optimize:
sdfg.optimize()

# Compile SDFG
sdfg.compile(outpath)

# Copying header file to optional path
if outpath is not None:
source = os.path.join(sdfg.build_folder, 'include', sdfg.name + '.h')
if os.path.isdir(outpath):
outpath = os.path.join(outpath, sdfg.name + '.h')
else:
outpath = os.path.join(os.path.dirname(outpath), sdfg.name + '.h')
shutil.copyfile(source, outpath)


if __name__ == '__main__':
main()
Empty file.