summaryrefslogtreecommitdiff
path: root/codegen/yaml.py
diff options
context:
space:
mode:
Diffstat (limited to 'codegen/yaml.py')
-rw-r--r--codegen/yaml.py27
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))