forked from chipsalliance/verible
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodule.h
119 lines (97 loc) · 4.97 KB
/
module.h
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// Copyright 2017-2020 The Verible Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// This unit provides helper functions that pertain to SystemVerilog
// module declaration nodes in the parser-generated concrete syntax tree.
#ifndef VERIBLE_VERILOG_CST_MODULE_H_
#define VERIBLE_VERILOG_CST_MODULE_H_
#include <vector>
#include "common/analysis/syntax_tree_search.h"
#include "common/text/concrete_syntax_tree.h"
#include "common/text/symbol.h"
#include "common/text/token_info.h"
#include "common/text/tree_utils.h"
#include "verilog/CST/verilog_nonterminals.h"
#include "verilog/parser/verilog_token_enum.h"
namespace verilog {
template <typename T0, typename T1, typename T2, typename T3, typename T4,
typename T5, typename T6, typename T7>
verible::SymbolPtr MakeModuleHeader(T0&& keyword, T1&& lifetime, T2&& id,
T3&& imports, T4&& parameters, T5&& ports,
T6&& attribute, T7&& semi) {
verible::SymbolCastToLeaf(*keyword);
if (lifetime != nullptr) verible::SymbolCastToLeaf(*lifetime);
verible::SymbolCastToLeaf(*id); // SymbolIdentifier or other identifier
verible::CheckOptionalSymbolAsNode(imports, NodeEnum::kPackageImportList);
verible::CheckOptionalSymbolAsNode(parameters,
NodeEnum::kFormalParameterListDeclaration);
verible::CheckOptionalSymbolAsNode(ports, NodeEnum::kParenGroup);
verible::CheckOptionalSymbolAsNode(attribute,
NodeEnum::kModuleAttributeForeign);
ExpectString(semi, ";");
return verible::MakeTaggedNode(
NodeEnum::kModuleHeader, std::forward<T0>(keyword),
std::forward<T1>(lifetime), std::forward<T2>(id),
std::forward<T3>(imports), std::forward<T4>(parameters),
std::forward<T5>(ports), std::forward<T6>(attribute),
std::forward<T7>(semi));
}
// Find all module declarations.
std::vector<verible::TreeSearchMatch> FindAllModuleDeclarations(
const verible::Symbol&);
// Find all module headers.
std::vector<verible::TreeSearchMatch> FindAllModuleHeaders(
const verible::Symbol&);
// Find all interface declarations.
std::vector<verible::TreeSearchMatch> FindAllInterfaceDeclarations(
const verible::Symbol&);
// Find all program declarations.
std::vector<verible::TreeSearchMatch> FindAllProgramDeclarations(
const verible::Symbol& root);
// Returns the full header of a module (params, ports, etc...).
// Works also with interfaces and programs.
const verible::SyntaxTreeNode* GetModuleHeader(const verible::Symbol&);
// Returns the full header of an interface (params, ports, etc...).
const verible::SyntaxTreeNode* GetInterfaceHeader(const verible::Symbol&);
// Extract the subnode of a module declaration that is the module name or
// nullptr if not found.
const verible::SyntaxTreeLeaf* GetModuleName(const verible::Symbol&);
// Extract the subnode of an interface declaration that is the module name.
const verible::TokenInfo* GetInterfaceNameToken(const verible::Symbol&);
// Returns the node spanning the module's port paren group, or nullptr.
// e.g. from "module foo(input x); endmodule", this returns the node that spans
// "(input x)", including parentheses.
const verible::SyntaxTreeNode* GetModulePortParenGroup(
const verible::Symbol& module_declaration);
// Returns the node spanning module's port declarations list, or nullptr.
// e.g. from "module foo(input x); endmodule", this returns the node that spans
// PortDescriptionList
const verible::SyntaxTreeNode* GetModulePortDeclarationList(
const verible::Symbol& module_declaration);
// Returns module name leaf after endmodule.
// e.g. from "module foo(); endmodule: foo" returns the second "foo".
const verible::SyntaxTreeLeaf* GetModuleEndLabel(const verible::Symbol&);
// Returns the node spanning module's Item list.
const verible::SyntaxTreeNode* GetModuleItemList(
const verible::Symbol& module_declaration);
// Extract the subnode of a param declaration list from module decalration.
// e.g module m#(parameter x = 2) return the node spanning "#(parameter x = 2)".
const verible::SyntaxTreeNode* GetParamDeclarationListFromModuleDeclaration(
const verible::Symbol&);
// Extract the subnode of a param declaration list from interface decalration.
// e.g interface m#(parameter x = 2) return the node spanning "#(parameter x =
// 2)".
const verible::SyntaxTreeNode* GetParamDeclarationListFromInterfaceDeclaration(
const verible::Symbol&);
} // namespace verilog
#endif // VERIBLE_VERILOG_CST_MODULE_H_