diff options
author | aqua <aqua@iserlohn-fortress.net> | 2023-10-22 18:42:58 +0300 |
---|---|---|
committer | aqua <aqua@iserlohn-fortress.net> | 2023-10-22 18:42:58 +0300 |
commit | fbe4a5eeab2107dfe03fc097bc1f9627b222adbd (patch) | |
tree | 11dd6b18e324721b1b3f23ed3617ac6922774ea7 /codegen/yaml.py | |
download | codegen-fbe4a5eeab2107dfe03fc097bc1f9627b222adbd.tar.xz |
Diffstat (limited to 'codegen/yaml.py')
-rw-r--r-- | codegen/yaml.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/codegen/yaml.py b/codegen/yaml.py new file mode 100644 index 0000000..15ee7a4 --- /dev/null +++ b/codegen/yaml.py @@ -0,0 +1,27 @@ +""" yaml parser """ +__license__ = 'GPL-3.0-only' + +import yaml +from .types import Variable, Function, Struct +from .header import Header + +def read(path: str, hdr: Header): + with open(path, mode='r', encoding='utf-8') as stream: + data = yaml.safe_load(stream) + + for item, info in data['variables'].items(): + hdr.variables.append(Variable(item, data=info)) + + for item, info in data['functions'].items(): + hdr.functions.append(Function(item, data=info)) + + for struct in data['structs']: + name = struct.pop('name') + members = [] + for item, info in struct.items(): + match info['type']: + case 'fn_ptr': + members.append(Function(item, data=info)) + case _: + members.append(Variable(item, data=info)) + hdr.structs.append(Struct(name, members)) |