コード例 #1
0
ファイル: pass.py プロジェクト: RedlineResearch/oicdb
 def dbg(c):
     rubric_loc = copy.deepcopy(rubric)
     name = new_sym((filename, c.coord, c.decl.name, type(c)))
     decl = var_declare(name, rubric_loc, 0)
     ast_ops.sar_string(rubric_loc, "__DEBUG_ID", name)
     f_in = rubric_loc.block_items[1]
     f_out = rubric_loc.block_items[2]
     c.body.block_items = [decl, f_in] + c.body.block_items + [f_out]
     return c
コード例 #2
0
ファイル: pass.py プロジェクト: RedlineResearch/oicdb
 def dbg(a):
     a.rvalue = ast_ops.sar(a.rvalue, Assignment, dbg)
     a.lvalue = ast_ops.sar(a.lvalue, Assignment, dbg)
     r = copy.deepcopy(rubric)
     ast_ops.sar(r, Constant, lambda c: Constant("int", str(ID_count + 1)) if c.value == "0" else c)
     ast_ops.sar_string(r, "__DEBUG_ID", new_sym((filename, a.coord, a, type(a))))
     ast_ops.sar_ID(r, "LVALUE", a.lvalue)
     ast_ops.sar_ID(r, "RVALUE", a.rvalue)
     # print "OPERATION: "+a.op
     r.block_items[-2].op = a.op  # makes the operation (=, +=, -=) correct - TODO: magic number...
     return FuncCall(ID(""), ExprList([Compound(r.block_items, coord=a.coord)], coord=a.coord))
コード例 #3
0
ファイル: pass.py プロジェクト: RedlineResearch/oicdb
 def dbg(ret):
     rubric_loc = copy.deepcopy(rubric)
     name = new_sym((filename, ret.coord, "return", type(ret)))
     decl = var_declare(name, rubric_loc, 0)
     ast_ops.sar_string(rubric_loc, "__DEBUG_ID", name)
     fncn_out = rubric_loc.block_items[2]
     decl2 = var_declare("__DEBUG_RETURN", rubric, 1)
     decl2.init = ret.expr
     ret.expr = pycparser.c_ast.ID("__DEBUG_RETURN")
     fncn_ret = rubric_loc.block_items[5]
     return Compound(
         [decl, decl2, fncn_out, rubric_loc.block_items[3], rubric_loc.block_items[4], fncn_ret, ret],
         coord=ret.coord,
     )
コード例 #4
0
ファイル: pass.py プロジェクト: RedlineResearch/oicdb
    def dbg(u):
        # print u.op
        if not ("++" in u.op or "--" in u.op):
            return u
        r = copy.deepcopy(rubric)

        def fix_op(ur):
            if "++" in ur.op or "--" in ur.op:
                ur.op = u.op
            return ur

        ast_ops.sar(r, UnaryOp, fix_op)
        ast_ops.sar(r, Constant, lambda c: Constant("int", str(ID_count + 1)) if c.value == "0" else c)
        ast_ops.sar_string(r, "__DEBUG_ID", new_sym((filename, u.coord, u, type(u))))
        # print u.expr.__dict__
        ast_ops.sar_ID(r, "LVALUE", u.expr)
        return FuncCall(ID(""), ExprList([Compound(r.block_items, coord=u.coord)], coord=u.coord))
コード例 #5
0
ファイル: pass.py プロジェクト: RedlineResearch/oicdb
 def dbg(f):
     # print f.__dict__
     args = [d.name for d in f.decl.type.args.params]
     for arg in args[::-1]:
         r = copy.deepcopy(rubric)
         ast_ops.sar(r, Constant, lambda c: Constant("int", str(ID_count + 1)) if c.value == "0" else c)
         ast_ops.sar_string(r, "__DEBUG_ID", new_sym((filename, f.coord, arg, type(f.decl.type.args))))
         ast_ops.sar_string(r, "LVALUE", arg)
         ast_ops.sar_string(r, "RVALUE", arg)
         f.body.block_items.insert(0, r)
     return f
コード例 #6
0
ファイル: pass.py プロジェクト: RedlineResearch/oicdb
 def dbg(d):
     if not d.__dict__.has_key("init"):
         return None  # not the kind of Decl we're looking for
     if d.name.startswith("__DEBUG_"):
         return None  # skip VAR pass variables
     d.init = ast_ops.sar(d.init, Decl, dbg)
     r = copy.deepcopy(rubric)
     ast_ops.sar(r, Constant, lambda c: Constant("int", str(ID_count + 1)) if c.value == "0" else c)
     ast_ops.sar_string(r, "__DEBUG_ID", new_sym((filename, d.coord, d, type(d))))
     ast_ops.sar_string(r, "LVALUE", d.name)
     if d.init:
         ast_ops.sar_ID(r, "RVALUE", d.init)
     # No initial value, so RVALUE = *LVALUE implicitly (garbage value, but useful for debugging):
     else:
         ast_ops.sar_string(r, "RVALUE", d.name)
     return FuncCall(ID(""), ExprList([Compound(r.block_items, coord=d.coord)], coord=d.coord))