예제 #1
0
def do_preprocess(defn):
    """
    Run a string through the C preprocessor that ships with pycparser but is weirdly inaccessible?
    """
    from pycparser.ply import lex, cpp
    lexer = lex.lex(cpp)
    p = cpp.Preprocessor(lexer)
    p.parse(defn)
    return ''.join(tok.value for tok in p.parser if tok.type not in p.ignore)
예제 #2
0
def lazy_preprocess(source):
    pp = cpp.Preprocessor(lex.lex(module=cpp))
    pp.parse(source)
    result = ""
    while True:
        token = pp.token()
        if not token:
            return result
        result += token.value
예제 #3
0
파일: sim_type.py 프로젝트: wwwzbwcom/angr
def do_preprocess(defn):
    """
    Run a string through the C preprocessor that ships with pycparser but is weirdly inaccessible?
    """
    from pycparser.ply import lex, cpp  # pylint:disable=import-outside-toplevel
    lexer = lex.lex(cpp)
    p = cpp.Preprocessor(lexer)
    # p.add_path(dir) will add dir to the include search path
    p.parse(defn)
    return ''.join(tok.value for tok in p.parser if tok.type not in p.ignore)
예제 #4
0
파일: sim_type.py 프로젝트: AmesianX/angr
def do_preprocess(defn):
    """
    Run a string through the C preprocessor that ships with pycparser but is weirdly inaccessible?
    """
    from pycparser.ply import lex, cpp
    lexer = lex.lex(cpp)
    p = cpp.Preprocessor(lexer)
    # p.add_path(dir) will add dir to the include search path
    p.parse(defn)
    return ''.join(tok.value for tok in p.parser if tok.type not in p.ignore)
예제 #5
0
def do_preprocess(defn):
    """
    Run a string through the C preprocessor that ships with pycparser but is weirdly inaccessable?
    """
    import pycparser.ply.lex as lex
    import pycparser.ply.cpp as cpp
    lexer = lex.lex(cpp)
    p = cpp.Preprocessor(lexer)
    # p.add_path(dir) will add dir to the include search path
    p.parse(defn)
    return ''.join(tok.value for tok in p.parser if tok.type not in p.ignore)
예제 #6
0
def preprocess_defs(defn):
    from pycparser.ply import lex, cpp
    lexer = lex.lex(cpp)
    p = cpp.Preprocessor(lexer)
    list(p.parsegen(defn))
    defs = {x: y.value[0].value for x, y in p.macros.items() if not x.startswith("__")}
    ret = {}
    for x, y in defs.items():
        y = y.strip("'").strip('"')
        v = None
        if y.isnumeric():
            v = int(y)
        elif y.startswith("0x") and all(c in string.hexdigits for c in y[2:]):
            v = int(y, 16)
        elif len(y) == 1:
            v = ord(y)
        if v is not None:
            ret[x] = v
    return ret
예제 #7
0
 def __init__(self, **kwargs):
     self.lexer = lex.lex(module=self, **kwargs)