Add command-line options to accept paths of headers as a list of multiple file paths

This commit is contained in:
liang.he@intel.com 2025-10-28 07:24:44 +00:00
parent 7a9d37a20e
commit 1a1112f3d9

View File

@ -1,5 +1,6 @@
from pycparser import c_parser, c_ast, parse_file
import os
import argparse
def collect_typedefs(ast):
@ -172,10 +173,23 @@ def generate_checked_function(func, typedefs):
return "\n".join(new_func)
def parse_arguments():
parser = argparse.ArgumentParser(
description="Generate checked functions from header files."
)
parser.add_argument(
"--headers",
nargs="+",
required=True,
help="List of header file paths to process.",
)
return parser.parse_args()
# Updated process_header to scan all return types and create a proper Result type
def process_header():
def process_headers(header_paths):
# Define the Result struct as a string
RESULT_STRUCT = """
typedef struct {
@ -186,11 +200,8 @@ def process_header():
} Result;
"""
# Based on current file location, adjust the path to the header file
input_header = os.path.join(
os.path.dirname(__file__), "../core/iwasm/include/wasm_export.h"
)
output_header = input_header.replace("wasm_export.h", "wasm_export_checked.h")
for input_header in header_paths:
output_header = input_header.replace(".h", "_checked.h")
# Parse the header file with preprocessing
ast = parse_file(
@ -266,4 +277,5 @@ def process_header():
if __name__ == "__main__":
process_header()
args = parse_arguments()
process_headers(args.headers)