]> git.unchartedbackwaters.co.uk Git - francis/ofc.git/commitdiff
Allow "allocatable" to be set on a per-array basis.
authorFrancis Russell <francis@unchartedbackwaters.co.uk>
Sun, 20 May 2012 18:54:38 +0000 (19:54 +0100)
committerFrancis Russell <francis@unchartedbackwaters.co.uk>
Sun, 20 May 2012 18:54:38 +0000 (19:54 +0100)
src/ofc/codegen/FortranGenerator.scala
src/ofc/codegen/FortranProperty.scala [new file with mode: 0644]
src/ofc/codegen/Symbol.scala
src/ofc/codegen/Type.scala
src/ofc/generators/onetep/DensePsincToReciprocal.scala
src/ofc/generators/onetep/Laplacian.scala
src/ofc/generators/onetep/PPDFunctionSet.scala
src/ofc/generators/onetep/ReciprocalToPsinc.scala
src/ofc/generators/onetep/SPAM3.scala
src/ofc/generators/onetep/ScaledField.scala

index 8c654078659a05382274bb6e7c235c44046f6e85..25b04b35220494c344be6cd8a3c7b1a10a8bbbf6 100644 (file)
@@ -46,8 +46,16 @@ class SymbolManager {
     }
 
   def getDeclarations : Seq[String] = {
-    for ((sym, info) <- symbols) yield
-     sym.getType.getFortranAttributes.mkString(", ") + " :: " + info.getName
+    for ((sym, info) <- symbols) yield {
+      var attributeStrings : Seq[String] = Nil
+      attributeStrings ++:= sym.getType.getFortranAttributes
+
+      for(property <- sym.getProperties) property match {
+        case (p: FortranProperty) => attributeStrings +:= p.getName
+        case _ => ()
+      }
+      attributeStrings.mkString(", ") + " :: " + info.getName
+    }
   }.toSeq.sorted
 }
 
diff --git a/src/ofc/codegen/FortranProperty.scala b/src/ofc/codegen/FortranProperty.scala
new file mode 100644 (file)
index 0000000..29680f1
--- /dev/null
@@ -0,0 +1,8 @@
+package ofc.codegen
+
+trait FortranProperty extends SymbolProperty {
+}
+
+class AllocatableProperty extends FortranProperty {
+  def getName = "allocatable"
+}
index 905920d855343ae532e9e978995d52681650cb0a..508ec6b73f424d8d6d44513308732f47e1969290 100644 (file)
@@ -1,6 +1,16 @@
 package ofc.codegen
 
 trait Symbol {
+  private var properties : Seq[SymbolProperty] = Nil
+
+  def getName : String
+  def addProperty(property: SymbolProperty) {
+    properties +:= property
+  }
+  def getProperties : Seq[SymbolProperty] = properties
+}
+
+trait SymbolProperty {
   def getName : String
 }
 
index 1a114de1cebcd7668138f01577f986cb6807e698..861960d357f2183bfceb5cf0932ac6daa4c73458 100644 (file)
@@ -34,7 +34,7 @@ final case class ComplexType() extends PrimitiveType {
 final case class ArrayType[ElementType <: Type](rank: Int, eType: ElementType) extends Type {
   def this(rank: Int)(implicit builder: TypeBuilder[ElementType]) = this(rank, builder())
   def getElementType = eType
-  def getFortranAttributes = eType.getFortranAttributes ++ Set("allocatable", (":"*rank).mkString("dimension(",",",")"))
+  def getFortranAttributes = eType.getFortranAttributes ++ Set((":"*rank).mkString("dimension(",",",")"))
   def getRank = rank
 }
 
index 35c77e17759d90244671aa14d368f17d42750b3c..5464f449bf84ad029d28d3d3c11de342eb3aa7e3 100644 (file)
@@ -4,6 +4,7 @@ import ofc.codegen._
 class DensePsincToReciprocal(op: DensePsincFragment, indices: Map[NamedIndex, Expression[IntType]]) extends ReciprocalFragment {
   import OnetepTypes.FunctionBasis
   val reciprocalBox = new DeclaredVarSymbol[ArrayType[ComplexType]]("reciprocal_box", new ArrayType[ComplexType](3))
+  reciprocalBox.addProperty(new AllocatableProperty)
 
   def setup(context: GenerationContext) {
     import OnetepTypes.FFTBoxInfo
index 46c6632a66475c097524a78dcb8c095ace924005..ee2c88a95d883d34efb9e4cf056404b49a1da70c 100644 (file)
@@ -4,6 +4,8 @@ import ofc.codegen._
 class Laplacian(op: Field)  extends Field {
   class LocalFragment(parent: Laplacian, indices: Map[NamedIndex, Expression[IntType]]) extends ReciprocalFragment {
     val transformed = new DeclaredVarSymbol[ArrayType[ComplexType]]("transformed", new ArrayType[ComplexType](3))
+    transformed.addProperty(new AllocatableProperty)
+
     val opFragment = parent.getOperand.getFragment(indices).toReciprocal
 
     def setup(context: GenerationContext) {
index cabffb6aa09e8bd7833884d86839d0e9ee66c0d7..c1456ffb05749bfcb735e3013ea03e0cb7a95ab1 100644 (file)
@@ -116,6 +116,8 @@ class PPDFunctionSet(val basis: Expression[StructType], val data: Expression[Arr
     }
 
     val fftbox = new DeclaredVarSymbol[ArrayType[FloatType]]("fftbox", new ArrayType[FloatType](3))
+    fftbox.addProperty(new AllocatableProperty)
+
     val tightbox = (~(basis % FunctionBasis.tightBoxes)).at(sphereIndex)
     val sphere = (~(basis % FunctionBasis.spheres)).at(sphereIndex) 
     val fftboxOffset = for(dim <- 0 to 2) yield new DeclaredVarSymbol[IntType]("fftbox_offset"+(dim+1)) 
index db36039967d340c25a4f223e0833a216cf09e1b8..0e17431f6f065680554c28889e00132b00e89a7a 100644 (file)
@@ -3,7 +3,10 @@ import ofc.codegen._
 
 class ReciprocalToPsinc(op: ReciprocalFragment) extends DensePsincFragment {
   val fftbox = new DeclaredVarSymbol[ArrayType[FloatType]]("fftbox", new ArrayType[FloatType](3))
+  fftbox.addProperty(new AllocatableProperty)
+
   val dummybox = new DeclaredVarSymbol[ArrayType[FloatType]]("dummybox", new ArrayType[FloatType](3))
+  dummybox.addProperty(new AllocatableProperty)
 
   def toReciprocal = op
 
index a76a7b7e6125c3d311a234f9dac55c03368900c0..f9cee0b5352656f2b6dc0e6c86f6acdda38e2b4c 100644 (file)
@@ -29,6 +29,8 @@ class SPAM3(mat: Expression[StructType], position: Seq[NamedIndex]) extends Scal
     val header = new BlockStatement
     val indexLength = new FunctionCall(OnetepFunctions.sparse_index_length, Seq(mat))
     val index = new DeclaredVarSymbol[ArrayType[IntType]]("sparse_idx", new ArrayType[IntType](1))
+    index.addProperty(new AllocatableProperty)
+
     header += new AllocateStatement(index, Seq(indexLength))
     header += new FunctionCallStatement(new FunctionCall(OnetepFunctions.sparse_generate_index, Seq(index, mat)))
     context.addHeader(header)
index 1e44f05c4f9ce6567ed6375d1bf7c8a8419dbd86..be401f3854ac78d7935a2f6e1a63b3d726ca515c 100644 (file)
@@ -4,6 +4,8 @@ import ofc.codegen._
 class ScaledField(op: Field, factor: Scalar) extends Field {
   class LocalFragment(parent: ScaledField, indices: Map[NamedIndex, Expression[IntType]]) extends DensePsincFragment {
     val transformed = new DeclaredVarSymbol[ArrayType[FloatType]]("scaled", new ArrayType[FloatType](3))
+    transformed.addProperty(new AllocatableProperty)
+
     val scaleFragment = parent.getScalingFactor.getFragment(indices)
     val opFragment = parent.getOperand.getFragment(indices).toDensePsinc