Skip to content
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

Unable to pass strings into C functions in compiled code #747

Closed
veripoolbot opened this issue Apr 21, 2014 · 5 comments
Closed

Unable to pass strings into C functions in compiled code #747

veripoolbot opened this issue Apr 21, 2014 · 5 comments
Assignees
Labels
resolution: fixed Closed; fixed type: feature-IEEE Request to add new feature, described in IEEE 1800

Comments

@veripoolbot
Copy link
Contributor


Author Name: Glen Gibb
Original Redmine Issue: 747 from https://www.veripool.org
Original Date: 2014-04-21
Original Assignee: Wilson Snyder (@wsnyder)


gcc produces the following error when I try to pass a Verilog string into a $display statement:

In file included from Vt_string_print__ALLboth.cpp:4:0:
Vt_string_print.cpp: In static member function ‘static void Vt_string_print::_sequent__TOP__1(Vt_string_print__Syms*)’:
Vt_string_print.cpp:83:44: error: cannot pass objects of non-trivially-copyable type ‘std::string {aka class std::basic_string<char>}’ through ‘...’
      VL_WRITEF("%s\n",64,vlTOPp->v__DOT__msg);

(This error is generated for the attached t_string_print.v file.)

@veripoolbot
Copy link
Contributor Author


Original Redmine Comment
Author Name: Wilson Snyder (@wsnyder)
Original Date: 2014-04-21T23:27:22Z


Verilator only supports strings in a few limited cases. Might you attempt a patch? This one houldn't be too bad in V3Width 's AstSFormat visitor look for 's' with the corresponding node having a dtypep->basicp of AstBasicDTypeKwd::STRING, change the code to %S, then in V3Emit use %S to mean add a ".c_ptr()" when printing the nodep.

@veripoolbot
Copy link
Contributor Author


Original Redmine Comment
Author Name: Glen Gibb
Original Date: 2014-04-22T02:16:16Z


I spent a little time playing with this and it looks like the code will require quite a bit more work.

The problem is that the generated C code assigns integers to string objects. For example, the attached .v file includes the following assignment in the resulting .cpp file:

     // in Vt_string_print.h:
     string v__DOT__msg;

     // in Vt_string_print.cpp:
     vlTOPp->v__DOT__msg = ((2 == vlTOPp->v__DOT__cyc)
			    ? VL_ULL(0x74776f) : VL_ULL(0x6e6f742074776f));

As you can see, the code is assigning my two strings as integers to the string object. This ends up assigning only the least-significant byte (0x6f) to my string object, not the sequence of bytes.

@veripoolbot
Copy link
Contributor Author


Original Redmine Comment
Author Name: Wilson Snyder (@wsnyder)
Original Date: 2014-04-22T11:08:10Z


I guess V3Width will need to be taught how to do string promotion. It's best if you wait until my present set of edits is in. Then you'd see that there's a dtype of string being assigned a dtype of a number, and would convert to a AstConstString.

@veripoolbot
Copy link
Contributor Author


Original Redmine Comment
Author Name: Wilson Snyder (@wsnyder)
Original Date: 2014-11-28T20:02:24Z


Fixed in git towards 3.867.

@veripoolbot
Copy link
Contributor Author


Original Redmine Comment
Author Name: Wilson Snyder (@wsnyder)
Original Date: 2014-12-20T21:52:36Z


In 3.868.

@veripoolbot veripoolbot added resolution: fixed Closed; fixed type: feature-IEEE Request to add new feature, described in IEEE 1800 labels Dec 22, 2019
tgorochowik pushed a commit to antmicro/verilator that referenced this issue Feb 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
resolution: fixed Closed; fixed type: feature-IEEE Request to add new feature, described in IEEE 1800
Projects
None yet
Development

No branches or pull requests

2 participants