forked from chipsalliance/verible
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparameters.h
142 lines (115 loc) · 5.64 KB
/
parameters.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// 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.
#ifndef VERIBLE_VERILOG_CST_PARAMETERS_H_
#define VERIBLE_VERILOG_CST_PARAMETERS_H_
// See comment at the top
// verilog/CST/verilog_treebuilder_utils.h that explains use
// of std::forward in Make* helper functions.
#include <utility>
#include <vector>
#include "absl/strings/string_view.h"
#include "common/analysis/syntax_tree_search.h"
#include "common/text/concrete_syntax_leaf.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 "common/util/logging.h"
#include "verilog/CST/verilog_nonterminals.h"
#include "verilog/parser/verilog_token_enum.h"
namespace verilog {
// Creates a node tagged kParamType.
// From "parameter type [dim] id [dim] = value;",
// this node spans "type [dim] id [dim]."
template <typename T0, typename T1, typename T2, typename T3>
verible::SymbolPtr MakeParamTypeDeclaration(T0&& type_info,
T1&& packed_dimensions,
T2&& identifier,
T3&& unpacked_dimensions) {
CHECK(verible::SymbolCastToNode(*ABSL_DIE_IF_NULL(type_info))
.MatchesTag(NodeEnum::kTypeInfo));
return verible::MakeTaggedNode(
NodeEnum::kParamType, std::forward<T0>(type_info),
std::forward<T1>(packed_dimensions), std::forward<T2>(identifier),
std::forward<T3>(unpacked_dimensions));
}
// Creates a node tagged kTypeInfo, which holds the parameter type information.
template <typename T0, typename T1, typename T2>
verible::SymbolPtr MakeTypeInfoNode(T0&& primitive_type, T1&& signed_unsigned,
T2&& user_defined_type) {
return verible::MakeTaggedNode(
NodeEnum::kTypeInfo, std::forward<T0>(primitive_type),
std::forward<T1>(signed_unsigned), std::forward<T2>(user_defined_type));
}
// Finds all parameter/localparam declarations.
std::vector<verible::TreeSearchMatch> FindAllParamDeclarations(
const verible::Symbol&);
// Finds all nodes tagged with kParamByName.
std::vector<verible::TreeSearchMatch> FindAllNamedParams(
const verible::Symbol&);
// Returns the token_enum of the parameter keyword from the node
// kParamDeclaration (either TK_parameter or TK_localparam).
verilog_tokentype GetParamKeyword(const verible::Symbol&);
// Returns a pointer to either TK_type or kParamType node, which holds the param
// type, id, and dimensions info for that parameter.
const verible::Symbol* GetParamTypeSymbol(const verible::Symbol&);
// Returns a pointer to the symbol holding the node kTypeInfo under the node
// kParamDeclaration.
const verible::Symbol* GetParamTypeInfoSymbol(const verible::Symbol&);
// Get right-hand side of a parameter assignment expression.
const verible::Symbol* GetParamAssignExpression(const verible::Symbol& symbol);
// Returns the token of the declared parameter.
const verible::TokenInfo* GetParameterNameToken(const verible::Symbol&);
// Returns all tokens for a parameter declaration.
std::vector<const verible::TokenInfo*> GetAllParameterNameTokens(
const verible::Symbol&);
// Get the token info for a given kParameterAssign node symbol
const verible::TokenInfo* GetAssignedParameterNameToken(
const verible::Symbol& symbol);
// Get the symbols for all kParameterAssign nodes
std::vector<const verible::Symbol*> GetAllAssignedParameterSymbols(
const verible::Symbol& root);
// Returns the token of the SymbolIdentifier from the node kParamDeclaration.
// Used specifically for 'parameter type' declarations.
const verible::TokenInfo* GetSymbolIdentifierFromParamDeclaration(
const verible::Symbol&);
// Returns true if the parameter is a parameter type declaration from the node
// kParamDeclaration.
bool IsParamTypeDeclaration(const verible::Symbol&);
// Returns a pointer to the symbol holding the node kTypeAssignment under the
// node kParamDeclaration.
const verible::SyntaxTreeNode* GetTypeAssignmentFromParamDeclaration(
const verible::Symbol&);
// Returns a pointer to the identifier leaf holding the SymbolIdentifier under
// the node kTypeAssignment.
const verible::SyntaxTreeLeaf* GetIdentifierLeafFromTypeAssignment(
const verible::Symbol&);
// Returns a pointer to the expression node holding under the node
// kTypeAssignment.
// e.g from "class m(type x = y)" returns the node spanning "y".
const verible::SyntaxTreeNode* GetExpressionFromTypeAssignment(
const verible::Symbol&);
// Returns true if the node kTypeInfo is empty (all children are nullptr).
bool IsTypeInfoEmpty(const verible::Symbol&);
// Return the node spanning param name from a node tagged with kParamByName.
// e.g from "module_type #(.N(x))" return the leaf spanning "N".
const verible::SyntaxTreeLeaf* GetNamedParamFromActualParam(
const verible::Symbol&);
// Return the node spanning the paren group from a node tagged with
// kParamByName.
// e.g from "module_type #(.N(x))" return the leaf spanning "(x)".
const verible::SyntaxTreeNode* GetParenGroupFromActualParam(
const verible::Symbol&);
} // namespace verilog
#endif // VERIBLE_VERILOG_CST_PARAMETERS_H_