Mercurial > games > semicongine
comparison svk/generate.nim @ 1485:6e062a84c157 default tip
add: more api-starting
author | sam <sam@basx.dev> |
---|---|
date | Sat, 03 May 2025 01:03:01 +0700 |
parents | a2af327f19df |
children |
comparison
equal
deleted
inserted
replaced
1484:a2af327f19df | 1485:6e062a84c157 |
---|---|
98 | 98 |
99 if pointerType > 0: | 99 if pointerType > 0: |
100 if typename == "void": | 100 if typename == "void": |
101 result = "pointer" | 101 result = "pointer" |
102 elif typename == "char": | 102 elif typename == "char": |
103 result = "cstring" | 103 if pointerType == 1: |
104 result = "cstring" | |
105 elif pointerType == 2: | |
106 result = "cstringArray" | |
107 else: | |
108 assert false, "Unsupported char pointer type" | |
104 else: | 109 else: |
105 result = "ptr " & result | 110 result = "ptr " & result |
106 if pointerType == 2: | 111 |
112 if pointerType == 2 and typename != "char": | |
107 result = "ptr " & result | 113 result = "ptr " & result |
108 | 114 |
109 func doIdentifier(typename: string): string = | 115 func doIdentifier(typename: string): string = |
110 if typename in ["type", "object"]: | 116 if typename in ["type", "object"]: |
111 return &"`{typename}`" | 117 return &"`{typename}`" |
163 return doMember(n[3][0].text, n[1][0].text, 1, n.attr("values")) | 169 return doMember(n[3][0].text, n[1][0].text, 1, n.attr("values")) |
164 else: | 170 else: |
165 assert n[0].text.strip() == "const" # can be ignored | 171 assert n[0].text.strip() == "const" # can be ignored |
166 assert n[1].tag == "type" | 172 assert n[1].tag == "type" |
167 assert n[2].text.strip() in ["*", "* const *", "* const*"] | 173 assert n[2].text.strip() in ["*", "* const *", "* const*"] |
168 # can be ignored, basically every type is a pointer | |
169 assert n[3].tag == "name" | 174 assert n[3].tag == "name" |
170 assert n[1].len == 1 | 175 assert n[1].len == 1 |
171 assert n[3].len == 1 | 176 assert n[3].len == 1 |
172 return doMember(n[3][0].text, n[1][0].text, 1, n.attr("values")) | 177 return doMember( |
178 n[3][0].text, n[1][0].text, n[2].text.strip().count("*"), n.attr("values") | |
179 ) | |
173 elif n.len in [5, 6]: | 180 elif n.len in [5, 6]: |
174 # array definition, using const-value for array length | 181 # array definition, using const-value for array length |
175 # <type>uint8_t</type>,<name>pipelineCacheUUID</name>[<enum>VK_UUID_SIZE</enum>] | 182 # <type>uint8_t</type>,<name>pipelineCacheUUID</name>[<enum>VK_UUID_SIZE</enum>] |
176 assert n[2].text.strip() == "[" | 183 assert n[2].text.strip() == "[" |
177 assert n[4].text.strip() == "]" | 184 assert n[4].text.strip() == "]" |
229 import ../semicongine/thirdparty/x11/x | 236 import ../semicongine/thirdparty/x11/x |
230 import ../semicongine/thirdparty/x11/xrandr | 237 import ../semicongine/thirdparty/x11/xrandr |
231 | 238 |
232 func VK_MAKE_API_VERSION*( | 239 func VK_MAKE_API_VERSION*( |
233 variant: uint32, major: uint32, minor: uint32, patch: uint32 | 240 variant: uint32, major: uint32, minor: uint32, patch: uint32 |
234 ): uint32 {.compileTime.} = | 241 ): uint32 = |
235 (variant shl 29) or (major shl 22) or (minor shl 12) or patch | 242 (variant shl 29) or (major shl 22) or (minor shl 12) or patch |
236 """ | 243 """ |
237 | 244 |
238 outFile.writeLine "type" | 245 outFile.writeLine "type" |
239 outFile.writeLine """ | 246 outFile.writeLine """ |
390 outFile.writeLine &"): {doTypename(retName, 0)} {{.cdecl.}}" | 397 outFile.writeLine &"): {doTypename(retName, 0)} {{.cdecl.}}" |
391 else: | 398 else: |
392 doAssert category in ["", "basetype", "enum"], "unknown type category: " & category | 399 doAssert category in ["", "basetype", "enum"], "unknown type category: " & category |
393 outFile.writeLine "" | 400 outFile.writeLine "" |
394 | 401 |
395 outFile.write &"var\n" | |
396 for command in commands: | 402 for command in commands: |
397 if command.attr("api") == "vulkansc": | 403 if command.attr("api") == "vulkansc": |
398 continue | 404 continue |
399 if command.attr("alias") != "": | 405 if command.attr("alias") != "": |
400 let funcName = command.attr("name") | 406 let funcName = command.attr("name") |
401 let funcAlias = command.attr("alias") | 407 let funcAlias = command.attr("alias") |
402 outFile.write &" {funcName}* = {funcAlias}\n" | 408 outFile.write &"var {funcName}* = {funcAlias}\n" |
403 continue | 409 continue |
404 | 410 |
405 let proto = command.findAll("proto")[0] | 411 let proto = command.findAll("proto")[0] |
406 let retType = proto.findAll("type")[0][0].text.strip() | 412 let retType = proto.findAll("type")[0][0].text.strip() |
407 let funcName = proto.findAll("name")[0][0].text.strip() | 413 let funcName = proto.findAll("name")[0][0].text.strip() |
408 | 414 |
409 if "Video" in funcName: # Video API not supported at this time | 415 if "Video" in funcName: # Video API not supported at this time |
410 continue | 416 continue |
411 | 417 |
412 outFile.write &" {funcName}*: proc(" | 418 outFile.write &"var {funcName}*: proc(" |
413 for param in command: | 419 for param in command: |
414 if param.tag != "param": | 420 if param.tag != "param": |
415 continue | 421 continue |
416 if param.attr("api") == "vulkansc": | 422 if param.attr("api") == "vulkansc": |
417 continue | 423 continue |
451 let vulkanLib = loadLib("vulkan-1.dll") | 457 let vulkanLib = loadLib("vulkan-1.dll") |
452 if vulkanLib == nil: | 458 if vulkanLib == nil: |
453 raise newException(Exception, "Unable to load vulkan library") | 459 raise newException(Exception, "Unable to load vulkan library") |
454 | 460 |
455 vkGetInstanceProcAddr = cast[proc(instance: VkInstance, pName: cstring, ): PFN_vkVoidFunction {.stdcall.}](checkedSymAddr(vulkanLib, "vkGetInstanceProcAddr")) | 461 vkGetInstanceProcAddr = cast[proc(instance: VkInstance, pName: cstring, ): PFN_vkVoidFunction {.stdcall.}](checkedSymAddr(vulkanLib, "vkGetInstanceProcAddr")) |
456 """ | 462 |
463 proc loadFunc[T](instance: VkInstance, f: var T, name: string) = | |
464 f = cast[T](vkGetInstanceProcAddr(instance, name)) | |
465 | |
466 """ | |
467 | |
468 for f in features: | |
469 let name = f.attr("name").replace(",", "_") | |
470 if f.attr("struct") != "": | |
471 continue | |
472 outFile.writeLine &"proc loadFeature_{name}(instance: VkInstance) =" | |
473 var hasEntries = false | |
474 for cmd in f.findAll("command"): | |
475 hasEntries = true | |
476 let cName = cmd.attr("name") | |
477 outFile.writeLine &" loadFunc(instance, {cName}, \"{cName}\")" | |
478 if not hasEntries: | |
479 outFile.writeLine " discard" | |
480 outFile.writeLine "" | |
457 | 481 |
458 outFile.close() | 482 outFile.close() |
459 | 483 |
460 assert execCmd("nim c " & outPath) == 0 | 484 assert execCmd("nim c " & outPath) == 0 |