]> git.unchartedbackwaters.co.uk Git - francis/ofc.git/commitdiff
Initial work on module support.
authorFrancis Russell <francis@unchartedbackwaters.co.uk>
Thu, 7 Jun 2012 10:39:06 +0000 (11:39 +0100)
committerFrancis Russell <francis@unchartedbackwaters.co.uk>
Thu, 7 Jun 2012 10:39:06 +0000 (11:39 +0100)
src/ofc/codegen/FortranGenerator.scala
src/ofc/codegen/FortranProperty.scala
src/ofc/codegen/FunctionSignature.scala
src/ofc/codegen/Statement.scala
src/ofc/codegen/Type.scala
src/ofc/generators/onetep/OnetepFunctions.scala
src/ofc/generators/onetep/OnetepTypes.scala
src/ofc/generators/onetep/OnetepVariables.scala

index d1f6bf2a1d921130b26d812d1f99e7d18b309b7a..13d39a94a4988c13f8cecd647f84ee2003ba9630 100644 (file)
@@ -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 _ => ()
       }
 
index 29680f18270b0ebbf5e3ed5c6b5fa93a3fef8edf..de4db58f1f8a41966fe93f61f60c1abcaa7db6e7 100644 (file)
@@ -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
+}
index 75b5b4e0adab2aa20f7e553a40c73321b331b430..e87cfe716334bd35ea62dd07cb01ea1186912699 100644 (file)
@@ -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)]
 }
index 4028f7d8895d1c4ba3f9da0ec698105344daafed..ee8862dabb07f0b86e2b8efcda7713a72f385ae0 100644 (file)
@@ -1,4 +1,7 @@
 package ofc.codegen
 
-trait Statement
+trait Statement {
+  def expressions: Traversable[Expression[_]]
+}
+
 class NullStatement extends Statement
index 861960d357f2183bfceb5cf0932ac6daa4c73458..2c6cbc4d8491b6debbb60bf518fea7efc1723420 100644 (file)
@@ -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
index 268232ea5edac6d67953758df2cb7112f7d6b70f..8ab132571c695ceae6dab5adab8dd64924a1dd4b 100644 (file)
@@ -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")))
 }
index dc965dab265b84ab6076385269dff8c66fbf7961..b0a3528dadc5bd37d331296c466856e758ac445f 100644 (file)
@@ -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"
   }
 }
index 7a38733e8a054983ab63a44465f581d30687247d..6d7648df3fb779331ae044f5976f3251c49f52a7 100644 (file)
@@ -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")))
 }