Skip to content
Snippets Groups Projects

Draft: Fortran Support

1 file
+ 10
5
Compare changes
  • Side-by-side
  • Inline
+ 10
5
@@ -334,7 +334,7 @@ class TemplateManager:
@@ -334,7 +334,7 @@ class TemplateManager:
inst.set_rank_executing(rank_to_execute)
inst.set_rank_executing(rank_to_execute)
self._instructions.append(inst)
self._instructions.append(inst)
def add_stack_variable(self, variable_type: str, name: str = "", init: str = "", arr_dim: int = 0) -> str:
def add_stack_variable(self, variable_type: str, name: str = "", init: str = "", arr_dim: int = 1) -> str:
"""
"""
Adds a new stack variable and returns its name to be used in the code.
Adds a new stack variable and returns its name to be used in the code.
the variable is initialized with the initializer given by the correctParameter class
the variable is initialized with the initializer given by the correctParameter class
@@ -355,14 +355,19 @@ class TemplateManager:
@@ -355,14 +355,19 @@ class TemplateManager:
return name
return name
def get_stack_var(self, typename: str, name: str):
def get_stack_var(self, typename: str, name: str):
init = self._stack_variable_inits[name] if name in self._stack_variable_inits else CorrectParameterFactory().get_initializer(typename)
init = ""
 
if name in self._stack_variable_inits: init = self._stack_variable_inits[name] # Explicit init has priority
 
if not init and CorrectParameterFactory().get_initializer(typename): # If no explicit init, but implicit exists...
 
for _ in range(self._stack_variable_dims[name]): # Initialize for each element in array
 
init = init + CorrectParameterFactory().get_initializer(typename) + ", "
 
init = init[:-2] # remove last ", "
 
if init and self._stack_variable_dims[name] > 1: init = "{" + init + "}" # Add initializer braces
if init: init = f"= {init}"
if init: init = f"= {init}"
dims = ""
if infvars.generator_language == "c":
if infvars.generator_language == "c":
if self._stack_variable_dims[name] > 0: dims = f"[{self._stack_variable_dims[name]}]"
dims = f"[{self._stack_variable_dims[name]}]" if self._stack_variable_dims[name] > 1 else "" # Set array dimension
return f"{typename} {name}{dims} {init};\n"
return f"{typename} {name}{dims} {init};\n"
else:
else:
if self._stack_variable_dims[name] > 0: dims = f"({self._stack_variable_dims[name]})"
dims = f"(0:{self._stack_variable_dims[name] - 1})" if self._stack_variable_dims[name] > 1 else "" # Set array dimension, including explicit starting index!
init = init.replace("{", "(/").replace("}", "/)")
init = init.replace("{", "(/").replace("}", "/)")
type_prefix = f"type({typename})"
type_prefix = f"type({typename})"
if typename == "int": type_prefix = "integer"
if typename == "int": type_prefix = "integer"
Loading