*/
class CodeGenerator(indexBindings: IndexBindings) {
+ private val indexSymbols = {
+ def createMapping(index: BindingIndex) = (index, new NamedUnboundVarSymbol[IntType](index.getName))
+ indexBindings.getBindingIndices.map(createMapping(_)).toMap
+ }
+
def apply(assignment: Assignment) {
//val declarations = collectDeclarations(assignment)
//for(declaration <- declarations) code append declaration+"\n"
for(operand <- space.getOperands) {
val opStatement = buildStatement(operand)
- for(discreteIndex <- operand.getDiscreteIndices; if indexBindings.contains(discreteIndex)) {
- //TODO: store the symbol!
- val symbol = new NamedUnboundVarSymbol[IntType](discreteIndex.getName)
- val newData = opStatement.addPredicate(symbol |==| discreteIndex.getValue)
+ for(discreteIndex <- operand.getDiscreteIndices) indexBindings.getBindingIndex(discreteIndex) match {
+ case Some(bindingIndex) => {
+ val symbol = indexSymbols.get(bindingIndex).get
+ val newData = opStatement.addPredicate(symbol |==| discreteIndex.getValue)
+ }
+ case _ => ()
}
- for(spatialIndex <- operand.getSpatialIndices; if indexBindings.contains(spatialIndex)) {
- //TODO: store the symbol!
- val symbol = new NamedUnboundVarSymbol[IntType](spatialIndex.getName)
- opStatement.addPredicate(symbol |==| spatialIndex.getValue)
+ for(spatialIndex <- operand.getSpatialIndices) indexBindings.getBindingIndex(spatialIndex) match {
+ case Some(bindingIndex) => {
+ val symbol = indexSymbols.get(bindingIndex).get
+ val newData = opStatement.addPredicate(symbol |==| spatialIndex.getValue)
+ }
+ case _ => ()
}
result.merge(opStatement)
package ofc.generators.onetep
+import ofc.LogicError
class IndexBindings {
import scala.collection.mutable.{Set,HashSet, HashMap}
def add(binding: BindingIndex, index: SpatialIndex) = spatial.getOrElseUpdate(binding, new HashSet()) += index
def add(binding: BindingIndex, index: DiscreteIndex) = discrete.getOrElseUpdate(binding, new HashSet()) += index
- def contains(index: SpatialIndex) : Boolean = {
+ def contains(index: SpatialIndex) : Boolean = getBindingIndex(index) match {
+ case Some(_) => true
+ case _ => false
+ }
+
+ def contains(index: DiscreteIndex) : Boolean = getBindingIndex(index) match {
+ case Some(_) => true
+ case _ => false
+ }
+
+ def getBindingIndex(index: SpatialIndex) : Option[BindingIndex] = {
for((bindingIndex, spatialIndices) <- spatial; if spatialIndices.contains(index))
- return true
+ return Some(bindingIndex)
- false
+ None
}
- def contains(index: DiscreteIndex) : Boolean = {
+ def getBindingIndex(index: DiscreteIndex) : Option[BindingIndex] = {
for((bindingIndex, discreteIndices) <- discrete; if discreteIndices.contains(index))
- return true
+ return Some(bindingIndex)
- false
+ None
}
+
+ def getBindingIndices = spatial.keys ++ discrete.keys
}