From: Francis Russell Date: Sun, 20 May 2012 18:54:38 +0000 (+0100) Subject: Allow "allocatable" to be set on a per-array basis. X-Git-Url: https://git.unchartedbackwaters.co.uk/w/?a=commitdiff_plain;h=1cdc7d8f9fdaf14f5e71da4316f5258224df0e37;p=francis%2Fofc.git Allow "allocatable" to be set on a per-array basis. --- diff --git a/src/ofc/codegen/FortranGenerator.scala b/src/ofc/codegen/FortranGenerator.scala index 8c65407..25b04b3 100644 --- a/src/ofc/codegen/FortranGenerator.scala +++ b/src/ofc/codegen/FortranGenerator.scala @@ -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 index 0000000..29680f1 --- /dev/null +++ b/src/ofc/codegen/FortranProperty.scala @@ -0,0 +1,8 @@ +package ofc.codegen + +trait FortranProperty extends SymbolProperty { +} + +class AllocatableProperty extends FortranProperty { + def getName = "allocatable" +} diff --git a/src/ofc/codegen/Symbol.scala b/src/ofc/codegen/Symbol.scala index 905920d..508ec6b 100644 --- a/src/ofc/codegen/Symbol.scala +++ b/src/ofc/codegen/Symbol.scala @@ -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 } diff --git a/src/ofc/codegen/Type.scala b/src/ofc/codegen/Type.scala index 1a114de..861960d 100644 --- a/src/ofc/codegen/Type.scala +++ b/src/ofc/codegen/Type.scala @@ -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 } diff --git a/src/ofc/generators/onetep/DensePsincToReciprocal.scala b/src/ofc/generators/onetep/DensePsincToReciprocal.scala index 35c77e1..5464f44 100644 --- a/src/ofc/generators/onetep/DensePsincToReciprocal.scala +++ b/src/ofc/generators/onetep/DensePsincToReciprocal.scala @@ -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 diff --git a/src/ofc/generators/onetep/Laplacian.scala b/src/ofc/generators/onetep/Laplacian.scala index 46c6632..ee2c88a 100644 --- a/src/ofc/generators/onetep/Laplacian.scala +++ b/src/ofc/generators/onetep/Laplacian.scala @@ -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) { diff --git a/src/ofc/generators/onetep/PPDFunctionSet.scala b/src/ofc/generators/onetep/PPDFunctionSet.scala index cabffb6..c1456ff 100644 --- a/src/ofc/generators/onetep/PPDFunctionSet.scala +++ b/src/ofc/generators/onetep/PPDFunctionSet.scala @@ -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)) diff --git a/src/ofc/generators/onetep/ReciprocalToPsinc.scala b/src/ofc/generators/onetep/ReciprocalToPsinc.scala index db36039..0e17431 100644 --- a/src/ofc/generators/onetep/ReciprocalToPsinc.scala +++ b/src/ofc/generators/onetep/ReciprocalToPsinc.scala @@ -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 diff --git a/src/ofc/generators/onetep/SPAM3.scala b/src/ofc/generators/onetep/SPAM3.scala index a76a7b7..f9cee0b 100644 --- a/src/ofc/generators/onetep/SPAM3.scala +++ b/src/ofc/generators/onetep/SPAM3.scala @@ -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) diff --git a/src/ofc/generators/onetep/ScaledField.scala b/src/ofc/generators/onetep/ScaledField.scala index 1e44f05..be401f3 100644 --- a/src/ofc/generators/onetep/ScaledField.scala +++ b/src/ofc/generators/onetep/ScaledField.scala @@ -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