-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Defining multiple structs after the same typedef causes compilation error #47
Comments
What happens if you run this line? |
Thanks, in that toast output, I found a gcc command, and running that I realized that I had forgotten to put this But after adding that too, I get error:
|
Seems like a bug. After typedef struct vpi_vecval {
uint32_t a;
uint32_t b;
} s_vpi_vecval, *p_vpi_vecval;
typedef s_vpi_vecval svLogicVecVal; After type
svLogicVecVal* = s_vpi_vecval Bug gets triggered by defining multiple structs after the same typedef. Possibly a tree-sitter bug? typedef struct foo {
int i;
} a, b; Gets translated to: (translation_unit 1 1 39
(type_definition 1 1 39
(struct_specifier 1 9 25
(type_identifier 1 16 3)
(field_declaration_list 1 20 14
(field_declaration 2 5 6
(primitive_type 2 5 3)
(field_identifier 2 9 1)
)
)
)
(ERROR 3 3 2
(type_identifier 3 3 1)
)
(type_identifier 3 6 1)
)
) But without the extra name: (translation_unit 1 1 36
(type_definition 1 1 36
(struct_specifier 1 9 25
(type_identifier 1 16 3)
(field_declaration_list 1 20 14
(field_declaration 2 5 6
(primitive_type 2 5 3)
(field_identifier 2 9 1)
)
)
)
(type_identifier 3 3 1)
)
) |
Issue addressing the bug here tree-sitter/tree-sitter-cpp#30 |
Thanks guys! It compiles after this workaround: import strformat
import nimterop/cimport
# Below manual definition of s_vpi_vecval is a workaround for
# https://github.com/genotrance/nimterop/issues/47.
type
s_vpi_vecval* {.importc: "s_vpi_vecval".} = object
aval: uint32
bval: uint32
cImport("svdpi.h")
# Input: none
# Return: none
proc hello() {.exportc.} =
echo svDpiVersion()
echo "Hello from Nim!" |
I'm thinking this can be marked as fixed by providing better error handling when preprocessor complains. Nimterop will now highlight preprocessor errors. It will make it more obvious to users. We can track the tree-sitter bug in their issue tracker. Let me know if this is acceptable. |
That's great! For this issue, I had to run
Agreed.
Yes, it is. Thanks. |
Yes you should see the error right there inline. Can you please try with this same library? |
Yes, now I get:
Minor nitpick: Can that last ERROR also be in red color as the Error above? Note that I reproduced the earlier error. Not the last one. |
Am not keen on adding a Closing. |
Should this issue be reopened given that the upstream bug is fixed: tree-sitter/tree-sitter-cpp#30? Will that fix auto-propagate to nimterop? Or does nimterop need to be updated to absorb that upstream fix? |
I believe this works in nimterop as of today. |
I removed this workaround code: type
s_vpi_vecval* {.importc: "s_vpi_vecval".} = object
aval: uint32
bval: uint32 and updated nimterop from head. But I still the same error:
Full Nim wrapper# svdpi.nim
import nimterop/cimport
import os
static:
cDisableCaching()
const
xlmIncludePath = getEnv("XCELIUM_ROOT") / ".." / "include"
static:
doAssert fileExists(xlmIncludePath / "svdpi.h")
doAssert fileExists(xlmIncludePath / "svdpi_compatibility.h")
cAddSearchDir(xlmIncludePath)
cDefine("DPI_COMPATIBILITY_VERSION_1800v2012")
# # Below manual definition of s_vpi_vecval is a workaround for
# # https://github.com/nimterop/nimterop/issues/47.
# type
# s_vpi_vecval* {.importc: "s_vpi_vecval", header: xlmIncludePath / "svdpi.h".} = object
# aval*: uint32 # we need to export the object elements too!
# bval*: uint32
cImport(cSearchPath("svdpi.h")) Snippet from
|
OK .. what's interesting is that import nimterop/cimport
import os
static:
cDisableCaching()
cDebug()
const
xlmIncludePath = getEnv("XCELIUM_ROOT") / ".." / "include"
static:
doAssert fileExists(xlmIncludePath / "svdpi_compatibility.h")
cAddSearchDir(xlmIncludePath)
cDefine("DPI_COMPATIBILITY_VERSION_1800v2012")
cImport(cSearchPath("svdpi_compatibility.h")) This outputs: {.passC: "-DDPI_COMPATIBILITY_VERSION_1800v2012".}
# Importing /masking/the/actual/company/internal/path/svdpi_compatibility.h
# Generated at 2019-05-14T15:38:10-04:00
# Command line:
# /home/kmodi/.nimble/pkgs/nimterop-#head/nimterop/toast --pnim --preprocess --defines+=DPI_COMPATIBILITY_VERSION_1800v2012 --nim:/home/kmodi/usr_local/apps/6/nim/devel/bin/nim /masking/the/actual/company/internal/path/svdpi_compatibility.h
{.hint[ConvFromXtoItselfNotNeeded]: off.}
import nimterop/types
const
headersvdpi_compatibility {.used.} = "/masking/the/actual/company/internal/path/svdpi_compatibility.h"
{.pragma: impsvdpi_compatibility, importc, header: headersvdpi_compatibility.}
{.pragma: impsvdpi_compatibilityC, impsvdpi_compatibility, cdecl.} |
Actually, it's the same bug. I can easily reproduce with just this in typedef struct t_vpi_vecval {
uint32_t aval;
uint32_t bval;
} s_vpi_vecval, *p_vpi_vecval; With above, I get: # Generated at 2019-05-14T15:44:52-04:00
# Command line:
# /home/kmodi/.nimble/pkgs/nimterop-#head/nimterop/toast --pnim --preprocess --defines+=DPI_COMPATIBILITY_VERSION_1800v2012 --nim:/home/kmodi/usr_local/apps/6/nim/devel/bin/nim ../includes/svdpi_compatibility.h
{.hint[ConvFromXtoItselfNotNeeded]: off.}
import nimterop/types
const
headersvdpi_compatibility {.used.} = "../includes/svdpi_compatibility.h"
{.pragma: impsvdpi_compatibility, importc, header: headersvdpi_compatibility.}
{.pragma: impsvdpi_compatibilityC, impsvdpi_compatibility, cdecl.} With: typedef struct t_vpi_vecval {
uint32_t aval;
uint32_t bval;
} s_vpi_vecval; ( I removed the I get: # Generated at 2019-05-14T15:46:53-04:00
# Command line:
# /home/kmodi/.nimble/pkgs/nimterop-#head/nimterop/toast --pnim --preprocess --defines+=DPI_COMPATIBILITY_VERSION_1800v2012 --nim:/home/kmodi/usr_local/apps/6/nim/devel/bin/nim ../includes/svdpi_compatibility.h
{.hint[ConvFromXtoItselfNotNeeded]: off.}
import nimterop/types
const
headersvdpi_compatibility {.used.} = "../includes/svdpi_compatibility.h"
{.pragma: impsvdpi_compatibility, importc, header: headersvdpi_compatibility.}
{.pragma: impsvdpi_compatibilityC, impsvdpi_compatibility, cdecl.}
type
t_vpi_vecval* {.importc: "struct t_vpi_vecval", header: headersvdpi_compatibility, bycopy.} = object
aval*: uint32
bval*: uint32
s_vpi_vecval* {.impsvdpi_compatibility, bycopy.} = t_vpi_vecval |
Can you delete the build folder and rebuild nimterop? You're probably still using the old tree-sitter. |
I had already done that. I again did:
and I got the same error. I confirmed the time stamp of the toast binary and the files under
How do I verify the tree-sitter version? |
Looks like the |
I can reproduce the same issue even after pulling latest nimterop and doing |
@genotrance Once you cut a new release of nimterop, I plan to update my svdpi wrapper with this change: kaushalmodi/nim-svdpi@57268e7 |
Ref: nimterop/nimterop#47 - Add "wrap" nimscript task. - Bump nimterop dep and svdpi version.
Hello,
I installed
nimterop
usingnimble
.Here is the minimum working example:
and the
svdpi.h
(this is a publicly shareable file, so you can add this to your tests too if you like).On running:
I get this error:
The text was updated successfully, but these errors were encountered: