SymbolTable.py (6999:f226c098c393) SymbolTable.py (8453:82fc1267d3bb)
1# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
2# Copyright (c) 2009 The Hewlett-Packard Development Company
3# All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions are
7# met: redistributions of source code must retain the above copyright
8# notice, this list of conditions and the following disclaimer;

--- 11 unchanged lines hidden (view full) ---

20# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
1# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
2# Copyright (c) 2009 The Hewlett-Packard Development Company
3# All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions are
7# met: redistributions of source code must retain the above copyright
8# notice, this list of conditions and the following disclaimer;

--- 11 unchanged lines hidden (view full) ---

20# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28from m5.util import code_formatter
28from m5.util import makeDir
29
30from slicc.generate import html
31from slicc.symbols.StateMachine import StateMachine
32from slicc.symbols.Type import Type
33from slicc.util import Location
34
35class SymbolTable(object):
36 def __init__(self, slicc):
37 self.slicc = slicc
38
39 self.sym_vec = []
40 self.sym_map_vec = [ {} ]
41 self.machine_components = {}
42
43 pairs = {}
44 pairs["enumeration"] = "yes"
29
30from slicc.generate import html
31from slicc.symbols.StateMachine import StateMachine
32from slicc.symbols.Type import Type
33from slicc.util import Location
34
35class SymbolTable(object):
36 def __init__(self, slicc):
37 self.slicc = slicc
38
39 self.sym_vec = []
40 self.sym_map_vec = [ {} ]
41 self.machine_components = {}
42
43 pairs = {}
44 pairs["enumeration"] = "yes"
45 MachineType = Type(self, "MachineType", Location("init", 0), pairs)
45 location = Location("init", 0, no_warning=not slicc.verbose)
46 MachineType = Type(self, "MachineType", location, pairs)
46 self.newSymbol(MachineType)
47
48 pairs = {}
49 pairs["primitive"] = "yes"
50 pairs["external"] = "yes"
47 self.newSymbol(MachineType)
48
49 pairs = {}
50 pairs["primitive"] = "yes"
51 pairs["external"] = "yes"
51 void = Type(self, "void", Location("init", 0), pairs)
52 location = Location("init", 0, no_warning=not slicc.verbose)
53 void = Type(self, "void", location, pairs)
52 self.newSymbol(void)
53
54 def __repr__(self):
55 return "[SymbolTable]" # FIXME
56
57 def codeFormatter(self, *args, **kwargs):
58 return self.slicc.codeFormatter(*args, **kwargs)
59

--- 58 unchanged lines hidden (view full) ---

118 self.sym_map_vec[0][ident] = symbol
119
120 def getAllType(self, type):
121 for symbol in self.sym_vec:
122 if isinstance(symbol, type):
123 yield symbol
124
125 def writeCodeFiles(self, path):
54 self.newSymbol(void)
55
56 def __repr__(self):
57 return "[SymbolTable]" # FIXME
58
59 def codeFormatter(self, *args, **kwargs):
60 return self.slicc.codeFormatter(*args, **kwargs)
61

--- 58 unchanged lines hidden (view full) ---

120 self.sym_map_vec[0][ident] = symbol
121
122 def getAllType(self, type):
123 for symbol in self.sym_vec:
124 if isinstance(symbol, type):
125 yield symbol
126
127 def writeCodeFiles(self, path):
128 makeDir(path)
129
126 code = self.codeFormatter()
127 code('''
128/** Auto generated C++ code started by $__file__:$__line__ */
129
130#include "mem/ruby/slicc_interface/RubySlicc_includes.hh"
131''')
132 for symbol in self.sym_vec:
133 if isinstance(symbol, Type) and not symbol.isPrimitive:
134 code('#include "mem/protocol/${{symbol.c_ident}}.hh"')
135
136 code.write(path, "Types.hh")
137
138 for symbol in self.sym_vec:
139 symbol.writeCodeFiles(path)
140
141 def writeHTMLFiles(self, path):
130 code = self.codeFormatter()
131 code('''
132/** Auto generated C++ code started by $__file__:$__line__ */
133
134#include "mem/ruby/slicc_interface/RubySlicc_includes.hh"
135''')
136 for symbol in self.sym_vec:
137 if isinstance(symbol, Type) and not symbol.isPrimitive:
138 code('#include "mem/protocol/${{symbol.c_ident}}.hh"')
139
140 code.write(path, "Types.hh")
141
142 for symbol in self.sym_vec:
143 symbol.writeCodeFiles(path)
144
145 def writeHTMLFiles(self, path):
146 makeDir(path)
147
142 machines = list(self.getAllType(StateMachine))
143 if len(machines) > 1:
144 name = "%s_table.html" % machines[0].ident
145 else:
146 name = "empty.html"
147
148 code = self.codeFormatter()
149 code('''

--- 20 unchanged lines hidden ---
148 machines = list(self.getAllType(StateMachine))
149 if len(machines) > 1:
150 name = "%s_table.html" % machines[0].ident
151 else:
152 name = "empty.html"
153
154 code = self.codeFormatter()
155 code('''

--- 20 unchanged lines hidden ---