From 43a7a9311c1ac2bc62bd25dcb8aba181132412b8 Mon Sep 17 00:00:00 2001 From: Francis Russell Date: Sun, 8 Apr 2012 03:57:00 +0100 Subject: [PATCH] Fix so generated code compiles (except for long lines). --- src/ofc/codegen/Expression.scala | 4 ++++ src/ofc/codegen/Type.scala | 1 + src/ofc/generators/onetep/OnetepTypes.scala | 23 +++++++++++++------ .../generators/onetep/PPDFunctionSet.scala | 2 +- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/ofc/codegen/Expression.scala b/src/ofc/codegen/Expression.scala index 7325ce4..fd5b00a 100644 --- a/src/ofc/codegen/Expression.scala +++ b/src/ofc/codegen/Expression.scala @@ -1,4 +1,5 @@ package ofc.codegen +import ofc.LogicError object Expression { implicit def fromInt(i: Int) : Expression[IntType] = new IntegerLiteral(i) @@ -84,6 +85,9 @@ class FieldAccess[T <: Type](expression: Expression[StructType], field: FieldSym } class ArrayRead[E <: Type](expression: Expression[ArrayType[E]], index: Seq[Expression[IntType]]) extends Expression[E] { + if (index.size != expression.getType.getRank) + throw new LogicError("Array of rank "+expression.getType.getRank+" indexed with rank "+index.size+" index.") + def foreach[U](f: Expression[_] => U) = (index :+ expression).foreach(f) def getArrayExpression = expression def getIndexExpressions = index diff --git a/src/ofc/codegen/Type.scala b/src/ofc/codegen/Type.scala index 4d07aec..8f90c1e 100644 --- a/src/ofc/codegen/Type.scala +++ b/src/ofc/codegen/Type.scala @@ -22,6 +22,7 @@ final case class ArrayType[ElementType <: Type](rank: Int, eType: ElementType) e def this(rank: Int)(implicit builder: TypeBuilder[ElementType]) = this(rank, builder()) def getElementType = eType def getFortranAttributes = eType.getFortranAttributes ++ Set("allocatable", (":"*rank).mkString("dimension(",",",")")) + def getRank = rank } final case class PointerType[TargetType <: Type](tType: TargetType) extends Type { diff --git a/src/ofc/generators/onetep/OnetepTypes.scala b/src/ofc/generators/onetep/OnetepTypes.scala index 9770d65..40e6cc7 100644 --- a/src/ofc/generators/onetep/OnetepTypes.scala +++ b/src/ofc/generators/onetep/OnetepTypes.scala @@ -8,11 +8,6 @@ object OnetepTypes { new FieldSymbol[PointerType[ArrayType[IntType]]]("n_ppds_sphere", fieldType) } - val ppdList = { - val fieldType = new PointerType[ArrayType[IntType]](new ArrayType[IntType](1)) - new FieldSymbol[PointerType[ArrayType[IntType]]]("ppd_list", fieldType) - } - val num = new FieldSymbol[IntType]("num") val tightBoxes = { @@ -20,9 +15,23 @@ object OnetepTypes { new FieldSymbol[PointerType[ArrayType[StructType]]]("tight_boxes", fieldType) } + val spheres = { + val fieldType = new PointerType[ArrayType[StructType]](new ArrayType[StructType](1, Sphere)) + new FieldSymbol[PointerType[ArrayType[StructType]]]("spheres", fieldType) + } + def getFortranAttributes = Set("type(FUNC_BASIS)") } + object Sphere extends StructType { + val ppdList = { + val fieldType = new PointerType[ArrayType[IntType]](new ArrayType[IntType](2)) + new FieldSymbol[PointerType[ArrayType[IntType]]]("ppd_list", fieldType) + } + + def getFortranAttributes = Set("type(SPHERE)") + } + object CellInfo extends StructType { val ppdWidth = {for (dim <- 1 to 3) yield new FieldSymbol[IntType]("n_pt"+dim)}.toSeq val numPPDs = {for (dim <- 1 to 3) yield new FieldSymbol[IntType]("n_ppds_a"+dim)}.toSeq @@ -32,8 +41,8 @@ object OnetepTypes { object TightBox extends StructType { val startPts = {for (dim <- 1 to 3) yield new FieldSymbol[IntType]("start_pts"+dim)}.toSeq 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_ppd"+dim)}.toSeq - val finishPPD = {for (dim <- 1 to 3) yield new FieldSymbol[IntType]("finish_ppd"+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)") } } diff --git a/src/ofc/generators/onetep/PPDFunctionSet.scala b/src/ofc/generators/onetep/PPDFunctionSet.scala index 827a02e..ce91b26 100644 --- a/src/ofc/generators/onetep/PPDFunctionSet.scala +++ b/src/ofc/generators/onetep/PPDFunctionSet.scala @@ -17,7 +17,7 @@ class PPDFunctionSet(val basisName: String, dataName: String) extends FunctionSe val sphereIndex = producer.addIteration("sphere_index", 1, numSpheres) val numPPDs = (~(basis % FunctionBasis.numPPDsInSphere)).readAt(sphereIndex) val ppdIndex = producer.addIteration("ppd_index", 1, numPPDs) - val ppdGlobalCount = (~(basis % FunctionBasis.ppdList)).readAt(ppdIndex, 1) - 1 + val ppdGlobalCount = (~((~(basis % FunctionBasis.spheres)).readAt(sphereIndex) % Sphere.ppdList)).readAt(ppdIndex, 1) - 1 // The integer co-ordinates of the PPD (0-based) val a3pos = producer.addExpression("ppd_pos1", ppdGlobalCount / (cellWidthInPPDs(0)*cellWidthInPPDs(1))) -- 2.47.3