summaryrefslogtreecommitdiff
path: root/src/mem/slicc
diff options
context:
space:
mode:
authorTony Gutierrez <anthony.gutierrez@amd.com>2015-07-20 09:15:18 -0500
committerTony Gutierrez <anthony.gutierrez@amd.com>2015-07-20 09:15:18 -0500
commita3177645773b8eb4b835050c395554d3e2b4664a (patch)
tree793299969de1562785063448ac12f9e06ac164e3 /src/mem/slicc
parent3f68884c0e432cdc241ed0442e19ade0d74aa6f4 (diff)
downloadgem5-a3177645773b8eb4b835050c395554d3e2b4664a.tar.xz
ruby: slicc: have a static MachineType
This patch is imported from reviewboard patch 2551 by Nilay. This patch moves from a dynamically defined MachineType to a statically defined one. The need for this patch was felt since a dynamically defined type prevents us from having types for which no machine definition may exist. The following changes have been made: i. each machine definition now uses a type from the MachineType enumeration instead of any random identifier. This required changing the grammar and the *.sm files. ii. MachineType enumeration defined statically in RubySlicc_Exports.sm. * * * normal protocol fixes for nilay's parser machine type fix
Diffstat (limited to 'src/mem/slicc')
-rw-r--r--src/mem/slicc/ast/DeclListAST.py5
-rw-r--r--src/mem/slicc/ast/MachineAST.py12
-rw-r--r--src/mem/slicc/parser.py10
-rw-r--r--src/mem/slicc/symbols/SymbolTable.py6
-rw-r--r--src/mem/slicc/symbols/Type.py15
5 files changed, 19 insertions, 29 deletions
diff --git a/src/mem/slicc/ast/DeclListAST.py b/src/mem/slicc/ast/DeclListAST.py
index 36c520070..4ba41ed6c 100644
--- a/src/mem/slicc/ast/DeclListAST.py
+++ b/src/mem/slicc/ast/DeclListAST.py
@@ -46,8 +46,5 @@ class DeclListAST(AST):
def generate(self):
for decl in self.decls:
- decl.generate()
-
- def findMachines(self):
- for decl in self.decls:
decl.findMachines()
+ decl.generate()
diff --git a/src/mem/slicc/ast/MachineAST.py b/src/mem/slicc/ast/MachineAST.py
index 4487b094e..c67d0e695 100644
--- a/src/mem/slicc/ast/MachineAST.py
+++ b/src/mem/slicc/ast/MachineAST.py
@@ -29,10 +29,10 @@ from slicc.ast.DeclAST import DeclAST
from slicc.symbols import StateMachine, Type
class MachineAST(DeclAST):
- def __init__(self, slicc, ident, pairs_ast, config_parameters, decls):
+ def __init__(self, slicc, mtype, pairs_ast, config_parameters, decls):
super(MachineAST, self).__init__(slicc, pairs_ast)
- self.ident = ident
+ self.ident = mtype.value
self.pairs_ast = pairs_ast
self.config_parameters = config_parameters
self.decls = decls
@@ -72,11 +72,5 @@ class MachineAST(DeclAST):
def findMachines(self):
mtype = self.ident
machine_type = self.symtab.find("MachineType", Type)
- pairs = self.pairs_ast.pairs
-
- pairs["Primary"] = True
- if not machine_type.addEnum(mtype, pairs):
+ if not machine_type.checkEnum(mtype):
self.error("Duplicate machine name: %s:%s" % (machine_type, mtype))
-
- # Generate code for all the internal decls
- self.decls.findMachines()
diff --git a/src/mem/slicc/parser.py b/src/mem/slicc/parser.py
index 364bb92f7..4afe0d367 100644
--- a/src/mem/slicc/parser.py
+++ b/src/mem/slicc/parser.py
@@ -62,7 +62,6 @@ class SLICC(Grammar):
return code
def process(self):
- self.decl_list.findMachines()
self.decl_list.generate()
def writeCodeFiles(self, code_path, includes):
@@ -72,10 +71,7 @@ class SLICC(Grammar):
self.symtab.writeHTMLFiles(html_path)
def files(self):
- f = set([
- 'MachineType.cc',
- 'MachineType.hh',
- 'Types.hh' ])
+ f = set(['Types.hh'])
f |= self.decl_list.files()
@@ -259,11 +255,11 @@ class SLICC(Grammar):
p[0] = self.parse_file(filename)
def p_decl__machine0(self, p):
- "decl : MACHINE '(' ident ')' ':' obj_decls '{' decls '}'"
+ "decl : MACHINE '(' enumeration ')' ':' obj_decls '{' decls '}'"
p[0] = ast.MachineAST(self, p[3], [], p[7], p[9])
def p_decl__machine1(self, p):
- "decl : MACHINE '(' ident pairs ')' ':' obj_decls '{' decls '}'"
+ "decl : MACHINE '(' enumeration pairs ')' ':' obj_decls '{' decls '}'"
p[0] = ast.MachineAST(self, p[3], p[4], p[7], p[9])
def p_decl__action(self, p):
diff --git a/src/mem/slicc/symbols/SymbolTable.py b/src/mem/slicc/symbols/SymbolTable.py
index 844e4c63f..e991fec2b 100644
--- a/src/mem/slicc/symbols/SymbolTable.py
+++ b/src/mem/slicc/symbols/SymbolTable.py
@@ -41,12 +41,6 @@ class SymbolTable(object):
self.machine_components = {}
pairs = {}
- pairs["enumeration"] = "yes"
- location = Location("init", 0, no_warning=not slicc.verbose)
- MachineType = Type(self, "MachineType", location, pairs)
- self.newSymbol(MachineType)
-
- pairs = {}
pairs["primitive"] = "yes"
pairs["external"] = "yes"
location = Location("init", 0, no_warning=not slicc.verbose)
diff --git a/src/mem/slicc/symbols/Type.py b/src/mem/slicc/symbols/Type.py
index a3223b3ac..bd92e20c9 100644
--- a/src/mem/slicc/symbols/Type.py
+++ b/src/mem/slicc/symbols/Type.py
@@ -42,6 +42,7 @@ class Enumeration(PairContainer):
def __init__(self, ident, pairs):
super(Enumeration, self).__init__(pairs)
self.ident = ident
+ self.primary = False
class Type(Symbol):
def __init__(self, table, ident, location, pairs, machine=None):
@@ -165,6 +166,14 @@ class Type(Symbol):
return True
+ ## Used to check if an enum has been already used and therefore
+ ## should not be used again.
+ def checkEnum(self, ident):
+ if ident in self.enums and not self.enums[ident].primary:
+ self.enums[ident].primary = True
+ return True
+ return False
+
def writeCodeFiles(self, path, includes):
if self.isExternal:
# Do nothing
@@ -567,7 +576,7 @@ AccessPermission ${{self.c_ident}}_to_permission(const ${{self.c_ident}}& obj)
if self.isMachineType:
for enum in self.enums.itervalues():
- if enum.get("Primary"):
+ if enum.primary:
code('#include "mem/protocol/${{enum.ident}}_Controller.hh"')
code('#include "mem/ruby/common/MachineID.hh"')
@@ -706,7 +715,7 @@ ${{self.c_ident}}_base_number(const ${{self.c_ident}}& obj)
code(' case ${{self.c_ident}}_NUM:')
for enum in reversed(self.enums.values()):
# Check if there is a defined machine with this type
- if enum.get("Primary"):
+ if enum.primary:
code(' base += ${{enum.ident}}_Controller::getNumControllers();')
else:
code(' base += 0;')
@@ -734,7 +743,7 @@ ${{self.c_ident}}_base_count(const ${{self.c_ident}}& obj)
# For each field
for enum in self.enums.itervalues():
code('case ${{self.c_ident}}_${{enum.ident}}:')
- if enum.get("Primary"):
+ if enum.primary:
code('return ${{enum.ident}}_Controller::getNumControllers();')
else:
code('return 0;')