Mercurial > games > semicongine
annotate svk/generate.nim @ 1484:a2af327f19df
add: final raw wrapper
| author | sam <sam@basx.dev> |
|---|---|
| date | Thu, 01 May 2025 00:59:40 +0700 |
| parents | 55911f736a5a |
| children | 6e062a84c157 |
| rev | line source |
|---|---|
| 1479 | 1 import std/strtabs |
|
1480
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
2 import std/syncio |
| 1479 | 3 import std/xmltree |
| 4 import std/tables | |
| 5 import std/options | |
| 6 import std/sequtils | |
| 7 import std/strutils | |
| 8 import std/strformat | |
| 9 import std/xmlparser | |
| 10 import std/os | |
|
1480
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
11 import std/osproc |
| 1479 | 12 import std/paths |
| 13 | |
| 14 # helpers | |
| 15 func smartParseInt(value: string): int = | |
| 16 if value.startsWith("0x"): | |
| 17 parseHexInt(value) | |
| 18 else: | |
| 19 parseInt(value) | |
| 20 | |
| 21 const TYPEMAP = { | |
| 22 "void": "void", | |
| 23 "char": "char", | |
| 24 "float": "float32", | |
| 25 "double": "float64", | |
| 26 "int8_t": "int8", | |
| 27 "uint8_t": "uint8", | |
| 28 "int16_t": "int16", | |
| 29 "uint16_t": "uint16", | |
| 30 "int32_t": "int32", | |
| 31 "uint32_t": "uint32", | |
| 32 "uint64_t": "uint64", | |
| 33 "int64_t": "int64", | |
| 34 "size_t": "csize_t", | |
| 35 "int": "cint", | |
| 36 }.toTable | |
| 37 # load xml | |
| 38 let xml = (system.currentSourcePath.parentDir() / "vk.xml").loadXml() | |
| 39 let platforms = xml.findAll("platforms")[0] | |
| 40 let types = xml.findAll("types")[0] | |
| 41 let xmlenums = xml.findAll("enums") | |
| 42 let commands = xml.findAll("commands")[0] | |
| 43 let features = xml.findAll("feature") # features has extends="<ENUM>" | |
| 44 let extensions = xml.findAll("extensions")[0] # extensions has extends="<ENUM>" | |
| 45 let formats = xml.findAll("formats")[0] | |
| 46 | |
| 47 # gather all enums | |
| 48 | |
| 49 type | |
| 50 EnumEntry = object | |
| 51 name: string | |
| 52 value: string | |
| 53 | |
| 54 EnumDef = object | |
| 55 name: string | |
| 56 values: seq[EnumEntry] | |
| 57 isBitmask: bool | |
| 58 | |
| 59 ConstantDef = object | |
| 60 name: string | |
| 61 datatype: string | |
| 62 value: string | |
| 63 | |
| 64 var consts: seq[ConstantDef] | |
| 65 var enums: Table[string, EnumDef] | |
| 66 | |
| 67 func addValue(edef: var EnumDef, n: XmlNode) = | |
| 68 if n.attr("deprecated") != "aliased" and n.attr("alias") == "": | |
| 69 if n.attr("name") in edef.values.mapIt(it.name): | |
| 70 return | |
| 71 | |
| 72 var value = "" | |
| 73 if n.attr("value") != "": | |
| 74 value = n.attr("value") | |
| 75 elif n.attr("bitpos") != "": | |
| 76 value = $(1 shl parseInt(n.attr("bitpos"))) | |
| 77 elif n.attr("offset") != "": | |
| 78 var enumBase = 1000000000 | |
| 79 if n.attr("extnumber") != "": | |
| 80 enumBase += (smartParseInt(n.attr("extnumber")) - 1) * 1000 | |
| 81 var v = smartParseInt(n.attr("offset")) + enumBase | |
| 82 if n.attr("dir") == "-": | |
| 83 v = -v | |
| 84 value = $(v) | |
| 85 | |
| 1482 | 86 if value notin edef.values.mapIt(it.value): |
| 87 edef.values.add EnumEntry(name: n.attr("name"), value: value) | |
| 1479 | 88 |
| 1484 | 89 func doTypename(typename: string, pointerType: int): string = |
| 90 ## pointerType == 0: no pointer | |
| 91 ## pointerType == 1: normal pointer (e.g. char *) | |
| 92 ## pointerType == 2: double pointer (e.g. void **) | |
| 93 assert pointerType in [0, 1, 2] | |
| 1481 | 94 result = TYPEMAP.getOrDefault(typename.strip(), typename.strip()).strip(chars = {'_'}) |
| 95 | |
| 96 if typename == "void": | |
| 1484 | 97 assert pointerType > 0 |
| 1481 | 98 |
| 1484 | 99 if pointerType > 0: |
| 1481 | 100 if typename == "void": |
| 101 result = "pointer" | |
| 102 elif typename == "char": | |
| 103 result = "cstring" | |
| 104 else: | |
| 105 result = "ptr " & result | |
| 1484 | 106 if pointerType == 2: |
| 107 result = "ptr " & result | |
| 1481 | 108 |
| 109 func doIdentifier(typename: string): string = | |
| 110 if typename in ["type", "object"]: | |
| 111 return &"`{typename}`" | |
| 112 return typename.strip() | |
| 113 | |
| 1484 | 114 func doMember(typename, theType: string, pointerType: int, value: string): string = |
| 1481 | 115 if value == "": |
| 1484 | 116 &"{doIdentifier(typename)}: {doTypename(theType, pointerType)}" |
| 1481 | 117 else: |
| 1484 | 118 &"{doIdentifier(typename)}: {doTypename(theType, pointerType)} = {value}" |
| 1481 | 119 |
|
1480
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
120 func memberDecl(n: XmlNode): string = |
|
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
121 for i in 0 ..< n.len: |
|
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
122 if n[i].kind == xnElement and n[i].tag == "comment": |
|
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
123 n.delete(i) |
|
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
124 break |
|
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
125 assert n.tag == "member" |
|
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
126 if n.len == 2: |
| 1484 | 127 return doMember(n[1][0].text, n[0][0].text, 0, n.attr("values")) |
|
1480
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
128 elif n.len == 3: |
| 1481 | 129 assert "*" notin n[0][0].text.strip() |
|
1480
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
130 if n[1].kind == xnElement and n[1].tag == "name": |
| 1481 | 131 # bitfield |
| 132 if n[2].text.strip().startsWith(":"): | |
| 133 return | |
| 1484 | 134 &"{doIdentifier(n[1][0].text)} {{.bitsize:{n[2].text.strip()[1 .. ^1]}.}}: {doTypename(n[0][0].text, 0)}" |
| 1481 | 135 # array definition |
| 136 elif n[2].text.strip().startsWith("["): | |
| 137 let arrayDim = n[2].text[1 ..< ^1] | |
| 138 if "][" in arrayDim: | |
| 139 let dims = arrayDim.split("][", 1) | |
| 140 let (dim1, dim2) = (dims[0], dims[1]) | |
| 141 return doMember( | |
| 142 n[1][0].text, | |
| 1484 | 143 &"array[{dim1}, array[{dim2}, {doTypename(n[0][0].text, 0)}]]", |
| 144 0, | |
| 1481 | 145 n.attr("values"), |
| 146 ) | |
| 147 else: | |
| 148 return doMember( | |
| 149 n[1][0].text, | |
| 1484 | 150 &"array[{arrayDim}, {doTypename(n[0][0].text, 0)}]", |
| 151 0, | |
| 1481 | 152 n.attr("values"), |
| 153 ) | |
| 154 else: | |
| 155 debugecho n.toSeq | |
| 156 doAssert false, "This should not happen" | |
|
1480
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
157 else: |
| 1481 | 158 # pointer definition |
|
1480
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
159 assert n[1].text.strip() == "*" |
| 1484 | 160 return doMember(n[2][0].text, n[0][0].text, 1, n.attr("values")) |
|
1480
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
161 elif n.len == 4: |
|
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
162 if n[0].text.strip() in ["struct", "const struct"]: |
| 1484 | 163 return doMember(n[3][0].text, n[1][0].text, 1, n.attr("values")) |
|
1480
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
164 else: |
| 1481 | 165 assert n[0].text.strip() == "const" # can be ignored |
| 166 assert n[1].tag == "type" | |
|
1480
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
167 assert n[2].text.strip() in ["*", "* const *", "* const*"] |
| 1481 | 168 # can be ignored, basically every type is a pointer |
| 169 assert n[3].tag == "name" | |
| 170 assert n[1].len == 1 | |
| 171 assert n[3].len == 1 | |
| 1484 | 172 return doMember(n[3][0].text, n[1][0].text, 1, n.attr("values")) |
|
1480
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
173 elif n.len in [5, 6]: |
| 1481 | 174 # array definition, using const-value for array length |
| 175 # <type>uint8_t</type>,<name>pipelineCacheUUID</name>[<enum>VK_UUID_SIZE</enum>] | |
| 176 assert n[2].text.strip() == "[" | |
| 177 assert n[4].text.strip() == "]" | |
| 178 return doMember( | |
| 179 n[1][0].text, | |
| 1484 | 180 &"array[{n[3][0].text}, {doTypename(n[0][0].text, 0)}]", |
| 181 0, | |
| 1481 | 182 n.attr("values"), |
| 183 ) | |
|
1480
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
184 assert false |
|
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
185 |
| 1479 | 186 for e in xmlenums: |
| 187 if e.attr("type") == "constants": | |
| 188 for c in e.findAll("enum"): | |
| 189 var value = c.attr("value").strip(chars = {'(', ')'}) | |
| 190 consts.add ConstantDef( | |
| 191 name: c.attr("name"), datatype: TYPEMAP[c.attr("type")], value: value | |
| 192 ) | |
| 193 elif e.attr("type") == "enum": | |
| 194 var edef = EnumDef(name: e.attr("name"), isBitmask: false) | |
| 195 for ee in e.findAll("enum"): | |
| 196 edef.addValue(ee) | |
| 197 enums[edef.name] = edef | |
| 198 elif e.attr("type") == "bitmask": | |
| 199 var edef = EnumDef(name: e.attr("name"), isBitmask: true) | |
| 200 for ee in e.findAll("enum"): | |
| 201 edef.addValue(ee) | |
| 202 enums[edef.name] = edef | |
| 203 | |
| 204 for f in features: | |
| 205 for extendenum in f.findAll("enum"): | |
| 206 if extendenum.attr("extends") != "": | |
| 207 enums[extendenum.attr("extends")].addValue(extendenum) | |
| 208 | |
| 209 for extension in extensions.findAll("extension"): | |
| 210 let extNum = extension.attr("number") | |
| 211 for extendenum in extension.findAll("enum"): | |
| 212 if extendenum.attr("extends") != "": | |
| 213 if extendenum.attr("extnumber") == "": | |
| 214 extendenum.attrs["extnumber"] = extNum | |
| 215 enums[extendenum.attr("extends")].addValue(extendenum) | |
| 216 | |
| 1481 | 217 let outPath = (system.currentSourcePath.parentDir() / "vkapi.nim") |
|
1480
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
218 let outFile = open(outPath, fmWrite) |
|
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
219 |
| 1479 | 220 # generate core types =============================================================================== |
| 221 # preamble, much easier to hardcode than to generate from xml | |
|
1480
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
222 outFile.writeLine """ |
| 1481 | 223 |
| 1484 | 224 import std/dynlib |
| 225 | |
| 1481 | 226 import ../semicongine/thirdparty/winim/winim/inc/winbase |
| 227 import ../semicongine/thirdparty/winim/winim/inc/windef | |
| 228 import ../semicongine/thirdparty/x11/xlib | |
| 229 import ../semicongine/thirdparty/x11/x | |
| 230 import ../semicongine/thirdparty/x11/xrandr | |
| 231 | |
| 1479 | 232 func VK_MAKE_API_VERSION*( |
| 233 variant: uint32, major: uint32, minor: uint32, patch: uint32 | |
| 234 ): uint32 {.compileTime.} = | |
| 235 (variant shl 29) or (major shl 22) or (minor shl 12) or patch | |
| 236 """ | |
| 237 | |
|
1480
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
238 outFile.writeLine "type" |
|
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
239 outFile.writeLine """ |
| 1481 | 240 # some unused native types |
| 241 # | |
| 242 # android | |
| 243 ANativeWindow = object | |
| 244 AHardwareBuffer = object | |
| 245 | |
| 1483 | 246 # apple/metal |
| 1481 | 247 CAMetalLayer = object |
| 248 MTLSharedEvent_id = object | |
| 1483 | 249 MTLDevice_id = object |
| 250 MTLCommandQueue_id = object | |
| 251 MTLBuffer_id = object | |
| 252 MTLTexture_id = object | |
| 253 IOSurfaceRef = object | |
| 1481 | 254 |
| 255 # wayland | |
| 256 wl_display = object | |
| 257 wl_surface = object | |
| 258 | |
| 259 # XCB | |
| 260 xcb_connection_t = object | |
| 261 xcb_window_t = object | |
| 262 xcb_visualid_t = object | |
| 263 | |
| 264 # directfb | |
| 265 IDirectFB = object | |
| 266 IDirectFBSurface = object | |
| 267 | |
| 268 # Zircon | |
| 269 zx_handle_t = object | |
| 270 | |
| 271 # GGP C | |
| 272 GgpStreamDescriptor = object | |
| 273 GgpFrameToken = object | |
| 274 | |
| 275 # Screen (nintendo switch?) | |
| 276 screen_context = object | |
| 277 screen_window = object | |
| 278 screen_buffer = object | |
| 279 | |
| 280 # Nvidia | |
| 281 NvSciSyncAttrList = object | |
| 282 NvSciSyncObj = object | |
| 283 NvSciSyncFence = object | |
| 284 NvSciBufAttrList = object | |
| 285 NvSciBufObj = object | |
| 286 | |
| 287 # some base vulkan base types | |
| 1483 | 288 VkSampleMask* = distinct uint32 |
| 289 VkBool32* = distinct uint32 | |
| 290 VkFlags* = distinct uint32 | |
| 291 VkFlags64* = distinct uint64 | |
| 292 VkDeviceSize* = distinct uint64 | |
| 293 VkDeviceAddress* = distinct uint64 | |
| 294 VkRemoteAddressNV* = pointer | |
|
1480
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
295 """ |
| 1479 | 296 |
| 297 # generate consts =============================================================================== | |
|
1480
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
298 outFile.writeLine "const" |
| 1479 | 299 for c in consts: |
| 300 var value = c.value | |
| 301 if value.endsWith("U"): | |
| 302 value = value[0 ..^ 2] & "'u32" | |
| 303 elif value.endsWith("ULL"): | |
| 304 value = value[0 ..^ 4] & "'u64" | |
| 305 if value[0] == '~': | |
| 306 value = "not " & value[1 ..^ 1] | |
|
1480
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
307 outFile.writeLine &" {c.name}*: {c.datatype} = {value}" |
|
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
308 outFile.writeLine "" |
| 1479 | 309 |
| 310 # generate enums =============================================================================== | |
| 1481 | 311 const nameCollisions = [ |
| 312 "VK_PIPELINE_CACHE_HEADER_VERSION_ONE", | |
| 313 "VK_PIPELINE_CACHE_HEADER_VERSION_SAFETY_CRITICAL_ONE", | |
| 314 "VK_DEVICE_FAULT_VENDOR_BINARY_HEADER_VERSION_ONE_EXT", | |
| 315 ] | |
|
1480
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
316 outFile.writeLine "type" |
| 1482 | 317 |
| 1479 | 318 for edef in enums.values(): |
| 319 if edef.values.len > 0: | |
|
1480
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
320 outFile.writeLine &" {edef.name}* {{.size: 4.}} = enum" |
| 1479 | 321 for ee in edef.values: |
| 1481 | 322 # due to the nim identifier-system, there might be collisions between typenames and enum-member names |
| 323 if ee.name in nameCollisions: | |
| 324 outFile.writeLine &" {ee.name}_VALUE = {ee.value}" | |
| 325 else: | |
| 326 outFile.writeLine &" {ee.name} = {ee.value}" | |
| 327 | |
| 328 outFile.writeLine "" | |
| 329 | |
| 330 # generate types =============================================================================== | |
| 331 for t in types: | |
| 332 let category = t.attr("category") | |
| 1483 | 333 let tName = t.attr("name") |
| 334 if tName.startsWith("VkVideo"): # we are not doing the video API, sorry | |
| 335 continue | |
| 336 if tName.startsWith("VkPhysicalDeviceVideo"): # we are not doing the video API, sorry | |
| 337 continue | |
| 1481 | 338 if t.attr("api") == "vulkansc": |
| 339 continue | |
| 340 elif t.attr("deprecated") == "true": | |
| 341 continue | |
| 342 elif category == "include": | |
| 343 continue | |
| 344 elif category == "define": | |
| 345 continue | |
| 346 elif t.attr("requires").startsWith("vk_video"): | |
| 347 continue | |
| 348 elif t.attr("alias") != "": | |
| 349 let a = t.attr("alias") | |
| 1483 | 350 outFile.writeLine &" {tName}* = {a}" |
| 1481 | 351 elif category == "bitmask": |
| 352 if t.len > 0 and t[0].text.startsWith("typedef"): | |
| 1483 | 353 outFile.writeLine &" {t[2][0].text}* = distinct {t[1][0].text}" |
| 1481 | 354 elif category == "union": |
| 1483 | 355 outFile.writeLine &" {tName}* {{.union.}} = object" |
| 1481 | 356 for member in t.findAll("member"): |
| 357 outFile.writeLine &" {member.memberDecl()}" | |
| 358 elif category == "handle": | |
| 1484 | 359 outFile.writeLine &" {t[2][0].text} = distinct pointer" |
| 1481 | 360 elif category == "struct": |
| 1483 | 361 outFile.writeLine &" {tName}* = object" |
| 1481 | 362 for member in t.findAll("member"): |
| 363 if member.attr("api") == "vulkansc": | |
| 364 continue | |
| 365 outFile.writeLine &" {member.memberDecl()}" | |
| 366 elif category == "funcpointer": | |
| 367 assert t[0].text.startsWith("typedef ") | |
| 1483 | 368 let retName = t[0].text[8 ..< ^13].strip() |
| 369 let funcName = t.findAll("name")[0][0].text | |
| 370 | |
| 371 outFile.write &" {funcname}* = proc(" | |
| 1484 | 372 let nParams = (t.len - 3) div 2 |
| 373 for i in 0 ..< nParams: | |
| 374 assert t[i * 2 + 3].tag == "type" | |
| 375 let typename = t[i * 2 + 3][0].text.strip() | |
| 376 var identifier = t[i * 2 + 4].text.strip(chars = {' ', ')', ';', ',', '\n'}) | |
| 377 var pointerType = if identifier.startsWith("*"): 1 else: 0 | |
| 378 if pointerType > 0: | |
| 379 identifier = identifier[1 .. ^1].strip(chars = {' ', ')', ';', ',', '\n'}) | |
| 380 if identifier.endsWith("const"): | |
| 381 identifier = identifier[0 .. ^6].strip(chars = {' ', ')', ';', ',', '\n'}) | |
| 382 identifier = identifier.strip(chars = {','}) | |
| 383 outFile.write &"{doIdentifier(identifier)}: {doTypename(typename, pointerType)}, " | |
| 1483 | 384 |
| 1484 | 385 if retName == "void": |
| 1483 | 386 outFile.writeLine &") {{.cdecl.}}" |
| 1484 | 387 elif retName == "void*": |
| 1483 | 388 outFile.writeLine &"): pointer {{.cdecl.}}" |
| 389 else: | |
| 1484 | 390 outFile.writeLine &"): {doTypename(retName, 0)} {{.cdecl.}}" |
| 1481 | 391 else: |
| 392 doAssert category in ["", "basetype", "enum"], "unknown type category: " & category | |
|
1480
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
393 outFile.writeLine "" |
|
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
394 |
| 1484 | 395 outFile.write &"var\n" |
| 1483 | 396 for command in commands: |
| 397 if command.attr("api") == "vulkansc": | |
| 398 continue | |
| 399 if command.attr("alias") != "": | |
| 400 let funcName = command.attr("name") | |
| 401 let funcAlias = command.attr("alias") | |
| 1484 | 402 outFile.write &" {funcName}* = {funcAlias}\n" |
| 1483 | 403 continue |
| 404 | |
| 405 let proto = command.findAll("proto")[0] | |
| 406 let retType = proto.findAll("type")[0][0].text.strip() | |
| 407 let funcName = proto.findAll("name")[0][0].text.strip() | |
| 408 | |
| 409 if "Video" in funcName: # Video API not supported at this time | |
| 410 continue | |
| 411 | |
| 1484 | 412 outFile.write &" {funcName}*: proc(" |
| 1483 | 413 for param in command: |
| 414 if param.tag != "param": | |
| 415 continue | |
| 416 if param.attr("api") == "vulkansc": | |
| 417 continue | |
| 418 assert param.len in [2, 3, 4] | |
| 419 let paramType = param.findAll("type")[0][0].text | |
| 420 let paramName = param.findAll("name")[0][0].text | |
| 421 assert "*" notin paramType, $param | |
| 1484 | 422 |
| 423 if param.len == 4: | |
| 424 param.delete(0) | |
| 425 | |
| 426 var pointerType = 0 | |
| 427 | |
| 428 if param.len == 3: | |
| 429 if param[param.len - 1].kind == xnText: | |
| 430 assert param[param.len - 1].text[^1] == ']' | |
| 431 else: | |
| 432 assert param[0].tag == "type" | |
| 433 assert param[param.len - 1].tag == "name" | |
| 434 if param[1].text.strip() == "*": | |
| 435 pointerType = 1 | |
| 436 elif param[1].text.strip() == "**": | |
| 437 pointerType = 2 | |
| 438 # echo "3: ", param[1].text, " ", paramType, " ", paramName | |
| 439 outFile.write &"{doIdentifier(paramName)}: {doTypename(paramType, pointerType)}, " | |
| 1483 | 440 |
| 441 outFile.write &")" | |
| 442 if retType != "void": | |
| 443 assert "*" notin retType | |
| 1484 | 444 outFile.write &": {doTypename(retType, 0)}" |
| 1483 | 445 outFile.write " {.stdcall.}\n" |
|
1480
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
446 |
| 1484 | 447 outFile.write """ |
| 448 when defined(linux): | |
| 449 let vulkanLib = loadLib("libvulkan.so.1") | |
| 450 when defined(windows): | |
| 451 let vulkanLib = loadLib("vulkan-1.dll") | |
| 452 if vulkanLib == nil: | |
| 453 raise newException(Exception, "Unable to load vulkan library") | |
| 454 | |
| 455 vkGetInstanceProcAddr = cast[proc(instance: VkInstance, pName: cstring, ): PFN_vkVoidFunction {.stdcall.}](checkedSymAddr(vulkanLib, "vkGetInstanceProcAddr")) | |
| 456 """ | |
| 457 | |
|
1480
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
458 outFile.close() |
|
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
459 |
|
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
460 assert execCmd("nim c " & outPath) == 0 |
