Пример #1
0
        def visit_Struct(self, node):
            if node.name is not None and (node.name.startswith("PPB_")
                                          or node.name.startswith("PPP_")
                                          ) and node.decls is not None:
                if node.name in uniq_trace_funcs:
                    return
                uniq_trace_funcs.add(node.name)
                for a in node.decls:
                    a_func = a.children()[0][1].children()[0][1].children()
                    a_func_args = a_func[0][1]
                    a_func_rettype = a_func[1][1]

                    print("static ", end="")
                    fname = "unknown"
                    if isinstance(a_func_rettype, c_ast.TypeDecl):
                        fname = a_func_rettype.declname
                        a_func_rettype.declname = ""
                        print(c_gen.visit(
                            c_ast.Typedef("dummy", [], [], a_func_rettype)),
                              end="")
                        a_func_rettype.declname = fname
                    elif isinstance(a_func_rettype, c_ast.PtrDecl):
                        a_func_rettype = a_func_rettype.children()[0][1]
                        fname = a_func_rettype.declname
                        a_func_rettype.declname = ""
                        print(c_gen.visit(
                            c_ast.Typedef("dummy", [], [], a_func_rettype)) +
                              " *",
                              end="")
                        a_func_rettype.declname = fname

                    arg_names = (list(c[1].name
                                      for c in a_func_args.children()
                                      if c[1].name is not None))
                    print(" trace_" + node.name + "_" + fname + "(" +
                          c_gen.visit(a_func_args) + ") {")
                    print("    printf(\"" + node.name + "." + fname +
                          "\\n\");")
                    print("    return orig_" + node.name + "->" + fname + "(" +
                          ", ".join(arg_names) + ");")
                    print("}")
        def visit_Struct(self, node):
            if node.name is not None and node.name.startswith(
                    "PPB_") and node.decls is not None:
                for a in node.decls:
                    a_func = a.children()[0][1].children()[0][1].children()
                    a_func_args = a_func[0][1]
                    a_func_rettype = a_func[1][1]

                    fname = "unknown"
                    if isinstance(a_func_rettype, c_ast.TypeDecl):
                        fname = a_func_rettype.declname
                        a_func_rettype.declname = ""
                        print(
                            c_gen.visit(
                                c_ast.Typedef("dummy", [], [],
                                              a_func_rettype)))
                        a_func_rettype.declname = fname
                    elif isinstance(a_func_rettype, c_ast.PtrDecl):
                        a_func_rettype = a_func_rettype.children()[0][1]
                        fname = a_func_rettype.declname
                        a_func_rettype.declname = ""
                        print(
                            c_gen.visit(
                                c_ast.Typedef("dummy", [], [], a_func_rettype))
                            + " *")
                        a_func_rettype.declname = fname

                    arg_names = (list(c[1].name
                                      for c in a_func_args.children()
                                      if c[1].name is not None))
                    print(lowcase_name(node.name, fname) + "(" +
                          c_gen.visit(a_func_args) + ")",
                          end="")
                    if gen_prototypes_only:
                        print(";")
                    else:
                        print("")
                        print("{")
                        print("}")
                    print("")
        def visit_Struct(self, node):
            if node.name is not None and node.name.startswith(
                    "PPB_") and node.decls is not None:
                for a in node.decls:
                    a_func = a.children()[0][1].children()[0][1].children()
                    a_func_args = a_func[0][1]
                    a_func_rettype = a_func[1][1]

                    print("TRACE_WRAPPER")
                    fname = "unknown"
                    if isinstance(a_func_rettype, c_ast.TypeDecl):
                        fname = a_func_rettype.declname
                        a_func_rettype.declname = ""
                        print(
                            c_gen.visit(
                                c_ast.Typedef("dummy", [], [],
                                              a_func_rettype)))
                        a_func_rettype.declname = fname
                    elif isinstance(a_func_rettype, c_ast.PtrDecl):
                        a_func_rettype = a_func_rettype.children()[0][1]
                        fname = a_func_rettype.declname
                        a_func_rettype.declname = ""
                        print(
                            c_gen.visit(
                                c_ast.Typedef("dummy", [], [], a_func_rettype))
                            + " *")
                        a_func_rettype.declname = fname

                    arg_names = (list(c[1].name
                                      for c in a_func_args.children()
                                      if c[1].name is not None))
                    print("trace_" + lowcase_name(node.name, fname) + "(" +
                          c_gen.visit(a_func_args) + ")")
                    print("{")
                    print('    trace_info("[PPB] {zilch} %s\\n", __func__+6);')
                    print("    return " + lowcase_name(node.name, fname) +
                          "(" + ", ".join(arg_names) + ");")
                    print("}")
                    print("")
Пример #4
0
def generate_sai_api_tbl_h(apis):
    def createDecl(api):
        apitype = 'sai_' + api + '_api_t'
        apivar = 'sai_' + api + '_api_tbl'
        return c_ast.Decl(
            apivar, list(), list(), list(),
            c_ast.PtrDecl(
                list(),
                c_ast.TypeDecl(apivar, list(), c_ast.IdentifierType([
                    apitype,
                ]))), None, None)

    tdecls = [createDecl(api) for api in apis]
    tstruct = c_ast.Struct('_sai_api_tbl_t', tdecls)
    tdec = c_ast.TypeDecl('sai_api_tbl_t', list(), tstruct)
    tdef = c_ast.Typedef('sai_api_tbl_t', list(), ['typedef'], tdec)
    externdec = c_ast.Decl(
        'sai_api_tbl', list(), ['extern'], list(),
        c_ast.TypeDecl('sai_api_tbl', list(),
                       c_ast.IdentifierType(['sai_api_tbl_t'])), None, None)
    api_t = c_ast.FileAST([tdef, externdec])
    generator = c_generator.CGenerator()
    sai_api_tbl_h_str = r'''#include "sai.h"
#ifndef SAI_API_TBL
#define SAI_API_TBL

'''
    sai_api_tbl_h_str += generator.visit(api_t)
    sai_api_tbl_h_str += r'''
extern sai_status_t sai_api_tbl_init();

#endif
'''
    # print(api_t)
    print(sai_api_tbl_h_str)
    with open('adaptor/gen-inc/sai_api_tbl.h', 'w') as f:
        f.write(sai_api_tbl_h_str)