(defn, preprocess=True, predefined_types=None, arch=None)
return out, extra_types
Parse a series of C definitions, returns a tuple of two type mappings, one for variable
    definitions and one for type definitions.
Parse a series of C definitions, returns a tuple of two type mappings, one for variable
    definitions and one for type definitions.
Parse a series of C definitions returns a tuple of two type mappings one for variable definitions and one for type definitions .
def parse_file(defn, preprocess=True, predefined_types=None, arch=None):
    """
    Parse a series of C definitions, returns a tuple of two type mappings, one for variable
    definitions and one for type definitions.
    """
    if pycparser is None:
        raise ImportError("Please install pycparser in order to parse C definitions")

    defn = '\n'.join(x for x in defn.split('\n') if _include_re.match(x) is None)

    if preprocess:
        defn = do_preprocess(defn)

    node = pycparser.c_parser.CParser().parse(defn, scope_stack=_make_scope(predefined_types))
    if not isinstance(node, pycparser.c_ast.FileAST):
        raise ValueError("Something went horribly wrong using pycparser")
    out = {}
    extra_types = {}
    for piece in node.ext:
        if isinstance(piece, pycparser.c_ast.FuncDef):
            out[piece.decl.name] = _decl_to_type(piece.decl.type, extra_types, arch=arch)
        elif isinstance(piece, pycparser.c_ast.Decl):
            ty = _decl_to_type(piece.type, extra_types, arch=arch)
            if piece.name is not None:
                out[piece.name] = ty

            # Don't forget to update typedef types
            if (isinstance(ty, SimStruct) or isinstance(ty, SimUnion)) and ty.name != '<anon>':
                for _, i in extra_types.items():
                    if type(i) is type(ty) and i.name == ty.name:
                        if isinstance(ty, SimStruct):
                            i.fields = ty.fields
                        else:
                            i.members = ty.members

        elif isinstance(piece, pycparser.c_ast.Typedef):
            extra_types[piece.name] = copy.copy(_decl_to_type(piece.type, extra_types, arch=arch))
            extra_types[piece.name].label = piece.name

    return out, extra_types
def parse_file ( defn , preprocess = True , predefined_types = None , arch = None ) : if pycparser is None : raise ImportError ( "Please install pycparser in order to parse C definitions" ) defn = '\n' . join ( x for x in defn . split ( '\n' ) if _include_re . match ( x ) is None ) if preprocess : defn = do_preprocess ( defn ) node = pycparser . c_parser . CParser ( ) . parse ( defn , scope_stack = _make_scope ( predefined_types ) ) if not isinstance ( node , pycparser . c_ast . FileAST ) : raise ValueError ( "Something went horribly wrong using pycparser" ) out = { } extra_types = { } for piece in node . ext : if isinstance ( piece , pycparser . c_ast . FuncDef ) : out [ piece . decl . name ] = _decl_to_type ( piece . decl . type , extra_types , arch = arch ) elif isinstance ( piece , pycparser . c_ast . Decl ) : ty = _decl_to_type ( piece . type , extra_types , arch = arch ) if piece . name is not None : out [ piece . name ] = ty # Don't forget to update typedef types if ( isinstance ( ty , SimStruct ) or isinstance ( ty , SimUnion ) ) and ty . name != '<anon>' : for _ , i in extra_types . items ( ) : if type ( i ) is type ( ty ) and i . name == ty . name : if isinstance ( ty , SimStruct ) : i . fields = ty . fields else : i . members = ty . members elif isinstance ( piece , pycparser . c_ast . Typedef ) : extra_types [ piece . name ] = copy . copy ( _decl_to_type ( piece . type , extra_types , arch = arch ) ) extra_types [ piece . name ] . label = piece . name return out , extra_types