def gen_code(self, parent): if self.field_space == "every": from psyclone.f2pygen import DeclGen from psyclone.psyir.nodes import BinaryOperation dim_var = DeclGen(parent, datatype="INTEGER", entity_decls=[self.variable.name]) parent.add(dim_var) # Update start loop bound self.start_expr = Literal("1", INTEGER_TYPE, parent=self) # Update stop loop bound if self._loop_type == "inner": index = "1" elif self._loop_type == "outer": index = "2" self.stop_expr = BinaryOperation(BinaryOperation.Operator.SIZE, parent=self) self.stop_expr.addchild( Reference(DataSymbol(self.field_name, INTEGER_TYPE), parent=self.stop_expr)) self.stop_expr.addchild( Literal(index, INTEGER_TYPE, parent=self.stop_expr)) else: # one of our spaces so use values provided by the infrastructure # loop bounds # TODO: Issue 440. Implement derive types in PSyIR if self._loop_type == "inner": self.start_expr = Reference(self.field_space + "%istart", parent=self) self.stop_expr = Reference(self.field_space + "%istop", parent=self) elif self._loop_type == "outer": self.start_expr = Reference(self.field_space + "%jstart", parent=self) self.stop_expr = Reference(self.field_space + "%jstop", parent=self) Loop.gen_code(self, parent)
def gen_code(self, parent): ''' Work out the appropriate loop bounds and then call the base class to generate the code ''' self.start_expr = Literal("1", INTEGER_TYPE, parent=self) if self._loop_type == "colours": self.stop_expr = Reference(DataSymbol("ncolour", INTEGER_TYPE), parent=self) elif self._loop_type == "colour": self.stop_expr = Array(DataSymbol("ncp_ncolour", INTEGER_TYPE), parent=self) self.stop_expr.addchild(Reference( DataSymbol("colour", INTEGER_TYPE)), parent=self.stop_expr) else: # This is a hack as the name is not a valid DataSymbol, it # is a call to a type-bound function. self.stop_expr = Reference(DataSymbol( self.field_name + "%get_ncell()", INTEGER_TYPE), parent=self) Loop.gen_code(self, parent)