mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2025-11-28 02:20:50 +00:00
Add command-line options to accept paths of headers as a list of multiple file paths
This commit is contained in:
parent
7a9d37a20e
commit
1a1112f3d9
|
|
@ -1,5 +1,6 @@
|
||||||
from pycparser import c_parser, c_ast, parse_file
|
from pycparser import c_parser, c_ast, parse_file
|
||||||
import os
|
import os
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
|
||||||
def collect_typedefs(ast):
|
def collect_typedefs(ast):
|
||||||
|
|
@ -172,10 +173,23 @@ def generate_checked_function(func, typedefs):
|
||||||
return "\n".join(new_func)
|
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
|
# 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
|
# Define the Result struct as a string
|
||||||
RESULT_STRUCT = """
|
RESULT_STRUCT = """
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
@ -186,11 +200,8 @@ def process_header():
|
||||||
} Result;
|
} Result;
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Based on current file location, adjust the path to the header file
|
for input_header in header_paths:
|
||||||
input_header = os.path.join(
|
output_header = input_header.replace(".h", "_checked.h")
|
||||||
os.path.dirname(__file__), "../core/iwasm/include/wasm_export.h"
|
|
||||||
)
|
|
||||||
output_header = input_header.replace("wasm_export.h", "wasm_export_checked.h")
|
|
||||||
|
|
||||||
# Parse the header file with preprocessing
|
# Parse the header file with preprocessing
|
||||||
ast = parse_file(
|
ast = parse_file(
|
||||||
|
|
@ -266,4 +277,5 @@ def process_header():
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
process_header()
|
args = parse_arguments()
|
||||||
|
process_headers(args.headers)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user