[Mesa-dev] [RESEND 08/13] anv: generate anv_entrypoints.{h, c} in one command
Dylan Baker
dylan at pnwbakers.com
Wed Feb 22 23:36:15 UTC 2017
This changes the python generator to write the files itself, rather than
piping them out. This has a couple of advantages: first, it encapsulates
the encoding. Second, it ensures that the header file and code file are
generated at the same time with the same data.
Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
src/intel/vulkan/Makefile.am | 7 ++----
src/intel/vulkan/anv_entrypoints_gen.py | 38 ++++++++++++---------------------
2 files changed, 16 insertions(+), 29 deletions(-)
diff --git a/src/intel/vulkan/Makefile.am b/src/intel/vulkan/Makefile.am
index 5a0e4ef4ff..68bc5ccf86 100644
--- a/src/intel/vulkan/Makefile.am
+++ b/src/intel/vulkan/Makefile.am
@@ -145,11 +145,8 @@ libvulkan_intel_la_SOURCES = $(VULKAN_GEM_FILES)
vulkan_api_xml = $(top_srcdir)/src/vulkan/registry/vk.xml
-anv_entrypoints.h : anv_entrypoints_gen.py $(vulkan_api_xml)
- $(AM_V_GEN)$(PYTHON2) $(srcdir)/anv_entrypoints_gen.py header > $@
-
-anv_entrypoints.c : anv_entrypoints_gen.py $(vulkan_api_xml)
- $(AM_V_GEN)$(PYTHON2) $(srcdir)/anv_entrypoints_gen.py code > $@
+anv_entrypoints.h anv_entrypoints.c: anv_entrypoints_gen.py $(vulkan_api_xml)
+ $(AM_V_GEN)$(PYTHON2) $(srcdir)/anv_entrypoints_gen.py
BUILT_SOURCES = $(VULKAN_GENERATED_FILES)
CLEANFILES = $(BUILT_SOURCES) dev_icd.json intel_icd. at host_cpu@.json
diff --git a/src/intel/vulkan/anv_entrypoints_gen.py b/src/intel/vulkan/anv_entrypoints_gen.py
index 0f943a0de1..9ccd9497a2 100644
--- a/src/intel/vulkan/anv_entrypoints_gen.py
+++ b/src/intel/vulkan/anv_entrypoints_gen.py
@@ -87,7 +87,7 @@ TEMPLATE_H = Template(textwrap.dedent("""\
#endif // ${guard}
% endif
% endfor
- """))
+ """), output_encoding='utf-8')
TEMPLATE_C = Template(textwrap.dedent(u"""\
/*
@@ -256,16 +256,6 @@ HASH_MASK = HASH_SIZE - 1
PRIME_FACTOR = 5024183
PRIME_STEP = 19
-opt_header = False
-opt_code = False
-
-if sys.argv[1] == "header":
- opt_header = True
- sys.argv.pop()
-elif sys.argv[1] == "code":
- opt_code = True
- sys.argv.pop()
-
def hash(name):
h = 0
@@ -351,15 +341,16 @@ def gen_code(entrypoints):
collisions[level] += 1
mapping[h & HASH_MASK] = num
- print TEMPLATE_C.render(entrypoints=entrypoints,
- offsets=offsets,
- collisions=collisions,
- mapping=mapping,
- hash_mask=HASH_MASK,
- prime_step=PRIME_STEP,
- prime_factor=PRIME_FACTOR,
- none=NONE,
- hash_size=HASH_SIZE)
+ with open('anv_entrypoints.c', 'wb') as f:
+ f.write(TEMPLATE_C.render(entrypoints=entrypoints,
+ offsets=offsets,
+ collisions=collisions,
+ mapping=mapping,
+ hash_mask=HASH_MASK,
+ prime_step=PRIME_STEP,
+ prime_factor=PRIME_FACTOR,
+ none=NONE,
+ hash_size=HASH_SIZE))
def main():
@@ -378,10 +369,9 @@ def main():
# For outputting entrypoints.h we generate a anv_EntryPoint() prototype
# per entry point.
- if opt_header:
- print TEMPLATE_H.render(entrypoints=entrypoints)
- else:
- gen_code(entrypoints)
+ with open('anv_entrypoints.h', 'wb') as f:
+ f.write(TEMPLATE_H.render(entrypoints=entrypoints))
+ gen_code(entrypoints)
if __name__ == '__main__':
--
2.11.1
More information about the mesa-dev
mailing list