-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathverilog_scope.cpp
78 lines (66 loc) · 2.26 KB
/
verilog_scope.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*******************************************************************\
Module: Verilog Scope
Author: Daniel Kroening, [email protected]
\*******************************************************************/
#include "verilog_scope.h"
#include "verilog_y.tab.h"
#include <ostream>
const verilog_scopet *verilog_scopest::lookup(irep_idt base_name) const
{
// we start from the current scope, and walk upwards to the root
auto scope = ¤t_scope();
while(scope != nullptr)
{
auto name_it = scope->scope_map.find(base_name);
if(name_it == scope->scope_map.end())
scope = scope->parent;
else
return &name_it->second; // found it
}
// not found, give up
return nullptr;
}
void verilog_scopet::print_rec(std::size_t indent, std::ostream &out) const
{
out << std::string(indent, ' ') << prefix << '\n';
for(auto &scope_it : scope_map)
scope_it.second.print_rec(indent + 2, out);
}
void verilog_scopest::enter_package_scope(irep_idt base_name)
{
// look in the global scope
auto name_it = top_scope.scope_map.find(base_name);
if(name_it == top_scope.scope_map.end())
enter_scope(current_scope());
else
enter_scope(name_it->second); // found it
}
unsigned verilog_scopest::identifier_token(irep_idt base_name) const
{
auto scope = lookup(base_name);
if(scope == nullptr)
{
return TOK_NON_TYPE_IDENTIFIER;
}
else
{
switch(scope->kind)
{
// clang-format off
case verilog_scopet::GLOBAL: return TOK_NON_TYPE_IDENTIFIER;
case verilog_scopet::FILE: return TOK_NON_TYPE_IDENTIFIER;
case verilog_scopet::PACKAGE: return TOK_PACKAGE_IDENTIFIER;
case verilog_scopet::MODULE: return TOK_NON_TYPE_IDENTIFIER;
case verilog_scopet::INTERFACE: return TOK_INTERFACE_IDENTIFIER;
case verilog_scopet::CLASS: return TOK_CLASS_IDENTIFIER;
case verilog_scopet::BLOCK: return TOK_NON_TYPE_IDENTIFIER;
case verilog_scopet::ENUM_NAME: return TOK_NON_TYPE_IDENTIFIER;
case verilog_scopet::TASK: return TOK_NON_TYPE_IDENTIFIER;
case verilog_scopet::FUNCTION: return TOK_NON_TYPE_IDENTIFIER;
case verilog_scopet::TYPEDEF: return TOK_TYPE_IDENTIFIER;
case verilog_scopet::OTHER: return TOK_NON_TYPE_IDENTIFIER;
// clang-format on
}
UNREACHABLE;
}
}