Changeset 924 for proto


Ignore:
Timestamp:
Mar 10, 2011, 4:48:53 PM (9 years ago)
Author:
cameron
Message:

Eliminate carry queues when neither carryin nor carryout is set.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • proto/Compiler/pablo.py

    r922 r924  
    215215  def visit_Call(self, callnode):
    216216    self.generic_visit(callnode)
     217    if self.carryin == '' and self.carryout == '': carry_args = []
     218    else: carry_args = [self.carryvar, ast.Num(self.current_carry)]
    217219    if is_BuiltIn_Call(callnode, 'Advance', 1):         
    218220      rtn = "BitBlock_advance%s%s" % (self.carryin, self.carryout)
    219       c = mkCall(rtn, [callnode.args[0], self.carryvar, ast.Num(self.current_carry)])
     221      c = mkCall(rtn, callnode.args + carry_args)
    220222      self.current_carry += 1
    221223      return c
    222224    elif is_BuiltIn_Call(callnode, 'ScanThru', 2):
    223225      rtn = "BitBlock_scanthru%s%s" % (self.carryin, self.carryout)
    224       c = mkCall(rtn, [callnode.args[0], callnode.args[1], self.carryvar, ast.Num(self.current_carry)])
     226      c = mkCall(rtn, callnode.args + carry_args)
    225227      self.current_carry += 1
    226228      return c
    227229    elif is_BuiltIn_Call(callnode, 'ScanTo', 2):
    228230      rtn = "BitBlock_scanto%s%s" % (self.carryin, self.carryout)
    229       c = mkCall(rtn, [callnode.args[0], callnode.args[1], self.carryvar, ast.Num(self.current_carry)])
     231      c = mkCall(rtn, callnode.args + carry_args)
    230232      self.current_carry += 1
    231233      return c
     
    239241  def visit_BinOp(self, exprnode):
    240242    self.generic_visit(exprnode)
     243    if self.carryin == '' and self.carryout == '': carry_args = []
     244    else: carry_args = [self.carryvar, ast.Num(self.current_carry)]
    241245    if isinstance(exprnode.op, ast.Sub):
    242246      rtn = "BitBlock_sub%s%s" % (self.carryin, self.carryout)
    243       c = mkCall(rtn, [exprnode.left, exprnode.right, self.carryvar, ast.Num(self.current_carry)])
     247      c = mkCall(rtn, [exprnode.left, exprnode.right] + carry_args)
    244248      self.current_carry += 1
    245249      return c
    246250    elif isinstance(exprnode.op, ast.Add):
    247251      rtn = "BitBlock_add%s%s" % (self.carryin, self.carryout)
    248       c = mkCall(rtn, [exprnode.left, exprnode.right, self.carryvar, ast.Num(self.current_carry)])
     252      c = mkCall(rtn, [exprnode.left, exprnode.right] + carry_args)
    249253      self.current_carry += 1
    250254      return c
     
    267271    inner_while = CarryIntro(local_carryvar, '', self.carryout).generic_xfrm(copy.deepcopy(whileNode))
    268272    self.generic_visit(whileNode)
    269     local_decl = mkCallStmt('CarryDeclare', [ast.Name(local_carryvar, ast.Load()), ast.Num(carries)])
    270     local_init = mkCallStmt('CarryInit', [ast.Name(local_carryvar, ast.Load()), ast.Num(carries)])
    271     inner_while.body.insert(0, local_decl)
    272     inner_while.body.insert(1, local_init)
    273     final_combine = mkCallStmt('CarryCombine', [self.carryvar, ast.Name(local_carryvar, ast.Load()), ast.Num(carry_base), ast.Num(carries)])
    274     inner_while.body.append(final_combine)
     273    if self.carryout == '_co':
     274      local_decl = mkCallStmt('CarryDeclare', [ast.Name(local_carryvar, ast.Load()), ast.Num(carries)])
     275      local_init = mkCallStmt('CarryInit', [ast.Name(local_carryvar, ast.Load()), ast.Num(carries)])
     276      inner_while.body.insert(0, local_decl)
     277      inner_while.body.insert(1, local_init)
     278      final_combine = mkCallStmt('CarryCombine', [self.carryvar, ast.Name(local_carryvar, ast.Load()), ast.Num(carry_base), ast.Num(carries)])
     279      inner_while.body.append(final_combine)
    275280    if self.carryin == '': new_test = whileNode.test
    276281    else: new_test = ast.BoolOp(ast.Or(), [whileNode.test, mkCall('CarryTest', carry_arglist)])
Note: See TracChangeset for help on using the changeset viewer.