Changeset 921


Ignore:
Timestamp:
Mar 10, 2011, 1:56:52 PM (8 years ago)
Author:
cameron
Message:

Separate control of _ci and _co modes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • proto/Compiler/pablo.py

    r908 r921  
    195195
    196196class CarryIntro(ast.NodeTransformer):
    197   def __init__(self, carryvar="carryQ", mode = "ci_co"):
     197  def __init__(self, carryvar="carryQ", carryin = "_ci", carryout = "_co"):
    198198    self.carryvar = ast.Name(carryvar, ast.Load())
    199     self.mode = mode
     199    self.carryin = carryin
     200    self.carryout = carryout
    200201  def xfrm_fndef(self, fndef):
    201202    self.current_carry = 0
     
    215216    self.generic_visit(callnode)
    216217    if is_BuiltIn_Call(callnode, 'Advance', 1):         
    217       rtn = "BitBlock_advance_%s" % self.mode
     218      rtn = "BitBlock_advance%s%s" % (self.carryin, self.carryout)
    218219      c = mkCall(rtn, [callnode.args[0], self.carryvar, ast.Num(self.current_carry)])
    219220      self.current_carry += 1
    220221      return c
    221222    elif is_BuiltIn_Call(callnode, 'ScanThru', 2):
    222       rtn = "BitBlock_scanthru_%s" % self.mode
     223      rtn = "BitBlock_scanthru%s%s" % (self.carryin, self.carryout)
    223224      c = mkCall(rtn, [callnode.args[0], callnode.args[1], self.carryvar, ast.Num(self.current_carry)])
    224225      self.current_carry += 1
    225226      return c
    226227    elif is_BuiltIn_Call(callnode, 'ScanTo', 2):
    227       rtn = "BitBlock_scanto_%s" % self.mode
     228      rtn = "BitBlock_scanto%s%s" % (self.carryin, self.carryout)
    228229      c = mkCall(rtn, [callnode.args[0], callnode.args[1], self.carryvar, ast.Num(self.current_carry)])
    229230      self.current_carry += 1
     
    239240    self.generic_visit(exprnode)
    240241    if isinstance(exprnode.op, ast.Sub):
    241       rtn = "BitBlock_sub_%s" % self.mode
     242      rtn = "BitBlock_sub%s%s" % (self.carryin, self.carryout)
    242243      c = mkCall(rtn, [exprnode.left, exprnode.right, self.carryvar, ast.Num(self.current_carry)])
    243244      self.current_carry += 1
    244245      return c
    245246    elif isinstance(exprnode.op, ast.Add):
    246       rtn = "BitBlock_add_%s" % self.mode
     247      rtn = "BitBlock_add%s%s" % (self.carryin, self.carryout)
    247248      c = mkCall(rtn, [exprnode.left, exprnode.right, self.carryvar, ast.Num(self.current_carry)])
    248249      self.current_carry += 1
     
    253254    carries = CarryCounter().count(ifNode)
    254255    self.generic_visit(ifNode)
    255     if carries == 0 or self.mode == "co": return ifNode
     256    if carries == 0 or self.carryin == "": return ifNode
    256257    carry_arglist = [self.carryvar, ast.Num(carry_base), ast.Num(carries)]
    257258    new_test = ast.BoolOp(ast.Or(), [ifNode.test, mkCall('CarryTest', carry_arglist)])
     
    264265    carry_arglist = [self.carryvar, ast.Num(carry_base), ast.Num(carries)]
    265266    local_carryvar = 'sub'+self.carryvar.id
    266     inner_while = CarryIntro(local_carryvar, 'co').generic_xfrm(copy.deepcopy(whileNode))
     267    inner_while = CarryIntro(local_carryvar, '', self.carryout).generic_xfrm(copy.deepcopy(whileNode))
    267268    self.generic_visit(whileNode)
    268269    local_decl = mkCallStmt('CarryDeclare', [ast.Name(local_carryvar, ast.Load()), ast.Num(carries)])
     
    272273    final_combine = mkCallStmt('CarryCombine', [self.carryvar, ast.Name(local_carryvar, ast.Load()), ast.Num(carry_base), ast.Num(carries)])
    273274    inner_while.body.append(final_combine)
    274     if self.mode == "co": new_test = whileNode.test
     275    if self.carryin == '': new_test = whileNode.test
    275276    else: new_test = ast.BoolOp(ast.Or(), [whileNode.test, mkCall('CarryTest', carry_arglist)])
    276277    else_part = [mkCallStmt('CarryDequeueEnqueue', carry_arglist)]
Note: See TracChangeset for help on using the changeset viewer.