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

$fopen("file") should have an implicit mode of "w" #624

Closed
veripoolbot opened this issue Feb 22, 2013 · 3 comments
Closed

$fopen("file") should have an implicit mode of "w" #624

veripoolbot opened this issue Feb 22, 2013 · 3 comments
Labels
resolution: fixed Closed; fixed type: feature-IEEE Request to add new feature, described in IEEE 1800

Comments

@veripoolbot
Copy link
Contributor


Author Name: Jason McMullan (@ezrec)
Original Redmine Issue: 624 from https://www.veripool.org
Original Date: 2013-02-22


The following testcase illustrates the issue:

module testcase_file ();
integer fd;
initial begin
     fd = $fopen("file.txt");
     $fdisplay(fd, "Hello World\n");
     $fclose(fd);
end
endmodule

Compiling with verilator results in a syntax error:

$ verilator --cc testcase_fopen.v 
%Error: testcase_fopen.v:4: syntax error, unexpected ')'
%Error: Exiting due to 1 error(s)
%Error: Command Failed /usr/bin/verilator_bin --cc testcase_fopen.v

The following patch resolves this issue:

diff --git a/src/verilog.y b/src/verilog.y
index fa0a208..a7d084f 100644
--- a/src/verilog.y
+++ b/src/verilog.y
@@ -2185,6 +2185,7 @@ statementVerilatorPragmas<nodep>:
 foperator_assignment<nodep>:	// IEEE: operator_assignment (for first part of expression)
 		fexprLvalue '=' delayE expr	{ $$ = new AstAssign($2,$1,$4); }
 	|	fexprLvalue '=' yD_FOPEN '(' expr ',' expr ')'	{ $$ = new AstFOpen($3,$1,$5,$7); }
+	|	fexprLvalue '=' yD_FOPEN '(' expr ')'	{ $$ = new AstFOpen($3,$1,$5,  new AstConst($<fl>1,V3Number(V3Number::VerilogString(),$<fl>5,GRAMMARP->deQuote($<fl>5, "w")))); }
 	//
 	//UNSUP	~f~exprLvalue '=' delay_or_event_controlE expr { UNSUP }
 	//UNSUP	~f~exprLvalue yP_PLUS(etc) expr		{ UNSUP }

@veripoolbot
Copy link
Contributor Author


Original Redmine Comment
Author Name: Wilson Snyder (@wsnyder)
Original Date: 2013-02-22T15:44:48Z


If only Verilog were that obvious. The absence of "w" means it's an old 1995 multichannel descriptor which Verilator does not support. Verilator only supports file descriptors. However I'll add a clear error message saying to add the "w".

@veripoolbot
Copy link
Contributor Author


Original Redmine Comment
Author Name: Jason McMullan (@ezrec)
Original Date: 2013-02-22T15:55:37Z


Understood - and thanks for the clarification.

I'll close this when the new warning message is committed.

@veripoolbot
Copy link
Contributor Author


Original Redmine Comment
Author Name: Wilson Snyder (@wsnyder)
Original Date: 2013-02-22T22:14:33Z


In git towards 3.846.

@veripoolbot veripoolbot added resolution: fixed Closed; fixed type: feature-IEEE Request to add new feature, described in IEEE 1800 labels Dec 22, 2019
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

1 participant