Example #1
0
def emod(mod, domain):
  def mixModWithLoc(loc):
    newMod = copy.deepcopy(mod)
    newMod["boolexp"] = substituteDataArrayElementInString("%loc", newMod["boolexp"], locations[loc])
    newMod["endexp"] = substituteDataArrayElementInString("%loc", newMod["endexp"], locations[loc])
    newMod["boolexp"] = newMod["boolexp"].replace("%loc",loc)
    newMod["endexp"] = newMod["endexp"].replace("%loc",loc)
    insertLocInEffect(newMod["effect"],loc)
    return newMod
  
  def mixModWithOrgDst(matrixCell):
    (org, dst, r) = matrixCell
    if (options.fullMatrix == False and r == 0):
      return nullInstruction
    if (org != dst):
      newMod = copy.deepcopy(mod)
      newMod["boolexp"] = substituteDataArrayElementInString("%org", newMod["boolexp"], locations[org])
      newMod["boolexp"] = substituteDataArrayElementInString("%dst", newMod["boolexp"], locations[dst])
      newMod["boolexp"] = newMod["boolexp"].replace("%cell",str(r))
      newMod["endexp"] = substituteDataArrayElementInString("%org", newMod["endexp"], locations[org])
      newMod["endexp"] = substituteDataArrayElementInString("%dst", newMod["endexp"], locations[dst])
      newMod["endexp"] = newMod["endexp"].replace("%cell",str(r))
      newMod["boolexp"] = newMod["boolexp"].replace("%org",org)
      newMod["boolexp"] = newMod["boolexp"].replace("%dst",dst)
      newMod["endexp"] = newMod["endexp"].replace("%org",org)
      newMod["endexp"] = newMod["endexp"].replace("%dst",dst)
      insertOrgInEffect(newMod["effect"],org)
      insertDstInEffect(newMod["effect"],dst)
      return newMod
    else:
      return nullInstruction

  modBuilder = None
  if (domain[0].__class__ == "".__class__): #if it is string, it is just loc
    modBuilder = mixModWithLoc
  else: #the type is tuple, it is a matrix
    modBuilder = mixModWithOrgDst
  for r in map(modBuilder, domain):
    printing.printMod(r)