From b76b5ea2f6896d2e390703d2364fbeb2150ff402 Mon Sep 17 00:00:00 2001 From: Raphael Roberts Date: Mon, 17 May 2021 11:03:32 -0500 Subject: [PATCH] Use pre-processor so I don't have to deal with comments. --- c2logic/instruction_definition.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/c2logic/instruction_definition.py b/c2logic/instruction_definition.py index 13714cd..aa5989c 100644 --- a/c2logic/instruction_definition.py +++ b/c2logic/instruction_definition.py @@ -1,4 +1,4 @@ -from pycparser import c_parser, c_ast +from pycparser import parse_file, c_ast def extract_asm(body: c_ast.Compound): for item in body.block_items: @@ -45,10 +45,7 @@ class InstructionReader(c_ast.NodeVisitor): except AttributeError: record['args'] = tuple() -if __name__ == "__main__": - parser = c_parser.CParser() - with open('/home/raphael/cloned-repos/c2logic/include/builtins.c') as c_file: - text = c_file.read() - my_ast = parser.parse(text) - reader = InstructionReader() - reader.visit(my_ast) +instructions = parse_file('instruction_definition.c', use_cpp=True) +reader = InstructionReader() +reader.visit(instructions) +FUNCS = reader.funcs