Skip to content

Commit 4a03b27

Browse files
author
Jean Luc Bouchot
committed
Updating var parsing for handling of real(wp) -- see snrm2
1 parent b86321e commit 4a03b27

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

run_tapenade_blas.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -669,11 +669,14 @@ def parse_fortran_function(file_path: Path, suppress_warnings=False):
669669
is_array = ('(' in line_stripped) and (')' in line_stripped)
670670

671671
# Parse variable declarations
672-
if line_stripped.startswith('REAL') or line_stripped.startswith('DOUBLE PRECISION') or line_stripped.startswith('FLOAT'):
672+
looking_for_var_decl = line_stripped[0:16].upper() # 16 is the length of DOUBLE PRECISION
673+
if looking_for_var_decl.startswith('REAL') or looking_for_var_decl.startswith('DOUBLE PRECISION') or looking_for_var_decl.startswith('FLOAT'):
673674
# Extract variable names from REAL, DOUBLE PRECISION, or FLOAT declaration
674-
real_decl = re.search(r'(?:REAL|DOUBLE PRECISION|FLOAT)\s+(.+)', line_stripped, re.IGNORECASE)
675+
real_decl = re.search(r'(?:REAL|DOUBLE PRECISION|FLOAT)(?:\(\w+\))?\s+(.+)', line_stripped, re.IGNORECASE)
675676
if real_decl:
676677
vars_str = real_decl.group(1)
678+
# Before anything, remove F90 style '::' declaration
679+
vars_str = vars_str.split("::")[-1]
677680
# First remove array dimensions, then split by comma
678681
vars_str_clean = re.sub(r'\([^)]*\)', '', vars_str)
679682
# Split by comma and clean up
@@ -686,10 +689,12 @@ def parse_fortran_function(file_path: Path, suppress_warnings=False):
686689
if is_array:
687690
array_vars.add(var)
688691

689-
elif line_stripped.startswith('INTEGER'):
692+
elif looking_for_var_decl.startswith('INTEGER'):
690693
int_decl = re.search(r'INTEGER\s+(.+)', line_stripped, re.IGNORECASE)
691694
if int_decl:
692695
vars_str = int_decl.group(1)
696+
# Before anything, remove F90 style '::' declaration
697+
vars_str = vars_str.split("::")[-1]
693698
# First remove array dimensions, then split by comma
694699
vars_str_clean = re.sub(r'\([^)]*\)', '', vars_str)
695700
for var in vars_str_clean.split(','):
@@ -700,10 +705,12 @@ def parse_fortran_function(file_path: Path, suppress_warnings=False):
700705
if is_array:
701706
array_vars.add(var)
702707

703-
elif line_stripped.startswith('CHARACTER'):
708+
elif looking_for_var_decl.startswith('CHARACTER'):
704709
char_decl = re.search(r'CHARACTER\s+(.+)', line_stripped, re.IGNORECASE)
705710
if char_decl:
706711
vars_str = char_decl.group(1)
712+
# Before anything, remove F90 style '::' declaration
713+
vars_str = vars_str.split("::")[-1]
707714
# First remove array dimensions, then split by comma
708715
vars_str_clean = re.sub(r'\([^)]*\)', '', vars_str)
709716
for var in vars_str_clean.split(','):
@@ -714,11 +721,13 @@ def parse_fortran_function(file_path: Path, suppress_warnings=False):
714721
if is_array:
715722
array_vars.add(var)
716723

717-
elif line_stripped.startswith('COMPLEX'):
724+
elif looking_for_var_decl.startswith('COMPLEX'):
718725
# Extract variable names from COMPLEX declaration
719726
complex_decl = re.search(r'COMPLEX\*?\d*\s+(.+)', line_stripped, re.IGNORECASE)
720727
if complex_decl:
721728
vars_str = complex_decl.group(1)
729+
# Before anything, remove F90 style '::' declaration
730+
vars_str = vars_str.split("::")[-1]
722731
# First remove array dimensions, then split by comma
723732
vars_str_clean = re.sub(r'\([^)]*\)', '', vars_str)
724733
# Split by comma and clean up
@@ -8384,7 +8393,7 @@ def parse_tap_trace4inout(fname):
83848393
f.write(("function " if func_type == 'FUNCTION' else "subroutine ") + src.stem + ":\n")
83858394
indent = " "
83868395
f.write(indent + "external:\n")
8387-
shape = "(" + ", ".join(["param " + str(i) for i in range(1,len(all_params)+1)] + ["result" if func_type == 'FUNCTION' else ""]) + ")" ## TODO: Need to add ', return' in case of a function,. dpeending on whether it is within the all params or not
8396+
shape = "(" + ", ".join(["param " + str(i) for i in range(1,len(all_params)+1)]) + (", result" if func_type == 'FUNCTION' else "" ) + ")" ## TODO: Need to add ', return' in case of a function,. dpeending on whether it is within the all params or not
83888397
f.write(indent + "shape: " + shape + "\n")
83898398
types = []
83908399
for p in param_for_genlib:

0 commit comments

Comments
 (0)