]> git.unchartedbackwaters.co.uk Git - francis/ofc.git/commitdiff
Calculate PPD locations (in PPD co-ordinate system).
authorFrancis Russell <francis@unchartedbackwaters.co.uk>
Wed, 4 Apr 2012 10:05:59 +0000 (11:05 +0100)
committerFrancis Russell <francis@unchartedbackwaters.co.uk>
Wed, 4 Apr 2012 10:05:59 +0000 (11:05 +0100)
src/ofc/codegen/BinaryOperator.scala [new file with mode: 0644]
src/ofc/codegen/Expression.scala
src/ofc/generators/onetep/PPDFunctionSet.scala

diff --git a/src/ofc/codegen/BinaryOperator.scala b/src/ofc/codegen/BinaryOperator.scala
new file mode 100644 (file)
index 0000000..406f507
--- /dev/null
@@ -0,0 +1,12 @@
+package ofc.codegen
+
+object BinaryOperator {
+  sealed abstract class Operator
+  case object Add extends Operator
+  case object Sub extends Operator
+  case object Mul extends Operator
+  case object Div extends Operator
+  case object Mod extends Operator
+}
+
+class BinaryOperator(op: BinaryOperator.Operator, left: Expression, right: Expression) extends Expression
index 7f132bf429e80b49e3f940abf3efe62d44c18dc3..0e93d92b6e60a4a1bab66c0f574e4980c2950c09 100644 (file)
@@ -1,9 +1,14 @@
 package ofc.codegen
 
 class Expression {
-  def %(field: FieldSymbol) : Expression = new FieldAccess(this, field)
+  def ~>(field: FieldSymbol) : Expression = new FieldAccess(this, field)
   def readAt(index: List[Expression]) : Expression = new ArrayRead(this, index)
   def apply(index: Expression*) : Expression = this.readAt(index.toList)
+  def +(rhs: Expression) : Expression = new BinaryOperator(BinaryOperator.Add, this, rhs)
+  def -(rhs: Expression) : Expression = new BinaryOperator(BinaryOperator.Sub, this, rhs)
+  def *(rhs: Expression) : Expression = new BinaryOperator(BinaryOperator.Mul, this, rhs)
+  def /(rhs: Expression) : Expression = new BinaryOperator(BinaryOperator.Div, this, rhs)
+  def %(rhs: Expression) : Expression = new BinaryOperator(BinaryOperator.Mod, this, rhs)
 }
 
 // Variable references
index 346e23971f5c302c06cb82fcd9d60cdf9358f7a0..bea3b71ad8971c778d1d2bb4e98483a47a2f4fbe 100644 (file)
@@ -6,21 +6,24 @@ class PPDFunctionSet(val basisName: String, dataName: String) extends FunctionSe
   val data =  NamedUnboundVarSymbol(dataName)
   val pubCell = NamedUnboundVarSymbol("pub_cell")
 
-  val numSpheres = basis % FieldSymbol("num");
-  val ppdWidths = for(dim <- 1 to 3) yield pubCell % FieldSymbol("n_pt"+dim)
-  val cellWidthInPPDs = for(dim <- 1 to 3) yield pubCell % FieldSymbol("n_ppds_a"+dim)
+  val numSpheres = basis~>FieldSymbol("num");
+  val ppdWidths = for(dim <- 1 to 3) yield pubCell~>FieldSymbol("n_pt"+dim)
+  val cellWidthInPPDs = for(dim <- 1 to 3) yield pubCell~>FieldSymbol("n_ppds_a"+dim)
 
   def getSuffixFragment = {
     val producer = new ProducerStatement
     val sphereIndex = producer.addIteration("sphere_index", numSpheres)
-    val numPPDs = (basis % FieldSymbol("n_ppds_sphere"))(sphereIndex)
+    val numPPDs = (basis~>FieldSymbol("n_ppds_sphere"))(sphereIndex)
     val ppdIndex = producer.addIteration("ppd_index", numPPDs)
-    val ppdGlobalCount = (basis % FieldSymbol("ppd_list"))(ppdIndex, new IntegerLiteral(1))
+    val ppdGlobalCount = (basis~>FieldSymbol("ppd_list"))(ppdIndex, new IntegerLiteral(1)) - new IntegerLiteral(1)
 
-    // We need to calculate the integer co-ordinates of the PPD
+    // We need to calculate the integer co-ordinates of the PPD (0-based)
+    val a3pos = ppdGlobalCount / (cellWidthInPPDs(0)*cellWidthInPPDs(1))
+    val a2pos = (ppdGlobalCount % (cellWidthInPPDs(0)*cellWidthInPPDs(1)))/cellWidthInPPDs(0)
+    val a1pos = ppdGlobalCount % cellWidthInPPDs(0)
 
     //val ppdRanges = for(dim <- 0 to 2) yield producer.addIteration("point"+(dim+1), ppdWidths(dim)) 
-    val tightbox = basis % FieldSymbol("tight_boxes")
+    val tightbox = basis~>FieldSymbol("tight_boxes")
     
     producer
   }