summaryrefslogtreecommitdiff
path: root/src/mem/slicc
diff options
context:
space:
mode:
authorJason Power <power.jg@gmail.com>2012-09-12 14:52:04 -0500
committerJason Power <power.jg@gmail.com>2012-09-12 14:52:04 -0500
commitaa8bcd15ec1ba916f3e750f41697a65e06b3c2ac (patch)
treeef66477d4b1904699ab751a841ff465768ab158e /src/mem/slicc
parentc6927ed13868c096a60df6a217f92857799b5be6 (diff)
downloadgem5-aa8bcd15ec1ba916f3e750f41697a65e06b3c2ac.tar.xz
Ruby: Modify Scons so that we can put .sm files in extras
Also allows for header files which are required in slicc generated code to be in a directory other than src/mem/ruby/slicc_interface.
Diffstat (limited to 'src/mem/slicc')
-rw-r--r--src/mem/slicc/parser.py12
-rw-r--r--src/mem/slicc/symbols/Func.py2
-rw-r--r--src/mem/slicc/symbols/StateMachine.py24
-rw-r--r--src/mem/slicc/symbols/SymbolTable.py12
-rw-r--r--src/mem/slicc/symbols/Type.py2
-rw-r--r--src/mem/slicc/symbols/Var.py2
6 files changed, 34 insertions, 20 deletions
diff --git a/src/mem/slicc/parser.py b/src/mem/slicc/parser.py
index e4f3ba952..77ac4de56 100644
--- a/src/mem/slicc/parser.py
+++ b/src/mem/slicc/parser.py
@@ -38,11 +38,12 @@ import slicc.util as util
from slicc.symbols import SymbolTable
class SLICC(Grammar):
- def __init__(self, filename, verbose=False, traceback=False, **kwargs):
+ def __init__(self, filename, base_dir, verbose=False, traceback=False, **kwargs):
self.protocol = None
self.traceback = traceback
self.verbose = verbose
self.symtab = SymbolTable(self)
+ self.base_dir = base_dir
try:
self.decl_list = self.parse_file(filename, **kwargs)
@@ -64,8 +65,8 @@ class SLICC(Grammar):
self.decl_list.findMachines()
self.decl_list.generate()
- def writeCodeFiles(self, code_path):
- self.symtab.writeCodeFiles(code_path)
+ def writeCodeFiles(self, code_path, includes):
+ self.symtab.writeCodeFiles(code_path, includes)
def writeHTMLFiles(self, html_path):
self.symtab.writeHTMLFiles(html_path)
@@ -249,7 +250,10 @@ class SLICC(Grammar):
def p_decl__include(self, p):
"decl : INCLUDE STRING SEMI"
dirname = os.path.dirname(self.current_source)
- filename = os.path.join(dirname, p[2])
+ if os.path.exists(os.path.join(dirname, p[2])):
+ filename = os.path.join(dirname, p[2])
+ else:
+ filename = os.path.join(self.base_dir, p[2])
p[0] = self.parse_file(filename)
def p_decl__machine(self, p):
diff --git a/src/mem/slicc/symbols/Func.py b/src/mem/slicc/symbols/Func.py
index 771144efd..ebbc5fe14 100644
--- a/src/mem/slicc/symbols/Func.py
+++ b/src/mem/slicc/symbols/Func.py
@@ -63,7 +63,7 @@ class Func(Symbol):
return "%s %s(%s);" % (return_type, self.c_ident,
", ".join(self.param_strings))
- def writeCodeFiles(self, path):
+ def writeCodeFiles(self, path, includes):
return
def generateCode(self):
diff --git a/src/mem/slicc/symbols/StateMachine.py b/src/mem/slicc/symbols/StateMachine.py
index 83ad88e8b..47f7daa00 100644
--- a/src/mem/slicc/symbols/StateMachine.py
+++ b/src/mem/slicc/symbols/StateMachine.py
@@ -162,12 +162,12 @@ class StateMachine(Symbol):
action.warning(error_msg)
self.table = table
- def writeCodeFiles(self, path):
+ def writeCodeFiles(self, path, includes):
self.printControllerPython(path)
self.printControllerHH(path)
- self.printControllerCC(path)
+ self.printControllerCC(path, includes)
self.printCSwitch(path)
- self.printCWakeup(path)
+ self.printCWakeup(path, includes)
self.printProfilerCC(path)
self.printProfilerHH(path)
self.printProfileDumperCC(path)
@@ -399,7 +399,7 @@ void unset_tbe(${{self.TBEType.c_ident}}*& m_tbe_ptr);
code('#endif // __${ident}_CONTROLLER_H__')
code.write(path, '%s.hh' % c_ident)
- def printControllerCC(self, path):
+ def printControllerCC(self, path, includes):
'''Output the actions for performing the actions'''
code = self.symtab.codeFormatter()
@@ -429,8 +429,12 @@ void unset_tbe(${{self.TBEType.c_ident}}*& m_tbe_ptr);
#include "mem/protocol/${ident}_State.hh"
#include "mem/protocol/Types.hh"
#include "mem/ruby/common/Global.hh"
-#include "mem/ruby/slicc_interface/RubySlicc_includes.hh"
#include "mem/ruby/system/System.hh"
+''')
+ for include_path in includes:
+ code('#include "${{include_path}}"')
+
+ code('''
using namespace std;
''')
@@ -988,7 +992,7 @@ $c_ident::${{action.ident}}(const Address& addr)
code.write(path, "%s.cc" % c_ident)
- def printCWakeup(self, path):
+ def printCWakeup(self, path, includes):
'''Output the wakeup loop for the events'''
code = self.symtab.codeFormatter()
@@ -1020,8 +1024,14 @@ $c_ident::${{action.ident}}(const Address& addr)
code('''
#include "mem/protocol/Types.hh"
#include "mem/ruby/common/Global.hh"
-#include "mem/ruby/slicc_interface/RubySlicc_includes.hh"
#include "mem/ruby/system/System.hh"
+''')
+
+
+ for include_path in includes:
+ code('#include "${{include_path}}"')
+
+ code('''
using namespace std;
diff --git a/src/mem/slicc/symbols/SymbolTable.py b/src/mem/slicc/symbols/SymbolTable.py
index 81d0768f9..d2c9337f1 100644
--- a/src/mem/slicc/symbols/SymbolTable.py
+++ b/src/mem/slicc/symbols/SymbolTable.py
@@ -124,15 +124,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"')
@@ -140,7 +140,7 @@ 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)
diff --git a/src/mem/slicc/symbols/Type.py b/src/mem/slicc/symbols/Type.py
index 3285b767f..aec05a678 100644
--- a/src/mem/slicc/symbols/Type.py
+++ b/src/mem/slicc/symbols/Type.py
@@ -184,7 +184,7 @@ class Type(Symbol):
return True
- def writeCodeFiles(self, path):
+ def writeCodeFiles(self, path, includes):
if self.isExternal:
# Do nothing
pass
diff --git a/src/mem/slicc/symbols/Var.py b/src/mem/slicc/symbols/Var.py
index 87a101f65..e16199a1e 100644
--- a/src/mem/slicc/symbols/Var.py
+++ b/src/mem/slicc/symbols/Var.py
@@ -44,7 +44,7 @@ class Var(Symbol):
def __repr__(self):
return "[Var id: %s]" % (self.c_ident)
- def writeCodeFiles(self, path):
+ def writeCodeFiles(self, path, includes):
pass
__all__ = [ "Var" ]