tools/spec: pass files rather than paths to write_foo functions
This commit is contained in:
parent
336e9632d3
commit
deca2ded59
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
import logging
|
import logging
|
||||||
from typing import List, Dict, Set
|
from typing import List, Dict, Set, TextIO
|
||||||
|
|
||||||
import xml.etree.ElementTree
|
import xml.etree.ElementTree
|
||||||
|
|
||||||
@ -699,8 +699,7 @@ def parse_extensions(reg: Registry, root):
|
|||||||
|
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
def write_header(path: str, q: List[Type], reg: Registry):
|
def write_header(dst: TextIO, q: List[Type], reg: Registry):
|
||||||
with open(path, 'w') as dst:
|
|
||||||
dst.write("#pragma once\n")
|
dst.write("#pragma once\n")
|
||||||
|
|
||||||
# Write the declarations and definitions for all types.
|
# Write the declarations and definitions for all types.
|
||||||
@ -750,15 +749,14 @@ def write_header(path: str, q: List[Type], reg: Registry):
|
|||||||
|
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
def write_icd(path: str, q: List[Type], reg: Registry):
|
def write_icd(dst: TextIO, q: List[Type], reg: Registry):
|
||||||
with open(path, 'w') as icd:
|
|
||||||
commands = [i for i in q if isinstance(i, Command)]
|
commands = [i for i in q if isinstance(i, Command)]
|
||||||
instance_commands = [i for i in commands if i.is_instance(reg)]
|
instance_commands = [i for i in commands if i.is_instance(reg)]
|
||||||
device_commands = [i for i in commands if i.is_device(reg)]
|
device_commands = [i for i in commands if i.is_device(reg)]
|
||||||
|
|
||||||
assert len(instance_commands) + len(device_commands) == len(commands)
|
assert len(instance_commands) + len(device_commands) == len(commands)
|
||||||
|
|
||||||
icd.write(f"""
|
dst.write(f"""
|
||||||
#include "vk.hpp"
|
#include "vk.hpp"
|
||||||
|
|
||||||
#include <cruft/util/preprocessor.hpp>
|
#include <cruft/util/preprocessor.hpp>
|
||||||
@ -779,27 +777,31 @@ def write_icd(path: str, q: List[Type], reg: Registry):
|
|||||||
instance_table (vendor &);
|
instance_table (vendor &);
|
||||||
""")
|
""")
|
||||||
|
|
||||||
for obj in instance_commands:
|
# Generate the vtable entries for instance methods
|
||||||
icd.write(f"{obj.result} (*{obj.name}) ({','.join(p.param for p in obj.params)}) = nullptr;\n")
|
dst.writelines((
|
||||||
|
f"{obj.result} (*{obj.name}) ({','.join(p.param for p in obj.params)}) = nullptr;"
|
||||||
icd.write("""};
|
for obj in instance_commands
|
||||||
|
))
|
||||||
|
|
||||||
|
dst.write("""};
|
||||||
struct device_table {
|
struct device_table {
|
||||||
""")
|
""")
|
||||||
|
|
||||||
for obj in device_commands:
|
# Generate the vtable and entries for device_commands
|
||||||
icd.write(f"{obj.result} (*{obj.name}) ({','.join(p.param for p in obj.params)}) = nullptr;\n")
|
dst.writelines((
|
||||||
|
f"{obj.result} (*{obj.name}) ({','.join(p.param for p in obj.params)}) = nullptr;"
|
||||||
|
for obj in device_commands
|
||||||
|
))
|
||||||
|
|
||||||
icd.write("""
|
dst.write("""
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
""")
|
""")
|
||||||
|
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
def write_dispatch(path: str, q: List[Type], reg: Registry):
|
def write_dispatch(dst: TextIO, q: List[Type], reg: Registry):
|
||||||
with open(path, 'w') as dispatch:
|
dst.write("""
|
||||||
dispatch.write("""
|
|
||||||
#include "../vk.hpp"
|
#include "../vk.hpp"
|
||||||
#include "vtable.hpp"
|
#include "vtable.hpp"
|
||||||
|
|
||||||
@ -828,7 +830,7 @@ def write_dispatch(path: str, q: List[Type], reg: Registry):
|
|||||||
first_arg = reg.types[obj.params[0].type]
|
first_arg = reg.types[obj.params[0].type]
|
||||||
|
|
||||||
if not isinstance(first_arg, Handle):
|
if not isinstance(first_arg, Handle):
|
||||||
dispatch.write(f"""
|
dst.write(f"""
|
||||||
extern "C" {obj.result} {rename(obj.name)} ({", ".join(p.param for p in obj.params)}) noexcept {{
|
extern "C" {obj.result} {rename(obj.name)} ({", ".join(p.param for p in obj.params)}) noexcept {{
|
||||||
unimplemented ();
|
unimplemented ();
|
||||||
}}""")
|
}}""")
|
||||||
@ -841,7 +843,7 @@ def write_dispatch(path: str, q: List[Type], reg: Registry):
|
|||||||
else:
|
else:
|
||||||
raise Exception("Unknown param type")
|
raise Exception("Unknown param type")
|
||||||
|
|
||||||
dispatch.write(f"""
|
dst.write(f"""
|
||||||
extern "C" {obj.result} {rename(obj.name)} ({", ".join(p.param for p in obj.params)}) noexcept {{
|
extern "C" {obj.result} {rename(obj.name)} ({", ".join(p.param for p in obj.params)}) noexcept {{
|
||||||
using first_arg_t = std::decay_t<decltype({obj.params[0].name})>;
|
using first_arg_t = std::decay_t<decltype({obj.params[0].name})>;
|
||||||
|
|
||||||
@ -860,8 +862,6 @@ def write_dispatch(path: str, q: List[Type], reg: Registry):
|
|||||||
""")
|
""")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
@ -918,9 +918,14 @@ def main():
|
|||||||
q = reg.serialise(args.platform)
|
q = reg.serialise(args.platform)
|
||||||
|
|
||||||
# Finally write out the header, icd, and dispatch code.
|
# Finally write out the header, icd, and dispatch code.
|
||||||
write_header(args.dst, q, reg)
|
with open(args.dst, 'w') as dst:
|
||||||
write_icd(args.icd, q, reg)
|
write_header(dst, q, reg)
|
||||||
write_dispatch(args.dispatch, q, reg)
|
|
||||||
|
with open(args.icd, 'w') as dst:
|
||||||
|
write_icd(dst, q, reg)
|
||||||
|
|
||||||
|
with open(args.dispatch, 'w') as dst:
|
||||||
|
write_dispatch(dst, q, reg)
|
||||||
|
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
|
Loading…
Reference in New Issue
Block a user