aboutsummaryrefslogtreecommitdiff
path: root/tools/interface_generator/bin/interface_declaration.py
diff options
context:
space:
mode:
Diffstat (limited to 'tools/interface_generator/bin/interface_declaration.py')
-rw-r--r--tools/interface_generator/bin/interface_declaration.py58
1 files changed, 58 insertions, 0 deletions
diff --git a/tools/interface_generator/bin/interface_declaration.py b/tools/interface_generator/bin/interface_declaration.py
new file mode 100644
index 0000000..4560bbd
--- /dev/null
+++ b/tools/interface_generator/bin/interface_declaration.py
@@ -0,0 +1,58 @@
+"""
+interface_declaration.py
+"""
+
+from dataclasses import dataclass, asdict
+from pathlib import Path
+
+
+@dataclass
+class InterfaceDeclaration:
+ """interface declaration class"""
+
+ name: str
+ license_hdr: str
+ system_includes: list[str]
+ types: list[dict]
+ functions: list[dict]
+
+ def read_license(self, path: Path):
+ """read and starrify a license"""
+ if path is None:
+ self.license_hdr = ""
+ return
+
+ with open(path, encoding="utf-8") as license_file:
+ self.license_hdr = "".join(
+ [
+ f" * { line.rstrip().ljust(72)[:72] } * \n"
+ for line in license_file.readlines()
+ ]
+ ).rstrip()
+
+ def __init__(self, name: str, license_path: Path):
+ self.name = name if name is not None else "kstdio"
+ self.read_license(license_path)
+ self.system_includes = ["stdarg.h"]
+ self.types = [
+ {
+ "name": "File",
+ "members": [
+ "int fd",
+ "int (*putc)(const struct kstdio_File*, const char)",
+ "int (*puts)(const struct kstdio_File*, const char*)",
+ ],
+ },
+ ]
+ self.functions = [
+ {
+ "name": "printf",
+ "return": "int",
+ "arguments": ["const char* format"],
+ "argument_names": ["format"],
+ },
+ ]
+
+ def into_dict(self) -> dict:
+ """create a dictionary for use in mako"""
+ return asdict(self)