ruby: slicc: have a static MachineType
[gem5.git] / src / mem / slicc / symbols / SymbolTable.py
index dd45ac06c0cf98215f9039edbc6aa38a137d427e..e991fec2b93d045ad3c28d5f92f19aa2d824c6df 100644 (file)
@@ -25,7 +25,7 @@
 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-from m5.util import code_formatter
+from m5.util import makeDir
 
 from slicc.generate import html
 from slicc.symbols.StateMachine import StateMachine
@@ -40,15 +40,11 @@ class SymbolTable(object):
         self.sym_map_vec = [ {} ]
         self.machine_components = {}
 
-        pairs = {}
-        pairs["enumeration"] = "yes"
-        MachineType = Type(self, "MachineType", Location("init", 0), pairs)
-        self.newSymbol(MachineType)
-
         pairs = {}
         pairs["primitive"] = "yes"
         pairs["external"] = "yes"
-        void = Type(self, "void", Location("init", 0), pairs)
+        location = Location("init", 0, no_warning=not slicc.verbose)
+        void = Type(self, "void", location, pairs)
         self.newSymbol(void)
 
     def __repr__(self):
@@ -66,6 +62,11 @@ class SymbolTable(object):
         if id in self.sym_map_vec[-1]:
             sym.error("Symbol '%s' redeclared in same scope.", id)
 
+        for sym_map in self.sym_map_vec:
+            if id in sym_map:
+                if type(sym_map[id]) != type(sym):
+                    sym.error("Conflicting declaration of Symbol '%s'", id)
+
         # FIXME - warn on masking of a declaration in a previous frame
         self.sym_map_vec[-1][id] = sym
 
@@ -78,9 +79,8 @@ class SymbolTable(object):
 
             if types is not None:
                 if not isinstance(symbol, types):
-                    symbol.error("Symbol '%s' is not of types '%s'.",
-                                 symbol,
-                                 types)
+                    continue # there could be a name clash with other symbol
+                             # so rather than producing an error, keep trying
 
             return symbol
 
@@ -122,13 +122,15 @@ class SymbolTable(object):
             if isinstance(symbol, type):
                 yield symbol
 
-    def writeCodeFiles(self, path):
+    def writeCodeFiles(self, path, includes):
+        makeDir(path)
+
         code = self.codeFormatter()
-        code('''
-/** Auto generated C++ code started by $__file__:$__line__ */
+        code('/** Auto generated C++ code started by $__file__:$__line__ */')
+
+        for include_path in includes:
+            code('#include "${{include_path}}"')
 
-#include "mem/ruby/slicc_interface/RubySlicc_includes.hh"
-''')
         for symbol in self.sym_vec:
             if isinstance(symbol, Type) and not symbol.isPrimitive:
                 code('#include "mem/protocol/${{symbol.c_ident}}.hh"')
@@ -136,9 +138,11 @@ class SymbolTable(object):
         code.write(path, "Types.hh")
 
         for symbol in self.sym_vec:
-            symbol.writeCodeFiles(path)
+            symbol.writeCodeFiles(path, includes)
 
     def writeHTMLFiles(self, path):
+        makeDir(path)
+
         machines = list(self.getAllType(StateMachine))
         if len(machines) > 1:
             name = "%s_table.html" % machines[0].ident