diff --git a/discipline.h b/discipline.h index 9cfc4294b..0726710a9 100644 --- a/discipline.h +++ b/discipline.h @@ -1,7 +1,7 @@ #ifndef __discipline_H #define __discipline_H /* - * Copyright (c) 2008 Stephen Williams (steve@icarus.com) + * Copyright (c) 2008-2010 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 @@ -55,8 +55,8 @@ class ivl_discipline_s : public LineInfo { perm_string name() const { return name_; } ivl_dis_domain_t domain() const { return domain_; } - const ivl_nature_t potential() const { return potential_; } - const ivl_nature_t flow() const { return flow_; } + ivl_nature_t potential() const { return potential_; } + ivl_nature_t flow() const { return flow_; } private: perm_string name_; diff --git a/tgt-vvp/draw_mux.c b/tgt-vvp/draw_mux.c index 68ae8cf2b..234834900 100644 --- a/tgt-vvp/draw_mux.c +++ b/tgt-vvp/draw_mux.c @@ -105,12 +105,13 @@ static void draw_lpm_mux_ab(ivl_lpm_t net, const char*muxz) static void draw_lpm_mux_nest(ivl_lpm_t net, const char*muxz) { - int idx, level; + unsigned idx, level; unsigned width = ivl_lpm_width(net); unsigned swidth = ivl_lpm_selects(net); char*select_input; - assert(ivl_lpm_size(net) == (1 << swidth)); + assert(swidth < sizeof(unsigned)); + assert(ivl_lpm_size(net) == (1U << swidth)); select_input = strdup(draw_net_input(ivl_lpm_select(net))); diff --git a/tgt-vvp/draw_net_input.c b/tgt-vvp/draw_net_input.c index d0bdbfcbb..b0d72afff 100644 --- a/tgt-vvp/draw_net_input.c +++ b/tgt-vvp/draw_net_input.c @@ -94,7 +94,8 @@ static char* draw_C4_to_string(ivl_net_const_t cptr) for (idx = 0 ; idx < ivl_const_width(cptr) ; idx += 1) { char bitchar = bits[ivl_const_width(cptr)-idx-1]; *dp++ = bitchar; - assert((dp - result) < result_len); + assert(dp >= result); + assert((unsigned)(dp - result) < result_len); } strcpy(dp, ">"); @@ -144,7 +145,8 @@ static char* draw_C8_to_string(ivl_net_const_t cptr, assert(0); break; } - assert(dp - result < nresult); + assert(dp >= result); + assert((unsigned)(dp - result) < nresult); } strcpy(dp, ">"); @@ -260,7 +262,8 @@ static char* draw_net_input_drive(ivl_nexus_t nex, ivl_nexus_ptr_t nptr) dp += ivl_logic_width(lptr); *dp++ = '>'; *dp = 0; - assert((dp-result) <= result_len); + assert(dp >= result); + assert((unsigned)(dp - result) <= result_len); return result; } else { char val[4]; @@ -279,7 +282,8 @@ static char* draw_net_input_drive(ivl_nexus_t nex, ivl_nexus_ptr_t nptr) dp += 3*ivl_logic_width(lptr); *dp++ = '>'; *dp = 0; - assert((dp-result) <= result_len); + assert(dp >= result); + assert((unsigned)(dp - result) <= result_len); return result; } } @@ -297,7 +301,8 @@ static char* draw_net_input_drive(ivl_nexus_t nex, ivl_nexus_ptr_t nptr) dp += ivl_logic_width(lptr); *dp++ = '>'; *dp = 0; - assert((dp-result) <= result_len); + assert(dp >= result); + assert((unsigned)(dp - result) <= result_len); } else { char val[4]; @@ -316,7 +321,8 @@ static char* draw_net_input_drive(ivl_nexus_t nex, ivl_nexus_ptr_t nptr) dp += 3*ivl_logic_width(lptr); *dp++ = '>'; *dp = 0; - assert((dp-result) <= result_len); + assert(dp >= result); + assert((unsigned)(dp - result) <= result_len); } diff --git a/tgt-vvp/draw_ufunc.c b/tgt-vvp/draw_ufunc.c index 1b30e9039..8e0f8fcfa 100644 --- a/tgt-vvp/draw_ufunc.c +++ b/tgt-vvp/draw_ufunc.c @@ -156,7 +156,7 @@ int draw_ufunc_real(ivl_expr_t expr) ivl_scope_t def = ivl_expr_def(expr); ivl_signal_t retval = ivl_scope_port(def, 0); int res = 0; - int idx; + unsigned idx; /* If this is an automatic function, allocate the local storage. */ if (ivl_scope_is_auto(def)) { diff --git a/tgt-vvp/draw_vpi.c b/tgt-vvp/draw_vpi.c index 0a2543cc0..ccf4db9da 100644 --- a/tgt-vvp/draw_vpi.c +++ b/tgt-vvp/draw_vpi.c @@ -282,7 +282,8 @@ static void draw_vpi_taskfunc_args(const char*call_string, for (bit = wid ; bit > 0 ; bit -= 1) *dp++ = bits[bit-1]; *dp++ = 0; - assert(dp - buffer <= sizeof buffer); + assert(dp >= buffer); + assert((unsigned)(dp - buffer) <= sizeof buffer); } args[idx].text = strdup(buffer); continue; diff --git a/tgt-vvp/eval_expr.c b/tgt-vvp/eval_expr.c index 335fa7e59..c0ed35ff2 100644 --- a/tgt-vvp/eval_expr.c +++ b/tgt-vvp/eval_expr.c @@ -929,9 +929,9 @@ static struct vector_info draw_binary_expr_le(ivl_expr_t expr, case 'G': rv = draw_eval_expr_wid(re, owid, STUFF_OK_XZ); if (number_is_immediate(le,16,0) && !number_is_unknown(le)) { - unsigned imm = get_number_immediate(le); + long imm = get_number_immediate(le); assert(imm >= 0); - fprintf(vvp_out, " %%cmpi/%c %u, %u, %u;\n", s_flag, + fprintf(vvp_out, " %%cmpi/%c %u, %ld, %u;\n", s_flag, rv.base, imm, rv.wid); } else { lv = draw_eval_expr_wid(le, owid, STUFF_OK_XZ); @@ -945,9 +945,9 @@ static struct vector_info draw_binary_expr_le(ivl_expr_t expr, case 'L': lv = draw_eval_expr_wid(le, owid, STUFF_OK_XZ); if (number_is_immediate(re,16,0) && !number_is_unknown(re)) { - unsigned imm = get_number_immediate(re); + long imm = get_number_immediate(re); assert(imm >= 0); - fprintf(vvp_out, " %%cmpi/%c %u, %u, %u;\n", s_flag, + fprintf(vvp_out, " %%cmpi/%c %u, %ld, %u;\n", s_flag, lv.base, imm, lv.wid); } else { rv = draw_eval_expr_wid(re, owid, STUFF_OK_XZ); @@ -961,9 +961,9 @@ static struct vector_info draw_binary_expr_le(ivl_expr_t expr, case '<': lv = draw_eval_expr_wid(le, owid, STUFF_OK_XZ); if (number_is_immediate(re,16,0) && !number_is_unknown(re)) { - unsigned imm = get_number_immediate(re); + long imm = get_number_immediate(re); assert(imm >= 0); - fprintf(vvp_out, " %%cmpi/%c %u, %u, %u;\n", s_flag, + fprintf(vvp_out, " %%cmpi/%c %u, %ld, %u;\n", s_flag, lv.base, imm, lv.wid); } else { rv = draw_eval_expr_wid(re, owid, STUFF_OK_XZ); @@ -976,9 +976,9 @@ static struct vector_info draw_binary_expr_le(ivl_expr_t expr, case '>': rv = draw_eval_expr_wid(re, owid, STUFF_OK_XZ); if (number_is_immediate(le,16,0) && !number_is_unknown(le)) { - unsigned imm = get_number_immediate(le); + long imm = get_number_immediate(le); assert(imm >= 0); - fprintf(vvp_out, " %%cmpi/%c %u, %u, %u;\n", s_flag, + fprintf(vvp_out, " %%cmpi/%c %u, %ld, %u;\n", s_flag, rv.base, imm, rv.wid); } else { lv = draw_eval_expr_wid(le, owid, STUFF_OK_XZ); @@ -2609,7 +2609,7 @@ static struct vector_info draw_select_unsized_literal(ivl_expr_t expr, fprintf(vvp_out, " %%mov %u, %u, %u; Pad sub-expression to match width\n", res.base, subv.base, subv.wid); if (ivl_expr_signed(sube)) { - int idx; + unsigned idx; for (idx = subv.wid ; idx < res.wid ; idx += 1) { fprintf(vvp_out, " %%mov %u, %u, 1;\n", res.base+idx, subv.base+subv.wid-1); diff --git a/tgt-vvp/modpath.c b/tgt-vvp/modpath.c index c26087e5e..e65f629e0 100644 --- a/tgt-vvp/modpath.c +++ b/tgt-vvp/modpath.c @@ -28,7 +28,7 @@ static ivl_signal_t find_path_source_port(ivl_delaypath_t path) { - int idx; + unsigned idx; ivl_nexus_t nex = ivl_path_source(path); ivl_scope_t path_scope = ivl_path_scope(path); diff --git a/tgt-vvp/vvp_scope.c b/tgt-vvp/vvp_scope.c index da38e9647..2c1836c83 100644 --- a/tgt-vvp/vvp_scope.c +++ b/tgt-vvp/vvp_scope.c @@ -929,14 +929,15 @@ static void draw_logic_in_scope(ivl_net_logic_t lptr) /* Get all the input label that I will use for parameters to the functor that I create later. */ ninp = ivl_logic_pins(lptr) - 1; + assert(ninp >= 0); input_strings = calloc(ninp, sizeof(char*)); - for (pdx = 0 ; pdx < ninp ; pdx += 1) + for (pdx = 0 ; pdx < (unsigned)ninp ; pdx += 1) input_strings[pdx] = draw_net_input(ivl_logic_pin(lptr, pdx+1)); level = 0; while (ninp) { - int inst; - for (inst = 0; inst < ninp; inst += 4) { + unsigned inst; + for (inst = 0; inst < (unsigned)ninp; inst += 4) { if (ninp > 4) fprintf(vvp_out, "L_%p/%d/%d .functor %s %u", lptr, level, inst, lcasc, vector_width); @@ -949,7 +950,7 @@ static void draw_logic_in_scope(ivl_net_logic_t lptr) fprintf(vvp_out, " [%u %u]", str0, str1); } - for (pdx = inst; pdx < ninp && pdx < inst+4 ; pdx += 1) { + for (pdx = inst; pdx < (unsigned)ninp && pdx < inst+4 ; pdx += 1) { if (level) { fprintf(vvp_out, ", L_%p/%d/%d", lptr, level - 1, pdx*4); diff --git a/vpi/sys_display.c b/vpi/sys_display.c index 2ce1dfde5..bc7773033 100644 --- a/vpi/sys_display.c +++ b/vpi/sys_display.c @@ -265,7 +265,8 @@ static unsigned int get_format_char(char **rtn, int ljust, int plus, unsigned int ini_size = 512; /* The initial size of the buffer. */ /* Make sure the width fits in the initial buffer. */ - if (width+1 > ini_size) ini_size = width + 1; + assert(width >= -1); + if ((unsigned int)(width+1) > ini_size) ini_size = width + 1; /* The default return value is the full format. */ result = malloc(ini_size*sizeof(char)); diff --git a/vpi/sys_fileio.c b/vpi/sys_fileio.c index eaf688663..0b13f4bb8 100644 --- a/vpi/sys_fileio.c +++ b/vpi/sys_fileio.c @@ -545,7 +545,7 @@ static unsigned fread_word(FILE *fp, vpiHandle word, * my local vector. */ val.format = vpiVectorVal; vpi_get_value(word, &val); - for (bidx = 0; bidx < words; bidx += 1) { + for (bidx = 0; (unsigned)bidx < words; bidx += 1) { vector[bidx].aval = val.value.vector[bidx].aval; vector[bidx].bval = val.value.vector[bidx].bval; } @@ -682,10 +682,11 @@ static PLI_INT32 sys_fread_calltf(PLI_BYTE8*name) vector = calloc(words, sizeof(s_vpi_vecval)); bpe = (width+7)/8; + assert(count >= 0); if (is_mem) { unsigned idx; rtn = 0; - for (idx = 0; idx < count; idx += 1) { + for (idx = 0; idx < (unsigned)count; idx += 1) { vpiHandle word; word = vpi_handle_by_index(mem_reg, start+(signed)idx); rtn += fread_word(fp, word, words, bpe, vector); diff --git a/vpi/sys_sdf.c b/vpi/sys_sdf.c index 048c16046..0c8c02760 100644 --- a/vpi/sys_sdf.c +++ b/vpi/sys_sdf.c @@ -71,7 +71,8 @@ void sdf_select_instance(const char*celltype, const char*cellinst) const char*src = cellinst; const char*dp; while ( (dp=strchr(src, '.')) ) { - int len = dp - src; + unsigned len = dp - src; + assert(dp >= src); assert(len < sizeof buffer); strncpy(buffer, src, len); buffer[len] = 0;