From 663f3592ba446ab65e59b9dcdafd61fa9d2e7cf5 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Tue, 19 May 2009 07:15:13 -0400 Subject: [PATCH] `__FILE__ now expands to a string, per draft SystemVerilog 2010(ish). --- Changes | 4 +++- src/V3PreLex.l | 6 ++++-- test_regress/t/t_pp_display.pl | 1 + test_regress/t/t_pp_display.v | 2 ++ test_regress/t/t_preproc.out | 4 ++-- 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Changes b/Changes index a2f904fb3..1ba786e6c 100644 --- a/Changes +++ b/Changes @@ -7,8 +7,10 @@ indicates the contributor was also the author of the fix; Thanks! ** Verilator is now licensed under LGPL v3 and/or Artistic v2.0. +*** `__FILE__ now expands to a string, per draft SystemVerilog 2010(ish). + **** The front end parser has been re-factored to enable more SV parsing. - Code should parse the same, but minor parsing bugs may pop up now. + Code should parse the same, but minor parsing bugs may pop up. **** Verilator_includer is no longer installed twice, bug48. [Lane Brooks] diff --git a/src/V3PreLex.l b/src/V3PreLex.l index e97f2452a..ebf4a02b7 100644 --- a/src/V3PreLex.l +++ b/src/V3PreLex.l @@ -91,8 +91,10 @@ psl [p]sl /* Optional directives we recognize */ "`__FILE__" { if (!pedantic()) { - yytext = (char*)V3PreLex::s_currentLexp->m_curFilelinep->cfilename(); - yyleng = strlen(yytext); return (VP_TEXT); + static string rtnfile; + rtnfile = '"'; rtnfile += V3PreLex::s_currentLexp->m_curFilelinep->cfilename(); + rtnfile += '"'; yytext=(char*)rtnfile.c_str(); yyleng = rtnfile.length(); + return (VP_STRING); } else return(VP_DEFREF); } "`__LINE__" { if (!pedantic()) { static char buf[10]; diff --git a/test_regress/t/t_pp_display.pl b/test_regress/t/t_pp_display.pl index 13b579d13..69799687b 100755 --- a/test_regress/t/t_pp_display.pl +++ b/test_regress/t/t_pp_display.pl @@ -25,6 +25,7 @@ na: "nana" left side: "right side" left side : "right side " twoline: "first second" +Line 38 File "t/t_pp_display.v" *-* All Finished *-* ')); diff --git a/test_regress/t/t_pp_display.v b/test_regress/t/t_pp_display.v index 7626eca81..c4d9c939a 100644 --- a/test_regress/t/t_pp_display.v +++ b/test_regress/t/t_pp_display.v @@ -35,6 +35,8 @@ module t; second $display(`msg(twoline, `twoline)); + $display("Line %0d File \"%s\"",`__LINE__,`__FILE__); + //$display(`msg(left side, \ right side \ )); // Not sure \{space} is legal. $write("*-* All Finished *-*\n"); $finish; diff --git a/test_regress/t/t_preproc.out b/test_regress/t/t_preproc.out index 5a1a60ff7..85833e9a1 100644 --- a/test_regress/t/t_preproc.out +++ b/test_regress/t/t_preproc.out @@ -13,7 +13,7 @@ -At file t/t_preproc_inc2.v line 4 +At file "t/t_preproc_inc2.v" line 4 `line 6 "t/t_preproc_inc2.v" 0 @@ -27,7 +27,7 @@ At file t/t_preproc_inc2.v line 4 - At file inc3_a_filename_from_line_directive line 10 + At file "inc3_a_filename_from_line_directive" line 10