}
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
}
--- /dev/null
+package ofc.codegen
+
+trait FortranProperty extends SymbolProperty {
+}
+
+class AllocatableProperty extends FortranProperty {
+ def getName = "allocatable"
+}
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
}
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
}
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
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) {
}
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))
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
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)
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