From: Francis Russell Date: Thu, 7 Jun 2012 10:39:06 +0000 (+0100) Subject: Initial work on module support. X-Git-Url: https://git.unchartedbackwaters.co.uk/w/?a=commitdiff_plain;h=5b4f1a3b94854864160f71255a9c6eaecd9afeb6;p=francis%2Fofc.git Initial work on module support. --- diff --git a/src/ofc/codegen/FortranGenerator.scala b/src/ofc/codegen/FortranGenerator.scala index d1f6bf2..13d39a9 100644 --- a/src/ofc/codegen/FortranGenerator.scala +++ b/src/ofc/codegen/FortranGenerator.scala @@ -51,7 +51,7 @@ class SymbolManager { // It seems these properties need to go after the type-related attributes for(property <- sym.getProperties) property match { - case (p: FortranProperty) => attributeStrings +:= p.getName + case (p: FortranAttribute) => attributeStrings +:= p.getName case _ => () } diff --git a/src/ofc/codegen/FortranProperty.scala b/src/ofc/codegen/FortranProperty.scala index 29680f1..de4db58 100644 --- a/src/ofc/codegen/FortranProperty.scala +++ b/src/ofc/codegen/FortranProperty.scala @@ -3,6 +3,15 @@ package ofc.codegen trait FortranProperty extends SymbolProperty { } -class AllocatableProperty extends FortranProperty { +trait FortranAttribute extends FortranProperty { + def getName : String +} + +case class AllocatableProperty() extends FortranAttribute { def getName = "allocatable" } + +case class FortranModule(module: String) extends FortranProperty { + def getName = module + def getModuleName : String = module +} diff --git a/src/ofc/codegen/FunctionSignature.scala b/src/ofc/codegen/FunctionSignature.scala index 75b5b4e..e87cfe7 100644 --- a/src/ofc/codegen/FunctionSignature.scala +++ b/src/ofc/codegen/FunctionSignature.scala @@ -1,7 +1,6 @@ package ofc.codegen -trait FunctionSignature[R <: Type] { - def getName: String +trait FunctionSignature[R <: Type] extends Symbol { def getReturnType: R def getParams: Seq[(String, Type)] } diff --git a/src/ofc/codegen/Statement.scala b/src/ofc/codegen/Statement.scala index 4028f7d..ee8862d 100644 --- a/src/ofc/codegen/Statement.scala +++ b/src/ofc/codegen/Statement.scala @@ -1,4 +1,7 @@ package ofc.codegen -trait Statement +trait Statement { + def expressions: Traversable[Expression[_]] +} + class NullStatement extends Statement diff --git a/src/ofc/codegen/Type.scala b/src/ofc/codegen/Type.scala index 861960d..2c6cbc4 100644 --- a/src/ofc/codegen/Type.scala +++ b/src/ofc/codegen/Type.scala @@ -44,7 +44,9 @@ final case class PointerType[TargetType <: Type](tType: TargetType) extends Type def getFortranAttributes = tType.getFortranAttributes + "pointer" } -abstract class StructType extends Type +abstract class StructType extends Type with Symbol { + def getFortranAttributes = Set("type(" + getName + ")") +} trait TypeBuilder[T <: Type] { def apply() : T diff --git a/src/ofc/generators/onetep/OnetepFunctions.scala b/src/ofc/generators/onetep/OnetepFunctions.scala index 268232e..8ab1325 100644 --- a/src/ofc/generators/onetep/OnetepFunctions.scala +++ b/src/ofc/generators/onetep/OnetepFunctions.scala @@ -2,6 +2,9 @@ package ofc.generators.onetep import ofc.codegen._ object OnetepFunctions { + + // module basis + val basis_copy_function_to_box = new FortranSubroutineSignature("basis_copy_function_to_box", Seq(("fa_box", new ArrayType[FloatType](3)), ("box_n1", new IntType), @@ -22,6 +25,10 @@ object OnetepFunctions { ("n2", new IntType), ("n3", new IntType))) + List(basis_copy_function_to_box, basis_ket_start_wrt_fftbox).map(_.addProperty(new FortranModule("basis"))) + + // module fourier + val fourier_apply_box_pair = new FortranSubroutineSignature("fourier_apply_box_pair", Seq(("grid", new CharType), ("dir", new CharType), @@ -29,6 +36,8 @@ object OnetepFunctions { ("rspc2", new ArrayType[FloatType](3)), ("gspc", new ArrayType[ComplexType](3)))) + List(fourier_apply_box_pair).map(_.addProperty(new FortranModule("fourier"))) + val sparse_first_elem_on_node = new FortranFunctionSignature[IntType]("sparse_first_elem_on_node", Seq(("node", new IntType), ("mat", OnetepTypes.SPAM3), @@ -52,4 +61,9 @@ object OnetepFunctions { ("jrow", new IntType), ("jcol", new IntType))) + List(sparse_first_elem_on_node, + sparse_index_length, + sparse_generate_index, + sparse_atom_of_elem, + sparse_put_element_real).map(_.addProperty(new FortranModule("fourier"))) } diff --git a/src/ofc/generators/onetep/OnetepTypes.scala b/src/ofc/generators/onetep/OnetepTypes.scala index dc965da..b0a3528 100644 --- a/src/ofc/generators/onetep/OnetepTypes.scala +++ b/src/ofc/generators/onetep/OnetepTypes.scala @@ -20,7 +20,7 @@ object OnetepTypes { new FieldSymbol[PointerType[ArrayType[StructType]]]("spheres", fieldType) } - def getFortranAttributes = Set("type(FUNC_BASIS)") + def getName = "FUNC_BASIS" } object Sphere extends StructType { @@ -30,8 +30,7 @@ object OnetepTypes { } val offset = new FieldSymbol[IntType]("offset") - - def getFortranAttributes = Set("type(SPHERE)") + def getName = "SPHERE" } object Point extends StructType { @@ -39,7 +38,7 @@ object OnetepTypes { val y = new FieldSymbol[FloatType]("Y") val z = new FieldSymbol[FloatType]("Z") val coord = List(x,y,z) - def getFortranAttributes = Set("type(POINT)") + def getName = "POINT" } object CellInfo extends StructType { @@ -49,7 +48,7 @@ object OnetepTypes { val pointsInPPD = new FieldSymbol[IntType]("n_pts") val latticeReciprocal = for(dim <- 1 to 3) yield new FieldSymbol[StructType]("b"+dim, Point) val weight = new FieldSymbol[FloatType]("weight") - def getFortranAttributes = Set("type(CELL_INFO)") + def getName = "CELL_INFO" } object TightBox extends StructType { @@ -57,17 +56,17 @@ object OnetepTypes { val finishPts = {for (dim <- 1 to 3) yield new FieldSymbol[IntType]("finish_pts"+dim)}.toSeq val startPPD = {for (dim <- 1 to 3) yield new FieldSymbol[IntType]("start_ppds"+dim)}.toSeq val finishPPD = {for (dim <- 1 to 3) yield new FieldSymbol[IntType]("finish_ppds"+dim)}.toSeq - def getFortranAttributes = Set("type(FUNCTION_TIGHT_BOX)") + def getName = "FUNCTION_TIGHT_BOX" } object FFTBoxInfo extends StructType { val public = new NamedUnboundVarSymbol[StructType]("pub_fftbox", FFTBoxInfo) val latticeReciprocal = for(dim <- 1 to 3) yield new FieldSymbol[StructType]("b"+dim, Point) val totalPts = {for (dim <- 1 to 3) yield new FieldSymbol[IntType]("total_pt"+dim)}.toSeq - def getFortranAttributes = Set("type(FFTBOX_INFO)") + def getName = "FFTBOX_INFO" } object SPAM3 extends StructType { - def getFortranAttributes = Set("type(SPAM3)") + def getName = "SPAM3" } } diff --git a/src/ofc/generators/onetep/OnetepVariables.scala b/src/ofc/generators/onetep/OnetepVariables.scala index 7a38733..6d7648d 100644 --- a/src/ofc/generators/onetep/OnetepVariables.scala +++ b/src/ofc/generators/onetep/OnetepVariables.scala @@ -6,4 +6,8 @@ object OnetepVariables { val pub_my_node_id = new NamedUnboundVarSymbol[IntType]("pub_my_node_id") val pub_first_atom_on_node = new NamedUnboundVarSymbol[ArrayType[IntType]]("pub_first_atom_on_node", new ArrayType[IntType](1)) val pub_num_atoms_on_node = new NamedUnboundVarSymbol[ArrayType[IntType]]("pub_num_atoms_on_node", new ArrayType[IntType](1)) + + List(pub_my_node_id, + pub_first_atom_on_node, + pub_num_atoms_on_node).map(_.addProperty(new FortranModule("parallel_strategy"))) }