Changeset 3452 for proto/Compiler


Ignore:
Timestamp:
Sep 9, 2013, 12:38:58 PM (6 years ago)
Author:
cameron
Message:

Clean out mkCall in favor of mkast.call, add C mode framework for mkast.call

Location:
proto/Compiler
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • proto/Compiler/mkast.py

    r3017 r3452  
    1010import ast
    1111
     12use_C_syntax = False
     13
     14C_map = {"esimd<%i>::mergeh" : "simd_mergeh_%i",
     15         "bitblock::any" : "bitblock_has_bit",
     16         "print_register<BitBlock>" : "print_bitblock"}
     17
     18def map_if_C(str):
     19        if not use_C_syntax: return str
     20        if not C_map.has_key(str): return str
     21        return C_map[str]
    1222#
    1323# Helper functions
     
    1626    if isinstance(testExpr, ast.Call):
    1727      assert isinstance(testExpr.func, ast.Name)
    18       assert testExpr.func.id == 'bitblock::any'
     28      assert testExpr.func.id == 'bitblock::any' or testExpr.func.id == 'bitblock_has_bit'
    1929      testExpr.args[0] = call('simd_or', [bitBlockExpr, testExpr.args[0]])
    2030      return testExpr
    2131    else:
    22       return ast.BinOp(testExpr, ast.BitOr(), call('bitblock::any', [bitBlockExpr]))
     32      return ast.BinOp(testExpr, ast.BitOr(), call(map_if_C('bitblock::any'), [bitBlockExpr]))
    2333
    2434def TestHelper_Integer_Or(testExpr, intExpr):
     
    5868  if isinstance(fn_name, str):
    5969        fn_name = ast.Name(fn_name, ast.Load())
    60   return ast.Call(fn_name, args, [], None, None)
     70  return ast.Call(map_if_C(fn_name), args, [], None, None)
    6171
    6272def callStmt(fn_name, args):
    6373  if isinstance(fn_name, str): fn_name = ast.Name(fn_name, ast.Load())
    64   return ast.Expr(ast.Call(fn_name, args, [], None, None))
     74  return ast.Expr(ast.Call(map_if_C(fn_name), args, [], None, None))
    6575
    6676def mergeh(fw, x, y):
    67   return call("esimd<%i>::mergeh" % fw, [var(x), var(y)])
     77  return call(map_if_C("esimd<%i>::mergeh") % fw, [var(x), var(y)])
    6878
    6979def zero(fw):
    70   return call("simd<%i>::constant<0>" % fw, [])
     80  return call(map_if_C("simd<%i>::constant<0>") % fw, [])
    7181
    7282def Qname(obj, field):
  • proto/Compiler/pablo.py

    r3389 r3452  
    1414import lookAhead
    1515
    16 name_substitution_map = {}
    1716do_block_inline_decorator = 'IDISA_INLINE '
    1817do_final_block_inline_decorator = ''
     
    3029def is_simd_not(e):
    3130  return isinstance(e, ast.Call) and isinstance(e.func, ast.Name) and e.func.id == 'simd_not'
    32 
    33 
    34 def mkCall(fn_name, args):
    35   if isinstance(fn_name, str):
    36         if name_substitution_map.has_key(fn_name): fn_name = name_substitution_map[fn_name]
    37         fn_name = ast.Name(fn_name, ast.Load())
    38   return ast.Call(fn_name, args, [], None, None)
    3931
    4032
     
    9587
    9688def CompileMatch(match_var, string_to_match):
    97         expr = mkCall('simd_and', [match_var, MkCharStream(string_to_match[0])])
     89        expr = mkast.call('simd_and', [match_var, MkCharStream(string_to_match[0])])
    9890        for i in range(1, len(string_to_match)):
    99                 expr = mkCall('simd_and', [expr, MkLookAheadExpr(MkCharStream(string_to_match[i]), i)])
     91                expr = mkast.call('simd_and', [expr, MkLookAheadExpr(MkCharStream(string_to_match[i]), i)])
    10092        return expr
    10193
     
    201193    self.generic_visit(t)
    202194    if isinstance(t.op, ast.Invert):
    203       return mkCall('simd_not', [t.operand])
     195      return mkast.call('simd_not', [t.operand])
    204196    else: return t
    205197  def visit_BinOp(self, t):
    206198    self.generic_visit(t)
    207199    if isinstance(t.op, ast.BitOr):
    208       return mkCall('simd_or', [t.left, t.right])
     200      return mkast.call('simd_or', [t.left, t.right])
    209201    elif isinstance(t.op, ast.BitAnd):
    210       if is_simd_not(t.right): return mkCall('simd_andc', [t.left, t.right.args[0]])
    211       elif is_simd_not(t.left): return mkCall('simd_andc', [t.right, t.left.args[0]])
    212       else: return mkCall('simd_and', [t.left, t.right])
     202      if is_simd_not(t.right): return mkast.call('simd_andc', [t.left, t.right.args[0]])
     203      elif is_simd_not(t.left): return mkast.call('simd_andc', [t.right, t.left.args[0]])
     204      else: return mkast.call('simd_and', [t.left, t.right])
    213205    elif isinstance(t.op, ast.BitXor):
    214       return mkCall('simd_xor', [t.left, t.right])
     206      return mkast.call('simd_xor', [t.left, t.right])
    215207    else: return t
    216208  def visit_Num(self, numnode):
    217209    n = numnode.n
    218     if n == 0: return mkCall('simd<1>::constant<0>', [])
    219     elif n == -1: return mkCall('simd<1>::constant<1>', [])
     210    if n == 0: return mkast.call('simd<1>::constant<0>', [])
     211    elif n == -1: return mkast.call('simd<1>::constant<1>', [])
    220212    else: return numnode
    221213  def visit_If(self, ifNode):
    222214    self.generic_visit(ifNode)
    223     ifNode.test = mkCall('bitblock::any', [ifNode.test])
     215    ifNode.test = mkast.call('bitblock::any', [ifNode.test])
    224216    return ifNode
    225217  def visit_While(self, whileNode):
    226218    self.generic_visit(whileNode)
    227     whileNode.test = mkCall('bitblock::any', [whileNode.test])
     219    whileNode.test = mkast.call('bitblock::any', [whileNode.test])
    228220    return whileNode
    229221  def visit_Subscript(self, numnode):
     
    299291      else:
    300292        stream_init = copy.deepcopy(node)
    301         stream_init.value = mkCall('sisd_from_int', [node.value])
     293        stream_init.value = mkast.call('sisd_from_int', [node.value])
    302294        loop_init = copy.deepcopy(node)
    303295        loop_init.value.n = 0
     
    378370    self.generic_visit(callnode)
    379371#    if self.carryout == "" and is_BuiltIn_Call(callnode, 'simd_not', 1):
    380 #      return [mkCall('simd_andc', [ast.Name('EOF_mask', ast.Load()), callnode.args[0]])]
     372#      return [mkast.call('simd_andc', [ast.Name('EOF_mask', ast.Load()), callnode.args[0]])]
    381373    if is_BuiltIn_Call(callnode, 'atEOF', 1):
    382374      if self.carryout != "": 
    383375        # Non final block: atEOF(x) = 0.
    384         return mkCall('simd<1>::constant<0>', [])
     376        return mkast.call('simd<1>::constant<0>', [])
    385377      else:
    386         mask1 = mkCall('bitblock::slli<1>', [mkCall('simd_not', [ast.Name('EOF_mask', ast.Load())])])
    387         return mkCall('simd_andc', [mkCall('simd_andc', [callnode.args[0], ast.Name('EOF_mask', ast.Load())]), mask1])
     378        mask1 = mkast.call('bitblock::slli<1>', [mkast.call('simd_not', [ast.Name('EOF_mask', ast.Load())])])
     379        return mkast.call('simd_andc', [mkast.call('simd_andc', [callnode.args[0], ast.Name('EOF_mask', ast.Load())]), mask1])
    388380    elif is_BuiltIn_Call(callnode, 'inFile', 1):
    389381      if self.carryout != "": 
    390382        # Non final block: inFile(x) = x.
    391383        return callnode.args[0]
    392       else: return mkCall('simd_and', [callnode.args[0], ast.Name('EOF_mask', ast.Load())])
     384      else: return mkast.call('simd_and', [callnode.args[0], ast.Name('EOF_mask', ast.Load())])
    393385    elif is_BuiltIn_Call(callnode, 'StreamScan', 2):
    394386      rtn = "StreamScan"           
    395       c = mkCall(rtn, [ast.Name('(ScanBlock *) &' + callnode.args[0].id, ast.Load()),
     387      c = mkast.call(rtn, [ast.Name('(ScanBlock *) &' + callnode.args[0].id, ast.Load()),
    396388                                           ast.Name('sizeof(BitBlock)/sizeof(ScanBlock)', ast.Load()),
    397389                                           ast.Name(callnode.args[1].id, ast.Load())])
     
    411403    carry_args = [ast.Num(self.current_carry)]
    412404    if self.carryin == "_ci":
    413         carry_args = [mkCall(self.carryvar.id + "." + 'get_carry_in', [ast.Num(self.current_carry)]), ast.Num(self.current_carry)]
     405        carry_args = [mkast.call(self.carryvar.id + "." + 'get_carry_in', [ast.Num(self.current_carry)]), ast.Num(self.current_carry)]
    414406    else:
    415         carry_args = [mkCall('simd<1>::constant<0>', []), ast.Num(self.current_carry)]
     407        carry_args = [mkast.call('simd<1>::constant<0>', []), ast.Num(self.current_carry)]
    416408    if isinstance(exprnode.op, ast.Sub):
    417409      assert False, "Subtraction no longer supported - use pablo.SpanUpTo ..."
     
    431423                carry_in_expr = self.ccgo.GenerateCarryInAccess(self.operation_count)
    432424            else:
    433                 carry_in_expr = mkCall('simd<1>::constant<0>', [])
     425                carry_in_expr = mkast.call('simd<1>::constant<0>', [])
    434426            callnode = assigNode.value
    435427            if isAdvance(f):
    436                pablo_routine_call = mkCall('pablo_blk_' + f, [assigNode.value.args[0], carry_in_expr, assigNode.targets[0]])
     428               pablo_routine_call = mkast.call('pablo_blk_' + f, [assigNode.value.args[0], carry_in_expr, assigNode.targets[0]])
    437429            elif f in ['ScanTo', 'AdvanceThenScanTo']:
    438                if self.carryout == "":  scanclass = mkCall('simd_andc', [ast.Name('EOF_mask', ast.Load()), callnode.args[1]])
    439                else: scanclass = mkCall('simd_not', [callnode.args[1]])
    440                pablo_routine_call = mkCall('pablo_blk_' +f[:-2] + 'Thru', [callnode.args[0], scanclass, carry_in_expr, assigNode.targets[0]])
     430               if self.carryout == "":  scanclass = mkast.call('simd_andc', [ast.Name('EOF_mask', ast.Load()), callnode.args[1]])
     431               else: scanclass = mkast.call('simd_not', [callnode.args[1]])
     432               pablo_routine_call = mkast.call('pablo_blk_' +f[:-2] + 'Thru', [callnode.args[0], scanclass, carry_in_expr, assigNode.targets[0]])
    441433            else:
    442                pablo_routine_call = mkCall('pablo_blk_' + f, assigNode.value.args + [carry_in_expr, assigNode.targets[0]])
     434               pablo_routine_call = mkast.call('pablo_blk_' + f, assigNode.value.args + [carry_in_expr, assigNode.targets[0]])
    443435            self.last_stmt = pablo_routine_call
    444436            compiled = self.ccgo.GenerateCarryOutStore(self.operation_count, pablo_routine_call)
     
    450442                carry_in_expr = self.ccgo.GenerateAdvanceInAccess(self.operation_count)
    451443            else:
    452                 carry_in_expr = mkCall('simd<1>::constant<0>', [])
     444                carry_in_expr = mkast.call('simd<1>::constant<0>', [])
    453445            callnode = assigNode.value
    454             pablo_routine_call = mkCall('pablo_blk_Advance_n_<%i>' %  assigNode.value.args[1].n, [assigNode.value.args[0], carry_in_expr, assigNode.targets[0]])
     446            pablo_routine_call = mkast.call('pablo_blk_Advance_n_<%i>' %  assigNode.value.args[1].n, [assigNode.value.args[0], carry_in_expr, assigNode.targets[0]])
    455447            self.last_stmt = pablo_routine_call
    456448            compiled = self.ccgo.GenerateAdvanceOutStore(self.operation_count, pablo_routine_call)
     
    471463    carry_base = self.current_carry
    472464    carries = CarryCounter().count(ifNode)
    473     assert adv_nCounter().count(ifNode) == 0, "Advance(x,n) within if: illegal\n"
     465    #assert adv_nCounter().count(ifNode) == 0, "Advance(x,n) within if: illegal\n"
    474466    self.generic_visit(ifNode)
    475467    if carries == 0: # or self.carryin == "":
     
    478470    #CARRYSET
    479471    carry_arglist = [ast.Num(carry_base), ast.Num(carries)]
    480     #new_test = ast.BoolOp(ast.Or(), [ifNode.test, mkCall(ast.Attribute(self.carryvar, 'CarryTest', ast.Load()), carry_arglist)])
     472    #new_test = ast.BoolOp(ast.Or(), [ifNode.test, mkast.call(ast.Attribute(self.carryvar, 'CarryTest', ast.Load()), carry_arglist)])
    481473    #new_else_part = ifNode.orelse + [mkast.callStmt(ast.Attribute(self.carryvar, 'CarryDequeueEnqueue', ast.Load()), carry_arglist)]
    482474    if self.carryin == "": new_test = ifNode.test
     
    519511    original_test_expr = whileNode.test.args[0]
    520512    if self.carryout == '':
    521       whileNode.test.args[0] = mkCall("simd_and", [original_test_expr, ast.Name('EOF_mask', ast.Load())])
     513      whileNode.test.args[0] = mkast.call("simd_and", [original_test_expr, ast.Name('EOF_mask', ast.Load())])
    522514
    523515    self.generic_visit(whileNode)
     
    537529    original_test_expr = whileNode.test.args[0]
    538530    if self.carryout == '':
    539       whileNode.test.args[0] = mkCall("simd_and", [original_test_expr, ast.Name('EOF_mask', ast.Load())])
     531      whileNode.test.args[0] = mkast.call("simd_and", [original_test_expr, ast.Name('EOF_mask', ast.Load())])
    540532    carry_base = self.current_carry
    541533    assert adv_nCounter().count(whileNode) == 0, "Advance(x,n) within while: illegal\n"
     
    660652                err_stream = node.value.args[0]
    661653                err_code = node.value.args[1]
    662                 return ast.If(mkCall('bitblock::any', [err_stream]),
    663                               [ast.Expr(mkCall(self.assert_routine, [err_code, err_stream]))],
     654                return ast.If(mkast.call('bitblock::any', [err_stream]),
     655                              [ast.Expr(mkast.call(self.assert_routine, [err_code, err_stream]))],
    664656                              [])
    665657        else: return node
     
    675667    self.generic_visit(t)
    676668    v = t.targets[0]
    677     dump_stmt = mkast.callStmt(' print_register<BitBlock>', [ast.Str(Cgen.py2C().gen(v)), v])
     669    dump_stmt = mkast.callStmt('print_register<BitBlock>', [ast.Str(Cgen.py2C().gen(v)), v])
    678670    return [t, dump_stmt]
    679671
     
    938930    self.main_node_id = main_node_id
    939931    self.use_C_syntax = C_syntax
     932    mkast.use_C_syntax = self.use_C_syntax
    940933    self.add_dump_stmts = add_dump_stmts
    941934    self.add_assert_bitblock_align = add_assert_bitblock_align
Note: See TracChangeset for help on using the changeset viewer.