Chia-I Wu | fb2559d | 2014-08-01 11:19:52 +0800 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Chia-I Wu | 44e4236 | 2014-09-02 08:32:09 +0800 | [diff] [blame] | 2 | # |
Karl Schultz | c85a02f | 2016-02-02 19:32:33 -0700 | [diff] [blame] | 3 | # Copyright (c) 2015-2016 The Khronos Group Inc. |
| 4 | # Copyright (c) 2015-2016 Valve Corporation |
| 5 | # Copyright (c) 2015-2016 LunarG, Inc. |
| 6 | # Copyright (c) 2015-2016 Google Inc. |
Chia-I Wu | 44e4236 | 2014-09-02 08:32:09 +0800 | [diff] [blame] | 7 | # |
Karl Schultz | c85a02f | 2016-02-02 19:32:33 -0700 | [diff] [blame] | 8 | # Permission is hereby granted, free of charge, to any person obtaining a copy |
| 9 | # of this software and/or associated documentation files (the "Materials"), to |
| 10 | # deal in the Materials without restriction, including without limitation the |
| 11 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 12 | # sell copies of the Materials, and to permit persons to whom the Materials |
| 13 | # are furnished to do so, subject to the following conditions: |
Chia-I Wu | 44e4236 | 2014-09-02 08:32:09 +0800 | [diff] [blame] | 14 | # |
Karl Schultz | c85a02f | 2016-02-02 19:32:33 -0700 | [diff] [blame] | 15 | # The above copyright notice(s) and this permission notice shall be included |
| 16 | # in all copies or substantial portions of the Materials. |
Chia-I Wu | 44e4236 | 2014-09-02 08:32:09 +0800 | [diff] [blame] | 17 | # |
Karl Schultz | c85a02f | 2016-02-02 19:32:33 -0700 | [diff] [blame] | 18 | # THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
Chia-I Wu | 44e4236 | 2014-09-02 08:32:09 +0800 | [diff] [blame] | 19 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
Karl Schultz | c85a02f | 2016-02-02 19:32:33 -0700 | [diff] [blame] | 20 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 21 | # |
| 22 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
| 23 | # DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 24 | # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE |
| 25 | # USE OR OTHER DEALINGS IN THE MATERIALS |
Chia-I Wu | 44e4236 | 2014-09-02 08:32:09 +0800 | [diff] [blame] | 26 | # |
Courtney Goeltzenleuchter | 96cd795 | 2015-10-30 11:14:30 -0600 | [diff] [blame] | 27 | # Author: Chia-I Wu <olv@lunarg.com> |
| 28 | # Author: Courtney Goeltzenleuchter <courtney@LunarG.com> |
| 29 | # Author: Jon Ashburn <jon@lunarg.com> |
Mun, Gwan-gyeong | 83ae0c0 | 2016-02-22 20:23:59 +0900 | [diff] [blame] | 30 | # Author: Gwan-gyeong Mun <kk.moon@samsung.com> |
Chia-I Wu | fb2559d | 2014-08-01 11:19:52 +0800 | [diff] [blame] | 31 | |
| 32 | import sys |
| 33 | |
Courtney Goeltzenleuchter | a8c0628 | 2015-04-14 14:55:44 -0600 | [diff] [blame] | 34 | import vulkan |
Chia-I Wu | fb2559d | 2014-08-01 11:19:52 +0800 | [diff] [blame] | 35 | |
Chia-I Wu | f7d6d3c | 2015-01-05 12:55:13 +0800 | [diff] [blame] | 36 | def generate_get_proc_addr_check(name): |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 37 | return " if (!%s || %s[0] != 'v' || %s[1] != 'k')\n" \ |
| 38 | " return NULL;" % ((name,) * 3) |
Chia-I Wu | f7d6d3c | 2015-01-05 12:55:13 +0800 | [diff] [blame] | 39 | |
Chia-I Wu | fb2559d | 2014-08-01 11:19:52 +0800 | [diff] [blame] | 40 | class Subcommand(object): |
| 41 | def __init__(self, argv): |
| 42 | self.argv = argv |
Courtney Goeltzenleuchter | a8c0628 | 2015-04-14 14:55:44 -0600 | [diff] [blame] | 43 | self.headers = vulkan.headers |
| 44 | self.protos = vulkan.protos |
Chia-I Wu | fb2559d | 2014-08-01 11:19:52 +0800 | [diff] [blame] | 45 | |
| 46 | def run(self): |
Chia-I Wu | fb2559d | 2014-08-01 11:19:52 +0800 | [diff] [blame] | 47 | print(self.generate()) |
| 48 | |
| 49 | def generate(self): |
| 50 | copyright = self.generate_copyright() |
| 51 | header = self.generate_header() |
| 52 | body = self.generate_body() |
| 53 | footer = self.generate_footer() |
| 54 | |
| 55 | contents = [] |
| 56 | if copyright: |
| 57 | contents.append(copyright) |
| 58 | if header: |
| 59 | contents.append(header) |
| 60 | if body: |
| 61 | contents.append(body) |
| 62 | if footer: |
| 63 | contents.append(footer) |
| 64 | |
| 65 | return "\n\n".join(contents) |
| 66 | |
| 67 | def generate_copyright(self): |
| 68 | return """/* THIS FILE IS GENERATED. DO NOT EDIT. */ |
| 69 | |
| 70 | /* |
Karl Schultz | c85a02f | 2016-02-02 19:32:33 -0700 | [diff] [blame] | 71 | * Copyright (c) 2015-2016 The Khronos Group Inc. |
| 72 | * Copyright (c) 2015-2016 Valve Corporation |
| 73 | * Copyright (c) 2015-2016 LunarG, Inc. |
Chia-I Wu | fb2559d | 2014-08-01 11:19:52 +0800 | [diff] [blame] | 74 | * |
Karl Schultz | c85a02f | 2016-02-02 19:32:33 -0700 | [diff] [blame] | 75 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 76 | * of this software and/or associated documentation files (the "Materials"), to |
| 77 | * deal in the Materials without restriction, including without limitation the |
| 78 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 79 | * sell copies of the Materials, and to permit persons to whom the Materials are |
| 80 | * furnished to do so, subject to the following conditions: |
Chia-I Wu | fb2559d | 2014-08-01 11:19:52 +0800 | [diff] [blame] | 81 | * |
Karl Schultz | c85a02f | 2016-02-02 19:32:33 -0700 | [diff] [blame] | 82 | * The above copyright notice(s) and this permission notice shall be included in |
| 83 | * all copies or substantial portions of the Materials. |
Chia-I Wu | fb2559d | 2014-08-01 11:19:52 +0800 | [diff] [blame] | 84 | * |
Karl Schultz | c85a02f | 2016-02-02 19:32:33 -0700 | [diff] [blame] | 85 | * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
Chia-I Wu | fb2559d | 2014-08-01 11:19:52 +0800 | [diff] [blame] | 86 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
Karl Schultz | c85a02f | 2016-02-02 19:32:33 -0700 | [diff] [blame] | 87 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 88 | * |
| 89 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
| 90 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 91 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE |
| 92 | * USE OR OTHER DEALINGS IN THE MATERIALS. |
Courtney Goeltzenleuchter | 96cd795 | 2015-10-30 11:14:30 -0600 | [diff] [blame] | 93 | * |
| 94 | * Author: Courtney Goeltzenleuchter <courtney@LunarG.com> |
Chia-I Wu | fb2559d | 2014-08-01 11:19:52 +0800 | [diff] [blame] | 95 | */""" |
| 96 | |
| 97 | def generate_header(self): |
Chia-I Wu | 6ae460f | 2014-09-13 13:36:06 +0800 | [diff] [blame] | 98 | return "\n".join(["#include <" + h + ">" for h in self.headers]) |
Chia-I Wu | fb2559d | 2014-08-01 11:19:52 +0800 | [diff] [blame] | 99 | |
| 100 | def generate_body(self): |
| 101 | pass |
| 102 | |
| 103 | def generate_footer(self): |
| 104 | pass |
| 105 | |
Chia-I Wu | 28b8d8c | 2015-01-04 10:19:50 +0800 | [diff] [blame] | 106 | class DispatchTableOpsSubcommand(Subcommand): |
| 107 | def run(self): |
| 108 | if len(self.argv) != 1: |
| 109 | print("DispatchTableOpsSubcommand: <prefix> unspecified") |
| 110 | return |
| 111 | |
| 112 | self.prefix = self.argv[0] |
Michael Lentine | 9268944 | 2015-09-09 12:39:13 -0700 | [diff] [blame] | 113 | super(DispatchTableOpsSubcommand, self).run() |
Chia-I Wu | 28b8d8c | 2015-01-04 10:19:50 +0800 | [diff] [blame] | 114 | |
| 115 | def generate_header(self): |
David Pinedo | 329ca9e | 2015-11-06 12:54:48 -0700 | [diff] [blame] | 116 | return "\n".join(["#include <vulkan/vulkan.h>", |
| 117 | "#include <vulkan/vk_layer.h>", |
Jon Ashburn | aef6588 | 2015-05-04 09:16:41 -0600 | [diff] [blame] | 118 | "#include <string.h>"]) |
Chia-I Wu | 28b8d8c | 2015-01-04 10:19:50 +0800 | [diff] [blame] | 119 | |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 120 | def _generate_init_dispatch(self, type): |
Chia-I Wu | 28b8d8c | 2015-01-04 10:19:50 +0800 | [diff] [blame] | 121 | stmts = [] |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 122 | func = [] |
| 123 | if type == "device": |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 124 | # GPA has to be first one and uses wrapped object |
Courtney Goeltzenleuchter | f83cd4a | 2015-06-26 15:05:29 -0600 | [diff] [blame] | 125 | stmts.append("memset(table, 0, sizeof(*table));") |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 126 | stmts.append("table->GetDeviceProcAddr =(PFN_vkGetDeviceProcAddr) gpa(device,\"vkGetDeviceProcAddr\");") |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 127 | for proto in self.protos: |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 128 | if proto.name == "CreateInstance" or proto.name == "EnumerateInstanceExtensionProperties" or proto.name == "EnumerateInstanceLayerProperties" or proto.params[0].ty == "VkInstance" or proto.params[0].ty == "VkPhysicalDevice": |
Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 129 | continue |
Jon Ashburn | 83334db | 2015-09-16 18:08:32 -0600 | [diff] [blame] | 130 | if proto.name != "GetDeviceProcAddr" and 'KHR' not in proto.name: |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 131 | stmts.append("table->%s = (PFN_vk%s) gpa(device, \"vk%s\");" % |
Chia-I Wu | 28b8d8c | 2015-01-04 10:19:50 +0800 | [diff] [blame] | 132 | (proto.name, proto.name, proto.name)) |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 133 | func.append("static inline void %s_init_device_dispatch_table(VkDevice device," |
Chia-I Wu | 28b8d8c | 2015-01-04 10:19:50 +0800 | [diff] [blame] | 134 | % self.prefix) |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 135 | func.append("%s VkLayerDispatchTable *table," |
| 136 | % (" " * len(self.prefix))) |
| 137 | func.append("%s PFN_vkGetDeviceProcAddr gpa)" |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 138 | % (" " * len(self.prefix))) |
| 139 | else: |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 140 | stmts.append("table->GetInstanceProcAddr =(PFN_vkGetInstanceProcAddr) gpa(instance,\"vkGetInstanceProcAddr\");") |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 141 | for proto in self.protos: |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 142 | if proto.params[0].ty != "VkInstance" and proto.params[0].ty != "VkPhysicalDevice": |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 143 | continue |
Courtney Goeltzenleuchter | be63799 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 144 | if proto.name == "CreateDevice": |
| 145 | continue |
Jon Ashburn | 83334db | 2015-09-16 18:08:32 -0600 | [diff] [blame] | 146 | if proto.name != "GetInstanceProcAddr" and 'KHR' not in proto.name: |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 147 | stmts.append("table->%s = (PFN_vk%s) gpa(instance, \"vk%s\");" % |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 148 | (proto.name, proto.name, proto.name)) |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 149 | func.append("static inline void %s_init_instance_dispatch_table(" % self.prefix) |
| 150 | func.append("%s VkInstance instance," % (" " * len(self.prefix))) |
| 151 | func.append("%s VkLayerInstanceDispatchTable *table," % (" " * len(self.prefix))) |
| 152 | func.append("%s PFN_vkGetInstanceProcAddr gpa)" % (" " * len(self.prefix))) |
Chia-I Wu | 28b8d8c | 2015-01-04 10:19:50 +0800 | [diff] [blame] | 153 | func.append("{") |
| 154 | func.append(" %s" % "\n ".join(stmts)) |
| 155 | func.append("}") |
| 156 | |
| 157 | return "\n".join(func) |
| 158 | |
Chia-I Wu | 28b8d8c | 2015-01-04 10:19:50 +0800 | [diff] [blame] | 159 | def generate_body(self): |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 160 | body = [self._generate_init_dispatch("device"), |
| 161 | self._generate_init_dispatch("instance")] |
Chia-I Wu | 28b8d8c | 2015-01-04 10:19:50 +0800 | [diff] [blame] | 162 | |
| 163 | return "\n\n".join(body) |
| 164 | |
Chia-I Wu | d98a23c | 2015-04-11 10:56:50 +0800 | [diff] [blame] | 165 | class WinDefFileSubcommand(Subcommand): |
| 166 | def run(self): |
| 167 | library_exports = { |
| 168 | "all": [], |
| 169 | "icd": [ |
Jon Ashburn | 89a1c46 | 2016-01-07 09:46:26 -0700 | [diff] [blame] | 170 | "vk_icdGetInstanceProcAddr", |
Chia-I Wu | d98a23c | 2015-04-11 10:56:50 +0800 | [diff] [blame] | 171 | ], |
| 172 | "layer": [ |
Jon Ashburn | 88049b1 | 2015-08-13 14:15:07 -0700 | [diff] [blame] | 173 | "vkGetInstanceProcAddr", |
| 174 | "vkGetDeviceProcAddr", |
Courtney Goeltzenleuchter | 74c4ce9 | 2015-09-14 17:22:16 -0600 | [diff] [blame] | 175 | "vkEnumerateInstanceLayerProperties", |
| 176 | "vkEnumerateInstanceExtensionProperties" |
Chia-I Wu | d98a23c | 2015-04-11 10:56:50 +0800 | [diff] [blame] | 177 | ], |
Mark Lobodzinski | 2e87e61 | 2015-12-30 08:16:12 -0700 | [diff] [blame] | 178 | "layer_multi": [ |
Jon Ashburn | 88049b1 | 2015-08-13 14:15:07 -0700 | [diff] [blame] | 179 | "multi2GetInstanceProcAddr", |
| 180 | "multi1GetDeviceProcAddr" |
| 181 | ] |
Chia-I Wu | d98a23c | 2015-04-11 10:56:50 +0800 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | if len(self.argv) != 2 or self.argv[1] not in library_exports: |
| 185 | print("WinDefFileSubcommand: <library-name> {%s}" % |
| 186 | "|".join(library_exports.keys())) |
| 187 | return |
| 188 | |
| 189 | self.library = self.argv[0] |
Mark Lobodzinski | 2e87e61 | 2015-12-30 08:16:12 -0700 | [diff] [blame] | 190 | if self.library == "VkLayer_multi": |
| 191 | self.exports = library_exports["layer_multi"] |
Jon Ashburn | 88049b1 | 2015-08-13 14:15:07 -0700 | [diff] [blame] | 192 | else: |
| 193 | self.exports = library_exports[self.argv[1]] |
Chia-I Wu | d98a23c | 2015-04-11 10:56:50 +0800 | [diff] [blame] | 194 | |
Jamie Madill | 725788c | 2016-04-04 11:20:24 -0400 | [diff] [blame] | 195 | super(WinDefFileSubcommand, self).run() |
Chia-I Wu | d98a23c | 2015-04-11 10:56:50 +0800 | [diff] [blame] | 196 | |
| 197 | def generate_copyright(self): |
| 198 | return """; THIS FILE IS GENERATED. DO NOT EDIT. |
| 199 | |
| 200 | ;;;; Begin Copyright Notice ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 201 | ; Vulkan |
Chia-I Wu | d98a23c | 2015-04-11 10:56:50 +0800 | [diff] [blame] | 202 | ; |
Karl Schultz | c85a02f | 2016-02-02 19:32:33 -0700 | [diff] [blame] | 203 | ; Copyright (c) 2015-2016 The Khronos Group Inc. |
| 204 | ; Copyright (c) 2015-2016 Valve Corporation |
| 205 | ; Copyright (c) 2015-2016 LunarG, Inc. |
Chia-I Wu | d98a23c | 2015-04-11 10:56:50 +0800 | [diff] [blame] | 206 | ; |
Karl Schultz | c85a02f | 2016-02-02 19:32:33 -0700 | [diff] [blame] | 207 | ; Permission is hereby granted, free of charge, to any person obtaining a copy |
| 208 | ; of this software and/or associated documentation files (the "Materials"), to |
| 209 | ; deal in the Materials without restriction, including without limitation the |
| 210 | ; rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 211 | ; sell copies of the Materials, and to permit persons to whom the Materials are |
| 212 | ; furnished to do so, subject to the following conditions: |
Chia-I Wu | d98a23c | 2015-04-11 10:56:50 +0800 | [diff] [blame] | 213 | ; |
Karl Schultz | c85a02f | 2016-02-02 19:32:33 -0700 | [diff] [blame] | 214 | ; The above copyright notice(s) and this permission notice shall be included in |
| 215 | ; all copies or substantial portions of the Materials. |
Chia-I Wu | d98a23c | 2015-04-11 10:56:50 +0800 | [diff] [blame] | 216 | ; |
Karl Schultz | c85a02f | 2016-02-02 19:32:33 -0700 | [diff] [blame] | 217 | ; THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
Chia-I Wu | d98a23c | 2015-04-11 10:56:50 +0800 | [diff] [blame] | 218 | ; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
Karl Schultz | c85a02f | 2016-02-02 19:32:33 -0700 | [diff] [blame] | 219 | ; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 220 | ; |
| 221 | ; IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
| 222 | ; DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 223 | ; OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE |
| 224 | ; USE OR OTHER DEALINGS IN THE MATERIALS. |
Courtney Goeltzenleuchter | cf8ff4f | 2015-12-16 14:57:27 -0700 | [diff] [blame] | 225 | ; |
| 226 | ; Author: Courtney Goeltzenleuchter <courtney@LunarG.com> |
Chia-I Wu | d98a23c | 2015-04-11 10:56:50 +0800 | [diff] [blame] | 227 | ;;;; End Copyright Notice ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;""" |
| 228 | |
| 229 | def generate_header(self): |
| 230 | return "; The following is required on Windows, for exporting symbols from the DLL" |
| 231 | |
| 232 | def generate_body(self): |
| 233 | body = [] |
| 234 | |
| 235 | body.append("LIBRARY " + self.library) |
| 236 | body.append("EXPORTS") |
| 237 | |
Jon Ashburn | 88049b1 | 2015-08-13 14:15:07 -0700 | [diff] [blame] | 238 | for proto in self.exports: |
Mark Lobodzinski | 2e87e61 | 2015-12-30 08:16:12 -0700 | [diff] [blame] | 239 | if self.library != "VkLayerSwapchain" or proto != "vkEnumerateInstanceExtensionProperties" and proto != "vkEnumerateInstanceLayerProperties": |
Ian Elliott | 329da01 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 240 | body.append( proto) |
Chia-I Wu | d98a23c | 2015-04-11 10:56:50 +0800 | [diff] [blame] | 241 | |
| 242 | return "\n".join(body) |
| 243 | |
Chia-I Wu | fb2559d | 2014-08-01 11:19:52 +0800 | [diff] [blame] | 244 | def main(): |
Mun, Gwan-gyeong | 83ae0c0 | 2016-02-22 20:23:59 +0900 | [diff] [blame] | 245 | wsi = { |
| 246 | "Win32", |
| 247 | "Android", |
| 248 | "Xcb", |
| 249 | "Xlib", |
| 250 | "Wayland", |
| 251 | "Mir" |
| 252 | } |
Chia-I Wu | fb2559d | 2014-08-01 11:19:52 +0800 | [diff] [blame] | 253 | subcommands = { |
Chia-I Wu | 28b8d8c | 2015-01-04 10:19:50 +0800 | [diff] [blame] | 254 | "dispatch-table-ops": DispatchTableOpsSubcommand, |
Chia-I Wu | d98a23c | 2015-04-11 10:56:50 +0800 | [diff] [blame] | 255 | "win-def-file": WinDefFileSubcommand, |
Chia-I Wu | fb2559d | 2014-08-01 11:19:52 +0800 | [diff] [blame] | 256 | } |
| 257 | |
Mun, Gwan-gyeong | 83ae0c0 | 2016-02-22 20:23:59 +0900 | [diff] [blame] | 258 | if len(sys.argv) < 3 or sys.argv[1] not in wsi or sys.argv[2] not in subcommands: |
| 259 | print("Usage: %s <wsi> <subcommand> [options]" % sys.argv[0]) |
Chia-I Wu | fb2559d | 2014-08-01 11:19:52 +0800 | [diff] [blame] | 260 | print |
| 261 | print("Available sucommands are: %s" % " ".join(subcommands)) |
| 262 | exit(1) |
| 263 | |
Mun, Gwan-gyeong | 83ae0c0 | 2016-02-22 20:23:59 +0900 | [diff] [blame] | 264 | subcmd = subcommands[sys.argv[2]](sys.argv[3:]) |
Chia-I Wu | fb2559d | 2014-08-01 11:19:52 +0800 | [diff] [blame] | 265 | subcmd.run() |
| 266 | |
| 267 | if __name__ == "__main__": |
| 268 | main() |