blob: 1a03d53cd16da9664337ca528b281171f4b5db39 [file] [log] [blame]
Chia-I Wufb2559d2014-08-01 11:19:52 +08001#!/usr/bin/env python3
Chia-I Wu44e42362014-09-02 08:32:09 +08002#
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003# VK
Chia-I Wu44e42362014-09-02 08:32:09 +08004#
5# Copyright (C) 2014 LunarG, Inc.
6#
7# Permission is hereby granted, free of charge, to any person obtaining a
8# copy of this software and associated documentation files (the "Software"),
9# to deal in the Software without restriction, including without limitation
10# the rights to use, copy, modify, merge, publish, distribute, sublicense,
11# and/or sell copies of the Software, and to permit persons to whom the
12# Software is furnished to do so, subject to the following conditions:
13#
14# The above copyright notice and this permission notice shall be included
15# in all copies or substantial portions of the Software.
16#
17# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23# DEALINGS IN THE SOFTWARE.
24#
25# Authors:
26# Chia-I Wu <olv@lunarg.com>
Chia-I Wufb2559d2014-08-01 11:19:52 +080027
28import sys
29
30import xgl
31
Chia-I Wuf7d6d3c2015-01-05 12:55:13 +080032def generate_get_proc_addr_check(name):
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060033 return " if (!%s || %s[0] != 'v' || %s[1] != 'k')\n" \
34 " return NULL;" % ((name,) * 3)
Chia-I Wuf7d6d3c2015-01-05 12:55:13 +080035
Chia-I Wufb2559d2014-08-01 11:19:52 +080036class Subcommand(object):
37 def __init__(self, argv):
38 self.argv = argv
Chia-I Wuec30dcb2015-01-01 08:46:31 +080039 self.headers = xgl.headers
40 self.protos = xgl.protos
Chia-I Wufb2559d2014-08-01 11:19:52 +080041
42 def run(self):
Chia-I Wufb2559d2014-08-01 11:19:52 +080043 print(self.generate())
44
45 def generate(self):
46 copyright = self.generate_copyright()
47 header = self.generate_header()
48 body = self.generate_body()
49 footer = self.generate_footer()
50
51 contents = []
52 if copyright:
53 contents.append(copyright)
54 if header:
55 contents.append(header)
56 if body:
57 contents.append(body)
58 if footer:
59 contents.append(footer)
60
61 return "\n\n".join(contents)
62
63 def generate_copyright(self):
64 return """/* THIS FILE IS GENERATED. DO NOT EDIT. */
65
66/*
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060067 * Vulkan
Chia-I Wufb2559d2014-08-01 11:19:52 +080068 *
69 * Copyright (C) 2014 LunarG, Inc.
70 *
71 * Permission is hereby granted, free of charge, to any person obtaining a
72 * copy of this software and associated documentation files (the "Software"),
73 * to deal in the Software without restriction, including without limitation
74 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
75 * and/or sell copies of the Software, and to permit persons to whom the
76 * Software is furnished to do so, subject to the following conditions:
77 *
78 * The above copyright notice and this permission notice shall be included
79 * in all copies or substantial portions of the Software.
80 *
81 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
82 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
83 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
84 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
85 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
86 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
87 * DEALINGS IN THE SOFTWARE.
88 */"""
89
90 def generate_header(self):
Chia-I Wu6ae460f2014-09-13 13:36:06 +080091 return "\n".join(["#include <" + h + ">" for h in self.headers])
Chia-I Wufb2559d2014-08-01 11:19:52 +080092
93 def generate_body(self):
94 pass
95
96 def generate_footer(self):
97 pass
98
Chia-I Wud4a76ae2015-01-04 10:15:48 +080099class LoaderEntrypointsSubcommand(Subcommand):
Chia-I Wu26864352015-01-02 00:21:24 +0800100 def generate_header(self):
Chia-I Wu1d6731b2015-04-11 15:34:07 +0800101 return "#include \"loader.h\""
Chia-I Wu26864352015-01-02 00:21:24 +0800102
Chia-I Wu565734c2015-01-04 15:32:52 +0800103 def _is_dispatchable(self, proto):
Courtney Goeltzenleuchter9d36ef42015-04-13 14:10:06 -0600104 if proto.name in ["GetProcAddr", "DestroyInstance", "EnumerateGpus",
Courtney Goeltzenleuchter0199e952015-02-27 15:19:33 -0700105 "EnumerateLayers", "DbgRegisterMsgCallback", "GetExtensionSupport",
Courtney Goeltzenleuchter9d36ef42015-04-13 14:10:06 -0600106 "DbgUnregisterMsgCallback", "DbgSetGlobalOption"]:
Chia-I Wu31b115a2015-01-04 15:38:47 +0800107 return False
Chia-I Wu565734c2015-01-04 15:32:52 +0800108
Chia-I Wu31b115a2015-01-04 15:38:47 +0800109 in_objs = proto.object_in_params()
110 return in_objs and in_objs[0] == proto.params[0]
Chia-I Wu565734c2015-01-04 15:32:52 +0800111
Chia-I Wu67a81c82015-04-11 16:07:13 +0800112 def _generate_object_setup(self, proto):
113 method = "loader_init_data"
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600114 cond = "res == VK_SUCCESS"
Chia-I Wu67a81c82015-04-11 16:07:13 +0800115
116 if "Get" in proto.name:
117 method = "loader_set_data"
118
119 setup = []
120
121 if proto.name == "AllocDescriptorSets":
122 psets = proto.params[-2].name
123 pcount = proto.params[-1].name
124 setup.append("uint32_t i;")
125 setup.append("for (i = 0; i < *%s; i++)" % pcount)
126 setup.append(" %s(%s[i], disp);" % (method, psets))
127 else:
128 obj_params = proto.object_out_params()
129 for param in obj_params:
130 setup.append("%s(*%s, disp);" % (method, param.name))
131
132 if setup:
133 joined = "\n ".join(setup)
134 setup = []
135 setup.append(" if (%s) {" % cond)
136 setup.append(" " + joined)
137 setup.append(" }")
138
139 return "\n".join(setup)
140
Chia-I Wu26864352015-01-02 00:21:24 +0800141 def _generate_loader_dispatch_entrypoints(self, qual=""):
Chia-I Wu468e3c32014-08-04 08:03:57 +0800142 if qual:
143 qual += " "
144
Chia-I Wudac3e492014-08-02 23:49:43 +0800145 funcs = []
146 for proto in self.protos:
Chia-I Wu565734c2015-01-04 15:32:52 +0800147 if not self._is_dispatchable(proto):
Tobin Ehlis66bbbf52014-11-12 11:47:07 -0700148 continue
Chia-I Wu67a81c82015-04-11 16:07:13 +0800149 func = []
150
151 obj_setup = self._generate_object_setup(proto)
152
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600153 func.append(qual + proto.c_func(prefix="vk", attr="VKAPI"))
Chia-I Wu67a81c82015-04-11 16:07:13 +0800154 func.append("{")
155
156 # declare local variables
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600157 func.append(" const VK_LAYER_DISPATCH_TABLE *disp;")
Chia-I Wu67a81c82015-04-11 16:07:13 +0800158 if proto.ret != 'void' and obj_setup:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600159 func.append(" VK_RESULT res;")
Chia-I Wu67a81c82015-04-11 16:07:13 +0800160 func.append("")
161
162 # active layers before dispatching CreateDevice
163 if proto.name == "CreateDevice":
164 func.append(" loader_activate_layers(%s, %s);" %
165 (proto.params[0].name, proto.params[1].name))
166 func.append("")
167
168 # get dispatch table and unwrap GPUs
169 for param in proto.params:
170 stmt = ""
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600171 if param.ty == "VK_PHYSICAL_GPU":
Chia-I Wu67a81c82015-04-11 16:07:13 +0800172 stmt = "loader_unwrap_gpu(&%s);" % param.name
173 if param == proto.params[0]:
174 stmt = "disp = " + stmt
175 elif param == proto.params[0]:
176 stmt = "disp = loader_get_data(%s);" % param.name
177
178 if stmt:
179 func.append(" " + stmt)
180 func.append("")
181
182 # dispatch!
183 dispatch = "disp->%s;" % proto.c_call()
184 if proto.ret == 'void':
185 func.append(" " + dispatch)
186 elif not obj_setup:
187 func.append(" return " + dispatch)
188 else:
189 func.append(" res = " + dispatch)
190 func.append(obj_setup)
191 func.append("")
192 func.append(" return res;")
193
194 func.append("}")
195
Ian Elliott81ac44c2015-01-13 17:52:38 -0700196 if 'WsiX11AssociateConnection' == proto.name:
Ian Elliotte977a6c2015-02-26 14:34:52 -0700197 funcs.append("#if defined(__linux__) || defined(XCB_NVIDIA)")
Chia-I Wu67a81c82015-04-11 16:07:13 +0800198
199 funcs.append("\n".join(func))
Chia-I Wudac3e492014-08-02 23:49:43 +0800200
Ian Elliott81ac44c2015-01-13 17:52:38 -0700201 funcs.append("#endif")
Chia-I Wudac3e492014-08-02 23:49:43 +0800202 return "\n\n".join(funcs)
203
Chia-I Wufb2559d2014-08-01 11:19:52 +0800204 def generate_body(self):
Chia-I Wu26864352015-01-02 00:21:24 +0800205 body = [self._generate_loader_dispatch_entrypoints("LOADER_EXPORT")]
Jon Ashburnd43f9b62014-10-14 19:15:22 -0600206
207 return "\n\n".join(body)
208
Chia-I Wu28b8d8c2015-01-04 10:19:50 +0800209class DispatchTableOpsSubcommand(Subcommand):
210 def run(self):
211 if len(self.argv) != 1:
212 print("DispatchTableOpsSubcommand: <prefix> unspecified")
213 return
214
215 self.prefix = self.argv[0]
216 super().run()
217
218 def generate_header(self):
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600219 return "\n".join(["#include <vulkan.h>",
220 "#include <vkLayer.h>",
Ian Elliott81ac44c2015-01-13 17:52:38 -0700221 "#include <string.h>",
222 "#include \"loader_platform.h\""])
Chia-I Wu28b8d8c2015-01-04 10:19:50 +0800223
224 def _generate_init(self):
225 stmts = []
226 for proto in self.protos:
Ian Elliott81ac44c2015-01-13 17:52:38 -0700227 if 'WsiX11AssociateConnection' == proto.name:
Ian Elliotte977a6c2015-02-26 14:34:52 -0700228 stmts.append("#if defined(__linux__) || defined(XCB_NVIDIA)")
Chia-I Wu28b8d8c2015-01-04 10:19:50 +0800229 if proto.name == "GetProcAddr":
230 stmts.append("table->%s = gpa; /* direct assignment */" %
231 proto.name)
232 else:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600233 stmts.append("table->%s = (vk%sType) gpa(gpu, \"vk%s\");" %
Chia-I Wu28b8d8c2015-01-04 10:19:50 +0800234 (proto.name, proto.name, proto.name))
Ian Elliott81ac44c2015-01-13 17:52:38 -0700235 stmts.append("#endif")
Chia-I Wu28b8d8c2015-01-04 10:19:50 +0800236
237 func = []
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600238 func.append("static inline void %s_initialize_dispatch_table(VK_LAYER_DISPATCH_TABLE *table,"
Chia-I Wu28b8d8c2015-01-04 10:19:50 +0800239 % self.prefix)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600240 func.append("%s vkGetProcAddrType gpa,"
Chia-I Wu28b8d8c2015-01-04 10:19:50 +0800241 % (" " * len(self.prefix)))
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600242 func.append("%s VK_PHYSICAL_GPU gpu)"
Chia-I Wu28b8d8c2015-01-04 10:19:50 +0800243 % (" " * len(self.prefix)))
244 func.append("{")
245 func.append(" %s" % "\n ".join(stmts))
246 func.append("}")
247
248 return "\n".join(func)
249
250 def _generate_lookup(self):
251 lookups = []
252 for proto in self.protos:
Ian Elliott81ac44c2015-01-13 17:52:38 -0700253 if 'WsiX11AssociateConnection' == proto.name:
Ian Elliotte977a6c2015-02-26 14:34:52 -0700254 lookups.append("#if defined(__linux__) || defined(XCB_NVIDIA)")
Chia-I Wu28b8d8c2015-01-04 10:19:50 +0800255 lookups.append("if (!strcmp(name, \"%s\"))" % (proto.name))
256 lookups.append(" return (void *) table->%s;"
257 % (proto.name))
Ian Elliott81ac44c2015-01-13 17:52:38 -0700258 lookups.append("#endif")
Chia-I Wu28b8d8c2015-01-04 10:19:50 +0800259
260 func = []
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600261 func.append("static inline void *%s_lookup_dispatch_table(const VK_LAYER_DISPATCH_TABLE *table,"
Chia-I Wu28b8d8c2015-01-04 10:19:50 +0800262 % self.prefix)
263 func.append("%s const char *name)"
264 % (" " * len(self.prefix)))
265 func.append("{")
Chia-I Wuf7d6d3c2015-01-05 12:55:13 +0800266 func.append(generate_get_proc_addr_check("name"))
Chia-I Wu28b8d8c2015-01-04 10:19:50 +0800267 func.append("")
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600268 func.append(" name += 2;")
Chia-I Wu28b8d8c2015-01-04 10:19:50 +0800269 func.append(" %s" % "\n ".join(lookups))
270 func.append("")
271 func.append(" return NULL;")
272 func.append("}")
273
274 return "\n".join(func)
275
276 def generate_body(self):
277 body = [self._generate_init(),
278 self._generate_lookup()]
279
280 return "\n\n".join(body)
281
Chia-I Wu731517d2015-01-03 23:48:15 +0800282class IcdDummyEntrypointsSubcommand(Subcommand):
Chia-I Wu30c78292014-08-04 10:08:08 +0800283 def run(self):
Chia-I Wu731517d2015-01-03 23:48:15 +0800284 if len(self.argv) == 1:
285 self.prefix = self.argv[0]
286 self.qual = "static"
287 else:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600288 self.prefix = "vk"
Chia-I Wu731517d2015-01-03 23:48:15 +0800289 self.qual = "ICD_EXPORT"
Chia-I Wu30c78292014-08-04 10:08:08 +0800290
291 super().run()
292
293 def generate_header(self):
294 return "#include \"icd.h\""
295
296 def _generate_stub_decl(self, proto):
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600297 return proto.c_pretty_decl(self.prefix + proto.name, attr="VKAPI")
Chia-I Wu30c78292014-08-04 10:08:08 +0800298
299 def _generate_stubs(self):
300 stubs = []
301 for proto in self.protos:
Chia-I Wu30c78292014-08-04 10:08:08 +0800302 decl = self._generate_stub_decl(proto)
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600303 if proto.ret != "void":
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600304 stmt = " return VK_ERROR_UNKNOWN;\n"
Chia-I Wu30c78292014-08-04 10:08:08 +0800305 else:
306 stmt = ""
307
Chia-I Wu731517d2015-01-03 23:48:15 +0800308 stubs.append("%s %s\n{\n%s}" % (self.qual, decl, stmt))
Chia-I Wu30c78292014-08-04 10:08:08 +0800309
310 return "\n\n".join(stubs)
311
Chia-I Wu30c78292014-08-04 10:08:08 +0800312 def generate_body(self):
Chia-I Wu731517d2015-01-03 23:48:15 +0800313 return self._generate_stubs()
Chia-I Wu30c78292014-08-04 10:08:08 +0800314
Chia-I Wu58f20852015-01-04 00:11:17 +0800315class IcdGetProcAddrSubcommand(IcdDummyEntrypointsSubcommand):
316 def generate_header(self):
317 return "\n".join(["#include <string.h>", "#include \"icd.h\""])
318
319 def generate_body(self):
320 for proto in self.protos:
321 if proto.name == "GetProcAddr":
322 gpa_proto = proto
323
324 gpa_decl = self._generate_stub_decl(gpa_proto)
325 gpa_pname = gpa_proto.params[-1].name
326
327 lookups = []
328 for proto in self.protos:
Ian Elliott81ac44c2015-01-13 17:52:38 -0700329 if 'WsiX11AssociateConnection' == proto.name:
Ian Elliotte977a6c2015-02-26 14:34:52 -0700330 lookups.append("#if defined(__linux__) || defined(XCB_NVIDIA)")
Chia-I Wu58f20852015-01-04 00:11:17 +0800331 lookups.append("if (!strcmp(%s, \"%s\"))" %
332 (gpa_pname, proto.name))
333 lookups.append(" return (%s) %s%s;" %
334 (gpa_proto.ret, self.prefix, proto.name))
Ian Elliott81ac44c2015-01-13 17:52:38 -0700335 lookups.append("#endif")
Chia-I Wu58f20852015-01-04 00:11:17 +0800336
337 body = []
338 body.append("%s %s" % (self.qual, gpa_decl))
339 body.append("{")
Chia-I Wuf7d6d3c2015-01-05 12:55:13 +0800340 body.append(generate_get_proc_addr_check(gpa_pname))
Chia-I Wu58f20852015-01-04 00:11:17 +0800341 body.append("")
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600342 body.append(" %s += 2;" % gpa_pname)
Chia-I Wu58f20852015-01-04 00:11:17 +0800343 body.append(" %s" % "\n ".join(lookups))
344 body.append("")
345 body.append(" return NULL;")
346 body.append("}")
347
348 return "\n".join(body)
349
Chia-I Wuf4bd2e42015-01-05 12:56:13 +0800350class LayerInterceptProcSubcommand(Subcommand):
351 def run(self):
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600352 self.prefix = "vk"
Chia-I Wuf4bd2e42015-01-05 12:56:13 +0800353
354 # we could get the list from argv if wanted
355 self.intercepted = [proto.name for proto in self.protos
Jon Ashburn457c5d12015-01-29 16:54:38 -0700356 if proto.name not in ["EnumerateGpus"]]
Chia-I Wuf4bd2e42015-01-05 12:56:13 +0800357
358 for proto in self.protos:
359 if proto.name == "GetProcAddr":
360 self.gpa = proto
361
362 super().run()
363
364 def generate_header(self):
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600365 return "\n".join(["#include <string.h>", "#include \"vkLayer.h\""])
Chia-I Wuf4bd2e42015-01-05 12:56:13 +0800366
367 def generate_body(self):
368 lookups = []
369 for proto in self.protos:
370 if proto.name not in self.intercepted:
371 lookups.append("/* no %s%s */" % (self.prefix, proto.name))
372 continue
373
Ian Elliott81ac44c2015-01-13 17:52:38 -0700374 if 'WsiX11AssociateConnection' == proto.name:
Ian Elliotte977a6c2015-02-26 14:34:52 -0700375 lookups.append("#if defined(__linux__) || defined(XCB_NVIDIA)")
Chia-I Wuf4bd2e42015-01-05 12:56:13 +0800376 lookups.append("if (!strcmp(name, \"%s\"))" % proto.name)
377 lookups.append(" return (%s) %s%s;" %
378 (self.gpa.ret, self.prefix, proto.name))
Ian Elliott81ac44c2015-01-13 17:52:38 -0700379 lookups.append("#endif")
Chia-I Wuf4bd2e42015-01-05 12:56:13 +0800380
381 body = []
Ian Elliotta742a622015-02-18 12:38:04 -0700382 body.append("static inline %s layer_intercept_proc(const char *name)" %
Chia-I Wuf4bd2e42015-01-05 12:56:13 +0800383 self.gpa.ret)
384 body.append("{")
385 body.append(generate_get_proc_addr_check("name"))
386 body.append("")
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600387 body.append(" name += 2;")
Chia-I Wuf4bd2e42015-01-05 12:56:13 +0800388 body.append(" %s" % "\n ".join(lookups))
389 body.append("")
390 body.append(" return NULL;")
391 body.append("}")
392
393 return "\n".join(body)
394
Chia-I Wud98a23c2015-04-11 10:56:50 +0800395class WinDefFileSubcommand(Subcommand):
396 def run(self):
397 library_exports = {
398 "all": [],
399 "icd": [
400 "EnumerateGpus",
401 "CreateInstance",
402 "DestroyInstance",
403 "GetProcAddr",
404 ],
405 "layer": [
406 "GetProcAddr",
407 "EnumerateLayers",
408 ],
409 }
410
411 if len(self.argv) != 2 or self.argv[1] not in library_exports:
412 print("WinDefFileSubcommand: <library-name> {%s}" %
413 "|".join(library_exports.keys()))
414 return
415
416 self.library = self.argv[0]
417 self.exports = library_exports[self.argv[1]]
418
419 super().run()
420
421 def generate_copyright(self):
422 return """; THIS FILE IS GENERATED. DO NOT EDIT.
423
424;;;; Begin Copyright Notice ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600425; Vulkan
Chia-I Wud98a23c2015-04-11 10:56:50 +0800426;
427; Copyright (C) 2015 LunarG, Inc.
428;
429; Permission is hereby granted, free of charge, to any person obtaining a
430; copy of this software and associated documentation files (the "Software"),
431; to deal in the Software without restriction, including without limitation
432; the rights to use, copy, modify, merge, publish, distribute, sublicense,
433; and/or sell copies of the Software, and to permit persons to whom the
434; Software is furnished to do so, subject to the following conditions:
435;
436; The above copyright notice and this permission notice shall be included
437; in all copies or substantial portions of the Software.
438;
439; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
440; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
441; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
442; THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
443; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
444; FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
445; DEALINGS IN THE SOFTWARE.
446;;;; End Copyright Notice ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"""
447
448 def generate_header(self):
449 return "; The following is required on Windows, for exporting symbols from the DLL"
450
451 def generate_body(self):
452 body = []
453
454 body.append("LIBRARY " + self.library)
455 body.append("EXPORTS")
456
457 for proto in self.protos:
458 if self.exports and proto.name not in self.exports:
459 continue
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600460 body.append(" vk" + proto.name)
Chia-I Wud98a23c2015-04-11 10:56:50 +0800461
462 return "\n".join(body)
463
Chia-I Wufb2559d2014-08-01 11:19:52 +0800464def main():
465 subcommands = {
Chia-I Wud4a76ae2015-01-04 10:15:48 +0800466 "loader-entrypoints": LoaderEntrypointsSubcommand,
Chia-I Wu28b8d8c2015-01-04 10:19:50 +0800467 "dispatch-table-ops": DispatchTableOpsSubcommand,
Chia-I Wu731517d2015-01-03 23:48:15 +0800468 "icd-dummy-entrypoints": IcdDummyEntrypointsSubcommand,
Chia-I Wu58f20852015-01-04 00:11:17 +0800469 "icd-get-proc-addr": IcdGetProcAddrSubcommand,
Chia-I Wuf4bd2e42015-01-05 12:56:13 +0800470 "layer-intercept-proc": LayerInterceptProcSubcommand,
Chia-I Wud98a23c2015-04-11 10:56:50 +0800471 "win-def-file": WinDefFileSubcommand,
Chia-I Wufb2559d2014-08-01 11:19:52 +0800472 }
473
474 if len(sys.argv) < 2 or sys.argv[1] not in subcommands:
475 print("Usage: %s <subcommand> [options]" % sys.argv[0])
476 print
477 print("Available sucommands are: %s" % " ".join(subcommands))
478 exit(1)
479
480 subcmd = subcommands[sys.argv[1]](sys.argv[2:])
481 subcmd.run()
482
483if __name__ == "__main__":
484 main()