gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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  * Authors: Nathan Binkert
30  Bobby R. Bruce
31  */
32 
33 #include "base/match.hh"
34 
35 #include "base/str.hh"
36 
37 using namespace std;
38 
40 {
41 }
42 
43 ObjectMatch::ObjectMatch(const string &expr)
44 {
45  setExpression(expr);
46 }
47 
48 void
50 {
51  tokens.insert(tokens.end(), other.tokens.begin(), other.tokens.end());
52 }
53 
54 void
55 ObjectMatch::setExpression(const string &expr)
56 {
57  tokens.resize(1);
58  tokenize(tokens[0], expr, '.');
59 }
60 
61 void
63 {
64  if (expr.empty()) {
65  tokens.resize(0);
66  } else {
67  tokens.resize(expr.size());
68  for (vector<string>::size_type i = 0; i < expr.size(); ++i)
69  tokenize(tokens[i], expr[i], '.');
70  }
71 }
72 
77 bool
78 ObjectMatch::domatch(const string &name) const
79 {
80  vector<string> name_tokens;
81  tokenize(name_tokens, name, '.');
82  int ntsize = name_tokens.size();
83 
84  int num_expr = tokens.size();
85  for (int i = 0; i < num_expr; ++i) {
86  const vector<string> &token = tokens[i];
87  int jstop = token.size();
88 
89  bool match = true;
90  for (int j = 0; j < jstop; ++j) {
91  if (j >= ntsize)
92  break;
93 
94  const string &var = token[j];
95  if (var != "*" && var != name_tokens[j]) {
96  match = false;
97  break;
98  }
99  }
100 
101  if (match)
102  return true;
103  }
104 
105  return false;
106 }
107 
110 {
112  for (const auto &expression: tokens) {
114  to_add.insert(to_add.end(), expression.begin(), expression.end());
115  to_return.push_back(to_add);
116  }
117 
118  return to_return;
119 }
120 
const std::string & name()
Definition: trace.cc:54
Bitfield< 7 > i
std::vector< std::vector< std::string > > tokens
Definition: match.hh:59
std::vector< std::vector< std::string > > getExpressions()
Definition: match.cc:109
Overload hash function for BasicBlockRange type.
Definition: vec_reg.hh:586
ObjectMatch()
Definition: match.cc:39
void setExpression(const std::string &expression)
bool domatch(const std::string &name) const
Definition: match.cc:78
void add(const ObjectMatch &other)
Definition: match.cc:49
Bitfield< 24 > j
void tokenize(vector< string > &v, const string &s, char token, bool ignore)
Definition: str.cc:69
ObjectMatch contains a vector of expressions.
Definition: match.hh:56

Generated on Fri Feb 28 2020 16:26:58 for gem5 by doxygen 1.8.13