diff options
Diffstat (limited to 'tools/interface_generator/interface_generator.py')
-rwxr-xr-x | tools/interface_generator/interface_generator.py | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/tools/interface_generator/interface_generator.py b/tools/interface_generator/interface_generator.py new file mode 100755 index 0000000..4eb8d69 --- /dev/null +++ b/tools/interface_generator/interface_generator.py @@ -0,0 +1,60 @@ +#!/usr/bin/env python3 + +from argparse import ArgumentParser +from mako.template import Template +from mako.lookup import TemplateLookup + +PROG = { + "name": "interface_generator", + "version": "0.1", +} + + +def generate_file(template, kwargs): + """generate file using a tempalte""" + lookup = TemplateLookup(directories=[".", "templates"]) + template = lookup.get_template(template) + result = template.render(**kwargs, PROG=PROG) + + # print(kwargs) + print(result) + + +def main(): + parser = ArgumentParser( + prog="interface_generator", + description="Generate a C header file from an interface definition", + ) + parser.add_argument("-l", "--license", required=True) + + parser_args = parser.parse_args() + print(parser_args) + + args = { + "name": "stdio", + "license": parser_args.license, + "system_includes": ["stdarg.h"], + "types": [ + { + "name": "FILE", + "members": [ + "int fd", + "int (*putc)(const struct FILE*, const char)", + "int (*puts)(const struct FILE*, const char*)", + ], + }, + ], + "functions": [ + { + "name": "printf", + "return": "int", + "arguments": ["const char*__restrict__ format", "..."], + }, + ], + } + + generate_file("c_header.mako", args) + + +if __name__ == "__main__": + main() |