Why capital letter proc? Why varargs?
arkanoid87 opened this issue · 3 comments
line in C header
CLIENT_NET_API DWORD CALL_METHOD CLIENT_GetSDKVersion();
after preprocessing
unsigned int CLIENT_GetSDKVersion();
after futhark pass
when not declared(Clientgetsdkversion):
proc Clientgetsdkversion*(): cuint {.cdecl, varargs,
importc: "CLIENT_GetSDKVersion".}
else:
static :
hint("Declaration of " & "CLIENT_GetSDKVersion" &
" already exists, not redeclaring")
generated C code by nim compiler
...
N_CDECL(unsigned int, CLIENT_GetSDKVersion)(...);
...
error
error: ISO C requires a named argument before ‘...’
removing varargs
from pragma fixes the problem
The capital letter is simply because the original C procedure starts with a capital letter. Futhark tries to maintain the best compatibility with the original, and thus also tutorials and such. Because of the case and underscore insensitivity of Nim that identifier can also be written as CLIENT_GetSDKVersion
, same as the C version.
The varargs praga is simply added because Clang tells us the procedure is variadic: https://github.com/PMunch/futhark/blob/master/src/opir.nim#L117 and has already been reported here #44. Why clang does this is still not known, which version of Clang are you using?
I understand. I've added a quick search/replace on the generated nim.
proc ([A-Z]) -> proc \L$1
I'm using clang 14
$ clang --version
Ubuntu clang version 14.0.0-1ubuntu1
Futhark compiled with
nimble install --passL:"-L/usr/lib/llvm-14/lib/" futhark
PS: I tend to edit Futhark generated nim file quite often. How can I hook a post-process logic to grab generated nim source and place it in local src dir?
The idea is that you shouldn't have to edit the Futhark file. Because of all the when declared
guards it should suffice to simply declare your procs before importc
. This isn't always feasible however due to how tangled types and procedures can get. Another option would be to add a opirOutputHook
or similar, this would allow you to change the data fed into Futhark in a very structured way.