Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion regression/verilog/modules/inout_and_reg.desc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
CORE
inout_and_reg.v

^file .* line 4: symbol `some_var' is declared both as input and as register$
^file .* line 4: variable `some_var' is already declared, at file .* line 3$
^EXIT=2$
^SIGNAL=0$
--
2 changes: 1 addition & 1 deletion regression/verilog/modules/input_and_reg.desc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
CORE
input_and_reg.v

^file .* line 4: symbol `some_var' is declared both as input and as register$
^file .* line 4: variable `some_var' is already declared, at file .* line 3$
^EXIT=2$
^SIGNAL=0$
--
4 changes: 2 additions & 2 deletions regression/verilog/modules/wire_and_reg.desc
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
KNOWNBUG
CORE
wire_and_reg.v

^file .* line 4: variable `some_var' is already declared, at file .* line 3$
^EXIT=2$
^SIGNAL=0$
--
--
This should be errored, as some_var must not be both wire and reg.
32 changes: 15 additions & 17 deletions src/verilog/verilog_elaborate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -485,34 +485,32 @@ void verilog_typecheckt::collect_symbols(const verilog_declt &decl)

if(result == nullptr)
{
// fresh identifier
symbol_table.add(symbol);
}
else
{
symbolt &osymbol = *result;

if(osymbol.type.id() == ID_code)
// we allow re-declaration if the original symbol
// is an output (not: an input/output).
if(osymbol.is_output && !osymbol.is_input)
{
throw errort().with_location(decl.source_location())
<< "symbol `" << symbol.base_name << "' is already declared";
}
// The type isn't required to match.
// We'll make it bigger, if need be.
if(symbol.type != osymbol.type)
{
if(get_width(symbol.type) > get_width(osymbol.type))
osymbol.type = symbol.type;
}

if(symbol.type != osymbol.type)
{
if(get_width(symbol.type) > get_width(osymbol.type))
osymbol.type = symbol.type;
osymbol.is_state_var = true;
}

osymbol.is_input = symbol.is_input || osymbol.is_input;
osymbol.is_output = symbol.is_output || osymbol.is_output;
osymbol.is_state_var = symbol.is_state_var || osymbol.is_state_var;

// a register can't be an input as well
if(osymbol.is_input && osymbol.is_state_var)
else
{
throw errort().with_location(decl.source_location())
<< "symbol `" << symbol.base_name
<< "' is declared both as input and as register";
<< "variable `" << symbol.base_name << "' is already declared, at "
<< osymbol.location;
}
}

Expand Down