Changeset 813 for proto/Compiler


Ignore:
Timestamp:
Dec 13, 2010, 2:37:13 PM (9 years ago)
Author:
ksherdy
Message:

Refactor is_Advance_Call and is_ScanThru_Call into a single method is_BuildIn_Call to avoid code duplication.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • proto/Compiler/pablo.py

    r810 r813  
    1111
    1212# HELPER functions for AST recognition/construction
     13# modified from old py2bitexpr.py
     14def is_BuiltIn_Call(fncall, builtin_fnname, builtin_arg_cnt, builtin_fnmod_noprefix='bitutil'):
     15        if isinstance(fncall.func, ast.Name): iscall = fncall.func.id == builtin_fnname
     16        elif isinstance(fncall.func, ast.Attribute) and isinstance(fncall.func.value, ast.Name):
     17                 iscall = fncall.func.value.id == builtin_fnmod_noprefix and fncall.func.attr == builtin_fnname
     18        return iscall and len(fncall.args) == builtin_arg_cnt and fncall.kwargs == None and fncall.starargs == None
    1319
    1420def is_Advance_Call(fncall):   # extracted from old py2bitexpr.py
     
    189195  def visit_Call(self, callnode):
    190196    self.generic_visit(callnode)
    191     if is_Advance_Call(callnode) or is_ScanThru_Call(callnode):
     197    if is_BuiltIn_Call(callnode,'Advance', 1) or is_BuiltIn_Call(callnode,'ScanThru', 2):       
    192198      self.carry_count += 1
    193199  def visit_BinOp(self, exprnode):
     
    223229  def visit_Call(self, callnode):
    224230    self.generic_visit(callnode)
    225     if is_Advance_Call(callnode):
     231    if is_BuiltIn_Call(callnode, 'Advance', 1):         
    226232      rtn = "BitBlock_advance_%s" % self.mode
    227233      c = mkCall(rtn, [callnode.args[0], self.carryvar, ast.Num(self.current_carry)])
    228234      self.current_carry += 1
    229235      return c
    230     elif is_ScanThru_Call(callnode):
     236    elif is_BuiltIn_Call(callnode, 'ScanThru', 2):
    231237      rtn = "BitBlock_scanthru_%s" % self.mode
    232238      c = mkCall(rtn, [callnode.args[0], callnode.args[1], self.carryvar, ast.Num(self.current_carry)])
     
    346352    return [t, dump_stmt]
    347353   
    348 
     354#
    349355#  Translate a function
    350356#
Note: See TracChangeset for help on using the changeset viewer.