Skip to content
Browse files

Check for extra digits in sized binary, octal and hex constants.

Print out a warning if extra digits are given for sized binary, octal
or hex constants. Decimal constants are very hard since we never
calculate the true number of bits the digits represent, so for now
decimal constants are not checked.
  • Loading branch information...
1 parent 58e4c56 commit 676695c78fbbcd65b9ccbbca817f5b09af368ffc @caryr caryr committed with Oct 11, 2007
Showing with 29 additions and 61 deletions.
  1. +22 −0 lexor.lex
  2. +4 −3 parse.y
  3. +2 −30 parse_misc.cc
  4. +1 −28 parse_misc.h
View
22 lexor.lex
@@ -294,6 +294,7 @@ W [ \t\b\f\r]+
[0-9][0-9_]* {
yylval.number = make_unsized_dec(yytext);
+ based_size = yylval.number->as_ulong();
return DEC_NUMBER; }
[0-9][0-9_]*\.[0-9][0-9_]*([Ee][+-]?[0-9][0-9_]*)? {
@@ -462,6 +463,9 @@ static verinum*make_unsized_binary(const char*txt)
for (const char*idx = ptr ; *idx ; idx += 1)
if (*idx != '_') size += 1;
+ if ((based_size > 0) && (size > based_size)) yywarn(yylloc,
+ "extra digits given for sized binary constant.");
+
verinum::V*bits = new verinum::V[size];
unsigned idx = size;
@@ -517,6 +521,13 @@ static verinum*make_unsized_octal(const char*txt)
for (const char*idx = ptr ; *idx ; idx += 1)
if (*idx != '_') size += 3;
+ if (based_size > 0) {
+ int rem = based_size % 3;
+ if (rem != 0) based_size += 3 - rem;
+ if (size > based_size) yywarn(yylloc,
+ "extra digits given for sized octal constant.");
+ }
+
verinum::V*bits = new verinum::V[size];
unsigned idx = size;
@@ -576,6 +587,13 @@ static verinum*make_unsized_hex(const char*txt)
for (const char*idx = ptr ; *idx ; idx += 1)
if (*idx != '_') size += 4;
+ if (based_size > 0) {
+ int rem = based_size % 4;
+ if (rem != 0) based_size += 4 - rem;
+ if (size > based_size) yywarn(yylloc,
+ "extra digits given for sized hex constant.");
+ }
+
verinum::V*bits = new verinum::V[size];
unsigned idx = size;
@@ -803,6 +821,10 @@ static verinum*make_unsized_dec(const char*ptr)
assert(size <= tmp_size);
}
+ /* Since we never have the real number of bits that a decimal
+ number represents we do not check for extra bits. */
+// if (based_size > 0) { }
+
verinum*res = new verinum(bits, size, false);
res->has_sign(signed_flag);
View
7 parse.y
@@ -274,11 +274,12 @@ source_file
;
number : BASED_NUMBER
- { $$ = $1; }
+ { $$ = $1; based_size = 0;}
| DEC_NUMBER
- { $$ = $1; }
+ { $$ = $1; based_size = 0;}
| DEC_NUMBER BASED_NUMBER
- { $$ = pform_verinum_with_size($1,$2, @2.text, @2.first_line); }
+ { $$ = pform_verinum_with_size($1,$2, @2.text, @2.first_line);
+ based_size = 0; }
;
/* Verilog-2001 supports attribute lists, which can be attached to a
View
32 parse_misc.cc
@@ -28,6 +28,7 @@
extern const char*vl_file;
unsigned error_count = 0;
unsigned warn_count = 0;
+unsigned long based_size = 0;
void VLerror(const char*msg)
{
@@ -42,6 +43,7 @@ void VLerror(const YYLTYPE&loc, const char*msg)
cerr << loc.text << ":";
cerr << loc.first_line << ": " << msg << endl;
+ based_size = 0; /* Clear the base information if we have an error. */
}
void yywarn(const YYLTYPE&loc, const char*msg)
@@ -58,33 +60,3 @@ int VLwrap()
return -1;
}
-/*
- * $Log: parse_misc.cc,v $
- * Revision 1.7 2002/08/12 01:35:00 steve
- * conditional ident string using autoconfig.
- *
- * Revision 1.6 2002/06/06 18:57:18 steve
- * Use standard name for iostream.
- *
- * Revision 1.5 2001/07/25 03:10:49 steve
- * Create a config.h.in file to hold all the config
- * junk, and support gcc 3.0. (Stephan Boettcher)
- *
- * Revision 1.4 2000/02/23 02:56:55 steve
- * Macintosh compilers do not support ident.
- *
- * Revision 1.3 1999/09/29 21:15:31 steve
- * Standardize formatting of warning messages.
- *
- * Revision 1.2 1998/11/07 17:05:05 steve
- * Handle procedural conditional, and some
- * of the conditional expressions.
- *
- * Elaborate signals and identifiers differently,
- * allowing the netlist to hold signal information.
- *
- * Revision 1.1 1998/11/03 23:29:02 steve
- * Introduce verilog to CVS.
- *
- */
-
View
29 parse_misc.h
@@ -55,33 +55,6 @@ extern void VLerror(const YYLTYPE&loc, const char*msg);
extern void VLwarn(const YYLTYPE&loc, const char*msg);
extern unsigned error_count, warn_count;
+extern unsigned long based_size;
-/*
- * $Log: parse_misc.h,v $
- * Revision 1.7 2003/03/08 20:58:18 steve
- * More C-like use of vlltype.
- *
- * Revision 1.6 2002/11/03 20:36:53 steve
- * Support old/new bison yylloc.
- *
- * Revision 1.5 2002/08/12 01:35:00 steve
- * conditional ident string using autoconfig.
- *
- * Revision 1.4 2000/02/23 02:56:55 steve
- * Macintosh compilers do not support ident.
- *
- * Revision 1.3 1999/07/10 01:03:18 steve
- * remove string from lexical phase.
- *
- * Revision 1.2 1998/11/07 17:05:05 steve
- * Handle procedural conditional, and some
- * of the conditional expressions.
- *
- * Elaborate signals and identifiers differently,
- * allowing the netlist to hold signal information.
- *
- * Revision 1.1 1998/11/03 23:29:03 steve
- * Introduce verilog to CVS.
- *
- */
#endif

0 comments on commit 676695c

Please sign in to comment.
Something went wrong with that request. Please try again.