From d3f7e4f1e6fa0c3b85b239c4f1bb4c0af964dacb Mon Sep 17 00:00:00 2001 From: Cary R Date: Wed, 27 Apr 2011 09:28:56 -0700 Subject: [PATCH] V0.9: Back port the down payment on const-correctness patch from Larry This patch is a back port of the applicable changes made in the patch originally submitted by Larry for development on (9/27/2010). --- ivlpp/lexor.lex | 6 +++--- ivlpp/main.c | 11 ++++++----- main.cc | 12 ++++++------ tgt-stub/stub.c | 6 +++--- tgt-vvp/eval_expr.c | 6 +++--- tgt-vvp/vvp_process.c | 6 +++--- vpi/lxt_write.c | 4 ++-- vpi/sys_display.c | 11 ++++++----- vpi/sys_priv.c | 4 ++-- vpi/sys_priv.h | 6 +++--- vpi/sys_table.c | 2 +- vpi/sys_vcd.c | 4 ++-- 12 files changed, 40 insertions(+), 38 deletions(-) diff --git a/ivlpp/lexor.lex b/ivlpp/lexor.lex index 5396bc007..286911178 100644 --- a/ivlpp/lexor.lex +++ b/ivlpp/lexor.lex @@ -1,6 +1,6 @@ %{ /* - * Copyright (c) 1999-2010 Stephen Williams (steve@icarus.com) + * Copyright (c) 1999-2011 Stephen Williams (steve@icarus.com) * * This source code is free software; you can redistribute it * and/or modify it in source code form under the terms of the GNU @@ -44,7 +44,7 @@ static void macro_start_args(); static void macro_add_to_arg(); static void macro_finish_arg(); static void do_expand(int use_args); -static char* macro_name(); +static const char* macro_name(); static void include_filename(); static void do_include(); @@ -1201,7 +1201,7 @@ static int macro_needs_args(const char*text) } } -static char* macro_name() +static const char* macro_name() { return cur_macro ? cur_macro->name : ""; } diff --git a/ivlpp/main.c b/ivlpp/main.c index e16e9b8cb..a5bcc5183 100644 --- a/ivlpp/main.c +++ b/ivlpp/main.c @@ -1,5 +1,5 @@ const char COPYRIGHT[] = - "Copyright (c) 1999-2010 Stephen Williams (steve@icarus.com)"; + "Copyright (c) 1999-2011 Stephen Williams (steve@icarus.com)"; /* * This source code is free software; you can redistribute it * and/or modify it in source code form under the terms of the GNU @@ -124,12 +124,13 @@ static int flist_read_flags(const char*path) if (strcmp(cp,"D") == 0) { char*val = strchr(arg, '='); - if (val) + const char *valo = "1"; + if (val) { *val++ = 0; - else - val = "1"; + valo = val; + } - define_macro(arg, val, 0, 0); + define_macro(arg, valo, 0, 0); } else if (strcmp(cp,"I") == 0) { include_dir = realloc(include_dir, diff --git a/main.cc b/main.cc index 20c728b13..92cc6f638 100644 --- a/main.cc +++ b/main.cc @@ -1,5 +1,5 @@ const char COPYRIGHT[] = - "Copyright (c) 1998-2010 Stephen Williams (steve@icarus.com)"; + "Copyright (c) 1998-2011 Stephen Williams (steve@icarus.com)"; /* * This source code is free software; you can redistribute it @@ -524,7 +524,7 @@ static void read_iconfig_file(const char*ipath) } if (strcmp(buf, "basedir") == 0) { - free((char *)basedir); + free((void *)basedir); basedir = strdup(cp); } else if (strcmp(buf, "debug") == 0) { @@ -598,7 +598,7 @@ static void read_iconfig_file(const char*ipath) flags["VPI_MODULE_LIST"] = vpi_module_list; } else if (strcmp(buf, "out") == 0) { - free((char *)flags["-o"]); + free((void *)flags["-o"]); flags["-o"] = strdup(cp); } else if (strcmp(buf, "sys_func") == 0) { @@ -709,17 +709,17 @@ static void EOC_cleanup(void) for (list::iterator suf = library_suff.begin() ; suf != library_suff.end() ; suf ++ ) { - free((char *)*suf); + free((void *)*suf); } library_suff.clear(); - free((char *) basedir); + free((void *) basedir); free(ivlpp_string); free(depfile_name); for (map::iterator flg = flags.begin() ; flg != flags.end() ; flg ++ ) { - free((char *)flg->second); + free((void *)flg->second); } flags.clear(); diff --git a/tgt-stub/stub.c b/tgt-stub/stub.c index 70974f49a..7f8f68adc 100644 --- a/tgt-stub/stub.c +++ b/tgt-stub/stub.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000-2010 Stephen Williams (steve@icarus.com) + * Copyright (c) 2000-2011 Stephen Williams (steve@icarus.com) * * This source code is free software; you can redistribute it * and/or modify it in source code form under the terms of the GNU @@ -35,7 +35,7 @@ static const char*version_string = "Icarus Verilog STUB Code Generator " VERSION " (" VERSION_TAG ")\n\n" -"Copyright (c) 2000-2009 Stephen Williams (steve@icarus.com)\n\n" +"Copyright (c) 2000-2011 Stephen Williams (steve@icarus.com)\n\n" " This program is free software; you can redistribute it and/or modify\n" " it under the terms of the GNU General Public License as published by\n" " the Free Software Foundation; either version 2 of the License, or\n" @@ -1525,7 +1525,7 @@ static void show_logic(ivl_net_logic_t net) static int show_scope(ivl_scope_t net, void*x) { unsigned idx; - char *is_auto; + const char *is_auto; fprintf(out, "scope: %s (%u parameters, %u signals, %u logic)", ivl_scope_name(net), ivl_scope_params(net), diff --git a/tgt-vvp/eval_expr.c b/tgt-vvp/eval_expr.c index 0d3fe395b..052823b21 100644 --- a/tgt-vvp/eval_expr.c +++ b/tgt-vvp/eval_expr.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001-2010 Stephen Williams (steve@icarus.com) + * Copyright (c) 2001-2011 Stephen Williams (steve@icarus.com) * * This source code is free software; you can redistribute it * and/or modify it in source code form under the terms of the GNU @@ -219,7 +219,7 @@ static void eval_logic_into_integer(ivl_expr_t expr, unsigned ix) unsigned word = 0; if (ivl_signal_dimensions(sig) > 0) { ivl_expr_t ixe; - char*type = ivl_expr_signed(expr) ? "/s" : ""; + const char*type = ivl_expr_signed(expr) ? "/s" : ""; /* Detect the special case that this is a variable array. In this case, the ix/getv @@ -246,7 +246,7 @@ static void eval_logic_into_integer(ivl_expr_t expr, unsigned ix) break; } } - char*type = ivl_signal_signed(sig) ? "/s" : ""; + const char*type = ivl_signal_signed(sig) ? "/s" : ""; fprintf(vvp_out, " %%ix/getv%s %u, v%p_%u;\n", type, ix, sig, word); break; diff --git a/tgt-vvp/vvp_process.c b/tgt-vvp/vvp_process.c index 665474d82..3eafef9f3 100644 --- a/tgt-vvp/vvp_process.c +++ b/tgt-vvp/vvp_process.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001-2010 Stephen Williams (steve@icarus.com) + * Copyright (c) 2001-2011 Stephen Williams (steve@icarus.com) * * This source code is free software; you can redistribute it * and/or modify it in source code form under the terms of the GNU @@ -723,7 +723,7 @@ static int show_stmt_assign_nb(ivl_statement_t net) if (cnt) { int count_index = allocate_word(); - char*type = ivl_expr_signed(cnt) ? "/s" : ""; + const char*type = ivl_expr_signed(cnt) ? "/s" : ""; draw_eval_expr_into_integer(cnt, count_index); fprintf(vvp_out, " %%evctl%s %s, %d;\n", type, name, count_index); @@ -1634,7 +1634,7 @@ static int show_stmt_repeat(ivl_statement_t net, ivl_scope_t sscope) unsigned lab_top = local_count++, lab_out = local_count++; ivl_expr_t expr = ivl_stmt_cond_expr(net); struct vector_info cnt = draw_eval_expr(expr, 0); - char *sign = ivl_expr_signed(expr) ? "s" : "u"; + const char *sign = ivl_expr_signed(expr) ? "s" : "u"; /* Test that 0 < expr */ fprintf(vvp_out, "T_%u.%u %%cmp/%s 0, %u, %u;\n", thread_count, diff --git a/vpi/lxt_write.c b/vpi/lxt_write.c index 3ed778cc5..9731363e9 100644 --- a/vpi/lxt_write.c +++ b/vpi/lxt_write.c @@ -996,8 +996,8 @@ if(rgh) lt_recurse_dictionary_free(lt, rgh); static int lt_dictval_compare(const void *v1, const void *v2) { -dslxt_Tree *s1 = *(dslxt_Tree **)v1; -dslxt_Tree *s2 = *(dslxt_Tree **)v2; +const dslxt_Tree *s1 = *(const dslxt_Tree * const *)v1; +const dslxt_Tree *s2 = *(const dslxt_Tree * const *)v2; if(s1->val > s2->val) return(1); else return(-1); /* they're *never* equal */ } diff --git a/vpi/sys_display.c b/vpi/sys_display.c index 090362f53..1ab395e63 100644 --- a/vpi/sys_display.c +++ b/vpi/sys_display.c @@ -879,6 +879,7 @@ static unsigned int get_numeric(char **rtn, struct strobe_cb_info *info, static char *get_display(unsigned int *rtnsz, struct strobe_cb_info *info) { char *result, *fmt, *rtn, *func_name; + const char *cresult; s_vpi_value value; unsigned int idx, size, width; char buf[256]; @@ -999,10 +1000,10 @@ static char *get_display(unsigned int *rtnsz, struct strobe_cb_info *info) vpi_printf("WARNING: %s:%d: unknown argument type (%s) given to %s!\n", info->filename, info->lineno, vpi_get_str(vpiType, item), info->name); - result = ""; - width = strlen(result); + cresult = ""; + width = strlen(cresult); rtn = realloc(rtn, (size+width)*sizeof(char)); - memcpy(rtn+size-1, result, width); + memcpy(rtn+size-1, cresult, width); break; } size += width; @@ -1756,9 +1757,9 @@ static PLI_INT32 sys_timeformat_calltf(PLI_BYTE8*xx) return 0; } -static char *pts_convert(int value) +static const char *pts_convert(int value) { - char *string; + const char *string; switch (value) { case 0: string = "1s"; break; case -1: string = "100ms"; break; diff --git a/vpi/sys_priv.c b/vpi/sys_priv.c index f6846e45b..26f33b257 100644 --- a/vpi/sys_priv.c +++ b/vpi/sys_priv.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2010 Stephen Williams (steve@icarus.com) + * Copyright (c) 2003-2011 Stephen Williams (steve@icarus.com) * * This source code is free software; you can redistribute it * and/or modify it in source code form under the terms of the GNU @@ -102,7 +102,7 @@ char *get_filename(vpiHandle callh, char *name, vpiHandle file) } void check_for_extra_args(vpiHandle argv, vpiHandle callh, char *name, - char *arg_str, unsigned opt) + const char *arg_str, unsigned opt) { /* Check that there are no extra arguments. */ if (vpi_scan(argv) != 0) { diff --git a/vpi/sys_priv.h b/vpi/sys_priv.h index 3a13d1851..a7814fcdf 100644 --- a/vpi/sys_priv.h +++ b/vpi/sys_priv.h @@ -1,7 +1,7 @@ #ifndef __vpi_sys_priv_H #define __vpi_sys_priv_H /* - * Copyright (c) 2002-2010 Stephen Williams (steve@icarus.com) + * Copyright (c) 2002-2011 Stephen Williams (steve@icarus.com) * * This source code is free software; you can redistribute it * and/or modify it in source code form under the terms of the GNU @@ -38,8 +38,8 @@ extern PLI_UINT64 timerec_to_time64(const struct t_vpi_time*timerec); extern char *as_escaped(char *arg); extern char *get_filename(vpiHandle callh, char *name, vpiHandle file); -extern void check_for_extra_args(vpiHandle argv, vpiHandle callh, - char *name, char *arg_str, unsigned opt); +extern void check_for_extra_args(vpiHandle argv, vpiHandle callh, char *name, + const char *arg_str, unsigned opt); struct timeformat_info_s { int units; diff --git a/vpi/sys_table.c b/vpi/sys_table.c index 448600384..aa1b72c78 100644 --- a/vpi/sys_table.c +++ b/vpi/sys_table.c @@ -60,7 +60,7 @@ static void sys_lxt_or_vcd_register() int idx; struct t_vpi_vlog_info vlog_info; - char*dumper; + const char*dumper; /* Get the dumper of choice from the IVERILOG_DUMPER environment variable. */ diff --git a/vpi/sys_vcd.c b/vpi/sys_vcd.c index 29ad91ac7..800d47488 100644 --- a/vpi/sys_vcd.c +++ b/vpi/sys_vcd.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999-2010 Stephen Williams (steve@icarus.com) + * Copyright (c) 1999-2011 Stephen Williams (steve@icarus.com) * * This source code is free software; you can redistribute it * and/or modify it in source code form under the terms of the GNU @@ -710,7 +710,7 @@ static int draw_scope(vpiHandle item, vpiHandle callh) { int depth; const char *name; - char *type; + const char *type; vpiHandle scope = vpi_handle(vpiScope, item); if (!scope) return 0;