slicc: removed unused atomics code from StateMachine
[gem5.git] / src / mem / slicc / symbols / Transition.cc
1
2 /*
3 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
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 /*
31 * $Id$
32 *
33 * */
34
35 #include "mem/slicc/symbols/Transition.hh"
36 #include "mem/slicc/symbols/State.hh"
37 #include "mem/slicc/symbols/Event.hh"
38 #include "mem/slicc/symbols/Action.hh"
39 #include "mem/gems_common/util.hh"
40 #include "mem/slicc/symbols/Var.hh"
41
42 Transition::Transition(string state, string event, string nextState,
43 const Vector<string>& actionList,
44 const Location& location,
45 const Map<string, string>& pairMap)
46 : Symbol(state + "|" + event, location, pairMap)
47 {
48 m_state = state;
49 m_event = event;
50 m_nextState = nextState;
51 m_actionList = actionList;
52
53 // Ptrs are undefined at this point
54 m_statePtr = NULL;
55 m_eventPtr = NULL;
56 m_nextStatePtr = NULL;
57 m_actionPtrsValid = false;
58 }
59
60 void Transition::checkIdents(const Vector<State*>& states,
61 const Vector<Event*>& events,
62 const Vector<Action*>& actions)
63 {
64 m_statePtr = findIndex(states, m_state);
65 m_eventPtr = findIndex(events, m_event);
66 m_nextStatePtr = findIndex(states, m_nextState);
67
68 for(int i=0; i < m_actionList.size(); i++) {
69 Action* action_ptr = findIndex(actions, m_actionList[i]);
70 int size = action_ptr->getResources().keys().size();
71 for (int j=0; j < size; j++) {
72 Var* var_ptr = action_ptr->getResources().keys()[j];
73 if (var_ptr->getType()->cIdent() != "DNUCAStopTable") {
74 int num = atoi((action_ptr->getResources().lookup(var_ptr)).c_str());
75 if (m_resources.exist(var_ptr)) {
76 num += atoi((m_resources.lookup(var_ptr)).c_str());
77 }
78 m_resources.add(var_ptr, int_to_string(num));
79 } else {
80 m_resources.add(var_ptr, action_ptr->getResources().lookup(var_ptr));
81 }
82 }
83 m_actionPtrs.insertAtBottom(action_ptr);
84 }
85 m_actionPtrsValid = true;
86 }
87
88 const string& Transition::getStateShorthand() const
89 {
90 assert(m_statePtr != NULL);
91 return m_statePtr->getShorthand();
92 }
93
94 const string& Transition::getEventShorthand() const
95 {
96 assert(m_eventPtr != NULL);
97 return m_eventPtr->getShorthand();
98 }
99
100 const string& Transition::getNextStateShorthand() const
101 {
102 assert(m_nextStatePtr != NULL);
103 return m_nextStatePtr->getShorthand();
104 }
105
106 string Transition::getActionShorthands() const
107 {
108 assert(m_actionPtrsValid);
109 string str;
110 int numActions = m_actionPtrs.size();
111 for (int i=0; i<numActions; i++) {
112 str += m_actionPtrs[i]->getShorthand();
113 }
114 return str;
115 }
116
117 void Transition::print(ostream& out) const
118 {
119 out << "[Transition: ";
120 out << "(" << m_state;
121 if (m_statePtr != NULL) {
122 out << ":" << *m_statePtr;
123 }
124 out << ", " << m_event;
125 if (m_eventPtr != NULL) {
126 out << ":" << *m_eventPtr;
127 }
128 out << ") -> ";
129 out << m_nextState;
130 if (m_nextStatePtr != NULL) {
131 out << ":" << *m_nextStatePtr;
132 }
133 out << ", ";
134 out << m_actionList;
135 out << "]";
136 }
137
138 Event* Transition::findIndex(const Vector<Event*>& vec, string ident)
139 {
140 int size = vec.size();
141 for(int i=0; i<size; i++) {
142 if (ident == vec[i]->getIdent()) {
143 return vec[i];
144 }
145 }
146 error("Event not found: " + ident);
147 return NULL;
148 }
149
150 State* Transition::findIndex(const Vector<State*>& vec, string ident)
151 {
152 int size = vec.size();
153 for(int i=0; i<size; i++) {
154 if (ident == vec[i]->getIdent()) {
155 return vec[i];
156 }
157 }
158 error("State not found: " + ident);
159 return NULL;
160 }
161
162 Action* Transition::findIndex(const Vector<Action*>& vec, string ident)
163 {
164 int size = vec.size();
165 for(int i=0; i<size; i++) {
166 if (ident == vec[i]->getIdent()) {
167 return vec[i];
168 }
169 }
170 error("Action not found: " + ident);
171 return NULL;
172 }
173