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 logging
|
||||
from typing import List, Dict, Set
|
||||
from typing import List, Dict, Set, TextIO
|
||||
|
||||
import xml.etree.ElementTree
|
||||
|
||||
@ -699,8 +699,7 @@ def parse_extensions(reg: Registry, root):
|
||||
|
||||
|
||||
###############################################################################
|
||||
def write_header(path: str, q: List[Type], reg: Registry):
|
||||
with open(path, 'w') as dst:
|
||||
def write_header(dst: TextIO, q: List[Type], reg: Registry):
|
||||
dst.write("#pragma once\n")
|
||||
|
||||
# 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):
|
||||
with open(path, 'w') as icd:
|
||||
def write_icd(dst: TextIO, q: List[Type], reg: Registry):
|
||||
commands = [i for i in q if isinstance(i, Command)]
|
||||
instance_commands = [i for i in commands if i.is_instance(reg)]
|
||||
device_commands = [i for i in commands if i.is_device(reg)]
|
||||
|
||||
assert len(instance_commands) + len(device_commands) == len(commands)
|
||||
|
||||
icd.write(f"""
|
||||
dst.write(f"""
|
||||
#include "vk.hpp"
|
||||
|
||||
#include <cruft/util/preprocessor.hpp>
|
||||
@ -779,27 +777,31 @@ def write_icd(path: str, q: List[Type], reg: Registry):
|
||||
instance_table (vendor &);
|
||||
""")
|
||||
|
||||
for obj in instance_commands:
|
||||
icd.write(f"{obj.result} (*{obj.name}) ({','.join(p.param for p in obj.params)}) = nullptr;\n")
|
||||
|
||||
icd.write("""};
|
||||
# Generate the vtable entries for instance methods
|
||||
dst.writelines((
|
||||
f"{obj.result} (*{obj.name}) ({','.join(p.param for p in obj.params)}) = nullptr;"
|
||||
for obj in instance_commands
|
||||
))
|
||||
|
||||
dst.write("""};
|
||||
struct device_table {
|
||||
""")
|
||||
|
||||
for obj in device_commands:
|
||||
icd.write(f"{obj.result} (*{obj.name}) ({','.join(p.param for p in obj.params)}) = nullptr;\n")
|
||||
# Generate the vtable and entries for device_commands
|
||||
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):
|
||||
with open(path, 'w') as dispatch:
|
||||
dispatch.write("""
|
||||
def write_dispatch(dst: TextIO, q: List[Type], reg: Registry):
|
||||
dst.write("""
|
||||
#include "../vk.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]
|
||||
|
||||
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 {{
|
||||
unimplemented ();
|
||||
}}""")
|
||||
@ -841,7 +843,7 @@ def write_dispatch(path: str, q: List[Type], reg: Registry):
|
||||
else:
|
||||
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 {{
|
||||
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
|
||||
|
||||
@ -918,9 +918,14 @@ def main():
|
||||
q = reg.serialise(args.platform)
|
||||
|
||||
# Finally write out the header, icd, and dispatch code.
|
||||
write_header(args.dst, q, reg)
|
||||
write_icd(args.icd, q, reg)
|
||||
write_dispatch(args.dispatch, q, reg)
|
||||
with open(args.dst, 'w') as dst:
|
||||
write_header(dst, 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