gem5  v20.1.0.0
match.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019 The Regents of the University of California
3  * Copyright (c) 2004-2005 The Regents of The University of Michigan
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met: redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer;
10  * redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution;
13  * neither the name of the copyright holders nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #include "base/match.hh"
31 
32 #include "base/str.hh"
33 
34 using namespace std;
35 
37 {
38 }
39 
40 ObjectMatch::ObjectMatch(const string &expr)
41 {
42  setExpression(expr);
43 }
44 
45 void
47 {
48  tokens.insert(tokens.end(), other.tokens.begin(), other.tokens.end());
49 }
50 
51 void
52 ObjectMatch::setExpression(const string &expr)
53 {
54  tokens.resize(1);
55  tokenize(tokens[0], expr, '.');
56 }
57 
58 void
60 {
61  if (expr.empty()) {
62  tokens.resize(0);
63  } else {
64  tokens.resize(expr.size());
65  for (vector<string>::size_type i = 0; i < expr.size(); ++i)
66  tokenize(tokens[i], expr[i], '.');
67  }
68 }
69 
74 bool
75 ObjectMatch::domatch(const string &name) const
76 {
77  vector<string> name_tokens;
78  tokenize(name_tokens, name, '.');
79  int ntsize = name_tokens.size();
80 
81  int num_expr = tokens.size();
82  for (int i = 0; i < num_expr; ++i) {
83  const vector<string> &token = tokens[i];
84  int jstop = token.size();
85 
86  bool match = true;
87  for (int j = 0; j < jstop; ++j) {
88  if (j >= ntsize)
89  break;
90 
91  const string &var = token[j];
92  if (var != "*" && var != name_tokens[j]) {
93  match = false;
94  break;
95  }
96  }
97 
98  if (match)
99  return true;
100  }
101 
102  return false;
103 }
104 
107 {
109  for (const auto &expression: tokens) {
111  to_add.insert(to_add.end(), expression.begin(), expression.end());
112  to_return.push_back(to_add);
113  }
114 
115  return to_return;
116 }
117 
tokenize
void tokenize(vector< string > &v, const string &s, char token, bool ignore)
Definition: str.cc:67
ArmISA::i
Bitfield< 7 > i
Definition: miscregs_types.hh:63
ObjectMatch::ObjectMatch
ObjectMatch()
Definition: match.cc:36
std::vector< string >
str.hh
ObjectMatch::domatch
bool domatch(const std::string &name) const
Definition: match.cc:75
ArmISA::j
Bitfield< 24 > j
Definition: miscregs_types.hh:54
ObjectMatch::tokens
std::vector< std::vector< std::string > > tokens
Definition: match.hh:56
match.hh
name
const std::string & name()
Definition: trace.cc:50
ObjectMatch::setExpression
void setExpression(const std::string &expression)
std
Overload hash function for BasicBlockRange type.
Definition: vec_reg.hh:587
ObjectMatch::add
void add(const ObjectMatch &other)
Definition: match.cc:46
ObjectMatch
ObjectMatch contains a vector of expressions.
Definition: match.hh:53
ObjectMatch::getExpressions
std::vector< std::vector< std::string > > getExpressions()
Definition: match.cc:106

Generated on Wed Sep 30 2020 14:02:07 for gem5 by doxygen 1.8.17