Skip to content

Commit

Permalink
Merge branch 'master' into verilog-ams
Browse files Browse the repository at this point in the history
  • Loading branch information
steveicarus committed May 9, 2008
2 parents 2d068ca + 73dcace commit ba3660b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 23 deletions.
7 changes: 6 additions & 1 deletion driver/iverilog.man
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,14 @@ from preprocessor defines elsewhere in the file or the command line.

.SH PREDEFINED MACROS

The following macro is predefined by the compiler:
The following macros are predefined by the compiler:
.TP 8
.B __ICARUS__ = 1\fP
This is defined always when compiling with Icarus Verilog.

.TP 8
.B __VAMS_ENABLE__ = 1\fp
This is defined if Verilog-AMS is enabled.

.SH EXAMPLES
These examples assume that you have a Verilog source file called hello.v in
Expand Down
55 changes: 33 additions & 22 deletions ivlpp/lexor.lex
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ static void do_define();
static int def_is_done();
static int is_defined(const char*name);

static int macro_needs_args();
static int macro_needs_args(const char*name);
static void macro_start_args();
static void macro_add_to_arg();
static void macro_finish_arg();
Expand Down Expand Up @@ -72,6 +72,8 @@ struct include_stack_t
*/
int ebs;

int stringify_flag;

unsigned lineno;
YY_BUFFER_STATE yybs;

Expand All @@ -86,6 +88,8 @@ static void emit_pathline(struct include_stack_t* isp);
*/
static struct include_stack_t* file_queue = 0;

static int do_expand_stringify_flag = 0;

/*
* The istack is the inclusion stack.
*/
Expand Down Expand Up @@ -245,7 +249,7 @@ keywords (include|define|undef|ifdef|ifndef|else|elseif|endif)
}

<PCOMENT>`[a-zA-Z][a-zA-Z0-9_$]* {
if (macro_needs_args()) yy_push_state(MA_START); else do_expand(0);
if (macro_needs_args(yytext+1)) yy_push_state(MA_START); else do_expand(0);
}

/* Strings do not contain preprocessor directives, but can expand
Expand All @@ -262,21 +266,6 @@ keywords (include|define|undef|ifdef|ifndef|else|elseif|endif)
<CSTRING>\" { BEGIN(string_enter); ECHO; }
<CSTRING>. { ECHO; }

<CSTRING>`{keywords} {
emit_pathline(istack);
error_count += 1;
fprintf
(
stderr,
"error: macro names cannot be directive keywords ('%s'); replaced with nothing.\n",
yytext
);
}

<CSTRING>`[a-zA-Z][a-zA-Z0-9_$]* {
if (macro_needs_args()) yy_push_state(MA_START); else do_expand(0);
}

/* This set of patterns matches the include directive and the name
* that follows it. when the directive ends, the do_include function
* performs the include operation.
Expand All @@ -295,7 +284,7 @@ keywords (include|define|undef|ifdef|ifndef|else|elseif|endif)
}

<PPINCLUDE>`[a-zA-Z][a-zA-Z0-9_]* {
if (macro_needs_args()) yy_push_state(MA_START); else do_expand(0);
if (macro_needs_args(yytext+1)) yy_push_state(MA_START); else do_expand(0);
}

<PPINCLUDE>\"[^\"]*\" { include_filename(); }
Expand Down Expand Up @@ -551,12 +540,23 @@ keywords (include|define|undef|ifdef|ifndef|else|elseif|endif)

/* This pattern notices macros and arranges for them to be replaced. */
`[a-zA-Z_][a-zA-Z0-9_$]* {
if (macro_needs_args())
if (macro_needs_args(yytext+1))
yy_push_state(MA_START);
else
do_expand(0);
}

/* Stringified version of macro expansion. */
``[a-zA-Z_][a-zA-Z0-9_$]* {
assert(do_expand_stringify_flag == 0);
do_expand_stringify_flag = 1;
fputc('"', yyout);
if (macro_needs_args(yytext+2))
yy_push_state(MA_START);
else
do_expand(0);
}

<MA_START>\( { BEGIN(MA_ADD); macro_start_args(); }

<MA_START>{W} {}
Expand Down Expand Up @@ -1171,16 +1171,16 @@ static void def_undefine()
*/
static struct define_t* cur_macro = 0;

static int macro_needs_args()
static int macro_needs_args(const char*text)
{
cur_macro = def_lookup(yytext+1);
cur_macro = def_lookup(text);

if (cur_macro)
return (cur_macro->argc > 1);
else
{
emit_pathline(istack);
fprintf(stderr, "warning: macro %s undefined (and assumed null) at this point.\n", yytext);
fprintf(stderr, "warning: macro %s undefined (and assumed null) at this point.\n", text);
return 0;
}
}
Expand Down Expand Up @@ -1348,6 +1348,8 @@ static void do_expand(int use_args)

isp = (struct include_stack_t*) calloc(1, sizeof(struct include_stack_t));

isp->stringify_flag = do_expand_stringify_flag;
do_expand_stringify_flag = 0;
if (use_args)
{
isp->str = &exp_buf[head];
Expand All @@ -1364,6 +1366,11 @@ static void do_expand(int use_args)
istack = isp;

yy_switch_to_buffer(yy_create_buffer(istack->file, YY_BUF_SIZE));
} else {
if (do_expand_stringify_flag) {
do_expand_stringify_flag = 0;
fputc('"', yyout);
}
}
}

Expand Down Expand Up @@ -1537,6 +1544,10 @@ static int load_next_input()
exp_buf_free += isp->ebs;
}

if (isp->stringify_flag) {
fputc('"', yyout);
}

free(isp);

/* If I am out of include stack, the main input is
Expand Down

0 comments on commit ba3660b

Please sign in to comment.