slicc: removed unused atomics code from StateMachine
[gem5.git] / src / mem / slicc / symbols / StateMachine.hh
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 #ifndef STATEMACHINE_H
36 #define STATEMACHINE_H
37
38 #include "mem/slicc/slicc_global.hh"
39 #include "mem/gems_common/Vector.hh"
40 #include "mem/gems_common/Map.hh"
41 #include "mem/slicc/symbols/Symbol.hh"
42 #include <list>
43
44 using namespace std;
45
46 class Transition;
47 class Event;
48 class State;
49 class Action;
50 class Var;
51 class Func;
52 class FormalParamAST;
53
54 class StateMachine : public Symbol {
55 public:
56 // Constructors
57 StateMachine(string ident, const Location& location, const Map<string, string>& pairs, Vector<FormalParamAST*>* config_parameters);
58
59 // Destructor
60 ~StateMachine();
61
62 // Public Methods
63
64 // Add items to the state machine
65 // void setMachine(string ident, const Map<string, string>& pairs);
66 void addState(State* state_ptr);
67 void addEvent(Event* event_ptr);
68 void addAction(Action* action_ptr);
69 void addTransition(Transition* trans_ptr);
70 void addInPort(Var* var) { m_in_ports.insertAtBottom(var); }
71 void addFunc(Func* func);
72 void addObj(Var* obj) { m_objs.insertAtBottom(obj); }
73
74 // Accessors to vectors
75 const State& getState(int index) const { return *m_states[index]; }
76 const Event& getEvent(int index) const { return *m_events[index]; }
77 const Action& getAction(int index) const { return *m_actions[index]; }
78 const Transition& getTransition(int index) const { return *m_transitions[index]; }
79 const Transition* getTransPtr(int stateIndex, int eventIndex) const;
80 const Var& getObject(int index) const { return *m_objs[index]; }
81
82 // Accessors for size of vectors
83 int numStates() const { return m_states.size(); }
84 int numEvents() const { return m_events.size(); }
85 int numActions() const { return m_actions.size(); }
86 int numTransitions() const { return m_transitions.size(); }
87 int numObjects() const { return m_objs.size(); }
88
89 void buildTable(); // Needs to be called before accessing the table
90
91 // Code generator methods
92 void writeCFiles(string path) ;
93 void writeHTMLFiles(string path) ;
94
95 void print(ostream& out) const { out << "[StateMachine: " << toString() << "]" << endl; }
96 private:
97
98 Vector<FormalParamAST*>* m_config_parameters;
99
100 // Private Methods
101 void checkForDuplicate(const Symbol& sym) const;
102
103 int getStateIndex(State* state_ptr) const { return m_state_map.lookup(state_ptr); }
104 int getEventIndex(Event* event_ptr) const { return m_event_map.lookup(event_ptr); }
105
106 // Private copy constructor and assignment operator
107 // StateMachine(const StateMachine& obj);
108 // StateMachine& operator=(const StateMachine& obj);
109
110 void printControllerH(ostream& out, string component) ;
111 void printControllerC(ostream& out, string component) ;
112 void printCWakeup(ostream& out, string component) ;
113 void printCSwitch(ostream& out, string component) ;
114 void printProfilerH(ostream& out, string component) ;
115 void printProfilerC(ostream& out, string component) ;
116
117 void printHTMLTransitions(ostream& out, int active_state) ;
118
119 // Data Members (m_ prefix)
120 Vector<State*> m_states;
121 Vector<Event*> m_events;
122 Vector<Action*> m_actions;
123 Vector<Transition*> m_transitions;
124 Vector<Func*> m_internal_func_vec;
125
126 Map<State*, int> m_state_map;
127 Map<Event*, int> m_event_map;
128
129 Vector<Var*> m_in_ports;
130
131 Vector<Var*> m_objs;
132
133 // Table variables
134 bool m_table_built;
135 Vector<Vector<Transition*> > m_table;
136
137 //added by SS
138 std::vector<std::string> m_message_buffer_names;
139
140 };
141
142 // Output operator declaration
143 ostream& operator<<(ostream& out, const StateMachine& obj);
144
145 // ******************* Definitions *******************
146
147 // Output operator definition
148 extern inline
149 ostream& operator<<(ostream& out, const StateMachine& obj)
150 {
151 obj.print(out);
152 out << flush;
153 return out;
154 }
155
156 #endif //STATEMACHINE_H