Skip to content

Commit

Permalink
Verilog: extract scope data structure from parser
Browse files Browse the repository at this point in the history
This extracts the scope data structure from the parser class into a separate
file, as the scopes need to be preserved until all Verilog parsing is
finished.
  • Loading branch information
kroening committed Jan 28, 2025
1 parent 7dfd0f2 commit 2e75751
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/verilog/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ SRC = aval_bval_encoding.cpp \
verilog_preprocessor.cpp \
verilog_preprocessor_lex.yy.cpp \
verilog_preprocessor_tokenizer.cpp \
verilog_scope.cpp \
verilog_simplifier.cpp \
verilog_standard.cpp \
verilog_symbol_table.cpp \
Expand Down
1 change: 1 addition & 0 deletions src/verilog/verilog_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Author: Daniel Kroening, [email protected]
#include <util/parser.h>

#include "verilog_parse_tree.h"
#include "verilog_scope.h"
#include "verilog_standard.h"

#include <map>
Expand Down
9 changes: 9 additions & 0 deletions src/verilog/verilog_scope.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*******************************************************************\
Module: Verilog Scope
Author: Daniel Kroening, [email protected]
\*******************************************************************/

#include "verilog_scope.h"
54 changes: 54 additions & 0 deletions src/verilog/verilog_scope.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*******************************************************************\
Module: Verilog Scopes
Author: Daniel Kroening, [email protected]
\*******************************************************************/

#ifndef CPROVER_VERILOG_SCOPE_H
#define CPROVER_VERILOG_SCOPE_H

#include <util/irep.h>

#include <map>

// parser scopes and identifiers
struct scopet
{
scopet() : parent(nullptr), prefix("Verilog::")
{
}

explicit scopet(
irep_idt _base_name,
const std::string &separator,
scopet *_parent)
: parent(_parent),
__base_name(_base_name),
prefix(id2string(_parent->prefix) + id2string(_base_name) + separator)
{
}

scopet *parent = nullptr;
bool is_type = false;
irep_idt __base_name;
std::string prefix;

irep_idt identifier() const
{
PRECONDITION(parent != nullptr);
return parent->prefix + id2string(__base_name);
}

const irep_idt &base_name() const
{
return __base_name;
}

// sub-scopes
using scope_mapt = std::map<irep_idt, scopet>;
scope_mapt scope_map;
};

#endif

0 comments on commit 2e75751

Please sign in to comment.