summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mem/protocol/SConscript82
-rw-r--r--src/mem/slicc/SConscript129
-rw-r--r--src/mem/slicc/__init__.py25
-rw-r--r--src/mem/slicc/ast/AST.cc39
-rw-r--r--src/mem/slicc/ast/AST.hh94
-rw-r--r--src/mem/slicc/ast/AST.py63
-rw-r--r--src/mem/slicc/ast/ASTs.hh91
-rw-r--r--src/mem/slicc/ast/ActionDeclAST.cc98
-rw-r--r--src/mem/slicc/ast/ActionDeclAST.hh86
-rw-r--r--src/mem/slicc/ast/ActionDeclAST.py72
-rw-r--r--src/mem/slicc/ast/AssignStatementAST.cc76
-rw-r--r--src/mem/slicc/ast/AssignStatementAST.hh85
-rw-r--r--src/mem/slicc/ast/AssignStatementAST.py59
-rw-r--r--src/mem/slicc/ast/CheckAllocateStatementAST.cc72
-rw-r--r--src/mem/slicc/ast/CheckAllocateStatementAST.hh82
-rw-r--r--src/mem/slicc/ast/CheckAllocateStatementAST.py47
-rw-r--r--src/mem/slicc/ast/CheckStopSlotsStatementAST.cc115
-rw-r--r--src/mem/slicc/ast/CheckStopSlotsStatementAST.hh85
-rw-r--r--src/mem/slicc/ast/CheckStopSlotsStatementAST.py74
-rw-r--r--src/mem/slicc/ast/ChipComponentAccessAST.cc244
-rw-r--r--src/mem/slicc/ast/ChipComponentAccessAST.hh101
-rw-r--r--src/mem/slicc/ast/ChipComponentAccessAST.py161
-rw-r--r--src/mem/slicc/ast/CopyHeadStatementAST.cc85
-rw-r--r--src/mem/slicc/ast/CopyHeadStatementAST.hh87
-rw-r--r--src/mem/slicc/ast/CopyHeadStatementAST.py52
-rw-r--r--src/mem/slicc/ast/DeclAST.cc39
-rw-r--r--src/mem/slicc/ast/DeclAST.hh85
-rw-r--r--src/mem/slicc/ast/DeclAST.py38
-rw-r--r--src/mem/slicc/ast/DeclListAST.cc86
-rw-r--r--src/mem/slicc/ast/DeclListAST.hh84
-rw-r--r--src/mem/slicc/ast/DeclListAST.py51
-rw-r--r--src/mem/slicc/ast/EnqueueStatementAST.cc111
-rw-r--r--src/mem/slicc/ast/EnqueueStatementAST.hh93
-rw-r--r--src/mem/slicc/ast/EnqueueStatementAST.py86
-rw-r--r--src/mem/slicc/ast/EnumDeclAST.cc98
-rw-r--r--src/mem/slicc/ast/EnumDeclAST.hh86
-rw-r--r--src/mem/slicc/ast/EnumDeclAST.py71
-rw-r--r--src/mem/slicc/ast/EnumExprAST.cc76
-rw-r--r--src/mem/slicc/ast/EnumExprAST.hh85
-rw-r--r--src/mem/slicc/ast/EnumExprAST.py53
-rw-r--r--src/mem/slicc/ast/ExprAST.cc39
-rw-r--r--src/mem/slicc/ast/ExprAST.hh84
-rw-r--r--src/mem/slicc/ast/ExprAST.py45
-rw-r--r--src/mem/slicc/ast/ExprStatementAST.cc73
-rw-r--r--src/mem/slicc/ast/ExprStatementAST.hh83
-rw-r--r--src/mem/slicc/ast/ExprStatementAST.py52
-rw-r--r--src/mem/slicc/ast/FormalParamAST.cc72
-rw-r--r--src/mem/slicc/ast/FormalParamAST.hh88
-rw-r--r--src/mem/slicc/ast/FormalParamAST.py52
-rw-r--r--src/mem/slicc/ast/FuncCallExprAST.cc224
-rw-r--r--src/mem/slicc/ast/FuncCallExprAST.hh89
-rw-r--r--src/mem/slicc/ast/FuncCallExprAST.py168
-rw-r--r--src/mem/slicc/ast/FuncDeclAST.cc112
-rw-r--r--src/mem/slicc/ast/FuncDeclAST.hh91
-rw-r--r--src/mem/slicc/ast/FuncDeclAST.py88
-rw-r--r--src/mem/slicc/ast/IfStatementAST.cc98
-rw-r--r--src/mem/slicc/ast/IfStatementAST.hh89
-rw-r--r--src/mem/slicc/ast/IfStatementAST.py74
-rw-r--r--src/mem/slicc/ast/InPortDeclAST.cc149
-rw-r--r--src/mem/slicc/ast/InPortDeclAST.hh91
-rw-r--r--src/mem/slicc/ast/InPortDeclAST.py130
-rw-r--r--src/mem/slicc/ast/InfixOperatorExprAST.cc121
-rw-r--r--src/mem/slicc/ast/InfixOperatorExprAST.hh85
-rw-r--r--src/mem/slicc/ast/InfixOperatorExprAST.py89
-rw-r--r--src/mem/slicc/ast/LiteralExprAST.cc55
-rw-r--r--src/mem/slicc/ast/LiteralExprAST.hh83
-rw-r--r--src/mem/slicc/ast/LiteralExprAST.py55
-rw-r--r--src/mem/slicc/ast/Location.cc87
-rw-r--r--src/mem/slicc/ast/Location.hh93
-rw-r--r--src/mem/slicc/ast/MachineAST.cc99
-rw-r--r--src/mem/slicc/ast/MachineAST.hh93
-rw-r--r--src/mem/slicc/ast/MachineAST.py81
-rw-r--r--src/mem/slicc/ast/MemberExprAST.cc72
-rw-r--r--src/mem/slicc/ast/MemberExprAST.hh83
-rw-r--r--src/mem/slicc/ast/MemberExprAST.py55
-rw-r--r--src/mem/slicc/ast/MethodCallExprAST.cc160
-rw-r--r--src/mem/slicc/ast/MethodCallExprAST.hh93
-rw-r--r--src/mem/slicc/ast/MethodCallExprAST.py127
-rw-r--r--src/mem/slicc/ast/NewExprAST.cc9
-rw-r--r--src/mem/slicc/ast/NewExprAST.hh20
-rw-r--r--src/mem/slicc/ast/NewExprAST.py47
-rw-r--r--src/mem/slicc/ast/ObjDeclAST.cc137
-rw-r--r--src/mem/slicc/ast/ObjDeclAST.hh86
-rw-r--r--src/mem/slicc/ast/ObjDeclAST.py94
-rw-r--r--src/mem/slicc/ast/OutPortDeclAST.cc79
-rw-r--r--src/mem/slicc/ast/OutPortDeclAST.hh89
-rw-r--r--src/mem/slicc/ast/OutPortDeclAST.py57
-rw-r--r--src/mem/slicc/ast/PairAST.cc72
-rw-r--r--src/mem/slicc/ast/PairAST.hh86
-rw-r--r--src/mem/slicc/ast/PairAST.py36
-rw-r--r--src/mem/slicc/ast/PairListAST.cc49
-rw-r--r--src/mem/slicc/ast/PairListAST.hh82
-rw-r--r--src/mem/slicc/ast/PairListAST.py37
-rw-r--r--src/mem/slicc/ast/PeekStatementAST.cc115
-rw-r--r--src/mem/slicc/ast/PeekStatementAST.hh91
-rw-r--r--src/mem/slicc/ast/PeekStatementAST.py73
-rw-r--r--src/mem/slicc/ast/ReturnStatementAST.cc79
-rw-r--r--src/mem/slicc/ast/ReturnStatementAST.hh83
-rw-r--r--src/mem/slicc/ast/ReturnStatementAST.py54
-rw-r--r--src/mem/slicc/ast/StatementAST.cc60
-rw-r--r--src/mem/slicc/ast/StatementAST.hh88
-rw-r--r--src/mem/slicc/ast/StatementAST.py34
-rw-r--r--src/mem/slicc/ast/StatementListAST.cc86
-rw-r--r--src/mem/slicc/ast/StatementListAST.hh85
-rw-r--r--src/mem/slicc/ast/StatementListAST.py46
-rw-r--r--src/mem/slicc/ast/TransitionDeclAST.cc89
-rw-r--r--src/mem/slicc/ast/TransitionDeclAST.hh89
-rw-r--r--src/mem/slicc/ast/TransitionDeclAST.py54
-rw-r--r--src/mem/slicc/ast/TypeAST.cc67
-rw-r--r--src/mem/slicc/ast/TypeAST.hh83
-rw-r--r--src/mem/slicc/ast/TypeAST.py53
-rw-r--r--src/mem/slicc/ast/TypeDeclAST.cc86
-rw-r--r--src/mem/slicc/ast/TypeDeclAST.hh86
-rw-r--r--src/mem/slicc/ast/TypeDeclAST.py62
-rw-r--r--src/mem/slicc/ast/TypeFieldAST.cc44
-rw-r--r--src/mem/slicc/ast/TypeFieldAST.hh83
-rw-r--r--src/mem/slicc/ast/TypeFieldAST.py32
-rw-r--r--src/mem/slicc/ast/TypeFieldEnumAST.cc82
-rw-r--r--src/mem/slicc/ast/TypeFieldEnumAST.hh86
-rw-r--r--src/mem/slicc/ast/TypeFieldEnumAST.py59
-rw-r--r--src/mem/slicc/ast/TypeFieldMemberAST.cc84
-rw-r--r--src/mem/slicc/ast/TypeFieldMemberAST.hh91
-rw-r--r--src/mem/slicc/ast/TypeFieldMemberAST.py57
-rw-r--r--src/mem/slicc/ast/TypeFieldMethodAST.cc81
-rw-r--r--src/mem/slicc/ast/TypeFieldMethodAST.hh87
-rw-r--r--src/mem/slicc/ast/TypeFieldMethodAST.py50
-rw-r--r--src/mem/slicc/ast/VarExprAST.cc76
-rw-r--r--src/mem/slicc/ast/VarExprAST.hh86
-rw-r--r--src/mem/slicc/ast/VarExprAST.py66
-rw-r--r--src/mem/slicc/ast/__init__.py69
-rw-r--r--src/mem/slicc/generate/__init__.py0
-rw-r--r--src/mem/slicc/generate/dot.py42
-rw-r--r--src/mem/slicc/generate/html.py80
-rw-r--r--src/mem/slicc/generate/tex.py71
-rw-r--r--src/mem/slicc/generator/fileio.cc66
-rw-r--r--src/mem/slicc/generator/fileio.hh46
-rw-r--r--src/mem/slicc/generator/html_gen.cc125
-rw-r--r--src/mem/slicc/generator/html_gen.hh49
-rw-r--r--src/mem/slicc/generator/mif_gen.cc1718
-rw-r--r--src/mem/slicc/generator/mif_gen.hh45
-rw-r--r--src/mem/slicc/main.cc246
-rw-r--r--src/mem/slicc/main.hh48
-rw-r--r--src/mem/slicc/main.py108
-rw-r--r--src/mem/slicc/parser.py669
-rw-r--r--src/mem/slicc/parser/lexer.ll125
-rw-r--r--src/mem/slicc/parser/parser.py563
-rw-r--r--src/mem/slicc/parser/parser.yy360
-rw-r--r--src/mem/slicc/slicc_global.hh125
-rw-r--r--src/mem/slicc/symbols/Action.hh52
-rw-r--r--src/mem/slicc/symbols/Action.py38
-rw-r--r--src/mem/slicc/symbols/Event.hh45
-rw-r--r--src/mem/slicc/symbols/Event.py34
-rw-r--r--src/mem/slicc/symbols/Func.cc143
-rw-r--r--src/mem/slicc/symbols/Func.hh96
-rw-r--r--src/mem/slicc/symbols/Func.py107
-rw-r--r--src/mem/slicc/symbols/State.hh45
-rw-r--r--src/mem/slicc/symbols/State.py34
-rw-r--r--src/mem/slicc/symbols/StateMachine.cc1534
-rw-r--r--src/mem/slicc/symbols/StateMachine.hh156
-rw-r--r--src/mem/slicc/symbols/StateMachine.py1222
-rw-r--r--src/mem/slicc/symbols/Symbol.cc72
-rw-r--r--src/mem/slicc/symbols/Symbol.hh100
-rw-r--r--src/mem/slicc/symbols/Symbol.py78
-rw-r--r--src/mem/slicc/symbols/SymbolTable.cc327
-rw-r--r--src/mem/slicc/symbols/SymbolTable.hh121
-rw-r--r--src/mem/slicc/symbols/SymbolTable.py218
-rw-r--r--src/mem/slicc/symbols/Transition.cc173
-rw-r--r--src/mem/slicc/symbols/Transition.hh120
-rw-r--r--src/mem/slicc/symbols/Transition.py61
-rw-r--r--src/mem/slicc/symbols/Type.cc779
-rw-r--r--src/mem/slicc/symbols/Type.hh155
-rw-r--r--src/mem/slicc/symbols/Type.py650
-rw-r--r--src/mem/slicc/symbols/Var.cc57
-rw-r--r--src/mem/slicc/symbols/Var.hh98
-rw-r--r--src/mem/slicc/symbols/Var.py50
-rw-r--r--src/mem/slicc/symbols/__init__.py38
-rw-r--r--src/mem/slicc/util.py75
-rwxr-xr-xutil/slicc38
178 files changed, 6515 insertions, 15231 deletions
diff --git a/src/mem/protocol/SConscript b/src/mem/protocol/SConscript
index 700ab40ea..425219580 100644
--- a/src/mem/protocol/SConscript
+++ b/src/mem/protocol/SConscript
@@ -29,30 +29,56 @@
# Authors: Nathan Binkert
import os
-import re
-import string
import sys
-from os.path import basename, dirname, exists, expanduser, isdir, isfile
-from os.path import join as joinpath
-
-import SCons
+from os.path import isdir, isfile, join as joinpath
Import('*')
if not env['RUBY']:
Return()
-slicc_dir = Dir('../slicc')
protocol_dir = Dir('.')
html_dir = Dir('html')
+slicc_dir = Dir('../slicc')
+
+sys.path[1:1] = [ Dir('..').srcnode().abspath ]
+from slicc.parser import SLICC
+
+slicc_depends = []
+for root,dirs,files in os.walk(slicc_dir.srcnode().abspath):
+ for f in files:
+ if f.endswith('.py'):
+ slicc_depends.append(File(joinpath(root, f)))
#
# Use SLICC
#
-def slicc_generator(target, source, env, for_signature):
- slicc_bin = str(source[0])
- protocol = source[1].get_contents()
+
+def slicc_scanner(node, env, path):
+ contents = node.get_contents()
+ files = [ line.strip() for line in contents.splitlines() ]
+ return files
+
+env.Append(SCANNERS=Scanner(function=slicc_scanner,skeys=['.slicc']))
+
+def slicc_emitter(target, source, env):
+ files = [s.srcnode().abspath for s in source[1:]]
+ slicc = SLICC(debug=True)
+ print "SLICC parsing..."
+ for name in slicc.load(files, verbose=True):
+ print " %s" % name
+
+ hh,cc = slicc.files()
+ target.extend(sorted(hh))
+ target.extend(sorted(cc))
+ f = file('/tmp/asdf', 'w')
+ for t in target:
+ print >>f, t
+ return target, source
+
+def slicc_action(target, source, env):
+ protocol = source[0].get_contents()
pdir = str(protocol_dir)
hdir = str(html_dir)
@@ -61,31 +87,31 @@ def slicc_generator(target, source, env, for_signature):
if not isdir(hdir):
os.mkdir(hdir)
- do_html = "html"
- cmdline = [ slicc_bin, pdir, hdir, protocol, do_html ]
- cmdline += [ str(s) for s in source[2:] ]
- cmdline = ' '.join(cmdline)
- return cmdline
+ slicc = SLICC(debug=True)
+ files = [str(s) for s in source[1:]]
+ slicc.load(files, verbose=False)
-slicc_builder = Builder(generator=slicc_generator)
+ print "SLICC Generator pass 1..."
+ slicc.findMachines()
-protocol = env['PROTOCOL']
-sources = [ protocol_dir.File("RubySlicc_interfaces.slicc"),
- protocol_dir.File("%s.slicc" % protocol) ]
+ print "SLICC Generator pass 2..."
+ slicc.generate()
-execfile(slicc_dir.File('parser/parser.py').srcnode().abspath)
+ print "SLICC writing C++ files..."
+ slicc.writeCodeFiles(pdir)
-sm_files = read_slicc([s.srcnode().abspath for s in sources])
-sm_files = [ protocol_dir.File(f) for f in sm_files ]
+ print "SLICC writing HTML files..."
+ slicc.writeHTMLFiles(hdir)
-hh, cc = scan([s.srcnode().abspath for s in sm_files])
-hh = [ protocol_dir.File(f) for f in hh ]
-cc = [ protocol_dir.File(f) for f in cc ]
+slicc_builder = Builder(action=slicc_action, emitter=slicc_emitter)
-slicc_bin = slicc_dir.File("slicc")
+protocol = env['PROTOCOL']
+sources = [ protocol_dir.File("RubySlicc_interfaces.slicc"),
+ protocol_dir.File("%s.slicc" % protocol) ]
env.Append(BUILDERS={'SLICC' : slicc_builder})
-env.SLICC(hh + cc, [ slicc_bin, Value(protocol) ] + sm_files)
+nodes = env.SLICC([], [ Value(protocol) ] + sources)
+env.Depends(nodes, slicc_depends)
-for f in cc:
+for f in sorted(s for s in nodes if str(s).endswith('.cc')):
Source(f)
diff --git a/src/mem/slicc/SConscript b/src/mem/slicc/SConscript
deleted file mode 100644
index e26ceb979..000000000
--- a/src/mem/slicc/SConscript
+++ /dev/null
@@ -1,129 +0,0 @@
-# -*- mode:python -*-
-
-# Copyright (c) 2009 The Hewlett-Packard Development Company
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions are
-# met: redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer;
-# redistributions in binary form must reproduce the above copyright
-# notice, this list of conditions and the following disclaimer in the
-# documentation and/or other materials provided with the distribution;
-# neither the name of the copyright holders nor the names of its
-# contributors may be used to endorse or promote products derived from
-# this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-# Authors: Nathan Binkert
-
-import os
-import re
-import string
-import sys
-
-from os.path import basename, dirname, exists, expanduser, isdir, isfile
-from os.path import join as joinpath
-
-import SCons
-
-Import('*')
-
-if not env['RUBY']:
- Return()
-
-common_dir = Dir('../gems_common')
-
-#
-# Build SLICC
-#
-slicc_env = env.Clone()
-slicc_env['CPPDEFINES'] = ''
-slicc_env['CPPPATH'] = Dir('../..')
-slicc_env.Append(CCFLAGS=['-g', '-O0'])
-slicc_env.Append(CPPDEFINES=['DEBUG', 'TRACING_ON=1'])
-slicc_env['LIBS'] = ''
-slicc_env['LIBPATH'] = ''
-all_slicc_sources = []
-def SliccSource(filename):
- if filename.endswith('.ll') or filename.endswith('.yy'):
- slicc_env.CXXFile(filename)
- filename = filename[:-2] + "cc"
- x = slicc_env.StaticObject(filename)
- all_slicc_sources.append(x)
- return x
-
-# BE CAREFUL WITH THE ORDER OF FILENAMES HERE. SLICC IS VERY FRAGILE
-# BECAUSE IT VIOLATES ESTABLISHED RULES ABOUT HOW YOU'RE ALLOWED TO
-# CREATE STATIC OBJECTS. (SLICC HAS DEPENDENCIES DURING STATIC OBJECT
-# CONSTRUCTION ACROSS FILES. THAT'S A NO-NO.) WITH THIS FILE ORDER,
-# WE GET LUCKY AND OBJECTS GET CONSTRUCTED IN THE RIGHT ORDER.
-SliccSource('parser/parser.yy')
-SliccSource('parser/lexer.ll')
-SliccSource('main.cc')
-SliccSource('symbols/Func.cc')
-SliccSource('symbols/StateMachine.cc')
-SliccSource('symbols/Symbol.cc')
-SliccSource('symbols/SymbolTable.cc')
-SliccSource('symbols/Transition.cc')
-SliccSource('symbols/Type.cc')
-SliccSource('symbols/Var.cc')
-SliccSource('generator/fileio.cc')
-SliccSource('generator/html_gen.cc')
-SliccSource('generator/mif_gen.cc')
-SliccSource('ast/AST.cc')
-SliccSource('ast/ActionDeclAST.cc')
-SliccSource('ast/AssignStatementAST.cc')
-SliccSource('ast/CheckAllocateStatementAST.cc')
-SliccSource('ast/CheckStopSlotsStatementAST.cc')
-SliccSource('ast/ChipComponentAccessAST.cc')
-SliccSource('ast/CopyHeadStatementAST.cc')
-SliccSource('ast/DeclAST.cc')
-SliccSource('ast/DeclListAST.cc')
-SliccSource('ast/EnqueueStatementAST.cc')
-SliccSource('ast/EnumDeclAST.cc')
-SliccSource('ast/EnumExprAST.cc')
-SliccSource('ast/ExprAST.cc')
-SliccSource('ast/ExprStatementAST.cc')
-SliccSource('ast/FormalParamAST.cc')
-SliccSource('ast/FuncCallExprAST.cc')
-SliccSource('ast/FuncDeclAST.cc')
-SliccSource('ast/IfStatementAST.cc')
-SliccSource('ast/InPortDeclAST.cc')
-SliccSource('ast/InfixOperatorExprAST.cc')
-SliccSource('ast/LiteralExprAST.cc')
-SliccSource('ast/Location.cc')
-SliccSource('ast/MachineAST.cc')
-SliccSource('ast/MemberExprAST.cc')
-SliccSource('ast/MethodCallExprAST.cc')
-SliccSource('ast/NewExprAST.cc')
-SliccSource('ast/ObjDeclAST.cc')
-SliccSource('ast/OutPortDeclAST.cc')
-SliccSource('ast/PairAST.cc')
-SliccSource('ast/PairListAST.cc')
-SliccSource('ast/PeekStatementAST.cc')
-SliccSource('ast/ReturnStatementAST.cc')
-SliccSource('ast/StatementAST.cc')
-SliccSource('ast/StatementListAST.cc')
-SliccSource('ast/TransitionDeclAST.cc')
-SliccSource('ast/TypeAST.cc')
-SliccSource('ast/TypeDeclAST.cc')
-SliccSource('ast/TypeFieldAST.cc')
-SliccSource('ast/TypeFieldEnumAST.cc')
-SliccSource('ast/TypeFieldMemberAST.cc')
-SliccSource('ast/TypeFieldMethodAST.cc')
-SliccSource('ast/VarExprAST.cc')
-
-slicc_bin = File('slicc')
-slicc_env.Program(slicc_bin, all_slicc_sources + [ common_dir.File('util.o') ])
diff --git a/src/mem/slicc/__init__.py b/src/mem/slicc/__init__.py
new file mode 100644
index 000000000..8ce04e77d
--- /dev/null
+++ b/src/mem/slicc/__init__.py
@@ -0,0 +1,25 @@
+# Copyright (c) 2009 The Hewlett-Packard Development Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/src/mem/slicc/ast/AST.cc b/src/mem/slicc/ast/AST.cc
deleted file mode 100644
index e893c453a..000000000
--- a/src/mem/slicc/ast/AST.cc
+++ /dev/null
@@ -1,39 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * AST.C
- *
- * Description: See AST.hh
- *
- * $Id$
- *
- */
-
-#include "mem/slicc/ast/AST.hh"
diff --git a/src/mem/slicc/ast/AST.hh b/src/mem/slicc/ast/AST.hh
deleted file mode 100644
index 33c9b84ed..000000000
--- a/src/mem/slicc/ast/AST.hh
+++ /dev/null
@@ -1,94 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * AST.hh
- *
- * Description:
- *
- * $Id$
- *
- */
-
-#ifndef AST_H
-#define AST_H
-
-#include "mem/slicc/slicc_global.hh"
-#include "mem/gems_common/Vector.hh"
-#include "mem/gems_common/Map.hh"
-#include "mem/slicc/ast/Location.hh"
-#include "mem/slicc/symbols/SymbolTable.hh"
-
-class AST {
-public:
- // Constructors
- AST(Map<string, string> pairs) { m_pairs = pairs; };
- AST() {};
-
- // Destructor
- virtual ~AST() {};
-
- // Public Methods
- virtual void print(ostream& out) const = 0;
- void error(string err_msg) const { m_location.error(err_msg); };
- string embedError(string err_msg) const { return m_location.embedError(err_msg); };
- void warning(string err_msg) const { m_location.warning(err_msg); };
-
- const Location& getLocation() const { return m_location; };
-
- const Map<string, string>& getPairs() const { return m_pairs; };
- Map<string, string>& getPairs() { return m_pairs; };
-
-private:
- // Private Methods
-
- // Private copy constructor and assignment operator
- // AST(const AST& obj);
- // AST& operator=(const AST& obj);
-
- // Data Members (m_ prefix)
- Location m_location;
- Map<string, string> m_pairs;
-};
-
-// Output operator declaration
-ostream& operator<<(ostream& out, const AST& obj);
-
-// ******************* Definitions *******************
-
-// Output operator definition
-extern inline
-ostream& operator<<(ostream& out, const AST& obj)
-{
- obj.print(out);
- out << flush;
- return out;
-}
-
-#endif //AST_H
diff --git a/src/mem/slicc/ast/AST.py b/src/mem/slicc/ast/AST.py
new file mode 100644
index 000000000..5b1b124cd
--- /dev/null
+++ b/src/mem/slicc/ast/AST.py
@@ -0,0 +1,63 @@
+# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
+# Copyright (c) 2009 The Hewlett-Packard Development Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (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 slicc.util import PairContainer, Location
+
+class AST(PairContainer):
+ def __init__(self, slicc, pairs=None):
+ self.slicc = slicc
+ self.location = Location(slicc.current_file, slicc.lexer.lineno)
+ self.pairs = {}
+ if pairs:
+ self.pairs.update(getattr(pairs, "pairs", pairs))
+
+ @property
+ def symtab(self):
+ return self.slicc.symtab
+
+ @property
+ def state_machine(self):
+ return self.slicc.symtab.state_machine
+
+ def warning(self, message, *args):
+ self.location.warning(message, *args)
+
+ def error(self, message, *args):
+ self.location.error(message, *args)
+
+ def embedError(self, message, *args):
+ if args:
+ message = message % args
+ code = code_formatter()
+ code('''
+cerr << "Runtime Error at ${{self.location}}, Ruby Time: " << g_eventQueue_ptr->getTime() << ": "<< $message << ", PID: " << getpid() << endl;
+char c; cerr << "press return to continue." << endl; cin.get(c); abort();
+''')
+
+ return code
diff --git a/src/mem/slicc/ast/ASTs.hh b/src/mem/slicc/ast/ASTs.hh
deleted file mode 100644
index 3363fbb09..000000000
--- a/src/mem/slicc/ast/ASTs.hh
+++ /dev/null
@@ -1,91 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * $Id$
- *
- */
-
-#ifndef ASTs_H
-#define ASTs_H
-
-#include "mem/slicc/slicc_global.hh"
-#include "mem/slicc/main.hh"
-#include "mem/slicc/symbols/StateMachine.hh"
-#include "mem/slicc/ast/AST.hh"
-
-#include "mem/slicc/ast/MachineAST.hh"
-
-#include "mem/slicc/ast/TypeAST.hh"
-#include "mem/slicc/ast/FormalParamAST.hh"
-
-#include "mem/slicc/ast/DeclListAST.hh"
-#include "mem/slicc/ast/DeclAST.hh"
-#include "mem/slicc/ast/ActionDeclAST.hh"
-#include "mem/slicc/ast/InPortDeclAST.hh"
-#include "mem/slicc/ast/OutPortDeclAST.hh"
-#include "mem/slicc/ast/TransitionDeclAST.hh"
-#include "mem/slicc/ast/EnumDeclAST.hh"
-#include "mem/slicc/ast/TypeDeclAST.hh"
-#include "mem/slicc/ast/ObjDeclAST.hh"
-#include "mem/slicc/ast/FuncDeclAST.hh"
-
-#include "mem/slicc/ast/TypeFieldAST.hh"
-#include "mem/slicc/ast/TypeFieldMethodAST.hh"
-#include "mem/slicc/ast/TypeFieldMemberAST.hh"
-#include "mem/slicc/ast/TypeFieldEnumAST.hh"
-
-#include "mem/slicc/ast/PairAST.hh"
-#include "mem/slicc/ast/PairListAST.hh"
-
-#include "mem/slicc/ast/ExprAST.hh"
-#include "mem/slicc/ast/VarExprAST.hh"
-#include "mem/slicc/ast/EnumExprAST.hh"
-#include "mem/slicc/ast/LiteralExprAST.hh"
-#include "mem/slicc/ast/MemberExprAST.hh"
-#include "mem/slicc/ast/InfixOperatorExprAST.hh"
-#include "mem/slicc/ast/FuncCallExprAST.hh"
-#include "mem/slicc/ast/MethodCallExprAST.hh"
-#include "mem/slicc/ast/NewExprAST.hh"
-
-#include "mem/slicc/ast/ChipComponentAccessAST.hh"
-
-#include "mem/slicc/ast/StatementListAST.hh"
-#include "mem/slicc/ast/StatementAST.hh"
-#include "mem/slicc/ast/ExprStatementAST.hh"
-#include "mem/slicc/ast/AssignStatementAST.hh"
-#include "mem/slicc/ast/EnqueueStatementAST.hh"
-#include "mem/slicc/ast/IfStatementAST.hh"
-#include "mem/slicc/ast/PeekStatementAST.hh"
-#include "mem/slicc/ast/CopyHeadStatementAST.hh"
-#include "mem/slicc/ast/CheckAllocateStatementAST.hh"
-#include "mem/slicc/ast/CheckStopSlotsStatementAST.hh"
-#include "mem/slicc/ast/ReturnStatementAST.hh"
-
-#endif //ASTs_H
diff --git a/src/mem/slicc/ast/ActionDeclAST.cc b/src/mem/slicc/ast/ActionDeclAST.cc
deleted file mode 100644
index e46412ff7..000000000
--- a/src/mem/slicc/ast/ActionDeclAST.cc
+++ /dev/null
@@ -1,98 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * ActionDeclAST.C
- *
- * Description: See ActionDeclAST.hh
- *
- * $Id$
- *
- */
-
-
-#include "mem/slicc/ast/ActionDeclAST.hh"
-#include "mem/slicc/symbols/Action.hh"
-#include "mem/slicc/ast/StatementListAST.hh"
-
-ActionDeclAST::ActionDeclAST(string* ident_ptr,
- PairListAST* pairs_ptr,
- StatementListAST* statement_list_ptr)
- : DeclAST(pairs_ptr)
-{
- m_ident_ptr = ident_ptr;
- m_statement_list_ptr = statement_list_ptr;
-}
-
-ActionDeclAST::~ActionDeclAST()
-{
- delete m_ident_ptr;
- delete m_statement_list_ptr;
-}
-
-void ActionDeclAST::generate()
-{
- Map<Var*, string> resource_list;
- if (m_statement_list_ptr != NULL) {
- string code;
-
- // Add new local vars
- g_sym_table.pushFrame();
-
- Type* type_ptr = g_sym_table.getType("Address");
-
- if (type_ptr == NULL) {
- error("Type 'Address' not declared.");
- }
-
- g_sym_table.newSym(new Var("address", getLocation(), type_ptr, "addr", getPairs()));
-
- // Don't allows returns in actions
- m_statement_list_ptr->generate(code, NULL);
-
- getPairs().add("c_code", code);
-
- m_statement_list_ptr->findResources(resource_list);
-
- g_sym_table.popFrame();
- }
-
- StateMachine* machine_ptr = g_sym_table.getStateMachine();
- if (machine_ptr == NULL) {
- error("Action declaration not part of a machine.");
- } else {
- machine_ptr->addAction(new Action(*m_ident_ptr, resource_list, getLocation(), getPairs()));
- }
-
-}
-
-void ActionDeclAST::print(ostream& out) const
-{
- out << "[ActionDecl: " << *m_ident_ptr << "]";
-}
diff --git a/src/mem/slicc/ast/ActionDeclAST.hh b/src/mem/slicc/ast/ActionDeclAST.hh
deleted file mode 100644
index 4970ee254..000000000
--- a/src/mem/slicc/ast/ActionDeclAST.hh
+++ /dev/null
@@ -1,86 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * ActionDeclAST.hh
- *
- * Description:
- *
- * $Id: ActionDeclAST.hh,v 3.2 2003/07/10 18:08:06 milo Exp $
- *
- */
-
-#ifndef ActionDeclAST_H
-#define ActionDeclAST_H
-
-#include "mem/slicc/slicc_global.hh"
-#include "mem/slicc/ast/DeclAST.hh"
-
-class StatementListAST;
-
-class ActionDeclAST : public DeclAST {
-public:
- // Constructors
- ActionDeclAST(string* ident_ptr,
- PairListAST* pairs_ptr,
- StatementListAST* statement_list_ptr);
-
- // Destructor
- ~ActionDeclAST();
-
- // Public Methods
- void generate();
- void print(ostream& out) const;
-private:
- // Private Methods
-
- // Private copy constructor and assignment operator
- ActionDeclAST(const ActionDeclAST& obj);
- ActionDeclAST& operator=(const ActionDeclAST& obj);
-
- // Data Members (m_ prefix)
- string* m_ident_ptr;
- StatementListAST* m_statement_list_ptr;
-};
-
-// Output operator declaration
-ostream& operator<<(ostream& out, const ActionDeclAST& obj);
-
-// ******************* Definitions *******************
-
-// Output operator definition
-extern inline
-ostream& operator<<(ostream& out, const ActionDeclAST& obj)
-{
- obj.print(out);
- out << flush;
- return out;
-}
-
-#endif //ActionDeclAST_H
diff --git a/src/mem/slicc/ast/ActionDeclAST.py b/src/mem/slicc/ast/ActionDeclAST.py
new file mode 100644
index 000000000..18bf443b9
--- /dev/null
+++ b/src/mem/slicc/ast/ActionDeclAST.py
@@ -0,0 +1,72 @@
+# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
+# Copyright (c) 2009 The Hewlett-Packard Development Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (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 slicc.ast.DeclAST import DeclAST
+from slicc.symbols import Action, Type, Var
+
+class ActionDeclAST(DeclAST):
+ def __init__(self, slicc, ident, pairs, statement_list):
+ super(ActionDeclAST, self).__init__(slicc, pairs)
+ self.ident = ident
+ self.statement_list = statement_list
+
+ def __repr__(self):
+ return "[ActionDecl: %r]" % (self.ident)
+
+ def generate(self):
+ resources = {}
+ if self.statement_list:
+ # Add new local vars
+ self.symtab.pushFrame()
+
+ addr_type = self.symtab.find("Address", Type)
+
+ if addr_type is None:
+ self.error("Type 'Address' not declared.")
+
+ var = Var(self.symtab, "address", self.location, addr_type,
+ "addr", self.pairs)
+ self.symtab.newSymbol(var)
+
+ # Do not allows returns in actions
+ code = code_formatter()
+ self.statement_list.generate(code, None)
+ self.pairs["c_code"] = str(code)
+
+ self.statement_list.findResources(resources)
+
+ self.symtab.popFrame()
+
+ machine = self.symtab.state_machine
+ if machine is None:
+ self.error("Action declaration not part of a machine.")
+
+ action = Action(self.symtab, self.ident, resources, self.location,
+ self.pairs)
+ machine.addAction(action)
diff --git a/src/mem/slicc/ast/AssignStatementAST.cc b/src/mem/slicc/ast/AssignStatementAST.cc
deleted file mode 100644
index 8cf42aa63..000000000
--- a/src/mem/slicc/ast/AssignStatementAST.cc
+++ /dev/null
@@ -1,76 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * AssignStatementAST.C
- *
- * Description: See AssignStatementAST.hh
- *
- * $Id: AssignStatementAST.C,v 3.2 2003/08/01 18:38:19 beckmann Exp $
- *
- */
-
-#include "mem/slicc/ast/AssignStatementAST.hh"
-
-AssignStatementAST::AssignStatementAST(ExprAST* lvalue_ptr, ExprAST* rvalue_ptr)
- : StatementAST()
-{
- m_lvalue_ptr = lvalue_ptr;
- m_rvalue_ptr = rvalue_ptr;
-}
-
-AssignStatementAST::~AssignStatementAST()
-{
- delete m_lvalue_ptr;
- delete m_rvalue_ptr;
-}
-
-void AssignStatementAST::generate(string& code, Type* return_type_ptr) const
-{
- code += indent_str();
- Type* lvalue_type_ptr = m_lvalue_ptr->generate(code);
- code += " = ";
- Type* rvalue_type_ptr = m_rvalue_ptr->generate(code);
- code += ";\n";
-
- if (lvalue_type_ptr != rvalue_type_ptr) {
- // FIXME - beckmann
- // the following if statement is a hack to allow NetDest objects to be assigned to Sets
- // this allows for the previous NetworkMessage Destiantion 'Set class' to migrate to the
- // new NetworkMessage Destiantion 'NetDest class'
- if (lvalue_type_ptr->toString() != "NetDest" && rvalue_type_ptr->toString() != "Set") {
- error("Assignment type mismatch '" + lvalue_type_ptr->toString() + "' and '" + rvalue_type_ptr->toString() + "'");
- }
- }
-}
-
-void AssignStatementAST::print(ostream& out) const
-{
- out << "[AssignStatementAST: " << *m_lvalue_ptr << " := " << *m_rvalue_ptr << "]";
-}
diff --git a/src/mem/slicc/ast/AssignStatementAST.hh b/src/mem/slicc/ast/AssignStatementAST.hh
deleted file mode 100644
index 2c19da831..000000000
--- a/src/mem/slicc/ast/AssignStatementAST.hh
+++ /dev/null
@@ -1,85 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * AssignStatementAST.hh
- *
- * Description:
- *
- * $Id: AssignStatementAST.hh,v 3.2 2001/12/12 01:00:09 milo Exp $
- *
- */
-
-#ifndef ASSIGNSTATEMENTAST_H
-#define ASSIGNSTATEMENTAST_H
-
-#include "mem/slicc/slicc_global.hh"
-#include "mem/slicc/ast/StatementAST.hh"
-#include "mem/slicc/ast/ExprAST.hh"
-
-
-
-class AssignStatementAST : public StatementAST {
-public:
- // Constructors
- AssignStatementAST(ExprAST* lvalue_ptr, ExprAST* rvalue_ptr);
-
- // Destructor
- ~AssignStatementAST();
-
- // Public Methods
- void generate(string& code, Type* return_type_ptr) const;
- void print(ostream& out) const;
-private:
- // Private Methods
-
- // Private copy constructor and assignment operator
- AssignStatementAST(const AssignStatementAST& obj);
- AssignStatementAST& operator=(const AssignStatementAST& obj);
-
- // Data Members (m_ prefix)
- ExprAST* m_lvalue_ptr;
- ExprAST* m_rvalue_ptr;
-};
-
-// Output operator declaration
-ostream& operator<<(ostream& out, const AssignStatementAST& obj);
-
-// ******************* Definitions *******************
-
-// Output operator definition
-extern inline
-ostream& operator<<(ostream& out, const AssignStatementAST& obj)
-{
- obj.print(out);
- out << flush;
- return out;
-}
-
-#endif //ASSIGNSTATEMENTAST_H
diff --git a/src/mem/slicc/ast/AssignStatementAST.py b/src/mem/slicc/ast/AssignStatementAST.py
new file mode 100644
index 000000000..f8e77b03b
--- /dev/null
+++ b/src/mem/slicc/ast/AssignStatementAST.py
@@ -0,0 +1,59 @@
+# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
+# Copyright (c) 2009 The Hewlett-Packard Development Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (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 slicc.ast.StatementAST import StatementAST
+
+class AssignStatementAST(StatementAST):
+ def __init__(self, slicc, lvalue, rvalue):
+ super(AssignStatementAST, self).__init__(slicc)
+ self.lvalue = lvalue
+ self.rvalue = rvalue
+
+ def __repr__(self):
+ return "[AssignStatementAST: %r := %r]" % (self.lvalue, self.rvalue)
+
+ def generate(self, code, return_type):
+ lcode = code_formatter()
+ rcode = code_formatter()
+
+ ltype = self.lvalue.generate(lcode)
+ rtype = self.rvalue.generate(rcode)
+
+ code("$lcode = $rcode;")
+
+ if ltype != rtype:
+ # FIXME - beckmann
+ # the following if statement is a hack to allow NetDest
+ # objects to be assigned to Sets this allows for the
+ # previous NetworkMessage Destiantion 'Set class' to
+ # migrate to the new NetworkMessage Destiantion 'NetDest
+ # class'
+ if str(ltype) != "NetDest" and str(rtype) != "Set":
+ self.error("Assignment type mismatch '%s' and '%s'",
+ ltype, rtype)
diff --git a/src/mem/slicc/ast/CheckAllocateStatementAST.cc b/src/mem/slicc/ast/CheckAllocateStatementAST.cc
deleted file mode 100644
index 1f498efe2..000000000
--- a/src/mem/slicc/ast/CheckAllocateStatementAST.cc
+++ /dev/null
@@ -1,72 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * $Id$
- *
- */
-
-#include "mem/slicc/ast/CheckAllocateStatementAST.hh"
-#include "mem/slicc/symbols/SymbolTable.hh"
-#include "mem/slicc/ast/VarExprAST.hh"
-#include "mem/gems_common/util.hh"
-
-CheckAllocateStatementAST::CheckAllocateStatementAST(VarExprAST* variable)
- : StatementAST()
-{
- m_variable = variable;
-}
-
-CheckAllocateStatementAST::~CheckAllocateStatementAST()
-{
- delete m_variable;
-}
-
-void CheckAllocateStatementAST::generate(string& code, Type* return_type_ptr) const
-{
- // FIXME - check the type of the variable
-
- // Make sure the variable is valid
- m_variable->getVar();
-}
-
-void CheckAllocateStatementAST::findResources(Map<Var*, string>& resource_list) const
-{
- Var* var_ptr = m_variable->getVar();
- int res_count = 0;
- if (resource_list.exist(var_ptr)) {
- res_count = atoi((resource_list.lookup(var_ptr)).c_str());
- }
- resource_list.add(var_ptr, int_to_string(res_count+1));
-}
-
-void CheckAllocateStatementAST::print(ostream& out) const
-{
- out << "[CheckAllocateStatementAst: " << *m_variable << "]";
-}
diff --git a/src/mem/slicc/ast/CheckAllocateStatementAST.hh b/src/mem/slicc/ast/CheckAllocateStatementAST.hh
deleted file mode 100644
index 1df853514..000000000
--- a/src/mem/slicc/ast/CheckAllocateStatementAST.hh
+++ /dev/null
@@ -1,82 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * $Id$
- *
- */
-
-#ifndef CHECKALLOCATESTATEMENTAST_H
-#define CHECKALLOCATESTATEMENTAST_H
-
-#include "mem/slicc/slicc_global.hh"
-#include "mem/slicc/ast/StatementAST.hh"
-#include "mem/slicc/ast/TypeAST.hh"
-
-class VarExprAST;
-class Var;
-
-class CheckAllocateStatementAST : public StatementAST {
-public:
- // Constructors
- CheckAllocateStatementAST(VarExprAST* variable);
-
- // Destructor
- ~CheckAllocateStatementAST();
-
- // Public Methods
- void generate(string& code, Type* return_type_ptr) const;
- void findResources(Map<Var*, string>& resource_list) const;
- void print(ostream& out) const;
-private:
- // Private Methods
-
- // Private copy constructor and assignment operator
- CheckAllocateStatementAST(const CheckAllocateStatementAST& obj);
- CheckAllocateStatementAST& operator=(const CheckAllocateStatementAST& obj);
-
- // Data Members (m_ prefix)
- VarExprAST* m_variable;
-};
-
-// Output operator declaration
-ostream& operator<<(ostream& out, const CheckAllocateStatementAST& obj);
-
-// ******************* Definitions *******************
-
-// Output operator definition
-extern inline
-ostream& operator<<(ostream& out, const CheckAllocateStatementAST& obj)
-{
- obj.print(out);
- out << flush;
- return out;
-}
-
-#endif //CHECKALLOCATESTATEMENTAST_H
diff --git a/src/mem/slicc/ast/CheckAllocateStatementAST.py b/src/mem/slicc/ast/CheckAllocateStatementAST.py
new file mode 100644
index 000000000..b96153b0a
--- /dev/null
+++ b/src/mem/slicc/ast/CheckAllocateStatementAST.py
@@ -0,0 +1,47 @@
+# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
+# Copyright (c) 2009 The Hewlett-Packard Development Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (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 slicc.ast.StatementAST import StatementAST
+
+class CheckAllocateStatementAST(StatementAST):
+ def __init__(self, slicc, variable):
+ super(StatementAST, self).__init__(slicc)
+ self.variable = variable
+
+ def __repr__(self):
+ return "[CheckAllocateStatementAst: %r]" % self.variable
+
+ def generate(self, code, return_type):
+ # FIXME - check the type of the variable
+
+ # Make sure the variable is valid
+ self.variable.var
+
+ def findResources(self, resources):
+ var = self.variable.var
+ res_count = int(resources.get(var, 0))
+ resources[var] = str(res_count + 1)
diff --git a/src/mem/slicc/ast/CheckStopSlotsStatementAST.cc b/src/mem/slicc/ast/CheckStopSlotsStatementAST.cc
deleted file mode 100644
index 38dc449d6..000000000
--- a/src/mem/slicc/ast/CheckStopSlotsStatementAST.cc
+++ /dev/null
@@ -1,115 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * $Id$
- *
- */
-
-#include "mem/slicc/ast/CheckStopSlotsStatementAST.hh"
-#include "mem/slicc/symbols/SymbolTable.hh"
-#include "mem/slicc/ast/VarExprAST.hh"
-#include "mem/slicc/ast/PairListAST.hh"
-
-CheckStopSlotsStatementAST::CheckStopSlotsStatementAST(VarExprAST* variable, string* condStr, string* bankStr)
- : StatementAST()
-{
- m_variable = variable;
- m_condStr_ptr = condStr;
- m_bankStr_ptr = bankStr;
-}
-
-CheckStopSlotsStatementAST::~CheckStopSlotsStatementAST()
-{
- delete m_variable;
- delete m_condStr_ptr;
- delete m_bankStr_ptr;
-}
-
-void CheckStopSlotsStatementAST::generate(string& code, Type* return_type_ptr) const
-{
-
- // Make sure the variable is valid
- m_variable->getVar();
-
-}
-
-void CheckStopSlotsStatementAST::findResources(Map<Var*, string>& resource_list) const
-{
- Type* type_ptr;
-
- Var* var_ptr = m_variable->getVar();
- string check_code;
-
- if (*m_condStr_ptr == "((*in_msg_ptr)).m_isOnChipSearch") {
- check_code += " const Response9Msg* in_msg_ptr;\n";
- check_code += " in_msg_ptr = dynamic_cast<const Response9Msg*>(((*(m_chip_ptr->m_L2Cache_responseToL2Cache9_vec[m_version]))).peek());\n";
- check_code += " assert(in_msg_ptr != NULL);\n";
- }
-
- check_code += " if (";
- check_code += *m_condStr_ptr;
- check_code += ") {\n";
-
- check_code += " if (!";
- type_ptr = m_variable->generate(check_code);
- check_code += ".isDisableSPossible((((*(m_chip_ptr->m_DNUCAmover_ptr))).getBankPos(";
- check_code += *m_bankStr_ptr;
- check_code += ")))) {\n";
- if(CHECK_INVALID_RESOURCE_STALLS) {
- check_code += " assert(priority >= ";
- type_ptr = m_variable->generate(check_code);
- check_code += ".getPriority());\n";
- }
- check_code += " return TransitionResult_ResourceStall;\n";
- check_code += " }\n";
- check_code += " } else {\n";
- check_code += " if (!";
- type_ptr = m_variable->generate(check_code);
- check_code += ".isDisableFPossible((((*(m_chip_ptr->m_DNUCAmover_ptr))).getBankPos(";
- check_code += *m_bankStr_ptr;
- check_code += ")))) {\n";
- if(CHECK_INVALID_RESOURCE_STALLS) {
- check_code += " assert(priority >= ";
- type_ptr = m_variable->generate(check_code);
- check_code += ".getPriority());\n";
- }
- check_code += " return TransitionResult_ResourceStall;\n";
- check_code += " }\n";
- check_code += " }\n";
-
- assert(!resource_list.exist(var_ptr));
- resource_list.add(var_ptr, check_code);
-
-}
-
-void CheckStopSlotsStatementAST::print(ostream& out) const
-{
- out << "[CheckStopSlotsStatementAst: " << *m_variable << "]";
-}
diff --git a/src/mem/slicc/ast/CheckStopSlotsStatementAST.hh b/src/mem/slicc/ast/CheckStopSlotsStatementAST.hh
deleted file mode 100644
index 6de068caa..000000000
--- a/src/mem/slicc/ast/CheckStopSlotsStatementAST.hh
+++ /dev/null
@@ -1,85 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * $Id$
- *
- */
-
-#ifndef CHECKSTOPSLOTSSTATEMENTAST_H
-#define CHECKSTOPSLOTSSTATEMENTAST_H
-
-#include "mem/slicc/slicc_global.hh"
-#include "mem/slicc/ast/ExprAST.hh"
-#include "mem/slicc/ast/StatementAST.hh"
-#include "mem/slicc/ast/TypeAST.hh"
-
-class VarExprAST;
-class Var;
-
-class CheckStopSlotsStatementAST : public StatementAST {
-public:
- // Constructors
- CheckStopSlotsStatementAST(VarExprAST* variable, string* condStr, string* bankStr);
-
- // Destructor
- ~CheckStopSlotsStatementAST();
-
- // Public Methods
- void generate(string& code, Type* return_type_ptr) const;
- void findResources(Map<Var*, string>& resource_list) const;
- void print(ostream& out) const;
-private:
- // Private Methods
-
- // Private copy constructor and assignment operator
- CheckStopSlotsStatementAST(const CheckStopSlotsStatementAST& obj);
- CheckStopSlotsStatementAST& operator=(const CheckStopSlotsStatementAST& obj);
-
- // Data Members (m_ prefix)
- VarExprAST* m_variable;
- string* m_condStr_ptr;
- string* m_bankStr_ptr;
-};
-
-// Output operator declaration
-ostream& operator<<(ostream& out, const CheckStopSlotsStatementAST& obj);
-
-// ******************* Definitions *******************
-
-// Output operator definition
-extern inline
-ostream& operator<<(ostream& out, const CheckStopSlotsStatementAST& obj)
-{
- obj.print(out);
- out << flush;
- return out;
-}
-
-#endif //CHECKSTOPSLOTSSTATEMENTAST_H
diff --git a/src/mem/slicc/ast/CheckStopSlotsStatementAST.py b/src/mem/slicc/ast/CheckStopSlotsStatementAST.py
new file mode 100644
index 000000000..307fbd6a1
--- /dev/null
+++ b/src/mem/slicc/ast/CheckStopSlotsStatementAST.py
@@ -0,0 +1,74 @@
+# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
+# Copyright (c) 2009 The Hewlett-Packard Development Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (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 slicc.ast.StatementAST import StatementAST
+
+class CheckStopSlotsStatementAST(StatementAST):
+ def __init__(self, slicc, variable, condStr, bankStr):
+ super(StatementAST, self).__init__(slicc)
+ self.variable = variable
+ self.condStr = condStr
+ self.bankStr = bankStr
+
+ def __repr__(self):
+ return "[CheckStopSlotsStatementAst: %r]" % self.variable
+
+ def generate(self, code, return_type):
+ # Make sure the variable is valid
+ self.variable.var
+
+ def findResources(self, resources):
+ var = self.variable.var
+ assert var not in self.resources
+
+ check_code = code_formatter()
+ if self.condStr == "((*in_msg_ptr)).m_isOnChipSearch":
+ check_code('''
+const Response9Msg* in_msg_ptr =
+ dynamic_cast<const Response9Msg*>(((*(m_chip_ptr.m_L2Cache_responseToL2Cache9_vec[m_version]))).peek());
+assert(in_msg_ptr != NULL);
+''')
+
+ vcode = self.variable.inline()
+ bank = self.bankStr
+ cond = self.condStr
+
+ check_code('''
+if ($cond) {
+ auto pos = m_chip_ptr.m_DNUCAmover_ptr->getBankPos($bank)
+
+ if (!$vcode.isDisableSPossible(pos)) {
+ return TransitionResult_ResourceStall;
+ }
+} else {
+ if (!$vcode.isDisableFPossible(pos)) {
+ return TransitionResult_ResourceStall;
+ }
+}
+''')
+
+ resources[var] = str(check_code)
diff --git a/src/mem/slicc/ast/ChipComponentAccessAST.cc b/src/mem/slicc/ast/ChipComponentAccessAST.cc
deleted file mode 100644
index 61dccf2c0..000000000
--- a/src/mem/slicc/ast/ChipComponentAccessAST.cc
+++ /dev/null
@@ -1,244 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * ChipComponentAccessAST.C
- *
- * Description: See ChipComponentAccessAST.hh
- *
- * $Id: ChipComponentAccessAST.C 1.9 04/06/18 21:00:08-00:00 beckmann@cottons.cs.wisc.edu $
- *
- */
-
-#include "mem/slicc/ast/ChipComponentAccessAST.hh"
-
-ChipComponentAccessAST::ChipComponentAccessAST(VarExprAST* machine, ExprAST* mach_version, VarExprAST* component, string* proc_name, Vector<ExprAST*>* expr_vec_ptr)
-
- : ExprAST()
-{
- m_chip_ver_expr_ptr = NULL;
- m_mach_var_ptr = machine;
- m_comp_var_ptr = component;
- m_mach_ver_expr_ptr = mach_version;
- m_expr_vec_ptr = expr_vec_ptr;
- m_proc_name_ptr = proc_name;
- m_field_name_ptr = NULL;
-}
-
-ChipComponentAccessAST::ChipComponentAccessAST(VarExprAST* machine, ExprAST* mach_version, VarExprAST* component, string* field_name)
-
- : ExprAST()
-{
- m_chip_ver_expr_ptr = NULL;
- m_mach_var_ptr = machine;
- m_comp_var_ptr = component;
- m_mach_ver_expr_ptr = mach_version;
- m_expr_vec_ptr = NULL;
- m_proc_name_ptr = NULL;
- m_field_name_ptr = field_name;
-}
-
-ChipComponentAccessAST::ChipComponentAccessAST(ExprAST* chip_version, VarExprAST* machine, ExprAST* mach_version, VarExprAST* component, string* proc_name, Vector<ExprAST*>* expr_vec_ptr)
-
- : ExprAST()
-{
- m_chip_ver_expr_ptr = chip_version;
- m_mach_var_ptr = machine;
- m_comp_var_ptr = component;
- m_mach_ver_expr_ptr = mach_version;
- m_expr_vec_ptr = expr_vec_ptr;
- m_proc_name_ptr = proc_name;
- m_field_name_ptr = NULL;
-}
-
-ChipComponentAccessAST::ChipComponentAccessAST(ExprAST* chip_version, VarExprAST* machine, ExprAST* mach_version, VarExprAST* component, string* field_name)
-
- : ExprAST()
-{
- m_chip_ver_expr_ptr = chip_version;
- m_mach_var_ptr = machine;
- m_comp_var_ptr = component;
- m_mach_ver_expr_ptr = mach_version;
- m_expr_vec_ptr = NULL;
- m_proc_name_ptr = NULL;
- m_field_name_ptr = field_name;
-}
-
-
-
-ChipComponentAccessAST::~ChipComponentAccessAST()
-{
- if (m_expr_vec_ptr != NULL) {
- int size = m_expr_vec_ptr->size();
- for(int i=0; i<size; i++) {
- delete (*m_expr_vec_ptr)[i];
- }
- }
-
- delete m_mach_var_ptr;
- delete m_comp_var_ptr;
- delete m_mach_ver_expr_ptr;
-
- if (m_proc_name_ptr != NULL) {
- delete m_proc_name_ptr;
- }
-
- if (m_field_name_ptr != NULL) {
- delete m_field_name_ptr;
- }
-
- if (m_chip_ver_expr_ptr != NULL) {
- delete m_chip_ver_expr_ptr;
- }
-}
-
-Type* ChipComponentAccessAST::generate(string& code) const
-{
- Type* void_type_ptr = g_sym_table.getType("void");
- Type* ret_type_ptr;
-
-
- code += "(";
-
- Var* v = g_sym_table.getMachComponentVar(m_mach_var_ptr->getName(), m_comp_var_ptr->getName());
-
- string orig_code = v->getCode();
- string working_code;
-
- if (m_chip_ver_expr_ptr != NULL) {
- // replace m_chip_ptr with specified chip
-
- unsigned int t = orig_code.find("m_chip_ptr");
- assert(t != string::npos);
- string code_temp0 = orig_code.substr(0, t);
- string code_temp1 = orig_code.substr(t+10);
-
- working_code += code_temp0;
- working_code += "g_system_ptr->getChip(";
- m_chip_ver_expr_ptr->generate(working_code);
- working_code += ")";
- working_code += code_temp1;
- }
- else {
- working_code += orig_code;
- }
-
- // replace default "m_version" with the version we really want
- unsigned int tmp_uint = working_code.find("m_version");
- assert(tmp_uint != string::npos);
- string code_temp2 = working_code.substr(0, tmp_uint);
- string code_temp3 = working_code.substr(tmp_uint+9);
-
- code += code_temp2;
- code += "(";
- m_mach_ver_expr_ptr->generate(code);
- code += ")";
- code += code_temp3;
- code += ")";
-
- if (m_proc_name_ptr != NULL) {
- // method call
- code += ".";
-
- Vector <Type*> paramTypes;
-
- // generate code
- int actual_size = m_expr_vec_ptr->size();
- code += (*m_proc_name_ptr) + "(";
- for(int i=0; i<actual_size; i++) {
- if (i != 0) {
- code += ", ";
- }
- // Check the types of the parameter
- Type* actual_type_ptr = (*m_expr_vec_ptr)[i]->generate(code);
- paramTypes.insertAtBottom(actual_type_ptr);
- }
- code += ")";
-
- Type* obj_type_ptr = v->getType();
- string methodId = obj_type_ptr->methodId(*m_proc_name_ptr, paramTypes);
-
- // Verify that this is a method of the object
- if (!obj_type_ptr->methodExist(methodId)) {
- error("Invalid method call: Type '" + obj_type_ptr->toString() + "' does not have a method '" + methodId + "'");
- }
-
- int expected_size = obj_type_ptr->methodParamType(methodId).size();
- if (actual_size != expected_size) {
- // Right number of parameters
- ostringstream err;
- err << "Wrong number of parameters for function name: '" << *m_proc_name_ptr << "'";
- err << ", expected: ";
- err << expected_size;
- err << ", actual: ";
- err << actual_size;
- error(err.str());
- }
-
- for(int i=0; i<actual_size; i++) {
- // Check the types of the parameter
- Type* actual_type_ptr = paramTypes[i];
- Type* expected_type_ptr = obj_type_ptr->methodParamType(methodId)[i];
- if (actual_type_ptr != expected_type_ptr) {
- (*m_expr_vec_ptr)[i]->error("Type mismatch: expected: " + expected_type_ptr->toString() +
- " actual: " + actual_type_ptr->toString());
- }
- }
-
- // Return the return type of the method
- ret_type_ptr = obj_type_ptr->methodReturnType(methodId);
- }
- else if (m_field_name_ptr != NULL) {
- Type* obj_type_ptr = v->getType();
- code += ").m_" + (*m_field_name_ptr);
-
- // Verify that this is a valid field name for this type
- if (!obj_type_ptr->dataMemberExist(*m_field_name_ptr)) {
- error("Invalid object field: Type '" + obj_type_ptr->toString() + "' does not have data member " + *m_field_name_ptr);
- }
-
- // Return the type of the field
- ret_type_ptr = obj_type_ptr->dataMemberType(*m_field_name_ptr);
- }
- else {
- assert(0);
- }
-
- return ret_type_ptr;
-}
-
-void ChipComponentAccessAST::findResources(Map<Var*, string>& resource_list) const
-{
-
-}
-
-void ChipComponentAccessAST::print(ostream& out) const
-{
- out << "[ChipAccessExpr: " << *m_expr_vec_ptr << "]";
-}
diff --git a/src/mem/slicc/ast/ChipComponentAccessAST.hh b/src/mem/slicc/ast/ChipComponentAccessAST.hh
deleted file mode 100644
index 1f22a79e4..000000000
--- a/src/mem/slicc/ast/ChipComponentAccessAST.hh
+++ /dev/null
@@ -1,101 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- *
- *
- * Description:
- *
- * $Id: ChipComponentAccessAST.hh 1.8 04/06/18 21:00:08-00:00 beckmann@cottons.cs.wisc.edu $
- *
- */
-
-#ifndef ChipComponentAccessAST_H
-#define ChipComponentAccessAST_H
-
-#include "mem/slicc/slicc_global.hh"
-#include "mem/slicc/ast/StatementAST.hh"
-#include "mem/slicc/ast/ExprAST.hh"
-#include "mem/slicc/ast/VarExprAST.hh"
-#include "mem/slicc/ast/TypeAST.hh"
-
-class ChipComponentAccessAST : public ExprAST {
-public:
- // Constructors
-
- // method call from local chip
- ChipComponentAccessAST(VarExprAST* machine, ExprAST* mach_version, VarExprAST* component, string* proc_name, Vector<ExprAST*>* expr_vec_ptr);
- // member access from local chip
- ChipComponentAccessAST(VarExprAST* machine, ExprAST* mach_version, VarExprAST* component, string* field_name);
-
- // method call from specified chip
- ChipComponentAccessAST(ExprAST* chip_version, VarExprAST* machine, ExprAST* mach_version, VarExprAST* component, string* proc_name, Vector<ExprAST*>* expr_vec_ptr);
-
- // member access from specified chip
- ChipComponentAccessAST(ExprAST* chip_version, VarExprAST* machine, ExprAST* mach_version, VarExprAST* component, string* field_name);
-
- // Destructor
- ~ChipComponentAccessAST();
-
- // Public Methods
- Type* generate(string& code) const;
- void findResources(Map<Var*, string>& resource_list) const;
- void print(ostream& out) const;
-private:
- // Private Methods
-
- // Private copy constructor and assignment operator
- ChipComponentAccessAST(const ChipComponentAccessAST& obj);
- ChipComponentAccessAST& operator=(const ChipComponentAccessAST& obj);
-
- // Data Members (m_ prefix)
- VarExprAST* m_mach_var_ptr;
- VarExprAST* m_comp_var_ptr;
- ExprAST* m_mach_ver_expr_ptr;
- ExprAST* m_chip_ver_expr_ptr;
- Vector<ExprAST*>* m_expr_vec_ptr;
- string* m_proc_name_ptr;
- string* m_field_name_ptr;
-};
-
-// Output operator declaration
-ostream& operator<<(ostream& out, const ChipComponentAccessAST& obj);
-
-// ******************* Definitions *******************
-
-// Output operator definition
-extern inline
-ostream& operator<<(ostream& out, const ChipComponentAccessAST& obj)
-{
- obj.print(out);
- out << flush;
- return out;
-}
-
-#endif // ChipComponentAccessAST_H
diff --git a/src/mem/slicc/ast/ChipComponentAccessAST.py b/src/mem/slicc/ast/ChipComponentAccessAST.py
new file mode 100644
index 000000000..841220c94
--- /dev/null
+++ b/src/mem/slicc/ast/ChipComponentAccessAST.py
@@ -0,0 +1,161 @@
+# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
+# Copyright (c) 2009 The Hewlett-Packard Development Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+import re
+
+from slicc.ast.ExprAST import ExprAST
+from slicc.symbols import Type
+
+class ChipComponentAccessAST(ExprAST):
+ def __init__(self, slicc, machine, mach_version, component):
+ super(ChipComponentAccessAST, self).__init__(slicc)
+ self.mach_var = machine
+ self.comp_var = component
+ self.mach_ver_expr = mach_version
+
+ def __repr__(self):
+ return "[ChipAccessExpr: %r]" % self.expr_vec
+
+ def generate(self, code):
+ void_type = self.symtab.find("void", Type)
+
+ mname = self.mach_var.name
+ cname = self.comp_var.name
+ var = self.symtab.machine_components[mname][cname]
+
+ vcode = str(var.code)
+
+ if self.chip_ver_expr is not None:
+ # replace self.chip with specified chip
+ gcode = "g_system.getChip(%s)" % self.chip_ver_expr.inline()
+ vcode = re.sub("m_chip", gcode, vcode)
+
+ # replace default "m_version" with the version we really want
+ gcode = "(%s)" % self.mach_ver_expr.inline()
+ vcode = re.sub("m_version", gcode, vcode)
+
+ return_type, gcode = self.generate_access(var)
+ code("($vcode)$gcode")
+ return return_type
+
+class ChipMethodAccessAST(ChipComponentAccessAST):
+ def __init__(self, slicc, chip_version, machine, mach_version, component,
+ proc_name, expr_vec):
+ s = super(ChipMethodAccessAST, self)
+ s.__init__(slicc, machine, mach_version, component)
+
+ self.chip_ver_expr = chip_version
+ self.expr_vec = expr_vec
+ self.proc_name = proc_name
+
+ def generate_access(self, var):
+ # generate code
+ paramTypes = []
+ gcode = []
+ for expr in self.expr_vec:
+ t,c = expr.generate()
+ paramTypes.append(t)
+ gcode.append(c)
+
+ methodId = var.type.methodId(self.proc_name, paramTypes)
+
+ # Verify that this is a method of the object
+ if not var.type.methodExist(methodId):
+ error("%s: Type '%s' does not have a method '%s'" % \
+ ("Invalid method call", var.type, methodId))
+
+ expected_size = len(var.type.methodParamType(methodId))
+ if len(self.expr_vec) != expected_size:
+ # Right number of parameters
+ self.error("Wrong number of parameters for function name: " +\
+ "'%s', expected: %d, actual: %d",
+ self.proc_name, expected_size, len(self.expr_vec))
+
+ for expr,expected,actual in zip(self.expr_vec,
+ var.type.methodParamType(methodId),
+ paramTypes):
+ # Check the types of the parameter
+ if actual != expected:
+ expr.error("Type mismatch: expected: %s actual: %s",
+ expected, actual)
+
+ # method call
+ code = ".%s(%s)" % (self.proc_name, ', '.join(gcode))
+
+ # Return the return type of the method
+ return var.type.methodReturnType(methodId), code
+
+class LocalChipMethodAST(ChipMethodAccessAST):
+ # method call from local chip
+ def __init__(self, slicc, machine, mach_version, component, proc_name,
+ expr_vec):
+ s = super(LocalChipMethodAST, self)
+ s.__init__(slicc, None, machine, mach_version, component, proc_name,
+ expr_vec)
+
+class SpecifiedChipMethodAST(ChipMethodAccessAST):
+ # method call from specified chip
+ def __init__(self, slicc, chip_version, machine, mach_version, component,
+ proc_name, expr_vec):
+ s = super(SpecifiedChipMethodAST, self)
+ s.__init__(slicc, chip_version, machine, mach_version, component,
+ proc_name, expr_vec)
+
+class ChipMemberAccessAST(ChipComponentAccessAST):
+ # member access from specified chip
+ def __init__(self, chip_version, machine, mach_version, component,
+ field_name):
+ s = super(ChipMemberAccessAST, self)
+ s.__init__(slicc, machine, mach_version, component)
+
+ self.chip_ver_expr = chip_version
+ self.field_name = field_name
+
+ def generate_access(self, var):
+ # Verify that this is a valid field name for this type
+ if not var.type.dataMemberExist(self.field_name):
+ self.error("Invalid object field: " +\
+ "Type '%s' does not have data member %s",
+ var.type, self.field_name)
+
+ code += ").m_%s" % self.field_name
+
+ return var.type.dataMemberType(self.field_name), code
+
+class LocalChipMemberAST(ChipMemberAccessAST):
+ # member access from local chip
+ def __init__(self, slicc, machine, mach_version, component, field_name):
+ s = super(LocalChipMemberAST, self)
+ s.__init__(slicc, None, machine, mach_version, component, field_name)
+
+class SpecifiedChipMemberAST(ChipMemberAccessAST):
+ # member access from specified chip
+ def __init__(self, chip_version, machine, mach_version, component,
+ field_name):
+ s = super(SpecifiedChipMemberAST, self)
+ s.__init__(slicc, chip_version, machine, mach_version, component,
+ field_name)
diff --git a/src/mem/slicc/ast/CopyHeadStatementAST.cc b/src/mem/slicc/ast/CopyHeadStatementAST.cc
deleted file mode 100644
index 8d455eb9d..000000000
--- a/src/mem/slicc/ast/CopyHeadStatementAST.cc
+++ /dev/null
@@ -1,85 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * $Id$
- *
- */
-
-#include "mem/slicc/ast/CopyHeadStatementAST.hh"
-#include "mem/slicc/symbols/SymbolTable.hh"
-#include "mem/slicc/ast/VarExprAST.hh"
-#include "mem/gems_common/util.hh"
-
-CopyHeadStatementAST::CopyHeadStatementAST(VarExprAST* in_queue_ptr,
- VarExprAST* out_queue_ptr,
- PairListAST* pairs_ptr)
- : StatementAST(pairs_ptr->getPairs())
-{
- m_in_queue_ptr = in_queue_ptr;
- m_out_queue_ptr = out_queue_ptr;
-}
-
-CopyHeadStatementAST::~CopyHeadStatementAST()
-{
- delete m_in_queue_ptr;
- delete m_out_queue_ptr;
-}
-
-void CopyHeadStatementAST::generate(string& code, Type* return_type_ptr) const
-{
- m_in_queue_ptr->assertType("InPort");
- m_out_queue_ptr->assertType("OutPort");
-
- code += indent_str();
- code += m_out_queue_ptr->getVar()->getCode() + ".enqueue(" + m_in_queue_ptr->getVar()->getCode() + ".getMsgPtrCopy()";
-
- if (getPairs().exist("latency")) {
- code += ", " + getPairs().lookup("latency");
- } else {
- code += ", COPY_HEAD_LATENCY";
- }
-
- code += ");\n";
-}
-
-void CopyHeadStatementAST::findResources(Map<Var*, string>& resource_list) const
-{
- Var* var_ptr = m_out_queue_ptr->getVar();
- int res_count = 0;
- if (resource_list.exist(var_ptr)) {
- res_count = atoi((resource_list.lookup(var_ptr)).c_str());
- }
- resource_list.add(var_ptr, int_to_string(res_count+1));
-}
-
-void CopyHeadStatementAST::print(ostream& out) const
-{
- out << "[CopyHeadStatementAst: " << *m_in_queue_ptr << " " << *m_out_queue_ptr << "]";
-}
diff --git a/src/mem/slicc/ast/CopyHeadStatementAST.hh b/src/mem/slicc/ast/CopyHeadStatementAST.hh
deleted file mode 100644
index 53d479136..000000000
--- a/src/mem/slicc/ast/CopyHeadStatementAST.hh
+++ /dev/null
@@ -1,87 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * $Id$
- *
- */
-
-#ifndef COPYHEADSTATEMENTAST_H
-#define COPYHEADTATEMENTAST_H
-
-#include "mem/slicc/slicc_global.hh"
-#include "mem/slicc/ast/StatementAST.hh"
-#include "mem/slicc/ast/StatementListAST.hh"
-#include "mem/slicc/ast/TypeAST.hh"
-#include "mem/slicc/ast/PairListAST.hh"
-
-class VarExprAST;
-class Var;
-
-class CopyHeadStatementAST : public StatementAST {
-public:
- // Constructors
- CopyHeadStatementAST(VarExprAST* in_queue_ptr,
- VarExprAST* out_queue_ptr,
- PairListAST* pairs_ptr);
-
- // Destructor
- ~CopyHeadStatementAST();
-
- // Public Methods
- void generate(string& code, Type* return_type_ptr) const;
- void findResources(Map<Var*, string>& resource_list) const;
- void print(ostream& out) const;
-private:
- // Private Methods
-
- // Private copy constructor and assignment operator
- CopyHeadStatementAST(const CopyHeadStatementAST& obj);
- CopyHeadStatementAST& operator=(const CopyHeadStatementAST& obj);
-
- // Data Members (m_ prefix)
- VarExprAST* m_in_queue_ptr;
- VarExprAST* m_out_queue_ptr;
-};
-
-// Output operator declaration
-ostream& operator<<(ostream& out, const CopyHeadStatementAST& obj);
-
-// ******************* Definitions *******************
-
-// Output operator definition
-extern inline
-ostream& operator<<(ostream& out, const CopyHeadStatementAST& obj)
-{
- obj.print(out);
- out << flush;
- return out;
-}
-
-#endif //COPYHEADSTATEMENTAST_H
diff --git a/src/mem/slicc/ast/CopyHeadStatementAST.py b/src/mem/slicc/ast/CopyHeadStatementAST.py
new file mode 100644
index 000000000..ba9970975
--- /dev/null
+++ b/src/mem/slicc/ast/CopyHeadStatementAST.py
@@ -0,0 +1,52 @@
+# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
+# Copyright (c) 2009 The Hewlett-Packard Development Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (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 slicc.ast.StatementAST import StatementAST
+
+class CopyHeadStatementAST(StatementAST):
+ def __init__(self, slicc, in_queue, out_queue, pairs):
+ super(CopyHeadStatementAST, self).__init__(slicc, pairs)
+
+ self.in_queue = in_queue
+ self.out_queue_ptr = out_queue
+
+ def __repr__(self):
+ return "[CopyHeadStatementAst: %r %r]" % (self.in_queue,
+ self.out_queue)
+
+ def generate(self, code, return_type):
+ self.in_queue.assertType("InPort")
+ self.out_queue.assertType("OutPort")
+
+ out_code = self.out_queue.var.code
+ in_code = self.in_queue.var.code
+ latency = self.get("latency", "COPY_HEAD_LATENCY")
+ code("$out_code.enqueue($in_code.getMsgPtrCopy(), $latency);")
+
+ def findResources(self, resources):
+ var = self.out_queue.var
+ resources[var] = str(int(resources.get(var, "0")) + 1)
diff --git a/src/mem/slicc/ast/DeclAST.cc b/src/mem/slicc/ast/DeclAST.cc
deleted file mode 100644
index 6ccf9a9d6..000000000
--- a/src/mem/slicc/ast/DeclAST.cc
+++ /dev/null
@@ -1,39 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * DeclAST.C
- *
- * Description: See DeclAST.hh
- *
- * $Id$
- *
- */
-
-#include "mem/slicc/ast/DeclAST.hh"
diff --git a/src/mem/slicc/ast/DeclAST.hh b/src/mem/slicc/ast/DeclAST.hh
deleted file mode 100644
index d9e4555b4..000000000
--- a/src/mem/slicc/ast/DeclAST.hh
+++ /dev/null
@@ -1,85 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * DeclAST.hh
- *
- * Description:
- *
- * $Id$
- *
- */
-
-#ifndef DECLAST_H
-#define DECLAST_H
-
-#include "mem/slicc/slicc_global.hh"
-#include "mem/slicc/ast/AST.hh"
-#include "mem/slicc/ast/PairListAST.hh"
-#include "mem/slicc/symbols/StateMachine.hh"
-#include "mem/slicc/ast/TypeAST.hh"
-
-class DeclAST : public AST {
-public:
- // Constructors
- DeclAST(PairListAST* pairs_ptr) : AST(pairs_ptr->getPairs()) {}
-
- // Destructor
- virtual ~DeclAST() {}
-
- // Public Methods
- virtual void generate() = 0;
- virtual void findMachines() {};
-
- // void print(ostream& out) const;
-private:
- // Private Methods
-
- // Private copy constructor and assignment operator
- // DeclAST(const DeclAST& obj);
- // DeclAST& operator=(const DeclAST& obj);
-
- // Data Members (m_ prefix)
-};
-
-// Output operator declaration
-ostream& operator<<(ostream& out, const DeclAST& obj);
-
-// ******************* Definitions *******************
-
-// Output operator definition
-extern inline
-ostream& operator<<(ostream& out, const DeclAST& obj)
-{
- obj.print(out);
- out << flush;
- return out;
-}
-
-#endif //DECLAST_H
diff --git a/src/mem/slicc/ast/DeclAST.py b/src/mem/slicc/ast/DeclAST.py
new file mode 100644
index 000000000..2303725a3
--- /dev/null
+++ b/src/mem/slicc/ast/DeclAST.py
@@ -0,0 +1,38 @@
+# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
+# Copyright (c) 2009 The Hewlett-Packard Development Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (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 slicc.ast.AST import AST
+
+class DeclAST(AST):
+ def __init__(self, slicc, pairs):
+ super(DeclAST, self).__init__(slicc, pairs)
+
+ def files(self, hh, cc, parent=None):
+ pass
+
+ def findMachines(self):
+ return
diff --git a/src/mem/slicc/ast/DeclListAST.cc b/src/mem/slicc/ast/DeclListAST.cc
deleted file mode 100644
index 8337d714b..000000000
--- a/src/mem/slicc/ast/DeclListAST.cc
+++ /dev/null
@@ -1,86 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * DeclListAST.C
- *
- * Description: See DeclListAST.hh
- *
- * $Id$
- *
- */
-
-#include "mem/slicc/ast/DeclListAST.hh"
-
-DeclListAST::DeclListAST(Vector<DeclAST*>* vec_ptr)
- : AST()
-{
- assert(vec_ptr != NULL);
- m_vec_ptr = vec_ptr;
-}
-
-// Singleton constructor.
-DeclListAST::DeclListAST(DeclAST* Decl_ptr)
- : AST()
-{
- assert(Decl_ptr != NULL);
- m_vec_ptr = new Vector<DeclAST*>;
- m_vec_ptr->insertAtTop(Decl_ptr);
-}
-
-DeclListAST::~DeclListAST()
-{
- int size = m_vec_ptr->size();
- for(int i=0; i<size; i++) {
- delete (*m_vec_ptr)[i];
- }
- delete m_vec_ptr;
-}
-
-void DeclListAST::generate() const
-{
- int size = m_vec_ptr->size();
- for(int i=0; i<size; i++) {
- (*m_vec_ptr)[i]->generate();
- }
-}
-
-void DeclListAST::findMachines() const
-{
- int size = m_vec_ptr->size();
- for(int i=0; i<size; i++) {
- (*m_vec_ptr)[i]->findMachines();
- }
-}
-
-void DeclListAST::print(ostream& out) const
-{
- assert(m_vec_ptr != NULL);
- out << "[DeclListAST: " << *m_vec_ptr << "]";
-}
diff --git a/src/mem/slicc/ast/DeclListAST.hh b/src/mem/slicc/ast/DeclListAST.hh
deleted file mode 100644
index 1c2bc3c05..000000000
--- a/src/mem/slicc/ast/DeclListAST.hh
+++ /dev/null
@@ -1,84 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * DeclListAST.hh
- *
- * Description:
- *
- * $Id: DeclListAST.hh,v 3.1 2001/12/12 01:00:12 milo Exp $
- *
- */
-
-#ifndef DeclListAST_H
-#define DeclListAST_H
-
-#include "mem/slicc/slicc_global.hh"
-#include "mem/slicc/ast/AST.hh"
-#include "mem/slicc/ast/DeclAST.hh"
-
-class DeclListAST : public AST {
-public:
- // Constructors
- DeclListAST(Vector<DeclAST*>* vec_ptr);
- DeclListAST(DeclAST* statement_ptr);
-
- // Destructor
- ~DeclListAST();
-
- // Public Methods
- void generate() const;
- void findMachines() const;
- void print(ostream& out) const;
-private:
- // Private Methods
-
- // Private copy constructor and assignment operator
- DeclListAST(const DeclListAST& obj);
- DeclListAST& operator=(const DeclListAST& obj);
-
- // Data Members (m_ prefix)
- Vector<DeclAST*>* m_vec_ptr;
-};
-
-// Output operator declaration
-ostream& operator<<(ostream& out, const DeclListAST& obj);
-
-// ******************* Definitions *******************
-
-// Output operator definition
-extern inline
-ostream& operator<<(ostream& out, const DeclListAST& obj)
-{
- obj.print(out);
- out << flush;
- return out;
-}
-
-#endif //DeclListAST_H
diff --git a/src/mem/slicc/ast/DeclListAST.py b/src/mem/slicc/ast/DeclListAST.py
new file mode 100644
index 000000000..42f98afc7
--- /dev/null
+++ b/src/mem/slicc/ast/DeclListAST.py
@@ -0,0 +1,51 @@
+# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
+# Copyright (c) 2009 The Hewlett-Packard Development Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (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 slicc.ast.AST import AST
+
+class DeclListAST(AST):
+ def __init__(self, slicc, decls):
+ super(DeclListAST, self).__init__(slicc)
+
+ if not isinstance(decls, (list, tuple)):
+ decls = [ decls ]
+ self.decls = decls
+
+ def __repr__(self):
+ return "[DeclListAST: %s]" % (', '.join(repr(d) for d in self.decls))
+
+ def files(self, hh, cc, parent=None):
+ for decl in self.decls:
+ decl.files(hh, cc, parent)
+
+ def generate(self):
+ for decl in self.decls:
+ decl.generate()
+
+ def findMachines(self):
+ for decl in self.decls:
+ decl.findMachines()
diff --git a/src/mem/slicc/ast/EnqueueStatementAST.cc b/src/mem/slicc/ast/EnqueueStatementAST.cc
deleted file mode 100644
index a422d8a28..000000000
--- a/src/mem/slicc/ast/EnqueueStatementAST.cc
+++ /dev/null
@@ -1,111 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * $Id$
- *
- */
-
-#include "mem/slicc/ast/EnqueueStatementAST.hh"
-#include "mem/slicc/symbols/SymbolTable.hh"
-#include "mem/slicc/ast/VarExprAST.hh"
-#include "mem/slicc/ast/PairListAST.hh"
-#include "mem/gems_common/util.hh"
-
-EnqueueStatementAST::EnqueueStatementAST(VarExprAST* queue_name_ptr,
- TypeAST* type_name_ptr,
- PairListAST* pairs_ptr,
- StatementListAST* statement_list_ast_ptr)
- : StatementAST(pairs_ptr->getPairs())
-{
- m_queue_name_ptr = queue_name_ptr;
- m_type_name_ptr = type_name_ptr;
- m_statement_list_ast_ptr = statement_list_ast_ptr;
-}
-
-EnqueueStatementAST::~EnqueueStatementAST()
-{
- delete m_queue_name_ptr;
- delete m_type_name_ptr;
- delete m_statement_list_ast_ptr;
-}
-
-void EnqueueStatementAST::generate(string& code, Type* return_type_ptr) const
-{
- code += indent_str() + "{\n"; // Start scope
- inc_indent();
- g_sym_table.pushFrame();
-
- Type* msg_type_ptr = m_type_name_ptr->lookupType();
-
- // Add new local var to symbol table
- g_sym_table.newSym(new Var("out_msg", getLocation(), msg_type_ptr, "out_msg", getPairs()));
-
- code += indent_str() + msg_type_ptr->cIdent() + " out_msg;\n"; // Declare message
- m_statement_list_ast_ptr->generate(code, NULL); // The other statements
-
- code += indent_str();
-
- m_queue_name_ptr->assertType("OutPort");
- code += "(" + m_queue_name_ptr->getVar()->getCode() + ")";
- code += ".enqueue(out_msg";
-
- if (getPairs().exist("latency")) {
- bool is_number = true;
- string val = getPairs().lookup("latency");
- for (int i=0; i<val.size(); i++)
- if (!isdigit(val[i])) is_number = false;
- if (is_number)
- code += ", " + getPairs().lookup("latency");
- else
- code += ", m_" + getPairs().lookup("latency");
- }
-
- code += ");\n";
-
- dec_indent();
- g_sym_table.popFrame();
- code += indent_str() + "}\n"; // End scope
-}
-
-void EnqueueStatementAST::findResources(Map<Var*, string>& resource_list) const
-{
- Var* var_ptr = m_queue_name_ptr->getVar();
- int res_count = 0;
- if (resource_list.exist(var_ptr)) {
- res_count = atoi((resource_list.lookup(var_ptr)).c_str());
- }
- resource_list.add(var_ptr, int_to_string(res_count+1));
-}
-
-void EnqueueStatementAST::print(ostream& out) const
-{
- out << "[EnqueueStatementAst: " << *m_queue_name_ptr << " "
- << m_type_name_ptr->toString() << " " << *m_statement_list_ast_ptr << "]";
-}
diff --git a/src/mem/slicc/ast/EnqueueStatementAST.hh b/src/mem/slicc/ast/EnqueueStatementAST.hh
deleted file mode 100644
index fc2776ed7..000000000
--- a/src/mem/slicc/ast/EnqueueStatementAST.hh
+++ /dev/null
@@ -1,93 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * EnqueueStatementAST.hh
- *
- * Description:
- *
- * $Id$
- *
- */
-
-#ifndef ENQUEUESTATEMENTAST_H
-#define ENQUEUESTATEMENTAST_H
-
-#include "mem/slicc/slicc_global.hh"
-#include "mem/slicc/ast/StatementAST.hh"
-#include "mem/slicc/ast/StatementListAST.hh"
-#include "mem/slicc/ast/TypeAST.hh"
-
-class VarExprAST;
-class Var;
-class PairListAST;
-
-class EnqueueStatementAST : public StatementAST {
-public:
- // Constructors
- EnqueueStatementAST(VarExprAST* queue_name_ptr,
- TypeAST* type_name_ptr,
- PairListAST* pairs_ptr,
- StatementListAST* statement_list_ast_ptr);
-
- // Destructor
- ~EnqueueStatementAST();
-
- // Public Methods
- void generate(string& code, Type* return_type_ptr) const;
- void findResources(Map<Var*, string>& resource_list) const;
- void print(ostream& out) const;
-private:
- // Private Methods
-
- // Private copy constructor and assignment operator
- EnqueueStatementAST(const EnqueueStatementAST& obj);
- EnqueueStatementAST& operator=(const EnqueueStatementAST& obj);
-
- // Data Members (m_ prefix)
- VarExprAST* m_queue_name_ptr;
- TypeAST* m_type_name_ptr;
- StatementListAST* m_statement_list_ast_ptr;
-};
-
-// Output operator declaration
-ostream& operator<<(ostream& out, const EnqueueStatementAST& obj);
-
-// ******************* Definitions *******************
-
-// Output operator definition
-extern inline
-ostream& operator<<(ostream& out, const EnqueueStatementAST& obj)
-{
- obj.print(out);
- out << flush;
- return out;
-}
-
-#endif //ENQUEUESTATEMENTAST_H
diff --git a/src/mem/slicc/ast/EnqueueStatementAST.py b/src/mem/slicc/ast/EnqueueStatementAST.py
new file mode 100644
index 000000000..faf966460
--- /dev/null
+++ b/src/mem/slicc/ast/EnqueueStatementAST.py
@@ -0,0 +1,86 @@
+# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
+# Copyright (c) 2009 The Hewlett-Packard Development Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (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 slicc.ast.StatementAST import StatementAST
+from slicc.symbols import Var
+
+class EnqueueStatementAST(StatementAST):
+ def __init__(self, slicc, queue_name, type_ast, pairs, statements):
+ super(EnqueueStatementAST, self).__init__(slicc, pairs)
+
+ self.queue_name = queue_name
+ self.type_ast = type_ast
+ self.statements = statements
+
+ def __repr__(self):
+ return "[EnqueueStatementAst: %s %s %s]" % \
+ (self.queue_name, self.type_ast.ident, self.statements)
+
+ def generate(self, code, return_type):
+ code("{")
+ code.indent()
+ self.symtab.pushFrame()
+
+ msg_type = self.type_ast.type
+
+ # Add new local var to symbol table
+ v = Var(self.symtab, "out_msg", self.location, msg_type, "out_msg",
+ self.pairs)
+ self.symtab.newSymbol(v)
+
+ # Declare message
+ code("${{msg_type.ident}} out_msg;")
+
+ # The other statements
+ t = self.statements.generate(code, None)
+
+ self.queue_name.assertType("OutPort")
+
+ args = [ "out_msg" ]
+ if "latency" in self:
+ latency = self["latency"]
+ try:
+ # see if this is an integer
+ latency = int(latency)
+ args.append("%s" % latency)
+ except ValueError:
+ # if not, it should be a member
+ args.append("m_%s" % latency)
+
+ args = ", ".join(args)
+ code('(${{self.queue_name.var.code}}).enqueue($args);')
+
+
+ # End scope
+ self.symtab.popFrame()
+ code.dedent()
+ code("}")
+
+ def findResources(self, resources):
+ var = self.queue_name.var
+ res_count = int(resources.get(var, 0))
+ resources[var] = str(res_count + 1)
diff --git a/src/mem/slicc/ast/EnumDeclAST.cc b/src/mem/slicc/ast/EnumDeclAST.cc
deleted file mode 100644
index b051f3c8f..000000000
--- a/src/mem/slicc/ast/EnumDeclAST.cc
+++ /dev/null
@@ -1,98 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * EnumDeclAST.C
- *
- * Description: See EnumDeclAST.hh
- *
- * $Id$
- *
- */
-
-#include "mem/slicc/ast/EnumDeclAST.hh"
-#include "mem/slicc/main.hh"
-#include "mem/slicc/symbols/SymbolTable.hh"
-
-EnumDeclAST::EnumDeclAST(TypeAST* type_ast_ptr,
- PairListAST* pairs_ptr,
- Vector<TypeFieldAST*>* field_vec_ptr)
- : DeclAST(pairs_ptr)
-{
- m_type_ast_ptr = type_ast_ptr;
- m_field_vec_ptr = field_vec_ptr;
-}
-
-EnumDeclAST::~EnumDeclAST()
-{
- delete m_type_ast_ptr;
- if (m_field_vec_ptr != NULL) {
- int size = m_field_vec_ptr->size();
- for(int i=0; i<size; i++) {
- delete (*m_field_vec_ptr)[i];
- }
- delete m_field_vec_ptr;
- }
-}
-
-void EnumDeclAST::generate()
-{
- string machine_name;
- string id = m_type_ast_ptr->toString();
-
- Vector<Type*> param_type_vec; // used by to_string func call
-
- // Make the new type
- Type* new_type_ptr = new Type(id, getLocation(), getPairs(),
- g_sym_table.getStateMachine());
- g_sym_table.newSym(new_type_ptr);
-
- // Add all of the fields of the type to it
- if (m_field_vec_ptr != NULL) {
- int size = m_field_vec_ptr->size();
- for(int i=0; i<size; i++) {
- (*m_field_vec_ptr)[i]->generate(new_type_ptr);
- }
- }
-
- // Add the implicit State_to_string method - FIXME, this is a bit dirty
- param_type_vec.insertAtBottom(new_type_ptr); // add state to param vector
- string func_id = new_type_ptr->cIdent()+"_to_string";
-
- Map<string, string> pairs;
- pairs.add("external", "yes");
- Vector<string> string_vec;
- g_sym_table.newSym(new Func(func_id, getLocation(), g_sym_table.getType("string"), param_type_vec, string_vec, string(""), pairs, NULL));
-}
-
-void EnumDeclAST::print(ostream& out) const
-{
- out << "[EnumDecl: " << m_type_ast_ptr->toString() << "]";
-}
-
diff --git a/src/mem/slicc/ast/EnumDeclAST.hh b/src/mem/slicc/ast/EnumDeclAST.hh
deleted file mode 100644
index 2af650e83..000000000
--- a/src/mem/slicc/ast/EnumDeclAST.hh
+++ /dev/null
@@ -1,86 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * EnummDeclAST.hh
- *
- * Description:
- *
- * $Id$
- *
- */
-
-#ifndef EnumDeclAST_H
-#define EnumDeclAST_H
-
-#include "mem/slicc/slicc_global.hh"
-#include "mem/slicc/ast/DeclAST.hh"
-#include "mem/slicc/ast/TypeAST.hh"
-#include "mem/slicc/ast/TypeFieldAST.hh"
-
-class EnumDeclAST : public DeclAST {
-public:
- // Constructors
- EnumDeclAST(TypeAST* type_ast_ptr,
- PairListAST* pairs_ptr,
- Vector<TypeFieldAST*>* field_vec_ptr);
-
- // Destructor
- ~EnumDeclAST();
-
- // Public Methods
- virtual void generate();
- void print(ostream& out) const;
-private:
- // Private Methods
-
- // Private copy constructor and assignment operator
- EnumDeclAST(const EnumDeclAST& obj);
- EnumDeclAST& operator=(const EnumDeclAST& obj);
-
- // Data Members (m_ prefix)
- TypeAST* m_type_ast_ptr;
- Vector<TypeFieldAST*>* m_field_vec_ptr;
-};
-
-// Output operator declaration
-ostream& operator<<(ostream& out, const EnumDeclAST& obj);
-
-// ******************* Definitions *******************
-
-// Output operator definition
-extern inline
-ostream& operator<<(ostream& out, const EnumDeclAST& obj)
-{
- obj.print(out);
- out << flush;
- return out;
-}
-
-#endif //EnumDeclAST_H
diff --git a/src/mem/slicc/ast/EnumDeclAST.py b/src/mem/slicc/ast/EnumDeclAST.py
new file mode 100644
index 000000000..c16fc8a75
--- /dev/null
+++ b/src/mem/slicc/ast/EnumDeclAST.py
@@ -0,0 +1,71 @@
+# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
+# Copyright (c) 2009 The Hewlett-Packard Development Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (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 slicc.ast.DeclAST import DeclAST
+from slicc.symbols import Func, Type
+
+class EnumDeclAST(DeclAST):
+ def __init__(self, slicc, type_ast, pairs, fields):
+ super(EnumDeclAST, self).__init__(slicc, pairs)
+
+ self.type_ast = type_ast
+ self.fields = fields
+
+ def __repr__(self):
+ return "[EnumDecl: %s]" % (self.type_ast)
+
+ def files(self, hh, cc, parent=None):
+ if "external" in self:
+ return
+
+ if parent:
+ ident = "%s_%s" % (parent, self.type_ast.ident)
+ else:
+ ident = self.type_ast.ident
+ hh.add("%s.hh" % ident)
+ cc.add("%s.cc" % ident)
+
+ def generate(self):
+ ident = str(self.type_ast)
+
+ # Make the new type
+ t = Type(self.symtab, ident, self.location, self.pairs,
+ self.state_machine)
+ self.symtab.newSymbol(t)
+
+ # Add all of the fields of the type to it
+ for field in self.fields:
+ field.generate(t)
+
+ # Add the implicit State_to_string method - FIXME, this is a bit dirty
+ func_id = "%s_to_string" % t.c_ident
+
+ pairs = { "external" : "yes" }
+ func = Func(self.symtab, func_id, self.location,
+ self.symtab.find("string", Type), [ t ], [], "",
+ pairs, None)
+ self.symtab.newSymbol(func)
diff --git a/src/mem/slicc/ast/EnumExprAST.cc b/src/mem/slicc/ast/EnumExprAST.cc
deleted file mode 100644
index 0d8af0e9f..000000000
--- a/src/mem/slicc/ast/EnumExprAST.cc
+++ /dev/null
@@ -1,76 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * EnumExprAST.C
- *
- * Description: See EnumExprAST.hh
- *
- * $Id: EnumExprAST.C,v 3.1 2003/07/10 18:08:06 milo Exp $
- *
- */
-
-#include "mem/slicc/ast/EnumExprAST.hh"
-
-EnumExprAST::EnumExprAST(TypeAST* type_ast_ptr,
- string* value_ptr)
- : ExprAST()
-{
- assert(value_ptr != NULL);
- assert(type_ast_ptr != NULL);
- m_type_ast_ptr = type_ast_ptr;
- m_value_ptr = value_ptr;
-}
-
-EnumExprAST::~EnumExprAST()
-{
- delete m_type_ast_ptr;
- delete m_value_ptr;
-}
-
-Type* EnumExprAST::generate(string& code) const
-{
- Type* type_ptr = m_type_ast_ptr->lookupType();
- code += type_ptr->cIdent() + "_" + (*m_value_ptr);
-
- // Make sure the enumeration value exists
- if (!type_ptr->enumExist(*m_value_ptr)) {
- error("Type '" + m_type_ast_ptr->toString() + "' does not have enumeration '" + *m_value_ptr + "'");
- }
-
- // Return the proper type
- return type_ptr;
-}
-
-void EnumExprAST::print(ostream& out) const
-{
- string str;
- str += m_type_ast_ptr->toString()+":"+(*m_value_ptr);
- out << "[EnumExpr: " << str << "]";
-}
diff --git a/src/mem/slicc/ast/EnumExprAST.hh b/src/mem/slicc/ast/EnumExprAST.hh
deleted file mode 100644
index 8af1c8891..000000000
--- a/src/mem/slicc/ast/EnumExprAST.hh
+++ /dev/null
@@ -1,85 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * EnumExprAST.hh
- *
- * Description:
- *
- * $Id: EnumExprAST.hh,v 3.2 2003/07/10 18:08:06 milo Exp $
- *
- */
-
-#ifndef EnumExprAST_H
-#define EnumExprAST_H
-
-#include "mem/slicc/slicc_global.hh"
-#include "mem/slicc/ast/ExprAST.hh"
-#include "mem/slicc/ast/TypeAST.hh"
-
-
-class EnumExprAST : public ExprAST {
-public:
- // Constructors
- EnumExprAST(TypeAST* type_ast_ptr,
- string* value_ptr);
-
- // Destructor
- ~EnumExprAST();
-
- // Public Methods
- Type* generate(string& code) const;
- void print(ostream& out) const;
-private:
- // Private Methods
-
- // Private copy constructor and assignment operator
- EnumExprAST(const EnumExprAST& obj);
- EnumExprAST& operator=(const EnumExprAST& obj);
-
- // Data Members (m_ prefix)
- TypeAST* m_type_ast_ptr;
- string* m_value_ptr;
-};
-
-// Output operator declaration
-ostream& operator<<(ostream& out, const EnumExprAST& obj);
-
-// ******************* Definitions *******************
-
-// Output operator definition
-extern inline
-ostream& operator<<(ostream& out, const EnumExprAST& obj)
-{
- obj.print(out);
- out << flush;
- return out;
-}
-
-#endif //EnumExprAST_H
diff --git a/src/mem/slicc/ast/EnumExprAST.py b/src/mem/slicc/ast/EnumExprAST.py
new file mode 100644
index 000000000..9cb76a8a1
--- /dev/null
+++ b/src/mem/slicc/ast/EnumExprAST.py
@@ -0,0 +1,53 @@
+# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
+# Copyright (c) 2009 The Hewlett-Packard Development Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (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 slicc.ast.ExprAST import ExprAST
+
+class EnumExprAST(ExprAST):
+ def __init__(self, slicc, type_ast, value):
+ super(EnumExprAST, self).__init__(slicc)
+
+ assert type_ast
+ assert value
+
+ self.type_ast = type_ast
+ self.value = value
+
+ def __repr__(self):
+ return "[EnumExpr: %s:%s]" % (self.type_ast, self.value)
+
+ def generate(self, code):
+ fix = code.nofix()
+ code('${{self.type_ast.type.c_ident}}_${{self.value}}')
+ code.fix(fix)
+
+ # Make sure the enumeration value exists
+ if self.value not in self.type_ast.type.enums:
+ self.error("Type '%s' does not have enumeration '%s'",
+ self.type_ast, self.value)
+
+ return self.type_ast.type
diff --git a/src/mem/slicc/ast/ExprAST.cc b/src/mem/slicc/ast/ExprAST.cc
deleted file mode 100644
index 3427d4dd9..000000000
--- a/src/mem/slicc/ast/ExprAST.cc
+++ /dev/null
@@ -1,39 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * ExprAST.C
- *
- * Description: See ExprAST.hh
- *
- * $Id$
- *
- */
-
-#include "mem/slicc/ast/ExprAST.hh"
diff --git a/src/mem/slicc/ast/ExprAST.hh b/src/mem/slicc/ast/ExprAST.hh
deleted file mode 100644
index 9566541da..000000000
--- a/src/mem/slicc/ast/ExprAST.hh
+++ /dev/null
@@ -1,84 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * ExprAST.hh
- *
- * Description:
- *
- * $Id$
- *
- */
-
-#ifndef EXPRAST_H
-#define EXPRAST_H
-
-#include "mem/slicc/slicc_global.hh"
-#include "mem/slicc/ast/AST.hh"
-
-
-class ExprAST : public AST {
-public:
- // Constructors
- ExprAST() : AST() { }
-
- // Destructor
- virtual ~ExprAST() { }
-
- // Public Methods
- virtual Type* generate(string& code) const = 0;
- virtual void findResources(Map<Var*, string>& resource_list) const {} // The default is no resources
-
- // void print(ostream& out) const;
-private:
- // Private Methods
-
- // Private copy constructor and assignment operator
- // ExprAST(const ExprAST& obj);
- // ExprAST& operator=(const ExprAST& obj);
-
- // Data Members (m_ prefix)
-
-};
-
-// Output operator declaration
-ostream& operator<<(ostream& out, const ExprAST& obj);
-
-// ******************* Definitions *******************
-
-// Output operator definition
-extern inline
-ostream& operator<<(ostream& out, const ExprAST& obj)
-{
- obj.print(out);
- out << flush;
- return out;
-}
-
-#endif //EXPRAST_H
diff --git a/src/mem/slicc/ast/ExprAST.py b/src/mem/slicc/ast/ExprAST.py
new file mode 100644
index 000000000..70a0aa0b5
--- /dev/null
+++ b/src/mem/slicc/ast/ExprAST.py
@@ -0,0 +1,45 @@
+# Copyright (c) 2009 The Hewlett-Packard Development Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (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 slicc.ast.AST import AST
+
+class ExprAST(AST):
+ def __init__(self, slicc):
+ super(ExprAST, self).__init__(slicc)
+
+ def findResources(self, resources):
+ # The default is no resources
+ pass
+
+ def inline(self, get_type=False):
+ code = code_formatter(fix_newlines=False)
+ return_type = self.generate(code)
+ if get_type:
+ return return_type, code
+ else:
+ return code
diff --git a/src/mem/slicc/ast/ExprStatementAST.cc b/src/mem/slicc/ast/ExprStatementAST.cc
deleted file mode 100644
index f4bffaab3..000000000
--- a/src/mem/slicc/ast/ExprStatementAST.cc
+++ /dev/null
@@ -1,73 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * ExprStatementAST.C
- *
- * Description: See ExprStatementAST.hh
- *
- * $Id$
- *
- */
-
-#include "mem/slicc/ast/ExprStatementAST.hh"
-
-ExprStatementAST::ExprStatementAST(ExprAST* expr_ptr)
- : StatementAST()
-{
- m_expr_ptr = expr_ptr;
-}
-
-ExprStatementAST::~ExprStatementAST()
-{
- delete m_expr_ptr;
-}
-
-void ExprStatementAST::generate(string& code, Type* return_type_ptr) const
-{
- code += indent_str();
- Type* actual_type_ptr = m_expr_ptr->generate(code);
- code += ";\n";
-
- // The return type must be void
- Type* expected_type_ptr = g_sym_table.getType("void");
- if (expected_type_ptr != actual_type_ptr) {
- m_expr_ptr->error("Non-void return must not be ignored, return type is '" + actual_type_ptr->toString() + "'");
- }
-}
-
-void ExprStatementAST::findResources(Map<Var*, string>& resource_list) const
-{
- m_expr_ptr->findResources(resource_list);
-}
-
-void ExprStatementAST::print(ostream& out) const
-{
- out << "[ExprStatementAST: " << *m_expr_ptr << "]";
-}
diff --git a/src/mem/slicc/ast/ExprStatementAST.hh b/src/mem/slicc/ast/ExprStatementAST.hh
deleted file mode 100644
index a47e86af5..000000000
--- a/src/mem/slicc/ast/ExprStatementAST.hh
+++ /dev/null
@@ -1,83 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * ExprStatementAST.hh
- *
- * Description:
- *
- * $Id$
- *
- */
-
-#ifndef ExprStatementAST_H
-#define ExprStatementAST_H
-
-#include "mem/slicc/slicc_global.hh"
-#include "mem/slicc/ast/StatementAST.hh"
-#include "mem/slicc/ast/ExprAST.hh"
-
-class ExprStatementAST : public StatementAST {
-public:
- // Constructors
- ExprStatementAST(ExprAST* expr_ptr);
-
- // Destructor
- ~ExprStatementAST();
-
- // Public Methods
- void generate(string& code, Type* return_type_ptr) const;
- void findResources(Map<Var*, string>& resource_list) const;
- void print(ostream& out) const;
-private:
- // Private Methods
-
- // Private copy constructor and assignment operator
- ExprStatementAST(const ExprStatementAST& obj);
- ExprStatementAST& operator=(const ExprStatementAST& obj);
-
- // Data Members (m_ prefix)
- ExprAST* m_expr_ptr;
-};
-
-// Output operator declaration
-ostream& operator<<(ostream& out, const ExprStatementAST& obj);
-
-// ******************* Definitions *******************
-
-// Output operator definition
-extern inline
-ostream& operator<<(ostream& out, const ExprStatementAST& obj)
-{
- obj.print(out);
- out << flush;
- return out;
-}
-
-#endif //ExprStatementAST_H
diff --git a/src/mem/slicc/ast/ExprStatementAST.py b/src/mem/slicc/ast/ExprStatementAST.py
new file mode 100644
index 000000000..b16d1d072
--- /dev/null
+++ b/src/mem/slicc/ast/ExprStatementAST.py
@@ -0,0 +1,52 @@
+# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
+# Copyright (c) 2009 The Hewlett-Packard Development Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (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 slicc.ast.StatementAST import StatementAST
+from slicc.symbols import Type
+
+class ExprStatementAST(StatementAST):
+ def __init__(self, slicc, expr):
+ super(ExprStatementAST, self).__init__(slicc)
+ self.expr = expr
+
+ def __repr__(self):
+ return "[ExprStatementAST: %s]" % (self.expr)
+
+ def generate(self, code, return_type):
+ actual_type,rcode = self.expr.inline(True)
+ code("$rcode;")
+
+ # The return type must be void
+ if actual_type != self.symtab.find("void", Type):
+ self.expr.error("Non-void return must not be ignored, " + \
+ "return type is '%s'", actual_type.ident)
+
+ def findResources(self, resources):
+ self.expr.findResources(resources)
+
diff --git a/src/mem/slicc/ast/FormalParamAST.cc b/src/mem/slicc/ast/FormalParamAST.cc
deleted file mode 100644
index 529811f25..000000000
--- a/src/mem/slicc/ast/FormalParamAST.cc
+++ /dev/null
@@ -1,72 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * FormalParamAST.C
- *
- * Description: See FormalParamAST.hh
- *
- * $Id: FormalParamAST.C,v 3.1 2000/10/05 21:22:20 milo Exp $
- *
- */
-
-#include "mem/slicc/ast/FormalParamAST.hh"
-#include "mem/slicc/ast/StatementAST.hh"
-#include "mem/slicc/ast/TypeAST.hh"
-#include "mem/slicc/symbols/SymbolTable.hh"
-
-FormalParamAST::~FormalParamAST()
-{
- delete m_ident_ptr;
- delete m_type_ast_ptr;
-}
-
-string FormalParamAST::getTypeName() const
-{
- return m_type_ast_ptr->toString();
-}
-
-Type* FormalParamAST::getType() const
-{
- return m_type_ast_ptr->lookupType();
-}
-
-Type* FormalParamAST::generate(string& code) const
-{
- string param = "param_" + *m_ident_ptr;
-
- Type* type_ptr = m_type_ast_ptr->lookupType();
- code += type_ptr->cIdent();
- code += " ";
- code += param;
-
- // Add to symbol table
- g_sym_table.newSym(new Var(*m_ident_ptr, getLocation(), type_ptr, param, getPairs()));
- return type_ptr;
-}
diff --git a/src/mem/slicc/ast/FormalParamAST.hh b/src/mem/slicc/ast/FormalParamAST.hh
deleted file mode 100644
index ca27948b7..000000000
--- a/src/mem/slicc/ast/FormalParamAST.hh
+++ /dev/null
@@ -1,88 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * FormalParamAST.hh
- *
- * Description:
- *
- * $Id: FormalParamAST.hh,v 3.1 2001/12/12 01:00:15 milo Exp $
- *
- */
-
-#ifndef FORMALPARAMAST_H
-#define FORMALPARAMAST_H
-
-#include "mem/slicc/slicc_global.hh"
-#include "mem/slicc/ast/AST.hh"
-
-class TypeAST;
-
-
-class FormalParamAST : public AST {
-public:
- // Constructors
- FormalParamAST(TypeAST* type_ast_ptr, string* ident_ptr) : AST() { m_type_ast_ptr = type_ast_ptr; m_ident_ptr = ident_ptr; }
-
- // Destructor
- ~FormalParamAST();
-
- // Public Methods
- Type* generate(string& code) const;
- void print(ostream& out) const { out << "[FormalParamAST: " << *m_ident_ptr << "]"; }
- string getName() const { return *m_ident_ptr; }
- string getTypeName() const;
- Type* getType() const;
-private:
- // Private Methods
-
- // Private copy constructor and assignment operator
- FormalParamAST(const FormalParamAST& obj);
- FormalParamAST& operator=(const FormalParamAST& obj);
-
- // Data Members (m_ prefix)
- string* m_ident_ptr;
- TypeAST* m_type_ast_ptr;
-};
-
-// Output operator declaration
-ostream& operator<<(ostream& out, const FormalParamAST& obj);
-
-// ******************* Definitions *******************
-
-// Output operator definition
-extern inline
-ostream& operator<<(ostream& out, const FormalParamAST& obj)
-{
- obj.print(out);
- out << flush;
- return out;
-}
-
-#endif //FORMALPARAMAST_H
diff --git a/src/mem/slicc/ast/FormalParamAST.py b/src/mem/slicc/ast/FormalParamAST.py
new file mode 100644
index 000000000..b169cbb1c
--- /dev/null
+++ b/src/mem/slicc/ast/FormalParamAST.py
@@ -0,0 +1,52 @@
+# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
+# Copyright (c) 2009 The Hewlett-Packard Development Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (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 slicc.ast.AST import AST
+from slicc.symbols import Var
+
+class FormalParamAST(AST):
+ def __init__(self, slicc, type_ast, ident):
+ super(FormalParamAST, self).__init__(slicc)
+ self.type_ast = type_ast
+ self.ident = ident
+
+ def __repr__(self):
+ return "[FormalParamAST: %s]" % self.ident
+
+ @property
+ def name(self):
+ return self.ident
+
+ def generate(self):
+ type = self.type_ast.type
+ param = "param_%s" % self.ident
+
+ # Add to symbol table
+ v = Var(self.symtab, self.ident, self.location, type, param,
+ self.pairs)
+ self.symtab.newSymbol(v)
+ return type, "%s %s" % (type.c_ident, param)
diff --git a/src/mem/slicc/ast/FuncCallExprAST.cc b/src/mem/slicc/ast/FuncCallExprAST.cc
deleted file mode 100644
index 5b19017e9..000000000
--- a/src/mem/slicc/ast/FuncCallExprAST.cc
+++ /dev/null
@@ -1,224 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * FuncCallExprAST.C
- *
- * Description: See FuncCallExprAST.hh
- *
- * $Id$
- *
- */
-
-#include "mem/slicc/ast/FuncCallExprAST.hh"
-#include "mem/slicc/symbols/SymbolTable.hh"
-
-FuncCallExprAST::FuncCallExprAST(string* proc_name_ptr,
- Vector<ExprAST*>* expr_vec_ptr)
- : ExprAST()
-{
- m_proc_name_ptr = proc_name_ptr;
- m_expr_vec_ptr = expr_vec_ptr;
-}
-
-FuncCallExprAST::~FuncCallExprAST()
-{
- delete m_proc_name_ptr;
- int size = m_expr_vec_ptr->size();
- for(int i=0; i<size; i++) {
- delete (*m_expr_vec_ptr)[i];
- }
- delete m_expr_vec_ptr;
-}
-
-Type* FuncCallExprAST::generate(string& code) const
-{
- // DEBUG_EXPR is strange since it takes parameters of multiple types
- if (*m_proc_name_ptr == "DEBUG_EXPR") {
- // FIXME - check for number of parameters
- code += "DEBUG_SLICC(MedPrio, \"";
- code += (*m_expr_vec_ptr)[0]->getLocation().toString();
- code += ": \", ";
- (*m_expr_vec_ptr)[0]->generate(code);
- code += ");\n";
- Type* void_type_ptr = g_sym_table.getType("void");
- assert(void_type_ptr != NULL);
- return void_type_ptr;
- }
-
- // hack for adding comments to profileTransition
- if (*m_proc_name_ptr == "APPEND_TRANSITION_COMMENT") {
- // FIXME - check for number of parameters
- code += "APPEND_TRANSITION_COMMENT(";
- //code += (*m_expr_vec_ptr)[0]->getLocation().toString();
- //code += ": \", ";
- (*m_expr_vec_ptr)[0]->generate(code);
- code += ");\n";
- Type* void_type_ptr = g_sym_table.getType("void");
- assert(void_type_ptr != NULL);
- return void_type_ptr;
- }
-
- // Look up the function in the symbol table
- Vector<string> code_vec;
- Func* func_ptr = g_sym_table.getFunc(*m_proc_name_ptr);
-
- // Check the types and get the code for the parameters
- if (func_ptr == NULL) {
- error("Unrecognized function name: '" + *m_proc_name_ptr + "'");
- } else {
- int size = m_expr_vec_ptr->size();
-
- Vector<Type*> f = func_ptr->getParamTypes();
-
- if (size != f.size() ) {
- error("Wrong number of arguments passed to function : '" + *m_proc_name_ptr + "'");
- }
- else {
- for(int i=0; i<size; i++) {
-
- // Check the types of the parameter
- string param_code;
- Type* actual_type_ptr = (*m_expr_vec_ptr)[i]->generate(param_code);
- Type* expected_type_ptr = func_ptr->getParamTypes()[i];
- if (actual_type_ptr != expected_type_ptr) {
- (*m_expr_vec_ptr)[i]->error("Type mismatch: expected: " + expected_type_ptr->toString() +
- " actual: " + actual_type_ptr->toString());
- }
- code_vec.insertAtBottom(param_code);
- }
- }
- }
-
- /* OK, the semantics of "trigger" here is that, ports in the machine have
- * different priorities. We always check the first port for doable
- * transitions. If nothing/stalled, we pick one from the next port.
- *
- * One thing we have to be careful as the SLICC protocol writter is :
- * If a port have two or more transitions can be picked from in one cycle,
- * they must be independent. Otherwise, if transition A and B mean to be
- * executed in sequential, and A get stalled, transition B can be issued
- * erroneously. In practice, in most case, there is only one transition
- * should be executed in one cycle for a given port. So as most of current
- * protocols.
- */
-
- if (*m_proc_name_ptr == "trigger") {
- code += indent_str() + "{\n";
- code += indent_str() + " Address addr = ";
- code += code_vec[1];
- code += ";\n";
- code += indent_str() + " TransitionResult result = doTransition(";
- code += code_vec[0];
- code += ", " + g_sym_table.getStateMachine()->toString() + "_getState(addr), addr";
- if(CHECK_INVALID_RESOURCE_STALLS) {
- // FIXME - the current assumption is that in_buffer_rank is declared in the msg buffer peek statement
- code += ", in_buffer_rank";
- }
- code += ");\n";
- code += indent_str() + " if (result == TransitionResult_Valid) {\n";
- code += indent_str() + " counter++;\n";
- code += indent_str() + " continue; // Check the first port again\n";
- code += indent_str() + " }\n";
- code += indent_str() + " if (result == TransitionResult_ResourceStall) {\n";
- code += indent_str() + " g_eventQueue_ptr->scheduleEvent(this, 1);\n";
- code += indent_str() + " // Cannot do anything with this transition, go check next doable transition (mostly likely of next port)\n";
- code += indent_str() + " }\n";
- code += indent_str() + "}\n";
- } else if (*m_proc_name_ptr == "doubleTrigger") {
- // NOTE: Use the doubleTrigger call with extreme caution
- // the key to double trigger is the second event triggered cannot fail becuase the first event cannot be undone
- assert(code_vec.size() == 4);
- code += indent_str() + "{\n";
- code += indent_str() + " Address addr1 = ";
- code += code_vec[1];
- code += ";\n";
- code += indent_str() + " TransitionResult result1 = doTransition(";
- code += code_vec[0];
- code += ", " + g_sym_table.getStateMachine()->toString() + "_getState(addr1), addr1";
- if(CHECK_INVALID_RESOURCE_STALLS) {
- // FIXME - the current assumption is that in_buffer_rank is declared in the msg buffer peek statement
- code += ", in_buffer_rank";
- }
- code += ");\n";
- code += indent_str() + " if (result1 == TransitionResult_Valid) {\n";
- code += indent_str() + " //this second event cannont fail because the first event already took effect\n";
- code += indent_str() + " Address addr2 = ";
- code += code_vec[3];
- code += ";\n";
- code += indent_str() + " TransitionResult result2 = doTransition(";
- code += code_vec[2];
- code += ", " + g_sym_table.getStateMachine()->toString() + "_getState(addr2), addr2";
- if(CHECK_INVALID_RESOURCE_STALLS) {
- // FIXME - the current assumption is that in_buffer_rank is declared in the msg buffer peek statement
- code += ", in_buffer_rank";
- }
- code += ");\n";
- code += indent_str() + " assert(result2 == TransitionResult_Valid); // ensure the event suceeded\n";
- code += indent_str() + " counter++;\n";
- code += indent_str() + " continue; // Check the first port again\n";
- code += indent_str() + " }\n";
- code += indent_str() + " if (result1 == TransitionResult_ResourceStall) {\n";
- code += indent_str() + " g_eventQueue_ptr->scheduleEvent(this, 1);\n";
- code += indent_str() + " // Cannot do anything with this transition, go check next doable transition (mostly likely of next port)\n";
- code += indent_str() + " }\n";
- code += indent_str() + "}\n";
- } else if (*m_proc_name_ptr == "error") {
- code += indent_str() + (*m_expr_vec_ptr)[0]->embedError(code_vec[0]) + "\n";
- } else if (*m_proc_name_ptr == "assert") {
- code += indent_str() + "if (ASSERT_FLAG && !(" + code_vec[0] + ")) {\n";
- code += indent_str() + " " + (*m_expr_vec_ptr)[0]->embedError("\"assert failure\"") + "\n";
- code += indent_str() + "}\n";
- } else if (*m_proc_name_ptr == "continueProcessing") {
- code += "counter++; continue; // Check the first port again";
- } else {
- // Normal function
- code += "(";
- // if the func is internal to the chip but not the machine then it can only be
- // accessed through the chip pointer
- if (!func_ptr->existPair("external") && !func_ptr->isInternalMachineFunc()) {
- code += "m_chip_ptr->";
- }
- code += func_ptr->cIdent() + "(";
- int size = code_vec.size();
- for(int i=0; i<size; i++) {
- if (i != 0) {
- code += ", ";
- }
- code += code_vec[i];
- }
- code += "))";
- }
- return func_ptr->getReturnType();
-}
-
-void FuncCallExprAST::print(ostream& out) const
-{
- out << "[FuncCallExpr: " << *m_proc_name_ptr << " " << *m_expr_vec_ptr << "]";
-}
diff --git a/src/mem/slicc/ast/FuncCallExprAST.hh b/src/mem/slicc/ast/FuncCallExprAST.hh
deleted file mode 100644
index 6c02122ee..000000000
--- a/src/mem/slicc/ast/FuncCallExprAST.hh
+++ /dev/null
@@ -1,89 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * FuncCallExprAST.hh
- *
- * Description:
- *
- * $Id$
- *
- */
-
-#ifndef FUNCCALLEXPRAST_H
-#define FUNCCALLEXPRAST_H
-
-#include "mem/slicc/slicc_global.hh"
-#include "mem/slicc/ast/StatementAST.hh"
-#include "mem/slicc/ast/ExprAST.hh"
-
-
-// ProcGen decl
-class FuncGen;
-
-class FuncCallExprAST : public ExprAST {
-public:
- // Constructors
- FuncCallExprAST(string* proc_name_ptr,
- Vector<ExprAST*>* expr_vec_ptr);
-
- // Destructor
- ~FuncCallExprAST();
-
- // Public Methods
- Type* generate(string& code) const;
- void print(ostream& out) const;
-
-private:
- // Private Methods
-
- // Private copy constructor and assignment operator
- FuncCallExprAST(const FuncCallExprAST& obj);
- FuncCallExprAST& operator=(const FuncCallExprAST& obj);
-
- // Data Members (m_ prefix)
- string* m_proc_name_ptr;
- Vector<ExprAST*>* m_expr_vec_ptr;
-};
-
-// Output operator declaration
-ostream& operator<<(ostream& out, const FuncCallExprAST& obj);
-
-// ******************* Definitions *******************
-
-// Output operator definition
-extern inline
-ostream& operator<<(ostream& out, const FuncCallExprAST& obj)
-{
- obj.print(out);
- out << flush;
- return out;
-}
-
-#endif //FUNCCALLEXPRAST_H
diff --git a/src/mem/slicc/ast/FuncCallExprAST.py b/src/mem/slicc/ast/FuncCallExprAST.py
new file mode 100644
index 000000000..abf7eec7b
--- /dev/null
+++ b/src/mem/slicc/ast/FuncCallExprAST.py
@@ -0,0 +1,168 @@
+# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
+# Copyright (c) 2009 The Hewlett-Packard Development Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (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 slicc.ast.ExprAST import ExprAST
+from slicc.symbols import Func, Type
+
+class FuncCallExprAST(ExprAST):
+ def __init__(self, slicc, proc_name, exprs):
+ super(FuncCallExprAST, self).__init__(slicc)
+ self.proc_name = proc_name
+ self.exprs = exprs
+
+ def __repr__(self):
+ return "[FuncCallExpr: %s %s]" % (self.proc_name, self.exprs)
+
+ def generate(self, code):
+ machine = self.state_machine
+
+ # DEBUG_EXPR is strange since it takes parameters of multiple types
+ if self.proc_name == "DEBUG_EXPR":
+ # FIXME - check for number of parameters
+ code('DEBUG_SLICC(MedPrio, "$0: ", $1)',
+ self.exprs[0].location, self.exprs[0].inline())
+
+ return self.symtab.find("void", Type)
+
+ # hack for adding comments to profileTransition
+ if self.proc_name == "APPEND_TRANSITION_COMMENT":
+ # FIXME - check for number of parameters
+ code("APPEND_TRANSITION_COMMENT($0)", self.exprs[0].inline())
+ return self.symtab.find("void", Type)
+
+ # Look up the function in the symbol table
+ func = self.symtab.find(self.proc_name, Func)
+
+ # Check the types and get the code for the parameters
+ if func is None:
+ self.error("Unrecognized function name: '%s'", self.proc_name)
+
+ if len(self.exprs) != len(func.param_types):
+ self.error("Wrong number of arguments passed to function : '%s'" +\
+ " Expected %d, got %d", self.proc_name,
+ len(func.param_types), len(self.exprs))
+
+ cvec = []
+ for expr,expected_type in zip(self.exprs, func.param_types):
+ # Check the types of the parameter
+ actual_type,param_code = expr.inline(True)
+ if actual_type != expected_type:
+ expr.error("Type mismatch: expected: %s actual: %s" % \
+ (expected_type, actual_type))
+ cvec.append(param_code)
+
+ # OK, the semantics of "trigger" here is that, ports in the
+ # machine have different priorities. We always check the first
+ # port for doable transitions. If nothing/stalled, we pick one
+ # from the next port.
+ #
+ # One thing we have to be careful as the SLICC protocol
+ # writter is : If a port have two or more transitions can be
+ # picked from in one cycle, they must be independent.
+ # Otherwise, if transition A and B mean to be executed in
+ # sequential, and A get stalled, transition B can be issued
+ # erroneously. In practice, in most case, there is only one
+ # transition should be executed in one cycle for a given
+ # port. So as most of current protocols.
+
+ if self.proc_name == "trigger":
+ code('''
+{
+ Address addr = ${{cvec[1]}};
+ TransitionResult result = doTransition(${{cvec[0]}}, ${machine}_getState(addr), addr);
+
+ if (result == TransitionResult_Valid) {
+ counter++;
+ continue; // Check the first port again
+ }
+
+ if (result == TransitionResult_ResourceStall) {
+ g_eventQueue_ptr->scheduleEvent(this, 1);
+
+ // Cannot do anything with this transition, go check next doable transition (mostly likely of next port)
+ }
+}
+''')
+ elif self.proc_name == "doubleTrigger":
+ # NOTE: Use the doubleTrigger call with extreme caution
+ # the key to double trigger is the second event triggered
+ # cannot fail becuase the first event cannot be undone
+ assert len(cvec) == 4
+ code('''
+{
+ Address addr1 = ${{cvec[1]}};
+ TransitionResult result1 =
+ doTransition(${{cvec[0]}}, ${machine}_getState(addr1), addr1);
+
+ if (result1 == TransitionResult_Valid) {
+ //this second event cannont fail because the first event
+ // already took effect
+ Address addr2 = ${{cvec[3]}};
+ TransitionResult result2 = doTransition(${{cvec[2]}}, ${machine}_getState(addr2), addr2);
+
+ // ensure the event suceeded
+ assert(result2 == TransitionResult_Valid);
+
+ counter++;
+ continue; // Check the first port again
+ }
+
+ if (result1 == TransitionResult_ResourceStall) {
+ g_eventQueue_ptr->scheduleEvent(this, 1);
+ // Cannot do anything with this transition, go check next
+ // doable transition (mostly likely of next port)
+ }
+}
+''')
+ elif self.proc_name == "error":
+ code("$0", self.exprs[0].embedError(cvec[0]))
+ elif self.proc_name == "assert":
+ error = self.exprs[0].embedError('"assert failure"')
+ code('''
+if (ASSERT_FLAG && !(${{cvec[0]}})) {
+ $error
+}
+''')
+
+ elif self.proc_name == "continueProcessing":
+ code("counter++;")
+ code("continue; // Check the first port again")
+ else:
+ # Normal function
+
+ # if the func is internal to the chip but not the machine
+ # then it can only be accessed through the chip pointer
+ internal = ""
+ if "external" not in func and not func.isInternalMachineFunc:
+ internal = "m_chip_ptr->"
+
+ params = ', '.join(str(c) for c in cvec)
+ fix = code.nofix()
+ code('(${internal}${{func.c_ident}}($params))')
+ code.fix(fix)
+
+ return func.return_type
diff --git a/src/mem/slicc/ast/FuncDeclAST.cc b/src/mem/slicc/ast/FuncDeclAST.cc
deleted file mode 100644
index 2a0905f06..000000000
--- a/src/mem/slicc/ast/FuncDeclAST.cc
+++ /dev/null
@@ -1,112 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * FuncDeclAST.C
- *
- * Description: See FuncDeclAST.hh
- *
- * $Id: FuncDeclAST.C,v 3.4 2003/08/22 18:19:34 beckmann Exp $
- *
- */
-
-#include "mem/slicc/ast/FuncDeclAST.hh"
-#include "mem/slicc/ast/FormalParamAST.hh"
-#include "mem/slicc/symbols/SymbolTable.hh"
-#include "mem/slicc/main.hh"
-
-FuncDeclAST::FuncDeclAST(TypeAST* return_type_ast_ptr,
- string* ident_ptr,
- Vector<FormalParamAST*>* formal_vec_ptr,
- PairListAST* pairs_ptr,
- StatementListAST* statement_list_ptr)
- : DeclAST(pairs_ptr)
-{
- m_return_type_ast_ptr = return_type_ast_ptr;
- m_ident_ptr = ident_ptr;
- m_formal_vec_ptr = formal_vec_ptr;
- m_statement_list_ptr = statement_list_ptr;
-}
-
-FuncDeclAST::~FuncDeclAST()
-{
- delete m_return_type_ast_ptr;
- delete m_ident_ptr;
-
- int size = m_formal_vec_ptr->size();
- for(int i=0; i<size; i++) {
- delete (*m_formal_vec_ptr)[i];
- }
- delete m_formal_vec_ptr;
- delete m_statement_list_ptr;
-}
-
-void FuncDeclAST::generate()
-{
- Vector<Type*> type_vec;
- Vector<string> param_vec;
- Type* void_type_ptr = g_sym_table.getType("void");
-
- // Generate definition code
- g_sym_table.pushFrame();
-
- // Lookup return type
- Type* return_type_ptr = m_return_type_ast_ptr->lookupType();
-
- // Generate function header
- int size = m_formal_vec_ptr->size();
- for(int i=0; i<size; i++) {
- // Lookup parameter types
- string ident;
- Type* type_ptr = (*m_formal_vec_ptr)[i]->generate(ident);
- type_vec.insertAtBottom(type_ptr);
- param_vec.insertAtBottom(ident);
- }
-
- string body;
- if (m_statement_list_ptr == NULL) {
- getPairs().add("external", "yes");
- } else {
- m_statement_list_ptr->generate(body, return_type_ptr);
- }
- g_sym_table.popFrame();
-
- StateMachine* machine_ptr = g_sym_table.getStateMachine();
- if (machine_ptr != NULL) {
- machine_ptr->addFunc(new Func(*m_ident_ptr, getLocation(), return_type_ptr, type_vec, param_vec, body, getPairs(), machine_ptr));
- } else {
- g_sym_table.newSym(new Func(*m_ident_ptr, getLocation(), return_type_ptr, type_vec, param_vec, body, getPairs(), machine_ptr));
- }
-
-}
-
-void FuncDeclAST::print(ostream& out) const
-{
- out << "[FuncDecl: " << *m_ident_ptr << "]";
-}
diff --git a/src/mem/slicc/ast/FuncDeclAST.hh b/src/mem/slicc/ast/FuncDeclAST.hh
deleted file mode 100644
index 205e71a85..000000000
--- a/src/mem/slicc/ast/FuncDeclAST.hh
+++ /dev/null
@@ -1,91 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * FuncDeclAST.hh
- *
- * Description:
- *
- * $Id: FuncDeclAST.hh,v 3.2 2003/07/10 18:08:06 milo Exp $
- *
- */
-
-#ifndef FuncDeclAST_H
-#define FuncDeclAST_H
-
-#include "mem/slicc/slicc_global.hh"
-#include "mem/slicc/ast/DeclAST.hh"
-#include "mem/slicc/ast/TypeFieldAST.hh"
-#include "mem/slicc/ast/TypeAST.hh"
-
-class FormalParamsAST;
-
-class FuncDeclAST : public DeclAST {
-public:
- // Constructors
- FuncDeclAST(TypeAST* return_type_ptr,
- string* ident_ptr,
- Vector<FormalParamAST*>* formal_vec_ptr,
- PairListAST* pairs_ptr,
- StatementListAST* statement_list_ptr);
- // Destructor
- ~FuncDeclAST();
-
- // Public Methods
- void generate();
- void print(ostream& out) const;
-private:
- // Private Methods
-
- // Private copy constructor and assignment operator
- FuncDeclAST(const FuncDeclAST& obj);
- FuncDeclAST& operator=(const FuncDeclAST& obj);
-
- // Data Members (m_ prefix)
- string* m_ident_ptr;
- TypeAST* m_return_type_ast_ptr;
- Vector<FormalParamAST*>* m_formal_vec_ptr;
- StatementListAST* m_statement_list_ptr;
-};
-
-// Output operator declaration
-ostream& operator<<(ostream& out, const FuncDeclAST& obj);
-
-// ******************* Definitions *******************
-
-// Output operator definition
-extern inline
-ostream& operator<<(ostream& out, const FuncDeclAST& obj)
-{
- obj.print(out);
- out << flush;
- return out;
-}
-
-#endif //FuncDeclAST_H
diff --git a/src/mem/slicc/ast/FuncDeclAST.py b/src/mem/slicc/ast/FuncDeclAST.py
new file mode 100644
index 000000000..7ff3bf8a7
--- /dev/null
+++ b/src/mem/slicc/ast/FuncDeclAST.py
@@ -0,0 +1,88 @@
+# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
+# Copyright (c) 2009 The Hewlett-Packard Development Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (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.code_formatter import code_formatter
+
+from slicc.ast.DeclAST import DeclAST
+from slicc.symbols import Func, Type
+
+class FuncDeclAST(DeclAST):
+ def __init__(self, slicc, return_type, ident, formals, pairs, statements):
+ super(FuncDeclAST, self).__init__(slicc, pairs)
+
+ self.return_type = return_type
+ self.ident = ident
+ self.formals = formals
+ self.statements = statements
+
+ def __repr__(self):
+ return "[FuncDecl: %s]" % self.ident
+
+ def files(self, hh, cc, parent=None):
+ if "external" in self or self.statements is None:
+ return
+
+ if parent:
+ ident = "%s_%s" % (parent, self.ident)
+ else:
+ ident = self.ident
+ cc.add("%s.cc" % ident)
+
+ def generate(self):
+ types = []
+ params = []
+ void_type = self.symtab.find("void", Type)
+
+ # Generate definition code
+ self.symtab.pushFrame()
+
+ # Lookup return type
+ return_type = self.return_type.type
+
+ # Generate function header
+ for formal in self.formals:
+ # Lookup parameter types
+ type, ident = formal.generate()
+ types.append(type)
+ params.append(ident)
+
+ body = code_formatter()
+ if self.statements is None:
+ self["external"] = "yes"
+ else:
+ rtype = self.statements.generate(body, return_type)
+
+ self.symtab.popFrame()
+
+ machine = self.state_machine
+ func = Func(self.symtab, self.ident, self.location, return_type,
+ types, params, str(body), self.pairs, machine)
+
+ if machine is not None:
+ machine.addFunc(func)
+ else:
+ self.symtab.newSymbol(func)
diff --git a/src/mem/slicc/ast/IfStatementAST.cc b/src/mem/slicc/ast/IfStatementAST.cc
deleted file mode 100644
index 40942a58d..000000000
--- a/src/mem/slicc/ast/IfStatementAST.cc
+++ /dev/null
@@ -1,98 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * IfStatementAST.C
- *
- * Description: See IfStatementAST.hh
- *
- * $Id$
- *
- */
-
-#include "mem/slicc/ast/IfStatementAST.hh"
-
-IfStatementAST::IfStatementAST(ExprAST* cond_ptr,
- StatementListAST* then_ptr,
- StatementListAST* else_ptr)
- : StatementAST()
-{
- assert(cond_ptr != NULL);
- assert(then_ptr != NULL);
- m_cond_ptr = cond_ptr;
- m_then_ptr = then_ptr;
- m_else_ptr = else_ptr;
-}
-
-IfStatementAST::~IfStatementAST()
-{
- delete m_cond_ptr;
- delete m_then_ptr;
- delete m_else_ptr;
-}
-
-
-void IfStatementAST::generate(string& code, Type* return_type_ptr) const
-{
- Type* type_ptr;
-
- // Conditional
- code += indent_str() + "if (";
- type_ptr = m_cond_ptr->generate(code);
- if (type_ptr != g_sym_table.getType("bool")) {
- m_cond_ptr->error("Condition of if statement must be boolean, type was '" + type_ptr->toString() + "'");
- }
- code += ") {\n";
- // Then part
- inc_indent();
- m_then_ptr->generate(code, return_type_ptr);
- dec_indent();
- // Else part
- if (m_else_ptr != NULL) {
- code += indent_str() + "} else {\n";
- inc_indent();
- m_else_ptr->generate(code, return_type_ptr);
- dec_indent();
- }
- code += indent_str() + "}\n"; // End scope
-}
-
-void IfStatementAST::findResources(Map<Var*, string>& resource_list) const
-{
- // Take a worse case look at both paths
- m_then_ptr->findResources(resource_list);
- if (m_else_ptr != NULL) {
- m_else_ptr->findResources(resource_list);
- }
-}
-
-void IfStatementAST::print(ostream& out) const
-{
- out << "[IfStatement: " << *m_cond_ptr << *m_then_ptr << *m_else_ptr << "]";
-}
diff --git a/src/mem/slicc/ast/IfStatementAST.hh b/src/mem/slicc/ast/IfStatementAST.hh
deleted file mode 100644
index 2c168913a..000000000
--- a/src/mem/slicc/ast/IfStatementAST.hh
+++ /dev/null
@@ -1,89 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * IfStatementAST.hh
- *
- * Description:
- *
- * $Id$
- *
- */
-
-#ifndef IFSTATEMENTAST_H
-#define IFSTATEMENTAST_H
-
-#include "mem/slicc/slicc_global.hh"
-#include "mem/slicc/ast/ExprAST.hh"
-#include "mem/slicc/ast/StatementAST.hh"
-#include "mem/slicc/ast/StatementListAST.hh"
-
-
-class IfStatementAST : public StatementAST {
-public:
- // Constructors
- IfStatementAST(ExprAST* cond_ptr,
- StatementListAST* then_ptr,
- StatementListAST* else_ptr);
-
- // Destructor
- ~IfStatementAST();
-
- // Public Methods
- void generate(string& code, Type* return_type_ptr) const;
- void findResources(Map<Var*, string>& resource_list) const;
- void print(ostream& out) const;
-private:
- // Private Methods
-
- // Private copy constructor and assignment operator
- IfStatementAST(const IfStatementAST& obj);
- IfStatementAST& operator=(const IfStatementAST& obj);
-
- // Data Members (m_ prefix)
- ExprAST* m_cond_ptr;
- StatementListAST* m_then_ptr;
- StatementListAST* m_else_ptr;
-};
-
-// Output operator declaration
-ostream& operator<<(ostream& out, const IfStatementAST& obj);
-
-// ******************* Definitions *******************
-
-// Output operator definition
-extern inline
-ostream& operator<<(ostream& out, const IfStatementAST& obj)
-{
- obj.print(out);
- out << flush;
- return out;
-}
-
-#endif //IFSTATEMENTAST_H
diff --git a/src/mem/slicc/ast/IfStatementAST.py b/src/mem/slicc/ast/IfStatementAST.py
new file mode 100644
index 000000000..788876fd1
--- /dev/null
+++ b/src/mem/slicc/ast/IfStatementAST.py
@@ -0,0 +1,74 @@
+# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
+# Copyright (c) 2009 The Hewlett-Packard Development Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (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 slicc.ast.StatementAST import StatementAST
+from slicc.symbols import Type
+
+class IfStatementAST(StatementAST):
+ def __init__(self, slicc, cond, then, else_):
+ super(IfStatementAST, self).__init__(slicc)
+
+ assert cond is not None
+ assert then is not None
+
+ self.cond = cond
+ self.then = then
+ self.else_ = else_
+
+ def __repr__(self):
+ return "[IfStatement: %r%r%r]" % (self.cond, self.then, self.else_)
+
+ def generate(self, code, return_type):
+ cond_code = code_formatter()
+ cond_type = self.cond.generate(cond_code)
+
+ if cond_type != self.symtab.find("bool", Type):
+ self.cond.error("Condition of if stmt must be bool, type was '%s'",
+ ctype)
+
+ # Conditional
+ code.indent()
+ code('if ($cond_code) {')
+ # Then part
+ code.indent()
+ self.then.generate(code, return_type)
+ code.dedent()
+ # Else part
+ if self.else_:
+ code('} else {')
+ code.indent()
+ self.else_.generate(code, return_type)
+ code.dedent()
+ code('}') # End scope
+
+ def findResources(self, resources):
+ # Take a worse case look at both paths
+ self.then.findResources(resources)
+ if self.else_ is not None:
+ self.else_.findResources(resources)
diff --git a/src/mem/slicc/ast/InPortDeclAST.cc b/src/mem/slicc/ast/InPortDeclAST.cc
deleted file mode 100644
index f62af9921..000000000
--- a/src/mem/slicc/ast/InPortDeclAST.cc
+++ /dev/null
@@ -1,149 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * InPortDeclAST.C
- *
- * Description: See InPortDeclAST.hh
- *
- * $Id$
- *
- */
-
-#include "mem/slicc/ast/InPortDeclAST.hh"
-#include "mem/slicc/symbols/SymbolTable.hh"
-#include "mem/slicc/symbols/Var.hh"
-
-InPortDeclAST::InPortDeclAST(string* ident_ptr,
- TypeAST* msg_type_ptr,
- ExprAST* var_expr_ptr,
- PairListAST* pairs_ptr,
- StatementListAST* statement_list_ptr)
- : DeclAST(pairs_ptr)
-{
- m_ident_ptr = ident_ptr;
- m_msg_type_ptr = msg_type_ptr;
- m_var_expr_ptr = var_expr_ptr;
- m_statement_list_ptr = statement_list_ptr;
- m_queue_type_ptr = new TypeAST(new string("InPort"));
-}
-
-InPortDeclAST::~InPortDeclAST()
-{
- delete m_ident_ptr;
- delete m_msg_type_ptr;
- delete m_var_expr_ptr;
- delete m_statement_list_ptr;
- delete m_queue_type_ptr;
-}
-
-void InPortDeclAST::generate()
-{
- string code;
- Type* queue_type_ptr = m_var_expr_ptr->generate(code);
- if (!queue_type_ptr->isInPort()) {
- error("Inport queues must be of a type that has the 'inport' attribute. The type '" +
- queue_type_ptr->toString() + "' does not have this attribute.");
- }
-
- Type* type_ptr = m_queue_type_ptr->lookupType();
- Var* in_port_ptr = new Var(*m_ident_ptr, getLocation(), type_ptr, code, getPairs());
- g_sym_table.newSym(in_port_ptr);
-
- g_sym_table.pushFrame();
- Vector<Type*> param_type_vec;
-
- // Check for Event
- type_ptr = g_sym_table.getType("Event");
- if (type_ptr == NULL) {
- error("in_port declarations require 'Event' enumeration to be defined");
- }
- param_type_vec.insertAtBottom(type_ptr);
-
- // Check for Address
- type_ptr = g_sym_table.getType("Address");
- if (type_ptr == NULL) {
- error("in_port declarations require 'Address' type to be defined");
- }
- param_type_vec.insertAtBottom(type_ptr);
-
- // Add the trigger method - FIXME, this is a bit dirty
- Map<string, string> pairs;
- pairs.add("external", "yes");
- Vector<string> string_vec;
- g_sym_table.newSym(new Func("trigger", getLocation(), g_sym_table.getType("void"), param_type_vec, string_vec, string(""), pairs, NULL));
-
- // Check for Event2
- type_ptr = g_sym_table.getType("Event");
- if (type_ptr == NULL) {
- error("in_port declarations require 'Event' enumeration to be defined");
- }
- param_type_vec.insertAtBottom(type_ptr);
-
- // Check for Address2
- type_ptr = g_sym_table.getType("Address");
- if (type_ptr == NULL) {
- error("in_port declarations require 'Address' type to be defined");
- }
- param_type_vec.insertAtBottom(type_ptr);
-
- // Add the doubleTrigger method - this hack supports tiggering two simulateous events
- // The key is that the second transistion cannot fail because the first event cannot be undone
- // therefore you must do some checks before calling double trigger to ensure that won't happen
- g_sym_table.newSym(new Func("doubleTrigger", getLocation(), g_sym_table.getType("void"), param_type_vec, string_vec, string(""), pairs, NULL));
-
- // Add the continueProcessing method - this hack supports messages that don't trigger events
- Vector<Type*> empty_param_type_vec;
- Vector<string> empty_string_vec;
- g_sym_table.newSym(new Func("continueProcessing", getLocation(), g_sym_table.getType("void"), empty_param_type_vec, empty_string_vec, string(""), pairs, NULL));
-
- if (m_statement_list_ptr != NULL) {
- inc_indent();
- inc_indent();
- string code;
- m_statement_list_ptr->generate(code, NULL);
- in_port_ptr->addPair("c_code_in_port", code);
- dec_indent();
- dec_indent();
- }
- g_sym_table.popFrame();
-
- // Add port to state machine
- StateMachine* machine_ptr = g_sym_table.getStateMachine();
- if (machine_ptr == NULL) {
- error("InPort declaration not part of a machine.");
- }
- machine_ptr->addInPort(in_port_ptr);
-}
-
-
-void InPortDeclAST::print(ostream& out) const
-{
- out << "[InPortDecl: " << *m_ident_ptr << "]";
-}
diff --git a/src/mem/slicc/ast/InPortDeclAST.hh b/src/mem/slicc/ast/InPortDeclAST.hh
deleted file mode 100644
index e6295a6e2..000000000
--- a/src/mem/slicc/ast/InPortDeclAST.hh
+++ /dev/null
@@ -1,91 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * InPortDeclAST.hh
- *
- * Description:
- *
- * $Id: InPortDeclAST.hh,v 3.2 2003/07/10 18:08:06 milo Exp $
- *
- */
-
-#ifndef InPortDeclAST_H
-#define InPortDeclAST_H
-
-#include "mem/slicc/slicc_global.hh"
-#include "mem/slicc/ast/DeclAST.hh"
-#include "mem/slicc/ast/StatementListAST.hh"
-#include "mem/slicc/ast/VarExprAST.hh"
-
-class InPortDeclAST : public DeclAST {
-public:
- // Constructors
- InPortDeclAST(string* ident_ptr,
- TypeAST* msg_type_ptr,
- ExprAST* var_expr_ptr,
- PairListAST* pairs_ptr,
- StatementListAST* statement_list_ptr);
-
- // Destructor
- ~InPortDeclAST();
-
- // Public Methods
- void generate();
- void print(ostream& out) const;
-private:
- // Private Methods
-
- // Private copy constructor and assignment operator
- InPortDeclAST(const InPortDeclAST& obj);
- InPortDeclAST& operator=(const InPortDeclAST& obj);
-
- // Data Members (m_ prefix)
- string* m_ident_ptr;
- TypeAST* m_msg_type_ptr;
- ExprAST* m_var_expr_ptr;
- StatementListAST* m_statement_list_ptr;
- TypeAST* m_queue_type_ptr;
-};
-
-// Output operator declaration
-ostream& operator<<(ostream& out, const InPortDeclAST& obj);
-
-// ******************* Definitions *******************
-
-// Output operator definition
-extern inline
-ostream& operator<<(ostream& out, const InPortDeclAST& obj)
-{
- obj.print(out);
- out << flush;
- return out;
-}
-
-#endif //InPortDeclAST_H
diff --git a/src/mem/slicc/ast/InPortDeclAST.py b/src/mem/slicc/ast/InPortDeclAST.py
new file mode 100644
index 000000000..3dde24557
--- /dev/null
+++ b/src/mem/slicc/ast/InPortDeclAST.py
@@ -0,0 +1,130 @@
+# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
+# Copyright (c) 2009 The Hewlett-Packard Development Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (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 slicc.ast.DeclAST import DeclAST
+from slicc.ast.TypeAST import TypeAST
+from slicc.symbols import Func, Type, Var
+
+class InPortDeclAST(DeclAST):
+ def __init__(self, slicc, ident, msg_type, var_expr, pairs, statements):
+ super(InPortDeclAST, self).__init__(slicc, pairs)
+
+ self.ident = ident
+ self.msg_type = msg_type
+ self.var_expr = var_expr
+ self.statements = statements
+ self.queue_type = TypeAST(slicc, "InPort")
+
+ def __repr__(self):
+ return "[InPortDecl: %s]" % self.ident
+
+ def generate(self):
+ symtab = self.symtab
+ void_type = symtab.find("void", Type)
+
+ code = code_formatter()
+ queue_type = self.var_expr.generate(code)
+ if not queue_type.isInPort:
+ self.error("The inport queue's type must have the 'inport' " + \
+ "attribute. Type '%s' does not have this attribute.",
+ queue_type)
+
+ type = self.queue_type.type
+ in_port = Var(self.symtab, self.ident, self.location, type, str(code),
+ self.pairs)
+ symtab.newSymbol(in_port)
+
+ symtab.pushFrame()
+ param_types = []
+
+ # Check for Event
+ type = symtab.find("Event", Type)
+ if type is None:
+ self.error("in_port decls require 'Event' enumeration defined")
+ param_types.append(type)
+
+ # Check for Address
+ type = symtab.find("Address", Type)
+ if type is None:
+ self.error("in_port decls require 'Address' type to be defined")
+
+ param_types.append(type)
+
+ # Add the trigger method - FIXME, this is a bit dirty
+ pairs = { "external" : "yes" }
+ func = Func(self.symtab, "trigger", self.location, void_type,
+ param_types, [], "", pairs, None)
+ symtab.newSymbol(func)
+
+ param_types = []
+ # Check for Event2
+ type = symtab.find("Event", Type)
+ if type is None:
+ self.error("in_port decls require 'Event' enumeration")
+
+ param_types.append(type)
+
+ # Check for Address2
+ type = symtab.find("Address", Type)
+ if type is None:
+ self.error("in_port decls require 'Address' type to be defined")
+
+ param_types.append(type)
+
+ # Add the doubleTrigger method - this hack supports tiggering
+ # two simulateous events
+ #
+ # The key is that the second transistion cannot fail because
+ # the first event cannot be undone therefore you must do some
+ # checks before calling double trigger to ensure that won't
+ # happen
+ func = Func(self.symtab, "doubleTrigger", self.location, void_type,
+ param_types, [], "", pairs, None)
+ symtab.newSymbol(func)
+
+ # Add the continueProcessing method - this hack supports
+ # messages that don't trigger events
+ func = Func(self.symtab, "continueProcessing", self.location,
+ void_type, [], [], "", pairs, None)
+ symtab.newSymbol(func)
+
+ if self.statements is not None:
+ rcode = code_formatter()
+ rcode.indent()
+ rcode.indent()
+ self.statements.generate(rcode, None)
+ in_port["c_code_in_port"] = str(rcode)
+ symtab.popFrame()
+
+ # Add port to state machine
+ machine = symtab.state_machine
+ if machine is None:
+ self.error("InPort declaration not part of a machine.")
+
+ machine.addInPort(in_port)
diff --git a/src/mem/slicc/ast/InfixOperatorExprAST.cc b/src/mem/slicc/ast/InfixOperatorExprAST.cc
deleted file mode 100644
index 40719fc66..000000000
--- a/src/mem/slicc/ast/InfixOperatorExprAST.cc
+++ /dev/null
@@ -1,121 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * InfixOperatorExprAST.C
- *
- * Description: See InfixOperatorExprAST.hh
- *
- * $Id: InfixOperatorExprAST.C,v 3.2 2004/01/31 20:46:15 milo Exp $
- *
- */
-
-#include "mem/slicc/ast/InfixOperatorExprAST.hh"
-
-InfixOperatorExprAST::InfixOperatorExprAST(ExprAST* left_ptr,
- string* op_ptr,
- ExprAST* right_ptr)
- : ExprAST()
-{
- m_left_ptr = left_ptr;
- m_op_ptr = op_ptr;
- m_right_ptr = right_ptr;
-}
-
-InfixOperatorExprAST::~InfixOperatorExprAST()
-{
- delete m_left_ptr;
- delete m_op_ptr;
- delete m_right_ptr;
-}
-
-Type* InfixOperatorExprAST::generate(string& code) const
-{
- code += "(";
- Type* left_type_ptr = m_left_ptr->generate(code);
- code += " " + *m_op_ptr + " ";
- Type* right_type_ptr = m_right_ptr->generate(code);
- code += ")";
-
- string inputs, output;
- // Figure out what the input and output types should be
- if ((*m_op_ptr == "==" ||
- *m_op_ptr == "!=")) {
- output = "bool";
- if (left_type_ptr != right_type_ptr) {
- error("Type mismatch: left & right operand of operator '" + *m_op_ptr +
- "' must be the same type." +
- "left: '" + left_type_ptr->toString() +
- "', right: '" + right_type_ptr->toString() + "'");
- }
- } else {
- if ((*m_op_ptr == "&&" ||
- *m_op_ptr == "||")) {
- // boolean inputs and output
- inputs = "bool";
- output = "bool";
- } else if ((*m_op_ptr == "==" ||
- *m_op_ptr == "!=" ||
- *m_op_ptr == ">=" ||
- *m_op_ptr == "<=" ||
- *m_op_ptr == ">" ||
- *m_op_ptr == "<")) {
- // Integer inputs, boolean output
- inputs = "int";
- output = "bool";
- } else {
- // integer inputs and output
- inputs = "int";
- output = "int";
- }
-
- Type* inputs_type = g_sym_table.getType(inputs);
-
- if (inputs_type != left_type_ptr) {
- m_left_ptr->error("Type mismatch: left operand of operator '" + *m_op_ptr +
- "' expects input type '" + inputs + "', actual was " + left_type_ptr->toString() + "'");
- }
-
- if (inputs_type != right_type_ptr) {
- m_right_ptr->error("Type mismatch: right operand of operator '" + *m_op_ptr +
- "' expects input type '" + inputs + "', actual was '" + right_type_ptr->toString() + "'");
- }
- }
-
- // All is well
- Type* output_type = g_sym_table.getType(output);
- return output_type;
-}
-
-
-void InfixOperatorExprAST::print(ostream& out) const
-{
- out << "[InfixExpr: " << *m_left_ptr
- << *m_op_ptr << *m_right_ptr << "]";
-}
diff --git a/src/mem/slicc/ast/InfixOperatorExprAST.hh b/src/mem/slicc/ast/InfixOperatorExprAST.hh
deleted file mode 100644
index f97ab8805..000000000
--- a/src/mem/slicc/ast/InfixOperatorExprAST.hh
+++ /dev/null
@@ -1,85 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * InfixOperatorExprAST.hh
- *
- * Description:
- *
- * $Id: InfixOperatorExprAST.hh,v 3.1 2001/12/12 01:00:19 milo Exp $
- *
- */
-
-#ifndef INFIXOPERATOREXPRAST_H
-#define INFIXOPERATOREXPRAST_H
-
-#include "mem/slicc/slicc_global.hh"
-#include "mem/slicc/ast/ExprAST.hh"
-
-
-class InfixOperatorExprAST : public ExprAST {
-public:
- // Constructors
- InfixOperatorExprAST(ExprAST* left_ptr, string* op_ptr, ExprAST* right_ptr);
-
- // Destructor
- ~InfixOperatorExprAST();
-
- // Public Methods
- Type* generate(string& code) const;
- void print(ostream& out) const;
-private:
- // Private Methods
-
- // Private copy constructor and assignment operator
- InfixOperatorExprAST(const InfixOperatorExprAST& obj);
- InfixOperatorExprAST& operator=(const InfixOperatorExprAST& obj);
-
- // Data Members (m_ prefix)
- ExprAST* m_left_ptr;
- string* m_op_ptr;
- ExprAST* m_right_ptr;
-
-};
-
-// Output operator declaration
-ostream& operator<<(ostream& out, const InfixOperatorExprAST& obj);
-
-// ******************* Definitions *******************
-
-// Output operator definition
-extern inline
-ostream& operator<<(ostream& out, const InfixOperatorExprAST& obj)
-{
- obj.print(out);
- out << flush;
- return out;
-}
-
-#endif //INFIXOPERATOREXPRAST_H
diff --git a/src/mem/slicc/ast/InfixOperatorExprAST.py b/src/mem/slicc/ast/InfixOperatorExprAST.py
new file mode 100644
index 000000000..c4fb4a4db
--- /dev/null
+++ b/src/mem/slicc/ast/InfixOperatorExprAST.py
@@ -0,0 +1,89 @@
+# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
+# Copyright (c) 2009 The Hewlett-Packard Development Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (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 slicc.ast.ExprAST import ExprAST
+from slicc.symbols import Type
+
+class InfixOperatorExprAST(ExprAST):
+ def __init__(self, slicc, left, op, right):
+ super(InfixOperatorExprAST, self).__init__(slicc)
+
+ self.left = left
+ self.op = op
+ self.right = right
+
+ def __repr__(self):
+ return "[InfixExpr: %r %s %r]" % (self.left, self.op, self.right)
+
+ def generate(self, code):
+ lcode = code_formatter()
+ rcode = code_formatter()
+
+ ltype = self.left.generate(lcode)
+ rtype = self.right.generate(rcode)
+
+ # Figure out what the input and output types should be
+ if self.op in ("==", "!="):
+ output = "bool"
+ if (ltype != rtype):
+ self.error("Type mismatch: left and right operands of " +
+ "operator '%s' must be the same type. " +
+ "left: '%s', right: '%s'",
+ self.op, ltype, rtype)
+ else:
+ if self.op in ("&&", "||"):
+ # boolean inputs and output
+ inputs = "bool"
+ output = "bool"
+ elif self.op in ("==", "!=", ">=", "<=", ">", "<"):
+ # Integer inputs, boolean output
+ inputs = "int"
+ output = "bool"
+ else:
+ # integer inputs and output
+ inputs = "int"
+ output = "int"
+
+ inputs_type = self.symtab.find(inputs, Type)
+
+ if inputs_type != ltype:
+ self.left.error("Type mismatch: left operand of operator " +
+ "'%s' expects type '%s', actual was '%s'",
+ self.op, inputs, ltype)
+
+ if inputs_type != rtype:
+ self.right.error("Type mismatch: right operand of operator " +
+ "'%s' expects type '%s', actual was '%s'",
+ self.op, inputs, rtype)
+
+ # All is well
+ fix = code.nofix()
+ code("($lcode ${{self.op}} $rcode)")
+ code.fix(fix)
+ return self.symtab.find(output, Type)
diff --git a/src/mem/slicc/ast/LiteralExprAST.cc b/src/mem/slicc/ast/LiteralExprAST.cc
deleted file mode 100644
index 4e384a3b3..000000000
--- a/src/mem/slicc/ast/LiteralExprAST.cc
+++ /dev/null
@@ -1,55 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * LiteralExprAST.C
- *
- * Description: See LiteralExprAST.hh
- *
- * $Id: LiteralExprAST.C,v 3.1 2002/10/22 21:27:52 milo Exp $
- *
- */
-
-#include "mem/slicc/ast/LiteralExprAST.hh"
-
-Type* LiteralExprAST::generate(string& code) const
-{
- if (m_type == "string") {
- code += "(\"" + *m_lit_ptr + "\")";
- } else {
- code += "(" + *m_lit_ptr + ")";
- }
-
- Type* type_ptr = g_sym_table.getType(m_type);
- if (type_ptr == NULL) {
- // Can't find the type
- error("Internal: can't primitive type '" + m_type + "'");
- }
- return type_ptr;
-}
diff --git a/src/mem/slicc/ast/LiteralExprAST.hh b/src/mem/slicc/ast/LiteralExprAST.hh
deleted file mode 100644
index c895fa9ae..000000000
--- a/src/mem/slicc/ast/LiteralExprAST.hh
+++ /dev/null
@@ -1,83 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * LiteralExprAST.hh
- *
- * Description:
- *
- * $Id: LiteralExprAST.hh,v 3.1 2001/12/12 01:00:20 milo Exp $
- *
- */
-
-#ifndef LITERALEXPRAST_H
-#define LITERALEXPRAST_H
-
-#include "mem/slicc/slicc_global.hh"
-#include "mem/slicc/ast/ExprAST.hh"
-
-
-class LiteralExprAST : public ExprAST {
-public:
- // Constructors
- LiteralExprAST(string* lit_ptr, string type) : ExprAST() { m_lit_ptr = lit_ptr; m_type = type; }
-
- // Destructor
- ~LiteralExprAST() { delete m_lit_ptr; }
-
- // Public Methods
- Type* generate(string& code) const;
- void print(ostream& out) const { out << "[Literal: " << *m_lit_ptr << "]"; }
-private:
- // Private Methods
-
- // Private copy constructor and assignment operator
- LiteralExprAST(const LiteralExprAST& obj);
- LiteralExprAST& operator=(const LiteralExprAST& obj);
-
- // Data Members (m_ prefix)
- string* m_lit_ptr;
- string m_type;
-};
-
-// Output operator declaration
-ostream& operator<<(ostream& out, const LiteralExprAST& obj);
-
-// ******************* Definitions *******************
-
-// Output operator definition
-extern inline
-ostream& operator<<(ostream& out, const LiteralExprAST& obj)
-{
- obj.print(out);
- out << flush;
- return out;
-}
-
-#endif //LITERALEXPRAST_H
diff --git a/src/mem/slicc/ast/LiteralExprAST.py b/src/mem/slicc/ast/LiteralExprAST.py
new file mode 100644
index 000000000..773e8f35c
--- /dev/null
+++ b/src/mem/slicc/ast/LiteralExprAST.py
@@ -0,0 +1,55 @@
+# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
+# Copyright (c) 2009 The Hewlett-Packard Development Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (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 slicc.ast.ExprAST import ExprAST
+from slicc.symbols import Type
+
+class LiteralExprAST(ExprAST):
+ def __init__(self, slicc, literal, type):
+ super(LiteralExprAST, self).__init__(slicc)
+ self.literal = literal
+ self.type = type
+
+ def __repr__(self):
+ return "[Literal: %s]" % self.literal
+
+ def generate(self, code):
+ fix = code.nofix()
+ if self.type == "string":
+ code('("${{self.literal}}")')
+ elif self.type == "bool":
+ code('(${{str(self.literal).lower()}})')
+ else:
+ code('(${{self.literal}})')
+ code.fix(fix)
+
+ type = self.symtab.find(self.type, Type)
+ if type is None:
+ # Can't find the type
+ self.error("Internal: can't primitive type '%s'" % self.type)
+
+ return type
diff --git a/src/mem/slicc/ast/Location.cc b/src/mem/slicc/ast/Location.cc
deleted file mode 100644
index fd224fe2f..000000000
--- a/src/mem/slicc/ast/Location.cc
+++ /dev/null
@@ -1,87 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * Location.C
- *
- * Description: See Location.hh
- *
- * $Id: Location.C,v 3.3 2004/05/30 22:19:02 kmoore Exp $
- *
- */
-
-#include "mem/slicc/ast/Location.hh"
-
-int g_line_number = 0;
-string &g_file_name()
-{
- static string the_string;
- return the_string;
-}
-
-Location::Location()
-{
- m_file_name = g_file_name();
- m_line_number = g_line_number;
-
- ostringstream sstr;
- sstr << getLineNumber();
- m_line_number_str = sstr.str();
-}
-
-void Location::error(string err_msg) const
-{
- cerr << endl;
- cerr << toString() << ": Error: " << err_msg << endl;
- exit(1);
-}
-
-string Location::embedError(string err_msg) const
-{
- string code;
- code += "cerr << \"Runtime Error at ";
- code += toString() + ", Ruby Time: \" << ";
- code += "g_eventQueue_ptr->getTime() << \": \" << ";
- code += err_msg;
- code += " << \", PID: \" << getpid() << endl;\n";
- code += "char c; cerr << \"press return to continue.\" << endl; cin.get(c); abort();\n";
-
- return code;
-}
-
-void Location::warning(string err_msg) const
-{
- cerr << toString() << ": Warning: "
- << err_msg << endl;
-}
-
-string Location::toString() const
-{
- return m_file_name + ":" + m_line_number_str;
-}
diff --git a/src/mem/slicc/ast/Location.hh b/src/mem/slicc/ast/Location.hh
deleted file mode 100644
index c9e20418e..000000000
--- a/src/mem/slicc/ast/Location.hh
+++ /dev/null
@@ -1,93 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * Location.hh
- *
- * Description:
- *
- * $Id: Location.hh,v 3.1 2001/12/12 01:00:20 milo Exp $
- *
- */
-
-#ifndef LOCATION_H
-#define LOCATION_H
-
-#include "mem/slicc/slicc_global.hh"
-
-extern int g_line_number;
-extern string &g_file_name();
-
-class Location {
-public:
- // Constructors
- Location();
-
- // Destructor
- //~Location();
-
- // Public Methods
-
- void print(ostream& out) const;
- void error(string err_msg) const;
- string embedError(string err_msg) const;
- void warning(string err_msg) const;
- string toString() const;
-
-private:
- // Private Methods
- const string& getFileName() const { return m_file_name; }
- int getLineNumber() const { return m_line_number; }
- string getLineNumberStr() const { return m_line_number_str; }
-
- // Private copy constructor and assignment operator
- //Location(const Location& obj);
- //Location& operator=(const Location& obj);
-
- // Data Members (m_ prefix)
- string m_file_name;
- int m_line_number;
- string m_line_number_str;
-};
-
-// Output operator declaration
-ostream& operator<<(ostream& out, const Location& obj);
-
-// ******************* Definitions *******************
-
-// Output operator definition
-extern inline
-ostream& operator<<(ostream& out, const Location& obj)
-{
- obj.print(out);
- out << flush;
- return out;
-}
-
-#endif //LOCATION_H
diff --git a/src/mem/slicc/ast/MachineAST.cc b/src/mem/slicc/ast/MachineAST.cc
deleted file mode 100644
index ae8026458..000000000
--- a/src/mem/slicc/ast/MachineAST.cc
+++ /dev/null
@@ -1,99 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * MachineAST.cc
- *
- * Description: See MachineAST.hh
- *
- * $Id: MachineAST.cc,v 3.1 2003/03/17 01:54:25 xu Exp $
- *
- */
-
-#include "mem/slicc/ast/MachineAST.hh"
-#include "mem/slicc/ast/FormalParamAST.hh"
-#include "mem/slicc/symbols/SymbolTable.hh"
-
-MachineAST::MachineAST(string* ident_ptr,
- PairListAST* pairs_ptr,
- Vector<FormalParamAST*>* config_parameters,
- DeclListAST* decl_list_ptr)
-
- : DeclAST(pairs_ptr)
-{
- m_ident_ptr = ident_ptr;
- m_pairs_ptr = pairs_ptr;
- m_config_parameters = config_parameters;
- m_decl_list_ptr = decl_list_ptr;
-}
-
-MachineAST::~MachineAST()
-{
- delete m_ident_ptr;
- delete m_pairs_ptr;
- delete m_decl_list_ptr;
-}
-
-void MachineAST::generate()
-{
- StateMachine* machine_ptr;
-
- // Make a new frame
- g_sym_table.pushFrame();
-
- // Create a new machine
- machine_ptr = new StateMachine(*m_ident_ptr, getLocation(), getPairs(), m_config_parameters);
- g_sym_table.newCurrentMachine(machine_ptr);
-
- // Generate code for all the internal decls
- m_decl_list_ptr->generate();
-
- // Build the transition table
- machine_ptr->buildTable();
-
- // Pop the frame
- g_sym_table.popFrame();
-}
-
-void MachineAST::findMachines()
-{
- // Add to MachineType enumeration
- Type* type_ptr = g_sym_table.getType("MachineType");
- if (!type_ptr->enumAdd(*m_ident_ptr, m_pairs_ptr->getPairs())) {
- error("Duplicate machine name: " + type_ptr->toString() + ":" + *m_ident_ptr);
- }
-
- // Generate code for all the internal decls
- m_decl_list_ptr->findMachines();
-}
-
-void MachineAST::print(ostream& out) const
-{
- out << "[Machine: " << *m_ident_ptr << "]";
-}
diff --git a/src/mem/slicc/ast/MachineAST.hh b/src/mem/slicc/ast/MachineAST.hh
deleted file mode 100644
index 5d1bc2a1c..000000000
--- a/src/mem/slicc/ast/MachineAST.hh
+++ /dev/null
@@ -1,93 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * ActionDeclAST.hh
- *
- * Description:
- *
- * $Id: MachineAST.hh,v 3.2 2003/07/10 18:08:06 milo Exp $
- *
- */
-
-#ifndef MachineAST_H
-#define MachineAST_H
-
-#include "mem/slicc/slicc_global.hh"
-#include "mem/slicc/ast/DeclAST.hh"
-#include "mem/slicc/ast/DeclListAST.hh"
-#include "mem/slicc/ast/TypeFieldAST.hh"
-#include "mem/slicc/symbols/StateMachine.hh"
-
-class FormalParamAST;
-
-class MachineAST : public DeclAST {
-public:
- // Constructors
- MachineAST(string* ident_ptr,
- PairListAST* pairs_ptr,
- Vector<FormalParamAST*>* config_parameters,
- DeclListAST* decl_list_ptr);
-
- // Destructor
- ~MachineAST();
-
- // Public Methods
- void print(ostream& out) const;
- void generate();
- void findMachines();
-private:
- // Private Methods
-
- // Private copy constructor and assignment operator
- MachineAST(const MachineAST& obj);
- MachineAST& operator=(const MachineAST& obj);
-
- // Data Members (m_ prefix)
- Vector<FormalParamAST*>* m_config_parameters;
- string* m_ident_ptr;
- DeclListAST* m_decl_list_ptr;
- PairListAST* m_pairs_ptr;
-};
-
-// Output operator declaration
-ostream& operator<<(ostream& out, const MachineAST& obj);
-
-// ******************* Definitions *******************
-
-// Output operator definition
-extern inline
-ostream& operator<<(ostream& out, const MachineAST& obj)
-{
- obj.print(out);
- out << flush;
- return out;
-}
-
-#endif //MachineAST_H
diff --git a/src/mem/slicc/ast/MachineAST.py b/src/mem/slicc/ast/MachineAST.py
new file mode 100644
index 000000000..8d48ccbf5
--- /dev/null
+++ b/src/mem/slicc/ast/MachineAST.py
@@ -0,0 +1,81 @@
+# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
+# Copyright (c) 2009 The Hewlett-Packard Development Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (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 slicc.ast.DeclAST import DeclAST
+from slicc.symbols import StateMachine, Type
+
+class MachineAST(DeclAST):
+ def __init__(self, slicc, ident, pairs_ast, config_parameters, decls):
+ super(MachineAST, self).__init__(slicc, pairs_ast)
+
+ self.ident = ident
+ self.pairs_ast = pairs_ast
+ self.config_parameters = config_parameters
+ self.decls = decls
+
+ def __repr__(self):
+ return "[Machine: %r]" % self.ident
+
+ def files(self, hh, cc, parent=None):
+ hh.add('%s_Controller.hh' % self.ident)
+ hh.add('%s_Profiler.hh' % self.ident)
+
+ cc.add('%s_Controller.cc' % self.ident)
+ cc.add('%s_Profiler.cc' % self.ident)
+ cc.add('%s_Transitions.cc' % self.ident)
+ cc.add('%s_Wakeup.cc' % self.ident)
+
+ self.decls.files(hh, cc, self.ident)
+
+ def generate(self):
+ # Make a new frame
+ self.symtab.pushFrame()
+
+ # Create a new machine
+ machine = StateMachine(self.symtab, self.ident, self.location,
+ self.pairs, self.config_parameters)
+
+ self.symtab.newCurrentMachine(machine)
+
+ # Generate code for all the internal decls
+ self.decls.generate()
+
+ # Build the transition table
+ machine.buildTable()
+
+ # Pop the frame
+ self.symtab.popFrame()
+
+ def findMachines(self):
+ # Add to MachineType enumeration
+ machine_type = self.symtab.find("MachineType", Type)
+ if not machine_type.enumAdd(self.ident, self.pairs_ast.pairs):
+ self.error("Duplicate machine name: %s:%s" % (machine_type,
+ self.ident))
+
+ # Generate code for all the internal decls
+ self.decls.findMachines()
diff --git a/src/mem/slicc/ast/MemberExprAST.cc b/src/mem/slicc/ast/MemberExprAST.cc
deleted file mode 100644
index 1bcfdc7f1..000000000
--- a/src/mem/slicc/ast/MemberExprAST.cc
+++ /dev/null
@@ -1,72 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * FieldExprAST.C
- *
- * Description: See FieldExprAST.hh
- *
- * $Id$
- *
- */
-
-#include "mem/slicc/ast/MemberExprAST.hh"
-
-MemberExprAST::MemberExprAST(ExprAST* expr_ast_ptr, string* field_ptr)
- : ExprAST()
-{
- m_expr_ast_ptr = expr_ast_ptr;
- m_field_ptr = field_ptr;
-}
-
-MemberExprAST::~MemberExprAST()
-{
- delete m_expr_ast_ptr;
- delete m_field_ptr;
-}
-
-Type* MemberExprAST::generate(string& code) const
-{
- code += "(";
- Type* type_ptr = m_expr_ast_ptr->generate(code);
- code += ").m_" + (*m_field_ptr);
-
- // Verify that this is a valid field name for this type
- if (!type_ptr->dataMemberExist(*m_field_ptr)) {
- error("Invalid object field: Type '" + type_ptr->toString() + "' does not have data member " + *m_field_ptr);
- }
-
- // Return the type of the field
- return type_ptr->dataMemberType(*m_field_ptr);
-}
-
-void MemberExprAST::print(ostream& out) const
-{
- out << "[MemberExprAST: " << *m_expr_ast_ptr << "." << *m_field_ptr << "]";
-}
diff --git a/src/mem/slicc/ast/MemberExprAST.hh b/src/mem/slicc/ast/MemberExprAST.hh
deleted file mode 100644
index 34b694882..000000000
--- a/src/mem/slicc/ast/MemberExprAST.hh
+++ /dev/null
@@ -1,83 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * MemberExprAST.hh
- *
- * Description:
- *
- * $Id: MemberExprAST.hh,v 3.1 2001/12/12 01:00:21 milo Exp $
- *
- */
-
-#ifndef MemberExprAST_H
-#define MemberExprAST_H
-
-#include "mem/slicc/slicc_global.hh"
-#include "mem/slicc/ast/ExprAST.hh"
-
-
-class MemberExprAST : public ExprAST {
-public:
- // Constructors
- MemberExprAST(ExprAST* expr_ast_ptr, string* field_ptr);
-
- // Destructor
- ~MemberExprAST();
-
- // Public Methods
- Type* generate(string& code) const;
- void print(ostream& out) const;
-private:
- // Private Methods
-
- // Private copy constructor and assignment operator
- MemberExprAST(const MemberExprAST& obj);
- MemberExprAST& operator=(const MemberExprAST& obj);
-
- // Data Members (m_ prefix)
- ExprAST* m_expr_ast_ptr;
- string* m_field_ptr;
-};
-
-// Output operator declaration
-ostream& operator<<(ostream& out, const MemberExprAST& obj);
-
-// ******************* Definitions *******************
-
-// Output operator definition
-extern inline
-ostream& operator<<(ostream& out, const MemberExprAST& obj)
-{
- obj.print(out);
- out << flush;
- return out;
-}
-
-#endif //MemberExprAST_H
diff --git a/src/mem/slicc/ast/MemberExprAST.py b/src/mem/slicc/ast/MemberExprAST.py
new file mode 100644
index 000000000..113bb188a
--- /dev/null
+++ b/src/mem/slicc/ast/MemberExprAST.py
@@ -0,0 +1,55 @@
+# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
+# Copyright (c) 2009 The Hewlett-Packard Development Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (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 slicc.ast.ExprAST import ExprAST
+
+class MemberExprAST(ExprAST):
+ def __init__(self, slicc, expr_ast, field):
+ super(MemberExprAST, self).__init__(slicc)
+
+ self.expr_ast = expr_ast
+ self.field = field
+
+ def __repr__(self):
+ return "[MemberExprAST: %r.%r]" % (self.expr_ast, self.field)
+
+ def generate(self, code):
+ return_type, gcode = self.expr_ast.inline(True)
+ fix = code.nofix()
+ code("($gcode).m_${{self.field}}")
+ code.fix(fix)
+
+ # Verify that this is a valid field name for this type
+ if self.field not in return_type.data_members:
+ error("Invalid object field: " +
+ "Type '%s' does not have data member %s" % \
+ (return_type, self.field))
+
+ # Return the type of the field
+ return return_type.data_members[self.field].type
diff --git a/src/mem/slicc/ast/MethodCallExprAST.cc b/src/mem/slicc/ast/MethodCallExprAST.cc
deleted file mode 100644
index 1bfe312ff..000000000
--- a/src/mem/slicc/ast/MethodCallExprAST.cc
+++ /dev/null
@@ -1,160 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * MethodCallExprAST.cc
- *
- * Description: See MethodCallExprAST.hh
- *
- * $Id$
- *
- */
-
-#include "mem/slicc/ast/MethodCallExprAST.hh"
-
-MethodCallExprAST::MethodCallExprAST(ExprAST* obj_expr_ptr,
- string* proc_name_ptr,
- Vector<ExprAST*>* expr_vec_ptr)
- : ExprAST()
-{
- m_obj_expr_ptr = obj_expr_ptr;
- m_type_ptr = NULL;
- m_proc_name_ptr = proc_name_ptr;
- m_expr_vec_ptr = expr_vec_ptr;
-}
-
-MethodCallExprAST::MethodCallExprAST(TypeAST* type_ptr,
- string* proc_name_ptr,
- Vector<ExprAST*>* expr_vec_ptr)
- : ExprAST()
-{
- m_obj_expr_ptr = NULL;
- m_type_ptr = type_ptr;
- m_proc_name_ptr = proc_name_ptr;
- m_expr_vec_ptr = expr_vec_ptr;
-}
-
-MethodCallExprAST::~MethodCallExprAST()
-{
- delete m_obj_expr_ptr;
- delete m_type_ptr;
- delete m_proc_name_ptr;
- int size = m_expr_vec_ptr->size();
- for(int i=0; i<size; i++) {
- delete (*m_expr_vec_ptr)[i];
- }
- delete m_expr_vec_ptr;
-}
-
-Type* MethodCallExprAST::generate(string& code) const
-{
- Type* obj_type_ptr = NULL;
-
- string methodId;
- Vector <Type*> paramTypes;
-
- int actual_size = m_expr_vec_ptr->size();
- for(int i=0; i<actual_size; i++) {
- string tmp;
- Type* actual_type_ptr = (*m_expr_vec_ptr)[i]->generate(tmp);
- paramTypes.insertAtBottom(actual_type_ptr);
- }
-
- if(m_obj_expr_ptr) {
- // member method call
- string tmp;
- obj_type_ptr = m_obj_expr_ptr->generate(tmp);
- methodId = obj_type_ptr->methodId(*m_proc_name_ptr, paramTypes);
- if (obj_type_ptr->methodReturnType(methodId)->isInterface())
- code += "static_cast<" + obj_type_ptr->methodReturnType(methodId)->cIdent() + "&>";
- code += "((";
- code += tmp;
- code += ").";
- } else if (m_type_ptr) {
- // class method call
- code += "(" + m_type_ptr->toString() + "::";
- obj_type_ptr = m_type_ptr->lookupType();
- methodId = obj_type_ptr->methodId(*m_proc_name_ptr, paramTypes);
- } else {
- // impossible
- assert(0);
- }
-
- // generate code
- actual_size = m_expr_vec_ptr->size();
- code += (*m_proc_name_ptr) + "(";
- for(int i=0; i<actual_size; i++) {
- if (i != 0) {
- code += ", ";
- }
- // Check the types of the parameter
- Type* actual_type_ptr = (*m_expr_vec_ptr)[i]->generate(code);
- }
- code += "))";
-
- // Verify that this is a method of the object
- if (!obj_type_ptr->methodExist(methodId)) {
- error("Invalid method call: Type '" + obj_type_ptr->toString() + "' does not have a method '" + methodId + "'");
- }
-
- int expected_size = obj_type_ptr->methodParamType(methodId).size();
- if (actual_size != expected_size) {
- // Right number of parameters
- ostringstream err;
- err << "Wrong number of parameters for function name: '" << *m_proc_name_ptr << "'";
- err << ", expected: ";
- err << expected_size;
- err << ", actual: ";
- err << actual_size;
- error(err.str());
- }
-
- for(int i=0; i<actual_size; i++) {
- // Check the types of the parameter
- Type* actual_type_ptr = paramTypes[i];
- Type* expected_type_ptr = obj_type_ptr->methodParamType(methodId)[i];
- if (actual_type_ptr != expected_type_ptr) {
- (*m_expr_vec_ptr)[i]->error("Type mismatch: expected: " + expected_type_ptr->toString() +
- " actual: " + actual_type_ptr->toString());
- }
- }
-
- // Return the return type of the method
- return obj_type_ptr->methodReturnType(methodId);
-}
-
-void MethodCallExprAST::findResources(Map<Var*, string>& resource_list) const
-{
-
-}
-
-void MethodCallExprAST::print(ostream& out) const
-{
- out << "[MethodCallExpr: " << *m_proc_name_ptr << *m_obj_expr_ptr << " " << *m_expr_vec_ptr << "]";
-}
diff --git a/src/mem/slicc/ast/MethodCallExprAST.hh b/src/mem/slicc/ast/MethodCallExprAST.hh
deleted file mode 100644
index d248e6ba4..000000000
--- a/src/mem/slicc/ast/MethodCallExprAST.hh
+++ /dev/null
@@ -1,93 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * MethodCallExprAST.hh
- *
- * Description:
- *
- * $Id$
- *
- */
-
-#ifndef MethodCallExprAST_H
-#define MethodCallExprAST_H
-
-#include "mem/slicc/slicc_global.hh"
-#include "mem/slicc/ast/StatementAST.hh"
-#include "mem/slicc/ast/ExprAST.hh"
-#include "mem/slicc/ast/TypeAST.hh"
-
-class MethodCallExprAST : public ExprAST {
-public:
- // Constructors
- MethodCallExprAST(ExprAST* m_obj_expr_ptr,
- string* proc_name_ptr,
- Vector<ExprAST*>* expr_vec_ptr);
-
- MethodCallExprAST(TypeAST* type_ptr,
- string* proc_name_ptr,
- Vector<ExprAST*>* expr_vec_ptr);
-
- // Destructor
- ~MethodCallExprAST();
-
- // Public Methods
- Type* generate(string& code) const;
- void findResources(Map<Var*, string>& resource_list) const;
- void print(ostream& out) const;
-private:
- // Private Methods
-
- // Private copy constructor and assignment operator
- MethodCallExprAST(const MethodCallExprAST& obj);
- MethodCallExprAST& operator=(const MethodCallExprAST& obj);
-
- // Data Members (m_ prefix)
- ExprAST* m_obj_expr_ptr;
- TypeAST* m_type_ptr;
- string* m_proc_name_ptr;
- Vector<ExprAST*>* m_expr_vec_ptr;
-};
-
-// Output operator declaration
-ostream& operator<<(ostream& out, const MethodCallExprAST& obj);
-
-// ******************* Definitions *******************
-
-// Output operator definition
-extern inline
-ostream& operator<<(ostream& out, const MethodCallExprAST& obj)
-{
- obj.print(out);
- out << flush;
- return out;
-}
-
-#endif // MethodCallExprAST_H
diff --git a/src/mem/slicc/ast/MethodCallExprAST.py b/src/mem/slicc/ast/MethodCallExprAST.py
new file mode 100644
index 000000000..ecfe43cdb
--- /dev/null
+++ b/src/mem/slicc/ast/MethodCallExprAST.py
@@ -0,0 +1,127 @@
+# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
+# Copyright (c) 2009 The Hewlett-Packard Development Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (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 slicc.ast.ExprAST import ExprAST
+
+class MethodCallExprAST(ExprAST):
+ def __init__(self, slicc, proc_name, expr_ast_vec):
+ super(MethodCallExprAST, self).__init__(slicc)
+ self.proc_name = proc_name
+ self.expr_ast_vec = expr_ast_vec
+
+ def generate(self, code):
+ tmp = code_formatter()
+ paramTypes = []
+ for expr_ast in self.expr_ast_vec:
+ return_type = expr_ast.generate(tmp)
+ paramTypes.append(return_type)
+
+ obj_type, methodId, prefix = self.generate_prefix(paramTypes)
+
+ # generate code
+ params = []
+ for expr_ast in self.expr_ast_vec:
+ return_type,tcode = expr_ast.inline(True)
+ params.append(str(tcode))
+ fix = code.nofix()
+ code("$prefix${{self.proc_name}}(${{', '.join(params)}}))")
+ code.fix(fix)
+
+ # Verify that this is a method of the object
+ if methodId not in obj_type.methods:
+ error("Invalid method call: Type '%s' does not have a method '%s'",
+ obj_type, methodId)
+
+ if len(self.expr_ast_vec) != \
+ len(obj_type.methods[methodId].param_types):
+ # Right number of parameters
+ error("Wrong number of parameters for function name: '%s', " + \
+ "expected: , actual: ", proc_name,
+ len(obj_type.methods[methodId].param_types),
+ len(self.expr_ast_vec))
+
+ for actual_type, expected_type in \
+ zip(paramTypes, obj_type.methods[methodId].param_types):
+ if actual_type != expected_type:
+ error("Type mismatch: expected: %s actual: %s",
+ expected_type, actual_type)
+
+ # Return the return type of the method
+ return obj_type.methods[methodId].return_type
+
+ def findResources(self, resources):
+ pass
+
+class MemberMethodCallExprAST(MethodCallExprAST):
+ def __init__(self, slicc, obj_expr_ast, proc_name, expr_ast_vec):
+ s = super(MemberMethodCallExprAST, self)
+ s.__init__(slicc, proc_name, expr_ast_vec)
+
+ self.obj_expr_ast = obj_expr_ast
+
+ def __repr__(self):
+ return "[MethodCallExpr: %r%r %r]" % (self.proc_name,
+ self.obj_expr_ast,
+ self.expr_ast_vec)
+ def generate_prefix(self, paramTypes):
+ code = code_formatter()
+
+ # member method call
+ obj_type = self.obj_expr_ast.generate(code)
+ methodId = obj_type.methodId(self.proc_name, paramTypes)
+
+ prefix = ""
+ return_type = obj_type.methods[methodId].return_type
+ if return_type.isInterface:
+ prefix = "static_cast<%s &>" % return_type.c_ident
+ prefix = "%s((%s)." % (prefix, code)
+
+ return obj_type, methodId, prefix
+
+
+class ClassMethodCallExprAST(MethodCallExprAST):
+ def __init__(self, slicc, type_ast, proc_name, expr_ast_vec):
+ s = super(ClassMethodCallExprAST, self)
+ s.__init__(slicc, proc_name, expr_ast_vec)
+
+ self.type_ast = type_ast
+
+ def __repr__(self):
+ return "[MethodCallExpr: %r %r]" % (self.proc_name, self.expr_ast_vec)
+
+ def generate_prefix(self, paramTypes):
+
+ # class method call
+ prefix = "(%s::" % self.type_ast
+ obj_type = self.type_ast.type
+ methodId = obj_type.methodId(self.proc_name, paramTypes)
+
+ return obj_type, methodId, prefix
+
+__all__ = [ "MemberMethodCallExprAST", "ClassMethodCallExprAST" ]
diff --git a/src/mem/slicc/ast/NewExprAST.cc b/src/mem/slicc/ast/NewExprAST.cc
deleted file mode 100644
index 95e57192f..000000000
--- a/src/mem/slicc/ast/NewExprAST.cc
+++ /dev/null
@@ -1,9 +0,0 @@
-
-#include "mem/slicc/ast/NewExprAST.hh"
-
-Type* NewExprAST::generate(string & code) const
-{
- Type* type = m_type_ptr->lookupType();
- code += "new " + type->cIdent();
- return type;
-}
diff --git a/src/mem/slicc/ast/NewExprAST.hh b/src/mem/slicc/ast/NewExprAST.hh
deleted file mode 100644
index 375f130d6..000000000
--- a/src/mem/slicc/ast/NewExprAST.hh
+++ /dev/null
@@ -1,20 +0,0 @@
-#ifndef NEWEXPRAST_H
-#define NEWEXPRAST_H
-
-#include "mem/slicc/ast/ExprAST.hh"
-#include "mem/slicc/ast/TypeAST.hh"
-#include "mem/slicc/symbols/Type.hh"
-
-class NewExprAST : public ExprAST
-{
-public:
- NewExprAST(TypeAST* type_ptr) : ExprAST() { m_type_ptr = type_ptr; }
- Type* generate(string & code) const;
- void print(ostream & out) const { out << "[NewExprAST: " << *m_type_ptr << "]"; }
- string getName() const { return m_type_ptr->toString(); }
-
-private:
- TypeAST* m_type_ptr;
-};
-
-#endif
diff --git a/src/mem/slicc/ast/NewExprAST.py b/src/mem/slicc/ast/NewExprAST.py
new file mode 100644
index 000000000..a42350768
--- /dev/null
+++ b/src/mem/slicc/ast/NewExprAST.py
@@ -0,0 +1,47 @@
+# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
+# Copyright (c) 2009 The Hewlett-Packard Development Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (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 slicc.ast.ExprAST import ExprAST
+
+class NewExprAST(ExprAST):
+ def __init__(self, slicc, type_ast):
+ super(NewExprAST, self).__init__(slicc)
+ self.type_ast = type_ast
+
+ def __repr__(self):
+ return "[NewExprAST: %r]" % self.type_ast
+
+ @property
+ def name(self):
+ return str(self.type_ast)
+
+ def generate(self, code):
+ type = self.type_ast.type
+ fix = code.nofix()
+ code("new ${{type.c_ident}}")
+ code.fix(fix)
+ return type
diff --git a/src/mem/slicc/ast/ObjDeclAST.cc b/src/mem/slicc/ast/ObjDeclAST.cc
deleted file mode 100644
index 3569395db..000000000
--- a/src/mem/slicc/ast/ObjDeclAST.cc
+++ /dev/null
@@ -1,137 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * ObjDeclAST.cc
- *
- * Description: See ObjDeclAST.hh
- *
- * $Id: ObjDeclAST.cc,v 3.13 2004/06/24 15:56:14 beckmann Exp $
- *
- */
-
-#include "mem/slicc/ast/ObjDeclAST.hh"
-#include "mem/slicc/symbols/SymbolTable.hh"
-#include "mem/slicc/main.hh"
-
-ObjDeclAST::ObjDeclAST(TypeAST* type_ptr,
- string* ident_ptr,
- PairListAST* pairs_ptr)
- : DeclAST(pairs_ptr)
-{
- m_type_ptr = type_ptr;
- m_ident_ptr = ident_ptr;
-}
-
-ObjDeclAST::~ObjDeclAST()
-{
- delete m_type_ptr;
- delete m_ident_ptr;
-}
-
-void ObjDeclAST::generate()
-{
-
- bool machineComponentSym = false;
-
- getPairs().add("chip_object", "yes");
-
- string c_code;
-
-
- if (getPairs().exist("hack")) {
- warning("'hack=' is now deprecated");
- }
-
- if (getPairs().exist("network")) {
- if (!getPairs().exist("virtual_network")) {
- error("Network queues require a 'virtual_network' attribute.");
- }
- }
-
- Type* type_ptr = m_type_ptr->lookupType();
- if (type_ptr->isBuffer()) {
- if (!getPairs().exist("ordered")) {
- error("Buffer object declarations require an 'ordered' attribute.");
- }
- }
-
- if (getPairs().exist("ordered")) {
- string value = getPairs().lookup("ordered");
- if (value != "true" && value != "false") {
- error("The 'ordered' attribute must be 'true' or 'false'.");
- }
- }
-
- if (getPairs().exist("random")) {
- string value = getPairs().lookup("random");
- if (value != "true" && value != "false") {
- error("The 'random' attribute must be 'true' or 'false'.");
- }
- }
-
- string machine;
- if (g_sym_table.getStateMachine() != NULL) {
- machine = g_sym_table.getStateMachine()->getIdent() + "_";
- }
-
- // FIXME : should all use accessors here to avoid public member variables
- if (*m_ident_ptr == "id") {
- c_code = "m_chip_ptr->getID()";
- } else if (*m_ident_ptr == "version") {
- c_code = "m_version";
- } else if (*m_ident_ptr == "machineID") {
- c_code = "m_machineID";
- } else {
- c_code = "(*m_" + machine + *m_ident_ptr + "_ptr)";
- // c_code = "(*(m_chip_ptr->m_" + machine + *m_ident_ptr + "_ptr))";
- // machineComponentSym = true;
- }
-
- Var* v = new Var(*m_ident_ptr, getLocation(), type_ptr, c_code,
- getPairs(), g_sym_table.getStateMachine());
-
- StateMachine* machine_ptr = g_sym_table.getStateMachine();
- if (machine_ptr != NULL) {
- machine_ptr->addObj(v);
- }// else {
- g_sym_table.newSym(v);
- //}
-
- // used to cheat-- that is, access components in other machines
- if (machineComponentSym) {
- g_sym_table.newMachComponentSym(v);
- }
-
-}
-
-void ObjDeclAST::print(ostream& out) const
-{
- out << "[ObjDecl: " << *m_ident_ptr << "]";
-}
diff --git a/src/mem/slicc/ast/ObjDeclAST.hh b/src/mem/slicc/ast/ObjDeclAST.hh
deleted file mode 100644
index 0b808f472..000000000
--- a/src/mem/slicc/ast/ObjDeclAST.hh
+++ /dev/null
@@ -1,86 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * ObjDeclAST.hh
- *
- * Description:
- *
- * $Id: ObjDeclAST.hh,v 3.2 2003/07/10 18:08:06 milo Exp $
- *
- */
-
-#ifndef ObjDeclAST_H
-#define ObjDeclAST_H
-
-#include "mem/slicc/slicc_global.hh"
-#include "mem/slicc/ast/DeclAST.hh"
-#include "mem/slicc/ast/TypeFieldAST.hh"
-#include "mem/slicc/ast/TypeAST.hh"
-
-class ObjDeclAST : public DeclAST {
-public:
- // Constructors
- ObjDeclAST(TypeAST* type_ptr,
- string* ident_ptr,
- PairListAST* pairs_ptr);
-
- // Destructor
- ~ObjDeclAST();
-
- // Public Methods
- void generate();
- void print(ostream& out) const;
-private:
- // Private Methods
-
- // Private copy constructor and assignment operator
- ObjDeclAST(const ObjDeclAST& obj);
- ObjDeclAST& operator=(const ObjDeclAST& obj);
-
- // Data Members (m_ prefix)
- string* m_ident_ptr;
- TypeAST* m_type_ptr;
-};
-
-// Output operator declaration
-ostream& operator<<(ostream& out, const ObjDeclAST& obj);
-
-// ******************* Definitions *******************
-
-// Output operator definition
-extern inline
-ostream& operator<<(ostream& out, const ObjDeclAST& obj)
-{
- obj.print(out);
- out << flush;
- return out;
-}
-
-#endif //ObjDeclAST_H
diff --git a/src/mem/slicc/ast/ObjDeclAST.py b/src/mem/slicc/ast/ObjDeclAST.py
new file mode 100644
index 000000000..8a967f7b8
--- /dev/null
+++ b/src/mem/slicc/ast/ObjDeclAST.py
@@ -0,0 +1,94 @@
+# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
+# Copyright (c) 2009 The Hewlett-Packard Development Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (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 slicc.ast.DeclAST import DeclAST
+from slicc.symbols import Var
+
+class ObjDeclAST(DeclAST):
+ def __init__(self, slicc, type_ast, ident, pairs):
+ super(ObjDeclAST, self).__init__(slicc, pairs)
+
+ self.type_ast = type_ast
+ self.ident = ident
+
+ def __repr__(self):
+ return "[ObjDecl: %r]" % self.ident
+
+ def generate(self):
+ machineComponentSym = False
+
+ self["chip_object"] = "yes"
+
+ if "hack" in self:
+ warning("'hack=' is now deprecated")
+
+ if "network" in self and "virtual_network" not in self:
+ self.error("Network queues require a 'virtual_network' attribute")
+
+ type = self.type_ast.type
+ if type.isBuffer and "ordered" not in self:
+ self.error("Buffer object decls require an 'ordered' attribute")
+
+ if "ordered" in self:
+ value = self["ordered"]
+
+ if value not in ("true", "false"):
+ self.error("The 'ordered' attribute is '%s' " + \
+ "must be 'true' or 'false'.", value)
+
+ if "random" in self:
+ value = self["random"]
+ if value not in ("true", "false"):
+ self.error("The 'random' attribute is '%s' " + \
+ "must be 'true' or 'false'.", value)
+
+ machine = self.symtab.state_machine
+
+ # FIXME : should all use accessors here to avoid public member
+ # variables
+ if self.ident == "id":
+ c_code = "m_chip_ptr.getID()"
+ elif self.ident == "version":
+ c_code = "m_version"
+ elif self.ident == "machineID":
+ c_code = "m_machineID"
+ elif machine:
+ c_code = "(*m_%s_%s_ptr)" % (machine.ident, self.ident)
+ else:
+ c_code = "(*m_%s_ptr)" % (self.ident)
+
+ v = Var(self.symtab, self.ident, self.location, type, c_code,
+ self.pairs, machine)
+
+ if machine:
+ machine.addObject(v)
+
+ self.symtab.newSymbol(v)
+
+ # used to cheat-- that is, access components in other machines
+ if machineComponentSym:
+ self.symtab.newMachComponentSym(v)
diff --git a/src/mem/slicc/ast/OutPortDeclAST.cc b/src/mem/slicc/ast/OutPortDeclAST.cc
deleted file mode 100644
index 56a377f23..000000000
--- a/src/mem/slicc/ast/OutPortDeclAST.cc
+++ /dev/null
@@ -1,79 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * OutPortDeclAST.C
- *
- * Description: See OutPortDeclAST.hh
- *
- * $Id: OutPortDeclAST.C,v 3.3 2004/02/02 22:37:51 milo Exp $
- *
- */
-
-#include "mem/slicc/ast/OutPortDeclAST.hh"
-#include "mem/slicc/symbols/SymbolTable.hh"
-
-OutPortDeclAST::OutPortDeclAST(string* ident_ptr,
- TypeAST* msg_type_ptr,
- ExprAST* var_expr_ptr,
- PairListAST* pairs_ptr)
- : DeclAST(pairs_ptr)
-{
- m_ident_ptr = ident_ptr;
- m_msg_type_ptr = msg_type_ptr;
- m_var_expr_ptr = var_expr_ptr;
- m_queue_type_ptr = new TypeAST(new string("OutPort"));
-}
-
-OutPortDeclAST::~OutPortDeclAST()
-{
- delete m_ident_ptr;
- delete m_msg_type_ptr;
- delete m_var_expr_ptr;
- delete m_queue_type_ptr;
-}
-
-void OutPortDeclAST::generate()
-{
- string code;
- Type* queue_type_ptr = m_var_expr_ptr->generate(code);
- if (!queue_type_ptr->isOutPort()) {
- error("Outport queues must be of a type that has the 'outport' attribute. The type '" +
- queue_type_ptr->toString() + "' does not have this attribute.");
- }
-
- Type* type_ptr = m_queue_type_ptr->lookupType();
- g_sym_table.newSym(new Var(*m_ident_ptr, getLocation(), type_ptr, code, getPairs()));
-}
-
-
-void OutPortDeclAST::print(ostream& out) const
-{
- out << "[OutPortDecl: " << *m_ident_ptr << "]";
-}
diff --git a/src/mem/slicc/ast/OutPortDeclAST.hh b/src/mem/slicc/ast/OutPortDeclAST.hh
deleted file mode 100644
index 0aa0172d3..000000000
--- a/src/mem/slicc/ast/OutPortDeclAST.hh
+++ /dev/null
@@ -1,89 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * OutPortDeclAST.hh
- *
- * Description:
- *
- * $Id: OutPortDeclAST.hh,v 3.2 2003/07/10 18:08:06 milo Exp $
- *
- */
-
-#ifndef OutPortDeclAST_H
-#define OutPortDeclAST_H
-
-#include "mem/slicc/slicc_global.hh"
-#include "mem/slicc/ast/DeclAST.hh"
-#include "mem/slicc/ast/StatementListAST.hh"
-#include "mem/slicc/ast/VarExprAST.hh"
-
-class OutPortDeclAST : public DeclAST {
-public:
- // Constructors
- OutPortDeclAST(string* ident_ptr,
- TypeAST* msg_type_ptr,
- ExprAST* var_expr_ptr,
- PairListAST* pairs_ptr);
-
- // Destructor
- ~OutPortDeclAST();
-
- // Public Methods
- void generate();
- void print(ostream& out) const;
-private:
- // Private Methods
-
- // Private copy constructor and assignment operator
- OutPortDeclAST(const OutPortDeclAST& obj);
- OutPortDeclAST& operator=(const OutPortDeclAST& obj);
-
- // Data Members (m_ prefix)
- string* m_ident_ptr;
- TypeAST* m_msg_type_ptr;
- TypeAST* m_queue_type_ptr;
- ExprAST* m_var_expr_ptr;
-};
-
-// Output operator declaration
-ostream& operator<<(ostream& out, const OutPortDeclAST& obj);
-
-// ******************* Definitions *******************
-
-// Output operator definition
-extern inline
-ostream& operator<<(ostream& out, const OutPortDeclAST& obj)
-{
- obj.print(out);
- out << flush;
- return out;
-}
-
-#endif //OutPortDeclAST_H
diff --git a/src/mem/slicc/ast/OutPortDeclAST.py b/src/mem/slicc/ast/OutPortDeclAST.py
new file mode 100644
index 000000000..e6ef31928
--- /dev/null
+++ b/src/mem/slicc/ast/OutPortDeclAST.py
@@ -0,0 +1,57 @@
+# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
+# Copyright (c) 2009 The Hewlett-Packard Development Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (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 slicc.ast.DeclAST import DeclAST
+from slicc.ast.TypeAST import TypeAST
+from slicc.symbols import Var
+
+class OutPortDeclAST(DeclAST):
+ def __init__(self, slicc, ident, msg_type, var_expr, pairs):
+ super(OutPortDeclAST, self).__init__(slicc, pairs)
+
+ self.ident = ident
+ self.msg_type = msg_type
+ self.var_expr = var_expr
+ self.queue_type = TypeAST(slicc, "OutPort")
+
+ def __repr__(self):
+ return "[OutPortDecl: %r]" % self.ident
+
+ def generate(self):
+ code = code_formatter(newlines=False)
+
+ queue_type = self.var_expr.generate(code)
+ if not queue_type.isOutPort:
+ self.error("The outport queue's type must have the 'outport' " +
+ "attribute. Type '%s' does not have this attribute.",
+ (queue_type))
+
+ var = Var(self.symtab, self.ident, self.location, self.queue_type.type,
+ str(code), self.pairs)
+ self.symtab.newSymbol(var)
diff --git a/src/mem/slicc/ast/PairAST.cc b/src/mem/slicc/ast/PairAST.cc
deleted file mode 100644
index c42843cce..000000000
--- a/src/mem/slicc/ast/PairAST.cc
+++ /dev/null
@@ -1,72 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * PairAST.C
- *
- * Description: See PairAST.hh
- *
- * $Id$
- *
- */
-
-#include "mem/slicc/ast/PairAST.hh"
-
-PairAST::PairAST(string* key_ptr, string* value_ptr)
- : AST()
-{
- m_key_ptr = key_ptr;
- m_value_ptr = value_ptr;
-}
-
-PairAST::PairAST(string key, string* value_ptr)
- : AST()
-{
- m_key_ptr = new string(key);
- m_value_ptr = value_ptr;
-}
-
-PairAST::PairAST(string key, string value)
- : AST()
-{
- m_key_ptr = new string(key);
- m_value_ptr = new string(value);
-}
-
-PairAST::~PairAST()
-{
- delete m_key_ptr;
- delete m_value_ptr;
-}
-
-void PairAST::print(ostream& out) const
-{
- out << "[" << *m_key_ptr << "=" << *m_value_ptr << "]" << endl;
-}
-
diff --git a/src/mem/slicc/ast/PairAST.hh b/src/mem/slicc/ast/PairAST.hh
deleted file mode 100644
index d1bb99b93..000000000
--- a/src/mem/slicc/ast/PairAST.hh
+++ /dev/null
@@ -1,86 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * PairAST.hh
- *
- * Description:
- *
- * $Id: PairAST.hh,v 3.1 2001/12/12 01:00:24 milo Exp $
- *
- */
-
-#ifndef PAIRAST_H
-#define PAIRAST_H
-
-#include "mem/slicc/slicc_global.hh"
-#include "mem/slicc/ast/AST.hh"
-
-class PairAST : public AST {
-public:
- // Constructors
- PairAST(string* key_ptr, string* value_ptr);
- PairAST(string key, string* value_ptr);
- PairAST(string key, string value);
-
- // Destructor
- ~PairAST();
-
- // Public Methods
- string key() const { return *m_key_ptr; }
- string value() const { return *m_value_ptr; }
-
- virtual void print(ostream& out) const;
-private:
- // Private Methods
-
- // Private copy constructor and assignment operator
- // PairAST(const PairAST& obj);
- // PairAST& operator=(const PairAST& obj);
-
- // Data Members (m_ prefix)
- string* m_key_ptr;
- string* m_value_ptr;
-};
-
-// Output operator declaration
-ostream& operator<<(ostream& out, const PairAST& obj);
-
-// ******************* Definitions *******************
-
-// Output operator definition
-extern inline
-ostream& operator<<(ostream& out, const PairAST& obj)
-{
- obj.print(out);
- out << flush;
- return out;
-}
-
-#endif //PAIRAST_H
diff --git a/src/mem/slicc/ast/PairAST.py b/src/mem/slicc/ast/PairAST.py
new file mode 100644
index 000000000..347f4d361
--- /dev/null
+++ b/src/mem/slicc/ast/PairAST.py
@@ -0,0 +1,36 @@
+# Copyright (c) 2009 The Hewlett-Packard Development Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (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 slicc.ast.AST import AST
+
+class PairAST(AST):
+ def __init__(self, slicc, key, value):
+ super(PairAST, self).__init__(slicc)
+ self.key = key
+ self.value = value
+
+ def __repr__(self):
+ return '[%s=%s]' % (self.key, self.value)
diff --git a/src/mem/slicc/ast/PairListAST.cc b/src/mem/slicc/ast/PairListAST.cc
deleted file mode 100644
index 76892d437..000000000
--- a/src/mem/slicc/ast/PairListAST.cc
+++ /dev/null
@@ -1,49 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * PairListAST.C
- *
- * Description: See PairListAST.hh
- *
- * $Id$
- *
- */
-
-#include "mem/slicc/ast/PairListAST.hh"
-
-void PairListAST::addPair(PairAST* pair_ptr)
-{
- getPairs().add(pair_ptr->key(), pair_ptr->value());
-}
-
-void PairListAST::print(ostream& out) const
-{
- out << "[PairListAST] " << getPairs();
-}
diff --git a/src/mem/slicc/ast/PairListAST.hh b/src/mem/slicc/ast/PairListAST.hh
deleted file mode 100644
index 7edcdc1e7..000000000
--- a/src/mem/slicc/ast/PairListAST.hh
+++ /dev/null
@@ -1,82 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * PairListAST.hh
- *
- * Description:
- *
- * $Id$
- *
- */
-
-#ifndef PairListAST_H
-#define PairListAST_H
-
-#include "mem/slicc/slicc_global.hh"
-#include "mem/slicc/ast/AST.hh"
-#include "mem/slicc/ast/PairAST.hh"
-
-
-class PairListAST : public AST {
-public:
- // Constructors
- PairListAST() : AST() {}
-
- // Destructor
- //~PairListAST();
-
- // Public Methods
- void addPair(PairAST* pair_ptr);
- void print(ostream& out) const;
-private:
- // Private Methods
-
- // Private copy constructor and assignment operator
- PairListAST(const PairListAST& obj);
- PairListAST& operator=(const PairListAST& obj);
-
- // Data Members (m_ prefix)
-};
-
-// Output operator declaration
-ostream& operator<<(ostream& out, const PairListAST& obj);
-
-// ******************* Definitions *******************
-
-// Output operator definition
-extern inline
-ostream& operator<<(ostream& out, const PairListAST& obj)
-{
- obj.print(out);
- out << flush;
- return out;
-}
-
-#endif //PairListAST_H
diff --git a/src/mem/slicc/ast/PairListAST.py b/src/mem/slicc/ast/PairListAST.py
new file mode 100644
index 000000000..6afe3f4fa
--- /dev/null
+++ b/src/mem/slicc/ast/PairListAST.py
@@ -0,0 +1,37 @@
+# Copyright (c) 2009 The Hewlett-Packard Development Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (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 slicc.ast.AST import AST
+
+class PairListAST(AST):
+ def __init__(self, slicc):
+ super(PairListAST, self).__init__(slicc)
+
+ def __repr__(self):
+ return "[PairListAST] %r" % self.pairs
+
+ def addPair(self, pair_ast):
+ self[pair_ast.key] = pair_ast.value
diff --git a/src/mem/slicc/ast/PeekStatementAST.cc b/src/mem/slicc/ast/PeekStatementAST.cc
deleted file mode 100644
index 3e92446dd..000000000
--- a/src/mem/slicc/ast/PeekStatementAST.cc
+++ /dev/null
@@ -1,115 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * PeekStatementAST.C
- *
- * Description: See PeekStatementAST.hh
- *
- * $Id$
- *
- */
-
-#include "mem/slicc/ast/PeekStatementAST.hh"
-#include "mem/slicc/symbols/SymbolTable.hh"
-#include "mem/slicc/ast/StatementListAST.hh"
-#include "mem/slicc/ast/TypeAST.hh"
-#include "mem/slicc/ast/VarExprAST.hh"
-
-PeekStatementAST::PeekStatementAST(VarExprAST* queue_name_ptr,
- TypeAST* type_ptr,
- StatementListAST* statementlist_ptr,
- string method)
- : StatementAST()
-{
- m_queue_name_ptr = queue_name_ptr;
- m_type_ptr = type_ptr;
- m_statementlist_ptr = statementlist_ptr;
- m_method = method;
-}
-
-PeekStatementAST::~PeekStatementAST()
-{
- delete m_queue_name_ptr;
- delete m_type_ptr;
- delete m_statementlist_ptr;
-}
-
-void PeekStatementAST::generate(string& code, Type* return_type_ptr) const
-{
- code += indent_str() + "{\n"; // Start scope
- inc_indent();
- g_sym_table.pushFrame();
-
- Type* msg_type_ptr = m_type_ptr->lookupType();
-
- // Add new local var to symbol table
- g_sym_table.newSym(new Var("in_msg", getLocation(), msg_type_ptr, "(*in_msg_ptr)", getPairs()));
-
- // Check the queue type
- m_queue_name_ptr->assertType("InPort");
-
- // Declare the new "in_msg_ptr" variable
- code += indent_str() + "const " + msg_type_ptr->cIdent() + "* in_msg_ptr;\n"; // Declare message
- // code += indent_str() + "in_msg_ptr = static_cast<const ";
- code += indent_str() + "in_msg_ptr = dynamic_cast<const ";
- code += msg_type_ptr->cIdent() + "*>(";
- code += "(" + m_queue_name_ptr->getVar()->getCode() + ")";
- code += ".";
- code += m_method;
- code += "());\n";
-
- code += indent_str() + "assert(in_msg_ptr != NULL);\n"; // Check the cast result
-
- if(CHECK_INVALID_RESOURCE_STALLS) {
- // Declare the "in_buffer_rank" variable
- code += indent_str() + "int in_buffer_rank = "; // Declare message
- code += "(" + m_queue_name_ptr->getVar()->getCode() + ")";
- code += ".getPriority();\n";
- }
-
- m_statementlist_ptr->generate(code, return_type_ptr); // The other statements
- dec_indent();
- g_sym_table.popFrame();
- code += indent_str() + "}\n"; // End scope
-}
-
-void PeekStatementAST::findResources(Map<Var*, string>& resource_list) const
-{
- m_statementlist_ptr->findResources(resource_list);
-}
-
-void PeekStatementAST::print(ostream& out) const
-{
- out << "[PeekStatementAST: " << m_method
- << " queue_name: " << *m_queue_name_ptr
- << " type: " << m_type_ptr->toString()
- << " " << *m_statementlist_ptr
- << "]";
-}
diff --git a/src/mem/slicc/ast/PeekStatementAST.hh b/src/mem/slicc/ast/PeekStatementAST.hh
deleted file mode 100644
index e8c65ce4f..000000000
--- a/src/mem/slicc/ast/PeekStatementAST.hh
+++ /dev/null
@@ -1,91 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * PeekStatementAST.hh
- *
- * Description:
- *
- * $Id$
- *
- */
-
-#ifndef PEEKSTATEMENTAST_H
-#define PEEKSTATEMENTAST_H
-
-#include "mem/slicc/slicc_global.hh"
-#include "mem/slicc/ast/StatementAST.hh"
-
-class StatementListAST;
-class TypeAST;
-class VarExprAST;
-
-class PeekStatementAST : public StatementAST {
-public:
- // Constructors
- PeekStatementAST(VarExprAST* queue_name_ptr,
- TypeAST* type_ptr,
- StatementListAST* statementlist_ptr,
- string method);
- // Destructor
- ~PeekStatementAST();
-
- // Public Methods
- void generate(string& code, Type* return_type_ptr) const;
- void findResources(Map<Var*, string>& resource_list) const;
- void print(ostream& out) const;
-private:
- // Private Methods
-
- // Private copy constructor and assignment operator
- PeekStatementAST(const PeekStatementAST& obj);
- PeekStatementAST& operator=(const PeekStatementAST& obj);
-
- // Data Members (m_ prefix)
- VarExprAST* m_queue_name_ptr;
- TypeAST* m_type_ptr;
- StatementListAST* m_statementlist_ptr;
- string m_method;
-};
-
-// Output operator declaration
-ostream& operator<<(ostream& out, const PeekStatementAST& obj);
-
-// ******************* Definitions *******************
-
-// Output operator definition
-extern inline
-ostream& operator<<(ostream& out, const PeekStatementAST& obj)
-{
- obj.print(out);
- out << flush;
- return out;
-}
-
-#endif //PEEKSTATEMENTAST_H
diff --git a/src/mem/slicc/ast/PeekStatementAST.py b/src/mem/slicc/ast/PeekStatementAST.py
new file mode 100644
index 000000000..5186bf0d5
--- /dev/null
+++ b/src/mem/slicc/ast/PeekStatementAST.py
@@ -0,0 +1,73 @@
+# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
+# Copyright (c) 2009 The Hewlett-Packard Development Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (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 slicc.ast.StatementAST import StatementAST
+from slicc.symbols import Var
+
+class PeekStatementAST(StatementAST):
+ def __init__(self, slicc, queue_name, type_ast, statements, method):
+ super(PeekStatementAST, self).__init__(slicc)
+
+ self.queue_name = queue_name
+ self.type_ast = type_ast
+ self.statements = statements
+ self.method = method
+
+ def __repr__(self):
+ return "[PeekStatementAST: %r queue_name: %r type: %r %r]" % \
+ (self.method, self.queue_name, self.type_ast, self.statements)
+
+ def generate(self, code, return_type):
+ self.symtab.pushFrame()
+
+ msg_type = self.type_ast.type
+
+ # Add new local var to symbol table
+ var = Var(self.symtab, "in_msg", self.location, msg_type, "(*in_msg_ptr)",
+ self.pairs)
+ self.symtab.newSymbol(var)
+
+ # Check the queue type
+ self.queue_name.assertType("InPort")
+
+ # Declare the new "in_msg_ptr" variable
+ mtid = msg_type.ident
+ qcode = self.queue_name.var.code
+ code('''
+{
+ const $mtid* in_msg_ptr;
+ in_msg_ptr = dynamic_cast<const $mtid *>(($qcode).${{self.method}}());
+ assert(in_msg_ptr != NULL);
+''')
+
+ # The other statements
+ self.statements.generate(code, return_type)
+ self.symtab.popFrame()
+ code("}")
+
+ def findResources(self, resources):
+ self.statements.findResources(resources)
diff --git a/src/mem/slicc/ast/ReturnStatementAST.cc b/src/mem/slicc/ast/ReturnStatementAST.cc
deleted file mode 100644
index 8ec937c87..000000000
--- a/src/mem/slicc/ast/ReturnStatementAST.cc
+++ /dev/null
@@ -1,79 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * ReturnStatementAST.C
- *
- * Description: See ReturnStatementAST.hh
- *
- * $Id$
- *
- */
-
-#include "mem/slicc/ast/ReturnStatementAST.hh"
-
-ReturnStatementAST::ReturnStatementAST(ExprAST* expr_ptr)
- : StatementAST()
-{
- m_expr_ptr = expr_ptr;
-}
-
-ReturnStatementAST::~ReturnStatementAST()
-{
- delete m_expr_ptr;
-}
-
-void ReturnStatementAST::generate(string& code, Type* return_type_ptr) const
-{
- code += indent_str();
- code += "return ";
- Type* actual_type_ptr = m_expr_ptr->generate(code);
- code += ";\n";
-
- // Is return valid here?
- if (return_type_ptr == NULL) {
- error("Invalid 'return' statement");
- }
-
- // The return type must match the return_type_ptr
- if (return_type_ptr != actual_type_ptr) {
- m_expr_ptr->error("Return type miss-match, expected return type is '" + return_type_ptr->toString() +
- "', actual is '" + actual_type_ptr->toString() + "'");
- }
-}
-
-void ReturnStatementAST::findResources(Map<Var*, string>& resource_list) const
-{
- m_expr_ptr->findResources(resource_list);
-}
-
-void ReturnStatementAST::print(ostream& out) const
-{
- out << "[ReturnStatementAST: " << *m_expr_ptr << "]";
-}
diff --git a/src/mem/slicc/ast/ReturnStatementAST.hh b/src/mem/slicc/ast/ReturnStatementAST.hh
deleted file mode 100644
index 1fa1b36d6..000000000
--- a/src/mem/slicc/ast/ReturnStatementAST.hh
+++ /dev/null
@@ -1,83 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * ReturnStatementAST.hh
- *
- * Description:
- *
- * $Id$
- *
- */
-
-#ifndef ReturnStatementAST_H
-#define ReturnStatementAST_H
-
-#include "mem/slicc/slicc_global.hh"
-#include "mem/slicc/ast/StatementAST.hh"
-#include "mem/slicc/ast/ExprAST.hh"
-
-class ReturnStatementAST : public StatementAST {
-public:
- // Constructors
- ReturnStatementAST(ExprAST* expr_ptr);
-
- // Destructor
- ~ReturnStatementAST();
-
- // Public Methods
- void generate(string& code, Type* return_type_ptr) const;
- void findResources(Map<Var*, string>& resource_list) const;
- void print(ostream& out) const;
-private:
- // Private Methods
-
- // Private copy constructor and assignment operator
- ReturnStatementAST(const ReturnStatementAST& obj);
- ReturnStatementAST& operator=(const ReturnStatementAST& obj);
-
- // Data Members (m_ prefix)
- ExprAST* m_expr_ptr;
-};
-
-// Output operator declaration
-ostream& operator<<(ostream& out, const ReturnStatementAST& obj);
-
-// ******************* Definitions *******************
-
-// Output operator definition
-extern inline
-ostream& operator<<(ostream& out, const ReturnStatementAST& obj)
-{
- obj.print(out);
- out << flush;
- return out;
-}
-
-#endif //ReturnStatementAST_H
diff --git a/src/mem/slicc/ast/ReturnStatementAST.py b/src/mem/slicc/ast/ReturnStatementAST.py
new file mode 100644
index 000000000..1d08a7234
--- /dev/null
+++ b/src/mem/slicc/ast/ReturnStatementAST.py
@@ -0,0 +1,54 @@
+# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
+# Copyright (c) 2009 The Hewlett-Packard Development Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (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 slicc.ast.StatementAST import StatementAST
+
+class ReturnStatementAST(StatementAST):
+ def __init__(self, slicc, expr_ast):
+ super(ReturnStatementAST, self).__init__(slicc)
+
+ self.expr_ast = expr_ast
+
+ def __repr__(self):
+ return "[ReturnStatementAST: %r]" % self.expr_ast
+
+ def generate(self, code, return_type):
+ actual_type, ecode = self.expr_ast.inline(True)
+ code('return $ecode;')
+
+ # Is return valid here?
+ if return_type is None:
+ error("Invalid 'return' statement")
+
+ # The return type must match
+ if return_type != actual_type:
+ self.expr_ast.error("Return type miss-match, expected return " +
+ "type is '%s', actual is '%s'",
+ return_type, actual_type)
+
+ def findResources(self, resources):
+ self.expr_ast.findResources(resources)
diff --git a/src/mem/slicc/ast/StatementAST.cc b/src/mem/slicc/ast/StatementAST.cc
deleted file mode 100644
index 35627722a..000000000
--- a/src/mem/slicc/ast/StatementAST.cc
+++ /dev/null
@@ -1,60 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * StatementAST.C
- *
- * Description: See StatementAST.hh
- *
- * $Id$
- *
- */
-
-#include "mem/slicc/ast/StatementAST.hh"
-
-static int indentation_depth = 1;
-
-void inc_indent()
-{
- indentation_depth++;
-}
-
-void dec_indent()
-{
- indentation_depth--;
-}
-
-string indent_str()
-{
- string temp;
- for(int i=0; i<indentation_depth; i++) {
- temp += " ";
- }
- return temp;
-}
diff --git a/src/mem/slicc/ast/StatementAST.hh b/src/mem/slicc/ast/StatementAST.hh
deleted file mode 100644
index 9946541d3..000000000
--- a/src/mem/slicc/ast/StatementAST.hh
+++ /dev/null
@@ -1,88 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * StatementAST.hh
- *
- * Description:
- *
- * $Id$
- *
- */
-
-#ifndef STATEMENTAST_H
-#define STATEMENTAST_H
-
-#include "mem/slicc/slicc_global.hh"
-#include "mem/slicc/ast/AST.hh"
-
-void inc_indent();
-void dec_indent();
-string indent_str();
-
-class StatementAST : public AST {
-public:
- // Constructors
- StatementAST() : AST() {}
- StatementAST(Map<string, string> pairs) : AST(pairs) {}
-
- // Destructor
- //~StatementAST();
-
- // Public Methods
- virtual void generate(string& code, Type* return_type_ptr) const = 0;
- virtual void findResources(Map<Var*, string>& resource_list) const { }
-
- //void print(ostream& out) const;
-private:
- // Private Methods
-
- // Private copy constructor and assignment operator
- //StatementAST(const StatementAST& obj);
- //StatementAST& operator=(const StatementAST& obj);
-
- // Data Members (m_ prefix)
-
-};
-
-// Output operator declaration
-ostream& operator<<(ostream& out, const StatementAST& obj);
-
-// ******************* Definitions *******************
-
-// Output operator definition
-extern inline
-ostream& operator<<(ostream& out, const StatementAST& obj)
-{
- obj.print(out);
- out << flush;
- return out;
-}
-
-#endif //STATEMENTAST_H
diff --git a/src/mem/slicc/ast/StatementAST.py b/src/mem/slicc/ast/StatementAST.py
new file mode 100644
index 000000000..017b2b1ed
--- /dev/null
+++ b/src/mem/slicc/ast/StatementAST.py
@@ -0,0 +1,34 @@
+# Copyright (c) 2009 The Hewlett-Packard Development Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (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 slicc.ast.AST import AST
+
+class StatementAST(AST):
+ def __init__(self, slicc, pairs=None):
+ super(StatementAST, self).__init__(slicc, pairs)
+
+ def findResources(self, resources):
+ pass
diff --git a/src/mem/slicc/ast/StatementListAST.cc b/src/mem/slicc/ast/StatementListAST.cc
deleted file mode 100644
index 0f5817f7c..000000000
--- a/src/mem/slicc/ast/StatementListAST.cc
+++ /dev/null
@@ -1,86 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * StatementListAST.C
- *
- * Description: See StatementListAST.hh
- *
- * $Id$
- *
- */
-
-#include "mem/slicc/ast/StatementListAST.hh"
-
-StatementListAST::StatementListAST(Vector<StatementAST*>* vec_ptr)
- : AST()
-{
- assert(vec_ptr != NULL);
- m_vec_ptr = vec_ptr;
-}
-
-// Singleton constructor.
-StatementListAST::StatementListAST(StatementAST* statement_ptr)
- : AST()
-{
- assert(statement_ptr != NULL);
- m_vec_ptr = new Vector<StatementAST*>;
- m_vec_ptr->insertAtTop(statement_ptr);
-}
-
-StatementListAST::~StatementListAST()
-{
- int size = m_vec_ptr->size();
- for(int i=0; i<size; i++) {
- delete (*m_vec_ptr)[i];
- }
- delete m_vec_ptr;
-}
-
-void StatementListAST::generate(string& code, Type* return_type_ptr) const
-{
- int size = m_vec_ptr->size();
- for(int i=0; i<size; i++) {
- (*m_vec_ptr)[i]->generate(code, return_type_ptr);
- }
-}
-
-void StatementListAST::findResources(Map<Var*, string>& resource_list) const
-{
- int size = m_vec_ptr->size();
- for(int i=0; i<size; i++) {
- (*m_vec_ptr)[i]->findResources(resource_list);
- }
-}
-
-void StatementListAST::print(ostream& out) const
-{
- assert(m_vec_ptr != NULL);
- out << "[StatementListAST: " << *m_vec_ptr << "]";
-}
diff --git a/src/mem/slicc/ast/StatementListAST.hh b/src/mem/slicc/ast/StatementListAST.hh
deleted file mode 100644
index 831e2481a..000000000
--- a/src/mem/slicc/ast/StatementListAST.hh
+++ /dev/null
@@ -1,85 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * StatementListAST.hh
- *
- * Description:
- *
- * $Id$
- *
- */
-
-#ifndef STATEMENTLISTAST_H
-#define STATEMENTLISTAST_H
-
-#include "mem/slicc/slicc_global.hh"
-#include "mem/slicc/ast/AST.hh"
-#include "mem/slicc/ast/StatementAST.hh"
-class Var;
-
-class StatementListAST : public AST {
-public:
- // Constructors
- StatementListAST(Vector<StatementAST*>* vec_ptr);
- StatementListAST(StatementAST* statement_ptr);
-
- // Destructor
- ~StatementListAST();
-
- // Public Methods
- void generate(string& code, Type* return_type_ptr) const;
- void findResources(Map<Var*, string>& resource_list) const;
- void print(ostream& out) const;
-private:
- // Private Methods
-
- // Private copy constructor and assignment operator
- StatementListAST(const StatementListAST& obj);
- StatementListAST& operator=(const StatementListAST& obj);
-
- // Data Members (m_ prefix)
- Vector<StatementAST*>* m_vec_ptr;
-};
-
-// Output operator declaration
-ostream& operator<<(ostream& out, const StatementListAST& obj);
-
-// ******************* Definitions *******************
-
-// Output operator definition
-extern inline
-ostream& operator<<(ostream& out, const StatementListAST& obj)
-{
- obj.print(out);
- out << flush;
- return out;
-}
-
-#endif //STATEMENTLISTAST_H
diff --git a/src/mem/slicc/ast/StatementListAST.py b/src/mem/slicc/ast/StatementListAST.py
new file mode 100644
index 000000000..1475c5c97
--- /dev/null
+++ b/src/mem/slicc/ast/StatementListAST.py
@@ -0,0 +1,46 @@
+# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
+# Copyright (c) 2009 The Hewlett-Packard Development Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (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 slicc.ast.AST import AST
+
+class StatementListAST(AST):
+ def __init__(self, slicc, statements):
+ super(StatementListAST, self).__init__(slicc)
+ if not isinstance(statements, (list, tuple)):
+ statements = [ statements ]
+ self.statements = statements
+
+ def __repr__(self):
+ return "[StatementListAST: %r]" % self.statements
+
+ def generate(self, code, return_type):
+ for statement in self.statements:
+ statement.generate(code, return_type)
+
+ def findResources(self, resources):
+ for statement in self.statements:
+ statement.findResources(resources)
diff --git a/src/mem/slicc/ast/TransitionDeclAST.cc b/src/mem/slicc/ast/TransitionDeclAST.cc
deleted file mode 100644
index 66b7ca132..000000000
--- a/src/mem/slicc/ast/TransitionDeclAST.cc
+++ /dev/null
@@ -1,89 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * TransitionDeclAST.C
- *
- * Description: See TransitionDeclAST.hh
- *
- * $Id$
- *
- */
-
-#include "mem/slicc/ast/TransitionDeclAST.hh"
-#include "mem/slicc/symbols/Transition.hh"
-
-TransitionDeclAST::TransitionDeclAST(Vector<string>* state_list_ptr,
- Vector<string>* event_list_ptr,
- string* next_state_ptr,
- PairListAST* pairs_ptr,
- Vector<string>* action_list_ptr)
- : DeclAST(pairs_ptr)
-{
- m_state_list_ptr = state_list_ptr;
- m_event_list_ptr = event_list_ptr;
- m_next_state_ptr = next_state_ptr;
- m_action_list_ptr = action_list_ptr;
-}
-
-TransitionDeclAST::~TransitionDeclAST()
-{
- delete m_state_list_ptr;
- delete m_event_list_ptr;
- delete m_next_state_ptr;
- delete m_action_list_ptr;
-}
-
-void TransitionDeclAST::generate()
-{
- Vector<string>& states = *m_state_list_ptr;
- Vector<string>& events = *m_event_list_ptr;
-
- StateMachine* machine_ptr = g_sym_table.getStateMachine();
- if (machine_ptr == NULL) {
- error("Transition declaration not part of a machine.");
- } else if (m_next_state_ptr == NULL) {
- for (int i=0; i<states.size(); i++) {
- for (int j=0; j<events.size(); j++) {
- machine_ptr->addTransition(new Transition(states[i], events[j], states[i], *m_action_list_ptr, getLocation(), getPairs()));
- }
- }
- } else {
- for (int i=0; i<states.size(); i++) {
- for (int j=0; j<events.size(); j++) {
- machine_ptr->addTransition(new Transition(states[i], events[j], *m_next_state_ptr, *m_action_list_ptr, getLocation(), getPairs()));
- }
- }
- }
-}
-
-void TransitionDeclAST::print(ostream& out) const
-{
- out << "[TransitionDecl: ]";
-}
diff --git a/src/mem/slicc/ast/TransitionDeclAST.hh b/src/mem/slicc/ast/TransitionDeclAST.hh
deleted file mode 100644
index f07f0a3c2..000000000
--- a/src/mem/slicc/ast/TransitionDeclAST.hh
+++ /dev/null
@@ -1,89 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * TransistionDeclAST.hh
- *
- * Description:
- *
- * $Id: TransitionDeclAST.hh,v 3.2 2003/07/10 18:08:07 milo Exp $
- *
- */
-
-#ifndef TransitionDeclAST_H
-#define TransitionDeclAST_H
-
-#include "mem/slicc/slicc_global.hh"
-#include "mem/slicc/ast/DeclAST.hh"
-#include "mem/slicc/ast/StatementListAST.hh"
-
-class TransitionDeclAST : public DeclAST {
-public:
- // Constructors
- TransitionDeclAST(Vector<string>* state_list_ptr,
- Vector<string>* event_list_ptr,
- string* next_state_ptr,
- PairListAST* pairs_ptr,
- Vector<string>* action_list_ptr);
-
- // Destructor
- ~TransitionDeclAST();
-
- // Public Methods
- void generate();
- void print(ostream& out) const;
-private:
- // Private Methods
-
- // Private copy constructor and assignment operator
- TransitionDeclAST(const TransitionDeclAST& obj);
- TransitionDeclAST& operator=(const TransitionDeclAST& obj);
-
- // Data Members (m_ prefix)
- Vector<string>* m_state_list_ptr;
- Vector<string>* m_event_list_ptr;
- string* m_next_state_ptr;
- Vector<string>* m_action_list_ptr;
-};
-
-// Output operator declaration
-ostream& operator<<(ostream& out, const TransitionDeclAST& obj);
-
-// ******************* Definitions *******************
-
-// Output operator definition
-extern inline
-ostream& operator<<(ostream& out, const TransitionDeclAST& obj)
-{
- obj.print(out);
- out << flush;
- return out;
-}
-
-#endif //TransitionDeclAST_H
diff --git a/src/mem/slicc/ast/TransitionDeclAST.py b/src/mem/slicc/ast/TransitionDeclAST.py
new file mode 100644
index 000000000..ef745fd50
--- /dev/null
+++ b/src/mem/slicc/ast/TransitionDeclAST.py
@@ -0,0 +1,54 @@
+# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
+# Copyright (c) 2009 The Hewlett-Packard Development Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (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 slicc.ast.DeclAST import DeclAST
+from slicc.symbols import Transition
+
+class TransitionDeclAST(DeclAST):
+ def __init__(self, slicc, states, events, next_state, pairs, actions):
+ super(TransitionDeclAST, self).__init__(slicc, pairs)
+
+ self.states = states
+ self.events = events
+ self.next_state = next_state
+ self.actions = actions
+
+ def __repr__(self):
+ return "[TransitionDecl: ]"
+
+ def generate(self):
+ machine = self.symtab.state_machine
+
+ if machine is None:
+ self.error("Transition declaration not part of a machine.")
+
+ for state in self.states:
+ next_state = self.next_state or state
+ for event in self.events:
+ t = Transition(self.symtab, machine, state, event, next_state,
+ self.actions, self.location, self.pairs)
+ machine.addTransition(t)
diff --git a/src/mem/slicc/ast/TypeAST.cc b/src/mem/slicc/ast/TypeAST.cc
deleted file mode 100644
index 7590b4e7c..000000000
--- a/src/mem/slicc/ast/TypeAST.cc
+++ /dev/null
@@ -1,67 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * TypeAST.C
- *
- * Description: See TypeAST.hh
- *
- * $Id: TypeAST.C,v 3.1 2003/03/22 15:15:16 xu Exp $
- *
- */
-
-#include "mem/slicc/ast/TypeAST.hh"
-
-TypeAST::TypeAST(string* ident_ptr)
- : AST()
-{
- m_ident_ptr = ident_ptr;
-}
-
-TypeAST::~TypeAST()
-{
- delete m_ident_ptr;
-
-}
-
-string TypeAST::toString() const
-{
- return *m_ident_ptr;
-}
-
-Type* TypeAST::lookupType() const
-{
- Type* type_ptr = g_sym_table.getType(*m_ident_ptr);
- if (type_ptr != NULL) {
- return type_ptr;
- } else {
- error("Type '" + *m_ident_ptr + "' not declared.");
- }
- return NULL; // Not reached
-}
diff --git a/src/mem/slicc/ast/TypeAST.hh b/src/mem/slicc/ast/TypeAST.hh
deleted file mode 100644
index f8e1fdc24..000000000
--- a/src/mem/slicc/ast/TypeAST.hh
+++ /dev/null
@@ -1,83 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * TypeAST.hh
- *
- * Description:
- *
- * $Id: TypeAST.hh,v 3.2 2003/03/22 15:15:17 xu Exp $
- *
- */
-
-#ifndef TYPEAST_H
-#define TYPEAST_H
-
-#include "mem/slicc/slicc_global.hh"
-#include "mem/slicc/ast/AST.hh"
-
-class TypeAST : public AST {
-public:
- // Constructors
- TypeAST(string* ident_ptr);
-
- // Destructor
- ~TypeAST();
-
- // Public Methods
- string toString() const;
- Type* lookupType() const;
-
- virtual void print(ostream& out) const {}
-private:
- // Private Methods
-
- // Private copy constructor and assignment operator
- TypeAST(const TypeAST& obj);
- TypeAST& operator=(const TypeAST& obj);
-
- // Data Members (m_ prefix)
- string* m_ident_ptr;
-};
-
-// Output operator declaration
-ostream& operator<<(ostream& out, const TypeAST& obj);
-
-// ******************* Definitions *******************
-
-// Output operator definition
-extern inline
-ostream& operator<<(ostream& out, const TypeAST& obj)
-{
- obj.print(out);
- out << flush;
- return out;
-}
-
-#endif //TYPEAST_H
diff --git a/src/mem/slicc/ast/TypeAST.py b/src/mem/slicc/ast/TypeAST.py
new file mode 100644
index 000000000..209859b8d
--- /dev/null
+++ b/src/mem/slicc/ast/TypeAST.py
@@ -0,0 +1,53 @@
+# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
+# Copyright (c) 2009 The Hewlett-Packard Development Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (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 slicc.ast.AST import AST
+
+from slicc.symbols import Type
+
+class TypeAST(AST):
+ def __init__(self, slicc, ident):
+ super(TypeAST, self).__init__(slicc)
+
+ self.ident = ident
+
+ def __repr__(self):
+ return self.ident
+
+ def __str__(self):
+ return self.ident
+
+ @property
+ def type(self, assert_type=None):
+ type = self.symtab.find(self.ident, Type)
+ if not type:
+ self.error("Type '%s' not declared.", self)
+
+ if assert_type is not None and type != assert_type:
+ self.error("Type '%s' is should be type '%s'", self, assert_type)
+
+ return type
diff --git a/src/mem/slicc/ast/TypeDeclAST.cc b/src/mem/slicc/ast/TypeDeclAST.cc
deleted file mode 100644
index bbf2f8491..000000000
--- a/src/mem/slicc/ast/TypeDeclAST.cc
+++ /dev/null
@@ -1,86 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * TypeDeclAST.C
- *
- * Description: See TypeDeclAST.hh
- *
- * $Id: TypeDeclAST.C,v 3.1 2003/03/22 15:15:17 xu Exp $
- *
- */
-
-#include "mem/slicc/ast/TypeDeclAST.hh"
-#include "mem/slicc/main.hh"
-#include "mem/slicc/symbols/SymbolTable.hh"
-
-TypeDeclAST::TypeDeclAST(TypeAST* type_ast_ptr,
- PairListAST* pairs_ptr,
- Vector<TypeFieldAST*>* field_vec_ptr)
- : DeclAST(pairs_ptr)
-{
- m_type_ast_ptr = type_ast_ptr;
- m_field_vec_ptr = field_vec_ptr;
-}
-
-TypeDeclAST::~TypeDeclAST()
-{
- delete m_type_ast_ptr;
- if (m_field_vec_ptr != NULL) {
- int size = m_field_vec_ptr->size();
- for(int i=0; i<size; i++) {
- delete (*m_field_vec_ptr)[i];
- }
- delete m_field_vec_ptr;
- }
-}
-
-void TypeDeclAST::generate()
-{
- string machine_name;
- string id = m_type_ast_ptr->toString();
-
- // Make the new type
- Type* new_type_ptr = new Type(id, getLocation(), getPairs(),
- g_sym_table.getStateMachine());
- g_sym_table.newSym(new_type_ptr);
-
- // Add all of the fields of the type to it
- if (m_field_vec_ptr != NULL) {
- int size = m_field_vec_ptr->size();
- for(int i=0; i<size; i++) {
- (*m_field_vec_ptr)[i]->generate(new_type_ptr);
- }
- }
-}
-
-void TypeDeclAST::print(ostream& out) const
-{
- out << "[TypeDecl: " << m_type_ast_ptr->toString() << "]";
-}
diff --git a/src/mem/slicc/ast/TypeDeclAST.hh b/src/mem/slicc/ast/TypeDeclAST.hh
deleted file mode 100644
index 8a72c0406..000000000
--- a/src/mem/slicc/ast/TypeDeclAST.hh
+++ /dev/null
@@ -1,86 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * TypeDeclAST.hh
- *
- * Description:
- *
- * $Id: TypeDeclAST.hh,v 3.2 2003/03/17 01:55:28 xu Exp $
- *
- */
-
-#ifndef TypeDeclAST_H
-#define TypeDeclAST_H
-
-#include "mem/slicc/slicc_global.hh"
-#include "mem/slicc/ast/DeclAST.hh"
-#include "mem/slicc/ast/TypeAST.hh"
-#include "mem/slicc/ast/TypeFieldAST.hh"
-
-class TypeDeclAST : public DeclAST {
-public:
- // Constructors
- TypeDeclAST(TypeAST* type_ast_ptr,
- PairListAST* pairs_ptr,
- Vector<TypeFieldAST*>* field_vec_ptr);
-
- // Destructor
- ~TypeDeclAST();
-
- // Public Methods
- virtual void generate();
- void print(ostream& out) const;
-private:
- // Private Methods
-
- // Private copy constructor and assignment operator
- TypeDeclAST(const TypeDeclAST& obj);
- TypeDeclAST& operator=(const TypeDeclAST& obj);
-
- // Data Members (m_ prefix)
- TypeAST* m_type_ast_ptr;
- Vector<TypeFieldAST*>* m_field_vec_ptr;
-};
-
-// Output operator declaration
-ostream& operator<<(ostream& out, const TypeDeclAST& obj);
-
-// ******************* Definitions *******************
-
-// Output operator definition
-extern inline
-ostream& operator<<(ostream& out, const TypeDeclAST& obj)
-{
- obj.print(out);
- out << flush;
- return out;
-}
-
-#endif //TypeDeclAST_H
diff --git a/src/mem/slicc/ast/TypeDeclAST.py b/src/mem/slicc/ast/TypeDeclAST.py
new file mode 100644
index 000000000..d2cc04eff
--- /dev/null
+++ b/src/mem/slicc/ast/TypeDeclAST.py
@@ -0,0 +1,62 @@
+# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
+# Copyright (c) 2009 The Hewlett-Packard Development Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (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 slicc.ast.DeclAST import DeclAST
+from slicc.symbols.Type import Type
+
+class TypeDeclAST(DeclAST):
+ def __init__(self, slicc, type_ast, pairs, field_asts):
+ super(TypeDeclAST, self).__init__(slicc, pairs)
+
+ self.type_ast = type_ast
+ self.field_asts = field_asts
+
+ def __repr__(self):
+ return "[TypeDecl: %r]" % (self.type_ast)
+
+ def files(self, hh, cc, parent=None):
+ if "external" in self:
+ return
+
+ if parent:
+ ident = "%s_%s" % (parent, self.type_ast.ident)
+ else:
+ ident = self.type_ast.ident
+ hh.add("%s.hh" % ident)
+ cc.add("%s.cc" % ident)
+
+ def generate(self):
+ ident = str(self.type_ast)
+
+ # Make the new type
+ new_type = Type(self.symtab, ident, self.location, self.pairs,
+ self.state_machine)
+ self.symtab.newSymbol(new_type)
+
+ # Add all of the fields of the type to it
+ for field in self.field_asts:
+ field.generate(new_type)
diff --git a/src/mem/slicc/ast/TypeFieldAST.cc b/src/mem/slicc/ast/TypeFieldAST.cc
deleted file mode 100644
index 5657d023c..000000000
--- a/src/mem/slicc/ast/TypeFieldAST.cc
+++ /dev/null
@@ -1,44 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * TypeFieldAST.C
- *
- * Description: See TypeFieldAST.hh
- *
- * $Id$
- *
- */
-
-#include "mem/slicc/ast/TypeFieldAST.hh"
-
-TypeFieldAST::TypeFieldAST(PairListAST* pairs_ptr)
- : AST(pairs_ptr->getPairs()) {
-}
-
diff --git a/src/mem/slicc/ast/TypeFieldAST.hh b/src/mem/slicc/ast/TypeFieldAST.hh
deleted file mode 100644
index 144372047..000000000
--- a/src/mem/slicc/ast/TypeFieldAST.hh
+++ /dev/null
@@ -1,83 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * TypeFieldAST.hh
- *
- * Description:
- *
- * $Id$
- *
- */
-
-#ifndef TypeFieldAST_H
-#define TypeFieldAST_H
-
-#include "mem/slicc/slicc_global.hh"
-#include "mem/slicc/symbols/StateMachine.hh"
-#include "mem/slicc/ast/StatementListAST.hh"
-#include "mem/slicc/ast/PairListAST.hh"
-#include "mem/slicc/ast/ExprAST.hh"
-
-class TypeFieldAST : public AST {
-public:
- // Constructors
- TypeFieldAST(PairListAST* pairs_ptr);
-
- // Destructor
- virtual ~TypeFieldAST() {}
-
- // Public Methods
- virtual void generate(Type *type_ptr) = 0;
- virtual void print(ostream& out) const = 0;
-private:
- // Private Methods
-
- // Private copy constructor and assignment operator
- // TypeFieldAST(const TypeFieldAST& obj);
- // TypeFieldAST& operator=(const TypeFieldAST& obj);
-
- // Data Members (m_ prefix)
-};
-
-// Output operator declaration
-ostream& operator<<(ostream& out, const TypeFieldAST& obj);
-
-// ******************* Definitions *******************
-
-// Output operator definition
-extern inline
-ostream& operator<<(ostream& out, const TypeFieldAST& obj)
-{
- obj.print(out);
- out << flush;
- return out;
-}
-
-#endif //TypeFieldAST_H
diff --git a/src/mem/slicc/ast/TypeFieldAST.py b/src/mem/slicc/ast/TypeFieldAST.py
new file mode 100644
index 000000000..7dd4c74aa
--- /dev/null
+++ b/src/mem/slicc/ast/TypeFieldAST.py
@@ -0,0 +1,32 @@
+# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
+# Copyright (c) 2009 The Hewlett-Packard Development Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (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 slicc.ast.AST import AST
+
+class TypeFieldAST(AST):
+ def __init__(self, slicc, pairs):
+ super(TypeFieldAST, self).__init__(slicc, pairs)
diff --git a/src/mem/slicc/ast/TypeFieldEnumAST.cc b/src/mem/slicc/ast/TypeFieldEnumAST.cc
deleted file mode 100644
index 1a02f7edd..000000000
--- a/src/mem/slicc/ast/TypeFieldEnumAST.cc
+++ /dev/null
@@ -1,82 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * TypeFieldEnumAST.C
- *
- * Description: See TypeFieldEnumAST.hh
- *
- * $Id$
- *
- */
-
-#include "mem/slicc/ast/TypeFieldEnumAST.hh"
-#include "mem/slicc/symbols/State.hh"
-#include "mem/slicc/symbols/Event.hh"
-
-TypeFieldEnumAST::TypeFieldEnumAST(string* field_id_ptr,
- PairListAST* pairs_ptr)
- : TypeFieldAST(pairs_ptr)
-{
- m_field_id_ptr = field_id_ptr;
- m_pairs_ptr = pairs_ptr;
-}
-
-TypeFieldEnumAST::~TypeFieldEnumAST()
-{
- delete m_field_id_ptr;
-}
-
-void TypeFieldEnumAST::generate(Type *type_ptr)
-{
- // Add enumeration
- if (!type_ptr->enumAdd(*m_field_id_ptr, m_pairs_ptr->getPairs())) {
- error("Duplicate enumeration: " + type_ptr->toString() + ":" + *m_field_id_ptr);
- }
-
- // Fill machine info
- StateMachine* machine_ptr = g_sym_table.getStateMachine();
- if (type_ptr->toString() == "State") {
- if (machine_ptr == NULL) {
- error("State declaration not part of a machine.");
- }
- machine_ptr->addState(new State(*m_field_id_ptr, getLocation(), getPairs()));
- }
- if (type_ptr->toString() == "Event") {
- if (machine_ptr == NULL) {
- error("Event declaration not part of a machine.");
- }
- machine_ptr->addEvent(new Event(*m_field_id_ptr, getLocation(), getPairs()));
- }
-}
-
-void TypeFieldEnumAST::print(ostream& out) const
-{
- out << "[TypeFieldEnum: " << *m_field_id_ptr << "]";
-}
diff --git a/src/mem/slicc/ast/TypeFieldEnumAST.hh b/src/mem/slicc/ast/TypeFieldEnumAST.hh
deleted file mode 100644
index cd02f03bb..000000000
--- a/src/mem/slicc/ast/TypeFieldEnumAST.hh
+++ /dev/null
@@ -1,86 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * TypeFieldEnumAST.hh
- *
- * Description:
- *
- * $Id: TypeFieldEnumAST.hh,v 3.2 2003/07/10 18:08:07 milo Exp $
- *
- */
-
-#ifndef TypeFieldEnumAST_H
-#define TypeFieldEnumAST_H
-
-#include "mem/slicc/slicc_global.hh"
-#include "mem/slicc/symbols/StateMachine.hh"
-#include "mem/slicc/ast/TypeFieldAST.hh"
-#include "mem/slicc/ast/StatementListAST.hh"
-#include "mem/slicc/ast/PairListAST.hh"
-
-class TypeFieldEnumAST : public TypeFieldAST {
-public:
- // Constructors
- TypeFieldEnumAST(string* field_id_ptr,
- PairListAST* pairs_ptr);
-
- // Destructor
- ~TypeFieldEnumAST();
-
- // Public Methods
- void generate(Type *type_ptr);
- void print(ostream& out) const;
-private:
- // Private Methods
-
- // Private copy constructor and assignment operator
- TypeFieldEnumAST(const TypeFieldEnumAST& obj);
- TypeFieldEnumAST& operator=(const TypeFieldEnumAST& obj);
-
- // Data Members (m_ prefix)
- string* m_field_id_ptr;
- PairListAST* m_pairs_ptr;
-};
-
-// Output operator declaration
-ostream& operator<<(ostream& out, const TypeFieldEnumAST& obj);
-
-// ******************* Definitions *******************
-
-// Output operator definition
-extern inline
-ostream& operator<<(ostream& out, const TypeFieldEnumAST& obj)
-{
- obj.print(out);
- out << flush;
- return out;
-}
-
-#endif //TypeFieldEnumAST_H
diff --git a/src/mem/slicc/ast/TypeFieldEnumAST.py b/src/mem/slicc/ast/TypeFieldEnumAST.py
new file mode 100644
index 000000000..d068666ad
--- /dev/null
+++ b/src/mem/slicc/ast/TypeFieldEnumAST.py
@@ -0,0 +1,59 @@
+# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
+# Copyright (c) 2009 The Hewlett-Packard Development Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (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 slicc.ast.TypeFieldAST import TypeFieldAST
+from slicc.symbols import Event, State
+
+class TypeFieldEnumAST(TypeFieldAST):
+ def __init__(self, slicc, field_id, pairs_ast):
+ super(TypeFieldEnumAST, self).__init__(slicc, pairs_ast)
+
+ self.field_id = field_id
+ self.pairs_ast = pairs_ast
+
+ def __repr__(self):
+ return "[TypeFieldEnum: %r]" % self.field_id
+
+ def generate(self, type):
+ # Add enumeration
+ if not type.enumAdd(self.field_id, self.pairs_ast.pairs):
+ error("Duplicate enumeration: %s:%s" % (type, self.field_id))
+
+ # Fill machine info
+ machine = self.symtab.state_machine
+
+ if str(type) == "State":
+ if not machine:
+ error("State declaration not part of a machine.")
+ s = State(self.symtab, self.field_id, self.location, self.pairs)
+ machine.addState(s)
+
+ if str(type) == "Event":
+ if not machine:
+ error("Event declaration not part of a machine.")
+ e = Event(self.symtab, self.field_id, self.location, self.pairs)
+ machine.addEvent(e)
diff --git a/src/mem/slicc/ast/TypeFieldMemberAST.cc b/src/mem/slicc/ast/TypeFieldMemberAST.cc
deleted file mode 100644
index 1fe0f6d4b..000000000
--- a/src/mem/slicc/ast/TypeFieldMemberAST.cc
+++ /dev/null
@@ -1,84 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * TypeFieldMemberAST.C
- *
- * Description: See TypeFieldMemberAST.hh
- *
- * $Id: TypeFieldMemberAST.C,v 3.1 2003/03/27 22:58:54 xu Exp $
- *
- */
-
-#include "mem/slicc/ast/TypeFieldMemberAST.hh"
-
-TypeFieldMemberAST::TypeFieldMemberAST(TypeAST* type_ast_ptr,
- string* field_id_ptr,
- PairListAST* pairs_ptr,
- ExprAST* rvalue_ptr)
- : TypeFieldAST(pairs_ptr)
-{
- m_type_ast_ptr = type_ast_ptr;
- m_field_id_ptr = field_id_ptr;
- m_rvalue_ptr = rvalue_ptr;
-}
-
-TypeFieldMemberAST::~TypeFieldMemberAST()
-{
- delete m_type_ast_ptr;
- delete m_field_id_ptr;
- if(m_rvalue_ptr) delete m_rvalue_ptr;
-}
-
-void TypeFieldMemberAST::generate(Type *type_ptr)
-{
- // Lookup type
- Type* field_type_ptr = m_type_ast_ptr->lookupType();
-
- // check type if this is a initialization
- string* init_code = NULL;
- if(m_rvalue_ptr) {
- init_code = new string();
- Type* rvalue_type_ptr = m_rvalue_ptr->generate(*init_code);
- if(field_type_ptr != rvalue_type_ptr) {
- error("Initialization type mismatch '" + field_type_ptr->toString() + "' and '" + rvalue_type_ptr->toString() + "'");
- }
- }
-
- // Add data member to the parent type
- if (!type_ptr->dataMemberAdd(*m_field_id_ptr, field_type_ptr, getPairs(),
- init_code)) {
- error("Duplicate data member: " + type_ptr->toString() + ":" + *m_field_id_ptr);
- }
-}
-
-void TypeFieldMemberAST::print(ostream& out) const
-{
- out << "[TypeFieldMember: " << *m_field_id_ptr << "]";
-}
diff --git a/src/mem/slicc/ast/TypeFieldMemberAST.hh b/src/mem/slicc/ast/TypeFieldMemberAST.hh
deleted file mode 100644
index 47355f3ac..000000000
--- a/src/mem/slicc/ast/TypeFieldMemberAST.hh
+++ /dev/null
@@ -1,91 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * TypeFieldMemberAST.hh
- *
- * Description:
- *
- * $Id$
- *
- */
-
-#ifndef TypeFieldMemberAST_H
-#define TypeFieldMemberAST_H
-
-#include "mem/slicc/slicc_global.hh"
-#include "mem/slicc/ast/TypeFieldAST.hh"
-#include "mem/slicc/symbols/StateMachine.hh"
-#include "mem/slicc/ast/StatementListAST.hh"
-#include "mem/slicc/ast/PairListAST.hh"
-#include "mem/slicc/ast/ExprAST.hh"
-#include "mem/slicc/ast/TypeAST.hh"
-
-class TypeFieldMemberAST : public TypeFieldAST {
-public:
- // Constructors
- TypeFieldMemberAST(TypeAST* type_ast_ptr,
- string* field_id_ptr,
- PairListAST* pairs_ptr,
- ExprAST* rvalue_ptr);
-
- // Destructor
- ~TypeFieldMemberAST();
-
- // Public Methods
- void generate(Type *type_ptr);
- void print(ostream& out) const;
-private:
- // Private Methods
-
- // Private copy constructor and assignment operator
- TypeFieldMemberAST(const TypeFieldMemberAST& obj);
- TypeFieldMemberAST& operator=(const TypeFieldMemberAST& obj);
-
- // Data Members (m_ prefix)
- TypeAST* m_type_ast_ptr;
- string* m_field_id_ptr;
- ExprAST* m_rvalue_ptr;
-};
-
-// Output operator declaration
-ostream& operator<<(ostream& out, const TypeFieldMemberAST& obj);
-
-// ******************* Definitions *******************
-
-// Output operator definition
-extern inline
-ostream& operator<<(ostream& out, const TypeFieldMemberAST& obj)
-{
- obj.print(out);
- out << flush;
- return out;
-}
-
-#endif //TypeFieldMemberAST_H
diff --git a/src/mem/slicc/ast/TypeFieldMemberAST.py b/src/mem/slicc/ast/TypeFieldMemberAST.py
new file mode 100644
index 000000000..285d5b622
--- /dev/null
+++ b/src/mem/slicc/ast/TypeFieldMemberAST.py
@@ -0,0 +1,57 @@
+# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
+# Copyright (c) 2009 The Hewlett-Packard Development Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (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 slicc.ast.TypeFieldAST import TypeFieldAST
+
+class TypeFieldMemberAST(TypeFieldAST):
+ def __init__(self, slicc, type_ast, field_id, pairs, rvalue):
+ super(TypeFieldMemberAST, self).__init__(slicc, pairs)
+
+ self.type_ast = type_ast
+ self.field_id = field_id
+ self.rvalue = rvalue
+
+ def __repr__(self):
+ return "[TypeFieldMember: %r]" % self.field_id
+
+ def generate(self, type):
+ # Lookup type
+ field_type = self.type_ast.type
+
+ # check type if this is a initialization
+ init_code = ""
+ if self.rvalue:
+ rvalue_type,init_code = self.rvalue.inline(True)
+ if field_type != rvalue_type:
+ self.error("Initialization type mismatch '%s' and '%s'" % \
+ (field_type, rvalue_type))
+
+ # Add data member to the parent type
+ if not type.dataMemberAdd(self.field_id, field_type, self.pairs,
+ init_code):
+
+ error("Duplicate data member: %s:%s" % (type_ptr, field_id))
diff --git a/src/mem/slicc/ast/TypeFieldMethodAST.cc b/src/mem/slicc/ast/TypeFieldMethodAST.cc
deleted file mode 100644
index 03c528f87..000000000
--- a/src/mem/slicc/ast/TypeFieldMethodAST.cc
+++ /dev/null
@@ -1,81 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * TypeFieldMethodAST.C
- *
- * Description: See TypeFieldMethodAST.hh
- *
- * $Id: TypeFieldMethodAST.C,v 3.1 2003/07/10 18:08:07 milo Exp $
- *
- */
-
-#include "mem/slicc/ast/TypeFieldMethodAST.hh"
-
-TypeFieldMethodAST::TypeFieldMethodAST(TypeAST* return_type_ast_ptr,
- string* ident_ptr,
- Vector<TypeAST*>* type_ast_vec_ptr,
- PairListAST* pairs_ptr)
- : TypeFieldAST(pairs_ptr)
-{
- m_return_type_ast_ptr = return_type_ast_ptr;
- m_ident_ptr = ident_ptr;
- m_type_ast_vec_ptr = type_ast_vec_ptr;
-}
-
-TypeFieldMethodAST::~TypeFieldMethodAST()
-{
- delete m_return_type_ast_ptr;
- delete m_ident_ptr;
-
- int size = m_type_ast_vec_ptr->size();
- for(int i=0; i<size; i++) {
- delete (*m_type_ast_vec_ptr)[i];
- }
- delete m_type_ast_vec_ptr;
-}
-
-void TypeFieldMethodAST::generate(Type *type_ptr)
-{
- // Lookup return type
- Type* return_type_ptr = m_return_type_ast_ptr->lookupType();
-
- // Lookup parameter types
- Vector<Type*> type_vec;
- int size = m_type_ast_vec_ptr->size();
- for(int i=0; i<size; i++) {
- Type* type_ptr = (*m_type_ast_vec_ptr)[i]->lookupType();
- type_vec.insertAtBottom(type_ptr);
- }
-
- // Add method
- if (!type_ptr->methodAdd(*m_ident_ptr, return_type_ptr, type_vec)) { // Return false on error
- error("Duplicate method: " + type_ptr->toString() + ":" + *m_ident_ptr + "()");
- }
-}
diff --git a/src/mem/slicc/ast/TypeFieldMethodAST.hh b/src/mem/slicc/ast/TypeFieldMethodAST.hh
deleted file mode 100644
index 10d53ef80..000000000
--- a/src/mem/slicc/ast/TypeFieldMethodAST.hh
+++ /dev/null
@@ -1,87 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * TypeFieldMethodAST.hh
- *
- * Description:
- *
- * $Id: TypeFieldMethodAST.hh,v 3.2 2003/07/10 18:08:07 milo Exp $
- *
- */
-
-#ifndef TYPEFIELDMETHODAST_H
-#define TYPEFIELDMETHODAST_H
-
-#include "mem/slicc/slicc_global.hh"
-#include "mem/slicc/ast/TypeFieldAST.hh"
-#include "mem/slicc/ast/TypeAST.hh"
-
-class TypeFieldMethodAST : public TypeFieldAST {
-public:
- // Constructors
- TypeFieldMethodAST(TypeAST* return_type_ast_ptr,
- string* ident_ptr,
- Vector<TypeAST*>* type_ast_vec_ptr,
- PairListAST* pairs_ptr);
- // Destructor
- ~TypeFieldMethodAST();
-
- // Public Methods
-
- void generate(Type *type_ptr);
- void print(ostream& out) const {}
-private:
- // Private Methods
-
- // Private copy constructor and assignment operator
- TypeFieldMethodAST(const TypeFieldMethodAST& obj);
- TypeFieldMethodAST& operator=(const TypeFieldMethodAST& obj);
-
- // Data Members (m_ prefix)
- TypeAST* m_return_type_ast_ptr;
- string* m_ident_ptr;
- Vector<TypeAST*>* m_type_ast_vec_ptr;
-};
-
-// Output operator declaration
-ostream& operator<<(ostream& out, const TypeFieldMethodAST& obj);
-
-// ******************* Definitions *******************
-
-// Output operator definition
-extern inline
-ostream& operator<<(ostream& out, const TypeFieldMethodAST& obj)
-{
- obj.print(out);
- out << flush;
- return out;
-}
-
-#endif //TYPEFIELDMETHODAST_H
diff --git a/src/mem/slicc/ast/TypeFieldMethodAST.py b/src/mem/slicc/ast/TypeFieldMethodAST.py
new file mode 100644
index 000000000..337b15597
--- /dev/null
+++ b/src/mem/slicc/ast/TypeFieldMethodAST.py
@@ -0,0 +1,50 @@
+# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
+# Copyright (c) 2009 The Hewlett-Packard Development Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (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 slicc.ast.TypeFieldAST import TypeFieldAST
+
+class TypeFieldMethodAST(TypeFieldAST):
+ def __init__(self, slicc, return_type_ast, ident, type_asts, pairs):
+ super(TypeFieldMethodAST, self).__init__(slicc, pairs)
+
+ self.return_type_ast = return_type_ast
+ self.ident = ident
+ self.type_asts = type_asts
+
+ def __repr__(self):
+ return ""
+
+ def generate(self, type):
+ # Lookup return type
+ return_type = self.return_type_ast.type
+
+ # Lookup parameter types
+ types = [ t.type for t in self.type_asts ]
+
+ # Add method
+ if not type.methodAdd(self.ident, return_type, types):
+ error("Duplicate method: %s:%s()" % (type, self.ident))
diff --git a/src/mem/slicc/ast/VarExprAST.cc b/src/mem/slicc/ast/VarExprAST.cc
deleted file mode 100644
index 13e265540..000000000
--- a/src/mem/slicc/ast/VarExprAST.cc
+++ /dev/null
@@ -1,76 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * VarExprAST.C
- *
- * Description: See VarExprAST.hh
- *
- * $Id$
- *
- */
-
-#include "mem/slicc/ast/VarExprAST.hh"
-#include "mem/slicc/ast/StatementAST.hh"
-#include "mem/slicc/symbols/SymbolTable.hh"
-
-VarExprAST::~VarExprAST()
-{
- delete m_var_ptr;
-}
-
-
-Var* VarExprAST::getVar() const
-{
- string var = *m_var_ptr;
- Var* var_ptr = g_sym_table.getVar(var);
- if (var_ptr == NULL) {
- error("Unrecognized variable: " + var);
- }
- return var_ptr;
-}
-
-void VarExprAST::assertType(string type_ident) const
-{
- Type* expected_type_ptr = g_sym_table.getType(type_ident);
- if (expected_type_ptr == NULL) {
- error("There must be a type '" + type_ident + "' declared in this scope");
- }
-
- if (getVar()->getType() != expected_type_ptr) {
- error("Incorrect type: '" + getVar()->getIdent() + "' is expected to be type '" + expected_type_ptr->toString() + "'");
- }
-}
-
-Type* VarExprAST::generate(string& code) const
-{
- Var* var_ptr = getVar();
- code += var_ptr->getCode();
- return var_ptr->getType();
-}
diff --git a/src/mem/slicc/ast/VarExprAST.hh b/src/mem/slicc/ast/VarExprAST.hh
deleted file mode 100644
index ea32582a2..000000000
--- a/src/mem/slicc/ast/VarExprAST.hh
+++ /dev/null
@@ -1,86 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * VarExprAST.hh
- *
- * Description:
- *
- * $Id$
- *
- */
-
-#ifndef VAREXPRAST_H
-#define VAREXPRAST_H
-
-#include "mem/slicc/slicc_global.hh"
-#include "mem/slicc/ast/ExprAST.hh"
-class Var;
-
-class VarExprAST : public ExprAST {
-public:
- // Constructors
- VarExprAST(string* var_ptr) : ExprAST() { m_var_ptr = var_ptr; }
-
- // Destructor
- ~VarExprAST();
-
- // Public Methods
- Type* generate(string& code) const;
- void print(ostream& out) const { out << "[VarExprAST: " << *m_var_ptr << "]"; }
- string getName() const { return *m_var_ptr; }
- Var* getVar() const;
- void assertType(string type_ident) const;
-private:
- // Private Methods
-
- // Private copy constructor and assignment operator
- VarExprAST(const VarExprAST& obj);
- VarExprAST& operator=(const VarExprAST& obj);
-
- // Data Members (m_ prefix)
- string* m_var_ptr;
-
-};
-
-// Output operator declaration
-ostream& operator<<(ostream& out, const VarExprAST& obj);
-
-// ******************* Definitions *******************
-
-// Output operator definition
-extern inline
-ostream& operator<<(ostream& out, const VarExprAST& obj)
-{
- obj.print(out);
- out << flush;
- return out;
-}
-
-#endif //VAREXPRAST_H
diff --git a/src/mem/slicc/ast/VarExprAST.py b/src/mem/slicc/ast/VarExprAST.py
new file mode 100644
index 000000000..ac440bb68
--- /dev/null
+++ b/src/mem/slicc/ast/VarExprAST.py
@@ -0,0 +1,66 @@
+# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
+# Copyright (c) 2009 The Hewlett-Packard Development Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (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 slicc.ast.ExprAST import ExprAST
+from slicc.symbols import Type, Var
+
+class VarExprAST(ExprAST):
+ def __init__(self, slicc, var):
+ super(VarExprAST, self).__init__(slicc)
+ self._var = var
+
+ def __repr__(self):
+ return "[VarExprAST: %r]" % self._var
+
+ @property
+ def name(self):
+ return str(self._var)
+
+ @property
+ def var(self):
+ var = self.symtab.find(self._var, Var)
+ if not var:
+ self.error("Unrecognized variable: %s", self._var)
+ return var
+
+ def assertType(self, type_ident):
+ expected_type = self.symtab.find(type_ident, Type)
+
+ if not expected_type:
+ self.error("There must be a type '%s' declared in this scope",
+ type_ident)
+
+ if self.var.type != expected_type:
+ self.error("Incorrect type: " + \
+ "'%s' is expected to be type '%s' not '%s'",
+ self.var.ident, expected_type, self.var.type)
+
+ def generate(self, code):
+ fix = code.nofix()
+ code("${{self.var.code}}")
+ code.fix(fix)
+ return self.var.type
diff --git a/src/mem/slicc/ast/__init__.py b/src/mem/slicc/ast/__init__.py
new file mode 100644
index 000000000..de50cbd49
--- /dev/null
+++ b/src/mem/slicc/ast/__init__.py
@@ -0,0 +1,69 @@
+# Copyright (c) 2009 The Hewlett-Packard Development Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (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 slicc.ast.AST import *
+
+# actual ASTs
+from slicc.ast.ActionDeclAST import *
+from slicc.ast.AssignStatementAST import *
+from slicc.ast.CheckAllocateStatementAST import *
+from slicc.ast.CheckStopSlotsStatementAST import *
+from slicc.ast.ChipComponentAccessAST import *
+from slicc.ast.CopyHeadStatementAST import *
+from slicc.ast.DeclAST import *
+from slicc.ast.DeclListAST import *
+from slicc.ast.EnqueueStatementAST import *
+from slicc.ast.EnumDeclAST import *
+from slicc.ast.EnumExprAST import *
+from slicc.ast.ExprAST import *
+from slicc.ast.ExprStatementAST import *
+from slicc.ast.FormalParamAST import *
+from slicc.ast.FuncCallExprAST import *
+from slicc.ast.FuncDeclAST import *
+from slicc.ast.IfStatementAST import *
+from slicc.ast.InPortDeclAST import *
+from slicc.ast.InfixOperatorExprAST import *
+from slicc.ast.LiteralExprAST import *
+from slicc.ast.MachineAST import *
+from slicc.ast.MemberExprAST import *
+from slicc.ast.MethodCallExprAST import *
+from slicc.ast.NewExprAST import *
+from slicc.ast.ObjDeclAST import *
+from slicc.ast.OutPortDeclAST import *
+from slicc.ast.PairAST import *
+from slicc.ast.PairListAST import *
+from slicc.ast.PeekStatementAST import *
+from slicc.ast.ReturnStatementAST import *
+from slicc.ast.StatementAST import *
+from slicc.ast.StatementListAST import *
+from slicc.ast.TransitionDeclAST import *
+from slicc.ast.TypeAST import *
+from slicc.ast.TypeDeclAST import *
+from slicc.ast.TypeFieldAST import *
+from slicc.ast.TypeFieldEnumAST import *
+from slicc.ast.TypeFieldMemberAST import *
+from slicc.ast.TypeFieldMethodAST import *
+from slicc.ast.VarExprAST import *
diff --git a/src/mem/slicc/generate/__init__.py b/src/mem/slicc/generate/__init__.py
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/src/mem/slicc/generate/__init__.py
diff --git a/src/mem/slicc/generate/dot.py b/src/mem/slicc/generate/dot.py
new file mode 100644
index 000000000..762658983
--- /dev/null
+++ b/src/mem/slicc/generate/dot.py
@@ -0,0 +1,42 @@
+# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
+# Copyright (c) 2009 The Hewlett-Packard Development Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (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.code_formatter import code_formatter
+
+def printDotty(sm, code):
+ code('digraph ${{sm.getIdent()}} {')
+ code.indent()
+ for t in sm.transitions:
+ # Don't print ignored transitions
+ if t.getActionShorthands() in ("--", "z"):
+ continue
+
+ code('${{t.getStateShorthand()}} -> ${{t.getNextStateShorthand()}')
+ code(' [label="${{t.getEventShorthand()}}/${{t.getActionShorthands()}}"')
+ code.dedent()
+ code('}')
+
diff --git a/src/mem/slicc/generate/html.py b/src/mem/slicc/generate/html.py
new file mode 100644
index 000000000..53252ce3c
--- /dev/null
+++ b/src/mem/slicc/generate/html.py
@@ -0,0 +1,80 @@
+# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
+# Copyright (c) 2009 The Hewlett-Packard Development Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (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.code_formatter import code_formatter
+
+def createSymbol(symbol, title):
+ code = code_formatter()
+ code('''<HTML><BODY><BIG>
+$title:
+${{formatShorthand(symbol.short)}} - ${{symbol.desc}}</BIG></BODY></HTML>''')
+ return code
+
+def formatShorthand(short):
+ munged_shorthand = ""
+ mode_is_normal = True
+
+ # -- Walk over the string, processing superscript directives
+ gen = enumerate(short)
+ for i,c in gen:
+ if c == '!':
+ # -- Reached logical end of shorthand name
+ break
+ elif c == '_':
+ munged_shorthand += " "
+ elif c == '^':
+ # -- Process super/subscript formatting
+ mode_is_normal = not mode_is_normal
+ if mode_is_normal:
+ # -- Back to normal mode
+ munged_shorthand += "</SUP>"
+ else:
+ # -- Going to superscript mode
+ munged_shorthand += "<SUP>"
+ elif c == '\\':
+ # -- Process Symbol character set
+ if i + 1 < len(short):
+ # -- Proceed to next char. Yes I know that changing
+ # the loop var is ugly!
+ i,c = gen.next()
+ munged_shorthand += "<B><FONT size=+1>"
+ munged_shorthand += c
+ munged_shorthand += "</FONT></B>"
+ else:
+ # -- FIXME: Add line number info later
+ panic("Encountered a `\\` without anything following it!")
+ else:
+ # -- Pass on un-munged
+ munged_shorthand += c
+
+ # -- Do any other munging
+ if not mode_is_normal:
+ # -- Back to normal mode
+ munged_shorthand += "</SUP>"
+
+ return munged_shorthand
+
diff --git a/src/mem/slicc/generate/tex.py b/src/mem/slicc/generate/tex.py
new file mode 100644
index 000000000..97c63ebc6
--- /dev/null
+++ b/src/mem/slicc/generate/tex.py
@@ -0,0 +1,71 @@
+# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
+# Copyright (c) 2009 The Hewlett-Packard Development Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (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.code_formatter import code_formatter
+
+class tex_formatter(code_formatter):
+ braced = "<>"
+ double_braced = "<<>>"
+
+def printTexTable(sm, code):
+ tex = tex_formatter()
+ tex(r'''
+%& latex
+\documentclass[12pt]{article}
+\usepackage{graphics}
+\begin{document}
+\begin{tabular}{|l||$<<"l" * len(sm.events)>>|} \hline
+''')
+
+ for event in sm.events:
+ code(r" & \rotatebox{90}{$<<event.short>>}")
+ tex(r'\\ \hline \hline')
+
+ for state in sm.states:
+ state_str = state.short
+ for event in sm.events:
+ state_str += ' & '
+ trans = sm.get_transition(state, event)
+ if trans:
+ actions = trans.getActionShorthands()
+ # FIXME: should compare index, not the string
+ if trans.getNextStateShorthand() != state.short:
+ nextState = trans.getNextStateShorthand()
+ else:
+ nextState = ""
+ state_str += actions
+ if nextState and actions:
+ state_str += '/'
+ state_str += nextState
+ tex(r'$0 \\', state_str)
+ tex(r'''
+\hline
+\end{tabular}
+\end{document}
+''')
+
+ code.append(tex)
diff --git a/src/mem/slicc/generator/fileio.cc b/src/mem/slicc/generator/fileio.cc
deleted file mode 100644
index 15eccd3ca..000000000
--- a/src/mem/slicc/generator/fileio.cc
+++ /dev/null
@@ -1,66 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * fileio.C
- *
- * Description: See fileio.hh
- *
- * $Id: fileio.C,v 3.3 2003/07/10 18:08:08 milo Exp $
- *
- * */
-
-#include "mem/slicc/generator/fileio.hh"
-
-void conditionally_write_file(string filename, ostringstream& sstr)
-{
- ofstream out;
- ifstream in;
- string input_file;
-
- // Read in the file if it exists
- in.open(filename.c_str());
- char c;
- while (in.get(c)) {
- input_file += c;
- }
- in.close();
-
- // Check to see if the file is the same as what we want to write
- if (input_file != sstr.str()) {
- cout << " Overwriting file: " << filename << endl;
- // Overwrite the old file with the new file
- out.open(filename.c_str());
- out << sstr.str();
- out.close();
- } else {
- //cout << " Keeping old file: " << filename << endl;
- }
-}
-
diff --git a/src/mem/slicc/generator/fileio.hh b/src/mem/slicc/generator/fileio.hh
deleted file mode 100644
index 81b7306bc..000000000
--- a/src/mem/slicc/generator/fileio.hh
+++ /dev/null
@@ -1,46 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * fileio.hh
- *
- * Description:
- *
- * $Id: fileio.hh,v 3.2 2003/02/24 20:54:25 xu Exp $
- *
- * */
-
-#ifndef FILEIO_H
-#define FILEIO_H
-
-#include "mem/slicc/slicc_global.hh"
-
-void conditionally_write_file(string filename, ostringstream& sstr);
-
-#endif //FILEIO_H
diff --git a/src/mem/slicc/generator/html_gen.cc b/src/mem/slicc/generator/html_gen.cc
deleted file mode 100644
index 2d35dccb6..000000000
--- a/src/mem/slicc/generator/html_gen.cc
+++ /dev/null
@@ -1,125 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * html_gen.C
- *
- * Description: See html_gen.hh
- *
- * $Id: html_gen.C,v 3.4 2004/01/31 20:46:50 milo Exp $
- *
- * */
-
-#include "mem/slicc/generator/html_gen.hh"
-#include "mem/slicc/generator/fileio.hh"
-#include "mem/slicc/symbols/SymbolTable.hh"
-
-string formatHTMLShorthand(const string shorthand);
-
-
-void createHTMLSymbol(const Symbol& sym, string title, ostream& out)
-{
- out << "<HTML><BODY><BIG>" << endl;
- out << title << ": " << endl;
- out << formatHTMLShorthand(sym.getShorthand()) << " - ";
- out << sym.getDescription();
- out << "</BIG></BODY></HTML>" << endl;
-}
-
-void createHTMLindex(string title, ostream& out)
-{
- out << "<html>" << endl;
- out << "<head>" << endl;
- out << "<title>" << title << "</title>" << endl;
- out << "</head>" << endl;
- out << "<frameset rows=\"*,30\">" << endl;
- Vector<StateMachine*> machine_vec = g_sym_table.getStateMachines();
- if (machine_vec.size() > 1) {
- string machine = machine_vec[0]->getIdent();
- out << " <frame name=\"Table\" src=\"" << machine << "_table.html\">" << endl;
- } else {
- out << " <frame name=\"Table\" src=\"empty.html\">" << endl;
- }
-
- out << " <frame name=\"Status\" src=\"empty.html\">" << endl;
- out << "</frameset>" << endl;
- out << "</html>" << endl;
-}
-
-string formatHTMLShorthand(const string shorthand)
-{
- string munged_shorthand = "";
- bool mode_is_normal = true;
-
- // -- Walk over the string, processing superscript directives
- for(unsigned int i = 0; i < shorthand.length(); i++) {
- if(shorthand[i] == '!') {
- // -- Reached logical end of shorthand name
- break;
- } else if( shorthand[i] == '_') {
- munged_shorthand += " ";
- } else if( shorthand[i] == '^') {
- // -- Process super/subscript formatting
- mode_is_normal = !mode_is_normal;
- if(mode_is_normal) {
- // -- Back to normal mode
- munged_shorthand += "</SUP>";
- } else {
- // -- Going to superscript mode
- munged_shorthand += "<SUP>";
- }
- } else if(shorthand[i] == '\\') {
- // -- Process Symbol character set
- if((i + 1) < shorthand.length()) {
- i++; // -- Proceed to next char. Yes I know that changing the loop var is ugly!
- munged_shorthand += "<B><FONT size=+1>";
- munged_shorthand += shorthand[i];
- munged_shorthand += "</FONT></B>";
- } else {
- // -- FIXME: Add line number info later
- cerr << "Encountered a `\\` without anything following it!" << endl;
- exit( -1 );
- }
- } else {
- // -- Pass on un-munged
- munged_shorthand += shorthand[i];
- }
- } // -- end for all characters in shorthand
-
- // -- Do any other munging
- if(!mode_is_normal) {
- // -- Back to normal mode
- munged_shorthand += "</SUP>";
- }
-
- // -- Return the formatted shorthand name
- return munged_shorthand;
-}
-
-
diff --git a/src/mem/slicc/generator/html_gen.hh b/src/mem/slicc/generator/html_gen.hh
deleted file mode 100644
index 6b1f8ea92..000000000
--- a/src/mem/slicc/generator/html_gen.hh
+++ /dev/null
@@ -1,49 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * html_gen.hh
- *
- * Description:
- *
- * $Id: html_gen.hh,v 3.1 2001/12/12 01:00:35 milo Exp $
- *
- * */
-
-#ifndef HTML_GEN_H
-#define HTML_GEN_H
-
-#include "mem/slicc/slicc_global.hh"
-#include "mem/slicc/symbols/StateMachine.hh"
-
-string formatHTMLShorthand(const string shorthand);
-void createHTMLindex(string title, ostream& out);
-void createHTMLSymbol(const Symbol& sym, string title, ostream& out);
-
-#endif //HTML_GEN_H
diff --git a/src/mem/slicc/generator/mif_gen.cc b/src/mem/slicc/generator/mif_gen.cc
deleted file mode 100644
index 2dca149b4..000000000
--- a/src/mem/slicc/generator/mif_gen.cc
+++ /dev/null
@@ -1,1718 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * $Id$
- *
- */
-
-#include "mem/slicc/generator/mif_gen.hh"
-#include "mem/slicc/symbols/State.hh"
-#include "mem/slicc/symbols/Event.hh"
-#include "mem/slicc/symbols/Action.hh"
-#include "mem/slicc/symbols/Transition.hh"
-
-// -- Helper functions
-string formatShorthand(const string shorthand);
-string formatCellRuling(const string shorthand);
-
-void printStateTableMIF(const StateMachine& sm, ostream& out)
-{
- const string mif_prolog1 =
-"<MIFFile 5.50> # Generated by Multifacet MIF Mungers Inc\n\
-<Tbls\n\
- <Tbl\n\
- <TblID 1>\n\
- <TblTag `Format A'>\n\
- <TblFormat\n\
-\n\
- <TblAlignment Center>\n\
-\n\
- # <TblXColumnNum 0>\n\
- <TblXColumnRuling `Medium'>\n\
-\n\
- <TblLRuling `Medium'>\n\
- <TblRRuling `Medium'>\n\
- <TblTRuling `Medium'>\n\
- <TblBRuling `Medium'>\n\
-\n\
- <TblColumn\n\
- <TblColumnNum 0>\n\
- <TblColumnWidth 0.51\">\n\
- <TblColumnH\n\
- <PgfTag `CellHeading'>\n\
- > # end of TblColumnH\n\
- <TblColumnBody\n\
- <PgfTag `CellBody'>\n\
- > # end of TblColumnBody\n\
- <TblColumnF\n\
- <PgfTag `CellHeading'>\n\
- > # end of TblColumnF\n\
- > # end of TblColumn\n\
- <TblColumn\n\
- <TblColumnNum 1>\n\
- <TblColumnWidth 0.51\">\n\
- <TblColumnH\n\
- <PgfTag `CellHeading'>\n\
- > # end of TblColumnH\n\
- <TblColumnBody\n\
- <PgfTag `CellBody'>\n\
- > # end of TblColumnBody\n\
- <TblColumnF\n\
- <PgfTag `CellHeading'>\n\
- > # end of TblColumnF\n\
- > # end of TblColumn\n\
- > # end of TblFormat\n\
-\n\
- <TblNumColumns 2>\n\
- <TblColumnWidth 0.51\">\n\
- <TblColumnWidth 6.00\">\n\
- <TblTitle\n\
- <TblTitleContent\n\
- <Para\n\
- <PgfTag `TableTitle'>\n\
- <Pgf\n\
- <PgfAlignment Center>\n\
- <PgfFont \n\
- <FTag `'>\n\
- <FFamily `Times'>\n\
- <FVar `Regular'>\n\
- <FWeight `Regular'>\n\
- <FAngle `Regular'>\n\
- <FPostScriptName `Times-Roman'>\n\
- <FEncoding `FrameRoman'>\n\
- <FSize 11.0 pt>\n\
- <FUnderlining FNoUnderlining>\n\
- <FOverline No>\n\
- <FStrike No>\n\
- <FChangeBar No>\n\
- <FOutline No>\n\
- <FShadow No>\n\
- <FPairKern Yes>\n\
- <FTsume No>\n\
- <FCase FAsTyped>\n\
- <FPosition FNormal>\n\
- <FDX 0.0%>\n\
- <FDY 0.0%>\n\
- <FDW 0.0%>\n\
- <FStretch 100.0%>\n\
- <FLanguage USEnglish>\n\
- <FLocked No>\n\
- <FSeparation 0>\n\
- <FColor `Black'>\n\
- > # end of PgfFont\n\
- > # end of Pgf\n\
- <PgfNumString `TABLE 1. '>\n\
- <ParaLine\n\
- <Marker\n\
- <MType 9>\n\
- <MTypeName `Cross-Ref'>\n\
- <MCurrPage `1'>\n\
- > # end of Marker\n\
- <String `";
-
- const string mif_prolog2 =
- "'>\n\
- > # end of ParaLine\n\
- > # end of Para\n\
- > # end of TblTitleContent\n\
- > # end of TblTitle\n\
-\n\
- <TblH\n\
- <Row\n\
- <RowMaxHeight 14.0\">\n\
- <RowHeight 0.44444\">\n\
- <Cell\n\
- <CellLRuling `Medium'>\n\
- <CellBRuling `Medium'>\n\
- <CellRRuling `Medium'>\n\
- <CellTRuling `Medium'>\n\
- <CellContent\n\
- <Para\n\
- <PgfTag `CellHeading'>\n\
- <Pgf\n\
- <PgfAlignment Center>\n\
- <PgfFont \n\
- <FTag `'>\n\
- <FFamily `Times'>\n\
- <FVar `Regular'>\n\
- <FWeight `Regular'>\n\
- <FAngle `Regular'>\n\
- <FPostScriptName `Times-Roman'>\n\
- <FEncoding `FrameRoman'>\n\
- <FSize 11.0 pt>\n\
- <FUnderlining FNoUnderlining>\n\
- <FOverline No>\n\
- <FStrike No>\n\
- <FChangeBar No>\n\
- <FOutline No>\n\
- <FShadow No>\n\
- <FPairKern Yes>\n\
- <FTsume No>\n\
- <FCase FAsTyped>\n\
- <FPosition FNormal>\n\
- <FDX 0.0%>\n\
- <FDY 0.0%>\n\
- <FDW 0.0%>\n\
- <FStretch 100.0%>\n\
- <FLanguage USEnglish>\n\
- <FLocked No>\n\
- <FSeparation 0>\n\
- <FColor `Black'>\n\
- > # end of PgfFont\n\
- >\n\
- <ParaLine\n\
- <String `State'>\n\
- > # end of ParaLine\n\
- > # end of Para\n\
- > # end of CellContent\n\
- > # end of Cell\n\
- <Cell\n\
- <CellLRuling `Medium'>\n\
- <CellBRuling `Medium'>\n\
- <CellRRuling `Medium'>\n\
- <CellTRuling `Medium'>\n\
- <CellContent\n\
- <Para\n\
- <PgfTag `CellHeading'>\n\
- <PgfFont \n\
- <FTag `'>\n\
- <FFamily `Times'>\n\
- <FVar `Regular'>\n\
- <FWeight `Regular'>\n\
- <FAngle `Regular'>\n\
- <FPostScriptName `Times-Roman'>\n\
- <FEncoding `FrameRoman'>\n\
- <FSize 11.0 pt>\n\
- <FUnderlining FNoUnderlining>\n\
- <FOverline No>\n\
- <FStrike No>\n\
- <FChangeBar No>\n\
- <FOutline No>\n\
- <FShadow No>\n\
- <FPairKern Yes>\n\
- <FTsume No>\n\
- <FCase FAsTyped>\n\
- <FPosition FNormal>\n\
- <FDX 0.0%>\n\
- <FDY 0.0%>\n\
- <FDW 0.0%>\n\
- <FStretch 100.0%>\n\
- <FLanguage USEnglish>\n\
- <FLocked No>\n\
- <FSeparation 0>\n\
- <FColor `Black'>\n\
- > # end of PgfFont\n\
- <ParaLine\n\
- <String `Description'>\n\
- > # end of ParaLine\n\
- > # end of Para\n\
- > # end of CellContent\n\
- > # end of Cell\n\
- > # end of Row\n\
- > # end of TblH\n\
-\n\
- <TblBody\n\
-";
-
- const string row_before_state =
-" <Row\n\
- <RowMaxHeight 14.0\">\n\
- <RowHeight 0.22222\">\n\
- <Cell\n\
- <CellContent\n\
- <Para\n\
- <PgfTag `CellBody'>\n\
- <Pgf\n\
- <PgfAlignment Center>\n\
- <PgfFont \n\
- <FTag `'>\n\
- <FFamily `Times'>\n\
- <FVar `Regular'>\n\
- <FWeight `Regular'>\n\
- <FAngle `Regular'>\n\
- <FPostScriptName `Times-Roman'>\n\
- <FEncoding `FrameRoman'>\n\
- <FSize 11.0 pt>\n\
- <FUnderlining FNoUnderlining>\n\
- <FOverline No>\n\
- <FStrike No>\n\
- <FChangeBar No>\n\
- <FOutline No>\n\
- <FShadow No>\n\
- <FPairKern Yes>\n\
- <FTsume No>\n\
- <FCase FAsTyped>\n\
- <FPosition FNormal>\n\
- <FDX 0.0%>\n\
- <FDY 0.0%>\n\
- <FDW 0.0%>\n\
- <FStretch 100.0%>\n\
- <FLanguage USEnglish>\n\
- <FLocked No>\n\
- <FSeparation 0>\n\
- <FColor `Black'>\n\
- > # end of PgfFont\n\
- >\n\
- <ParaLine\n\
- <String `";
-
- const string row_between_state_desc =
- "'>\n\
- > # end of ParaLine\n\
- > # end of Para\n\
- > # end of CellContent\n\
- > # end of Cell\n\
- <Cell\n\
- <CellContent\n\
- <Para\n\
- <PgfTag `CellBody'>\n\
- <ParaLine\n\
- <String `";
-
- const string row_after_desc =
- "'>\n\
- > # end of ParaLine\n\
- > # end of Para\n\
- > # end of CellContent\n\
- > # end of Cell\n\
- > # end of Row\n\
-";
-
- const string mif_epilog =
-" > # end of TblBody\n\
- > # end of Tbl\n\
-> # end of Tbls\n\
-\n\
- <Para\n\
- <ParaLine\n\
- <ATbl 1>\n\
- > # end of ParaLine\n\
- > # end of Para\n\
-\n\
-# End of MIFFile\n\
-";
-
- out << mif_prolog1;
- out << formatShorthand( sm.getShorthand() );
- out << " states";
- out << mif_prolog2;
-
- for( int i = 0; i < sm.numStates(); i++ )
- {
- out << row_before_state;
- out << formatShorthand( sm.getState( i ).getShorthand() );
- out << row_between_state_desc;
- out << sm.getState( i ).getDescription();
- out << row_after_desc;
- }
-
- out << mif_epilog;
-}
-
-
-void printEventTableMIF(const StateMachine& sm, ostream& out)
-{
- const string mif_prolog1 =
-"<MIFFile 5.50> # Generated by Multifacet MIF Mungers Inc\n\
-<Tbls\n\
- <Tbl\n\
- <TblID 1>\n\
- <TblTag `Format A'>\n\
- <TblFormat\n\
-\n\
- <TblAlignment Center>\n\
-\n\
- # <TblXColumnNum 0>\n\
- <TblXColumnRuling `Medium'>\n\
-\n\
- <TblLRuling `Medium'>\n\
- <TblRRuling `Medium'>\n\
- <TblTRuling `Medium'>\n\
- <TblBRuling `Medium'>\n\
-\n\
- <TblColumn\n\
- <TblColumnNum 0>\n\
- <TblColumnWidth 0.51\">\n\
- <TblColumnH\n\
- <PgfTag `CellHeading'>\n\
- > # end of TblColumnH\n\
- <TblColumnBody\n\
- <PgfTag `CellBody'>\n\
- > # end of TblColumnBody\n\
- <TblColumnF\n\
- <PgfTag `CellHeading'>\n\
- > # end of TblColumnF\n\
- > # end of TblColumn\n\
- <TblColumn\n\
- <TblColumnNum 1>\n\
- <TblColumnWidth 0.51\">\n\
- <TblColumnH\n\
- <PgfTag `CellHeading'>\n\
- > # end of TblColumnH\n\
- <TblColumnBody\n\
- <PgfTag `CellBody'>\n\
- > # end of TblColumnBody\n\
- <TblColumnF\n\
- <PgfTag `CellHeading'>\n\
- > # end of TblColumnF\n\
- > # end of TblColumn\n\
- > # end of TblFormat\n\
-\n\
- <TblNumColumns 2>\n\
- <TblColumnWidth 0.51\">\n\
- <TblColumnWidth 6.00\">\n\
- <TblTitle\n\
- <TblTitleContent\n\
- <Para\n\
- <PgfTag `TableTitle'>\n\
- <Pgf\n\
- <PgfAlignment Center>\n\
- <PgfFont \n\
- <FTag `'>\n\
- <FFamily `Times'>\n\
- <FVar `Regular'>\n\
- <FWeight `Regular'>\n\
- <FAngle `Regular'>\n\
- <FPostScriptName `Times-Roman'>\n\
- <FEncoding `FrameRoman'>\n\
- <FSize 11.0 pt>\n\
- <FUnderlining FNoUnderlining>\n\
- <FOverline No>\n\
- <FStrike No>\n\
- <FChangeBar No>\n\
- <FOutline No>\n\
- <FShadow No>\n\
- <FPairKern Yes>\n\
- <FTsume No>\n\
- <FCase FAsTyped>\n\
- <FPosition FNormal>\n\
- <FDX 0.0%>\n\
- <FDY 0.0%>\n\
- <FDW 0.0%>\n\
- <FStretch 100.0%>\n\
- <FLanguage USEnglish>\n\
- <FLocked No>\n\
- <FSeparation 0>\n\
- <FColor `Black'>\n\
- > # end of PgfFont\n\
- > # end of Pgf\n\
- <PgfNumString `TABLE 1. '>\n\
- <ParaLine\n\
- <Marker\n\
- <MType 9>\n\
- <MTypeName `Cross-Ref'>\n\
- <MCurrPage `1'>\n\
- > # end of Marker\n\
- <String `";
- const string mif_prolog2 =
-"'>\n\
- > # end of ParaLine\n\
- > # end of Para\n\
- > # end of TblTitleContent\n\
- > # end of TblTitle\n\
-\n\
- <TblH\n\
- <Row\n\
- <RowMaxHeight 14.0\">\n\
- <RowHeight 0.44444\">\n\
- <Cell\n\
- <CellLRuling `Medium'>\n\
- <CellBRuling `Medium'>\n\
- <CellRRuling `Medium'>\n\
- <CellTRuling `Medium'>\n\
- <CellContent\n\
- <Para\n\
- <PgfTag `CellHeading'>\n\
- <PgfFont \n\
- <FTag `'>\n\
- <FFamily `Times'>\n\
- <FVar `Regular'>\n\
- <FWeight `Regular'>\n\
- <FAngle `Regular'>\n\
- <FPostScriptName `Times-Roman'>\n\
- <FEncoding `FrameRoman'>\n\
- <FSize 11.0 pt>\n\
- <FUnderlining FNoUnderlining>\n\
- <FOverline No>\n\
- <FStrike No>\n\
- <FChangeBar No>\n\
- <FOutline No>\n\
- <FShadow No>\n\
- <FPairKern Yes>\n\
- <FTsume No>\n\
- <FCase FAsTyped>\n\
- <FPosition FNormal>\n\
- <FDX 0.0%>\n\
- <FDY 0.0%>\n\
- <FDW 0.0%>\n\
- <FStretch 100.0%>\n\
- <FLanguage USEnglish>\n\
- <FLocked No>\n\
- <FSeparation 0>\n\
- <FColor `Black'>\n\
- > # end of PgfFont\n\
- <Pgf\n\
- <PgfAlignment Center>\n\
- <PgfFont \n\
- <FTag `'>\n\
- <FFamily `Times'>\n\
- <FVar `Regular'>\n\
- <FWeight `Regular'>\n\
- <FAngle `Regular'>\n\
- <FPostScriptName `Times-Roman'>\n\
- <FEncoding `FrameRoman'>\n\
- <FSize 11.0 pt>\n\
- <FUnderlining FNoUnderlining>\n\
- <FOverline No>\n\
- <FStrike No>\n\
- <FChangeBar No>\n\
- <FOutline No>\n\
- <FShadow No>\n\
- <FPairKern Yes>\n\
- <FTsume No>\n\
- <FCase FAsTyped>\n\
- <FPosition FNormal>\n\
- <FDX 0.0%>\n\
- <FDY 0.0%>\n\
- <FDW 0.0%>\n\
- <FStretch 100.0%>\n\
- <FLanguage USEnglish>\n\
- <FLocked No>\n\
- <FSeparation 0>\n\
- <FColor `Black'>\n\
- > # end of PgfFont\n\
- >\n\
- <ParaLine\n\
- <String `Event'>\n\
- > # end of ParaLine\n\
- > # end of Para\n\
- > # end of CellContent\n\
- > # end of Cell\n\
- <Cell\n\
- <CellLRuling `Medium'>\n\
- <CellBRuling `Medium'>\n\
- <CellRRuling `Medium'>\n\
- <CellTRuling `Medium'>\n\
- <CellContent\n\
- <Para\n\
- <PgfTag `CellHeading'>\n\
- <ParaLine\n\
- <String `Description'>\n\
- > # end of ParaLine\n\
- > # end of Para\n\
- > # end of CellContent\n\
- > # end of Cell\n\
- > # end of Row\n\
- > # end of TblH\n\
-\n\
- <TblBody\n\
-";
-
- const string row_before_event =
-" <Row\n\
- <RowMaxHeight 14.0\">\n\
- <RowHeight 0.22222\">\n\
- <Cell\n\
- <CellContent\n\
- <Para\n\
- <PgfTag `CellBody'>\n\
- <Pgf\n\
- <PgfAlignment Center>\n\
- <PgfFont \n\
- <FTag `'>\n\
- <FFamily `Times'>\n\
- <FVar `Regular'>\n\
- <FWeight `Regular'>\n\
- <FAngle `Regular'>\n\
- <FPostScriptName `Times-Roman'>\n\
- <FEncoding `FrameRoman'>\n\
- <FSize 11.0 pt>\n\
- <FUnderlining FNoUnderlining>\n\
- <FOverline No>\n\
- <FStrike No>\n\
- <FChangeBar No>\n\
- <FOutline No>\n\
- <FShadow No>\n\
- <FPairKern Yes>\n\
- <FTsume No>\n\
- <FCase FAsTyped>\n\
- <FPosition FNormal>\n\
- <FDX 0.0%>\n\
- <FDY 0.0%>\n\
- <FDW 0.0%>\n\
- <FStretch 100.0%>\n\
- <FLanguage USEnglish>\n\
- <FLocked No>\n\
- <FSeparation 0>\n\
- <FColor `Black'>\n\
- > # end of PgfFont\n\
- >\n\
- <ParaLine\n\
- <String `";
-
- const string row_between_event_desc =
- "'>\n\
- > # end of ParaLine\n\
- > # end of Para\n\
- > # end of CellContent\n\
- > # end of Cell\n\
- <Cell\n\
- <CellContent\n\
- <Para\n\
- <PgfTag `CellBody'>\n\
- <ParaLine\n\
- <String `";
-
- const string row_after_desc =
- "'>\n\
- > # end of ParaLine\n\
- > # end of Para\n\
- > # end of CellContent\n\
- > # end of Cell\n\
- > # end of Row\n\
-";
-
- const string mif_epilog =
-" > # end of TblBody\n\
- > # end of Tbl\n\
-> # end of Tbls\n\
-\n\
- <Para\n\
- <ParaLine\n\
- <ATbl 1>\n\
- > # end of ParaLine\n\
- > # end of Para\n\
-\n\
-# End of MIFFile\n\
-";
-
- out << mif_prolog1;
- out << formatShorthand( sm.getShorthand() );
- out << " events";
- out << mif_prolog2;
-
- for( int i = 0; i < sm.numEvents(); i++ )
- {
- out << row_before_event;
- out << formatShorthand( sm.getEvent( i ).getShorthand() );
- out << row_between_event_desc;
- out << sm.getEvent( i ).getDescription();
- out << row_after_desc;
- }
-
- out << mif_epilog;
-}
-
-
-void printActionTableMIF(const StateMachine& sm, ostream& out)
-{
- const string mif_prolog1 =
-"<MIFFile 5.50> # Generated by Multifacet MIF Mungers Inc\n\
-<Tbls\n\
- <Tbl\n\
- <TblID 1>\n\
- <TblTag `Format A'>\n\
- <TblFormat\n\
-\n\
- <TblAlignment Center>\n\
-\n\
- # <TblXColumnNum 0>\n\
- <TblXColumnRuling `Medium'>\n\
-\n\
- <TblLRuling `Medium'>\n\
- <TblRRuling `Medium'>\n\
- <TblTRuling `Medium'>\n\
- <TblBRuling `Medium'>\n\
-\n\
- <TblColumn\n\
- <TblColumnNum 0>\n\
- <TblColumnWidth 0.51\">\n\
- <TblColumnH\n\
- <PgfTag `CellHeading'>\n\
- > # end of TblColumnH\n\
- <TblColumnBody\n\
- <PgfTag `CellBody'>\n\
- > # end of TblColumnBody\n\
- <TblColumnF\n\
- <PgfTag `CellHeading'>\n\
- > # end of TblColumnF\n\
- > # end of TblColumn\n\
- <TblColumn\n\
- <TblColumnNum 1>\n\
- <TblColumnWidth 0.51\">\n\
- <TblColumnH\n\
- <PgfTag `CellHeading'>\n\
- > # end of TblColumnH\n\
- <TblColumnBody\n\
- <PgfTag `CellBody'>\n\
- > # end of TblColumnBody\n\
- <TblColumnF\n\
- <PgfTag `CellHeading'>\n\
- > # end of TblColumnF\n\
- > # end of TblColumn\n\
- > # end of TblFormat\n\
-\n\
- <TblNumColumns 2>\n\
- <TblColumnWidth 0.51\">\n\
- <TblColumnWidth 6.00\">\n\
- <TblTitle\n\
- <TblTitleContent\n\
- <Para\n\
- <PgfTag `TableTitle'>\n\
- <Pgf\n\
- <PgfAlignment Center>\n\
- <PgfFont \n\
- <FTag `'>\n\
- <FFamily `Times'>\n\
- <FVar `Regular'>\n\
- <FWeight `Regular'>\n\
- <FAngle `Regular'>\n\
- <FPostScriptName `Times-Roman'>\n\
- <FEncoding `FrameRoman'>\n\
- <FSize 11.0 pt>\n\
- <FUnderlining FNoUnderlining>\n\
- <FOverline No>\n\
- <FStrike No>\n\
- <FChangeBar No>\n\
- <FOutline No>\n\
- <FShadow No>\n\
- <FPairKern Yes>\n\
- <FTsume No>\n\
- <FCase FAsTyped>\n\
- <FPosition FNormal>\n\
- <FDX 0.0%>\n\
- <FDY 0.0%>\n\
- <FDW 0.0%>\n\
- <FStretch 100.0%>\n\
- <FLanguage USEnglish>\n\
- <FLocked No>\n\
- <FSeparation 0>\n\
- <FColor `Black'>\n\
- > # end of PgfFont\n\
- > # end of Pgf\n\
- <PgfNumString `TABLE 1. '>\n\
- <ParaLine\n\
- <Marker\n\
- <MType 9>\n\
- <MTypeName `Cross-Ref'>\n\
- <MCurrPage `1'>\n\
- > # end of Marker\n\
- <String `";
- const string mif_prolog2 =
-"'>\n\
- > # end of ParaLine\n\
- > # end of Para\n\
- > # end of TblTitleContent\n\
- > # end of TblTitle\n\
-\n\
- <TblH\n\
- <Row\n\
- <RowMaxHeight 14.0\">\n\
- <RowHeight 0.44444\">\n\
- <Cell\n\
- <CellLRuling `Medium'>\n\
- <CellBRuling `Medium'>\n\
- <CellRRuling `Medium'>\n\
- <CellTRuling `Medium'>\n\
- <CellContent\n\
- <Para\n\
- <PgfTag `CellHeading'>\n\
- <Pgf\n\
- <PgfAlignment Center>\n\
- <PgfFont \n\
- <FTag `'>\n\
- <FFamily `Times'>\n\
- <FVar `Regular'>\n\
- <FWeight `Regular'>\n\
- <FAngle `Regular'>\n\
- <FPostScriptName `Times-Roman'>\n\
- <FEncoding `FrameRoman'>\n\
- <FSize 11.0 pt>\n\
- <FUnderlining FNoUnderlining>\n\
- <FOverline No>\n\
- <FStrike No>\n\
- <FChangeBar No>\n\
- <FOutline No>\n\
- <FShadow No>\n\
- <FPairKern Yes>\n\
- <FTsume No>\n\
- <FCase FAsTyped>\n\
- <FPosition FNormal>\n\
- <FDX 0.0%>\n\
- <FDY 0.0%>\n\
- <FDW 0.0%>\n\
- <FStretch 100.0%>\n\
- <FLanguage USEnglish>\n\
- <FLocked No>\n\
- <FSeparation 0>\n\
- <FColor `Black'>\n\
- > # end of PgfFont\n\
- >\n\
- <ParaLine\n\
- <String `Action'>\n\
- > # end of ParaLine\n\
- > # end of Para\n\
- > # end of CellContent\n\
- > # end of Cell\n\
- <Cell\n\
- <CellLRuling `Medium'>\n\
- <CellBRuling `Medium'>\n\
- <CellRRuling `Medium'>\n\
- <CellTRuling `Medium'>\n\
- <CellContent\n\
- <Para\n\
- <PgfTag `CellHeading'>\n\
- <ParaLine\n\
- <String `Description'>\n\
- > # end of ParaLine\n\
- > # end of Para\n\
- > # end of CellContent\n\
- > # end of Cell\n\
- > # end of Row\n\
- > # end of TblH\n\
-\n\
- <TblBody\n\
-";
-
- const string row_before_action =
-" <Row\n\
- <RowMaxHeight 14.0\">\n\
- <RowHeight 0.22222\">\n\
- <Cell\n\
- <CellContent\n\
- <Para\n\
- <PgfTag `CellBody'>\n\
- <Pgf\n\
- <PgfAlignment Center>\n\
- <PgfFont \n\
- <FTag `'>\n\
- <FFamily `Times'>\n\
- <FVar `Regular'>\n\
- <FWeight `Regular'>\n\
- <FAngle `Regular'>\n\
- <FPostScriptName `Times-Roman'>\n\
- <FEncoding `FrameRoman'>\n\
- <FSize 11.0 pt>\n\
- <FUnderlining FNoUnderlining>\n\
- <FOverline No>\n\
- <FStrike No>\n\
- <FChangeBar No>\n\
- <FOutline No>\n\
- <FShadow No>\n\
- <FPairKern Yes>\n\
- <FTsume No>\n\
- <FCase FAsTyped>\n\
- <FPosition FNormal>\n\
- <FDX 0.0%>\n\
- <FDY 0.0%>\n\
- <FDW 0.0%>\n\
- <FStretch 100.0%>\n\
- <FLanguage USEnglish>\n\
- <FLocked No>\n\
- <FSeparation 0>\n\
- <FColor `Black'>\n\
- > # end of PgfFont\n\
- >\n\
- <ParaLine\n\
- <String `";
-
- const string row_between_action_desc =
- "'>\n\
- > # end of ParaLine\n\
- > # end of Para\n\
- > # end of CellContent\n\
- > # end of Cell\n\
- <Cell\n\
- <CellContent\n\
- <Para\n\
- <PgfTag `CellBody'>\n\
- <ParaLine\n\
- <String `";
-
- const string row_after_desc =
- "'>\n\
- > # end of ParaLine\n\
- > # end of Para\n\
- > # end of CellContent\n\
- > # end of Cell\n\
- > # end of Row\n\
-";
-
- const string mif_epilog =
-" > # end of TblBody\n\
- > # end of Tbl\n\
-> # end of Tbls\n\
-\n\
- <Para\n\
- <ParaLine\n\
- <ATbl 1>\n\
- > # end of ParaLine\n\
- > # end of Para\n\
-\n\
-# End of MIFFile\n\
-";
-
- out << mif_prolog1;
- out << formatShorthand( sm.getShorthand() );
- out << " actions";
- out << mif_prolog2;
-
- for( int i = 0; i < sm.numActions(); i++ )
- {
- out << row_before_action;
- out << formatShorthand( sm.getAction( i ).getShorthand() );
- out << row_between_action_desc;
- out << sm.getAction( i ).getDescription();
- out << row_after_desc;
- }
-
- out << mif_epilog;
-}
-
-
-void printTransitionTableMIF(const StateMachine& sm, ostream& out)
-{
- const string mif_prolog =
-"<MIFFile 5.50> # Generated by Multifacet MIF Mungers Inc\n\
-<Tbls\n\
- <Tbl\n\
- <TblID 1>\n\
- <TblTag `Format A'>\n\
- <TblFormat\n\
-\n\
- <TblAlignment Center>\n\
-\n\
- # <TblXColumnNum 0>\n\
- <TblXColumnRuling `Medium'>\n\
-\n\
- <TblLRuling `Medium'>\n\
- <TblRRuling `Medium'>\n\
- <TblTRuling `Medium'>\n\
- <TblBRuling `Medium'>\n\
- \n\
-";
-
- const string tbl_fmt_before_col_num =
-" <TblColumn\n\
- <TblColumnNum ";
-
- const string tbl_fmt_after_col_num =
- ">\n\
- <TblColumnWidth 0.51\">\n\
- <TblColumnH\n\
- <PgfTag `CellHeading'>\n\
- > # end of TblColumnH\n\
- <TblColumnBody\n\
- <PgfTag `CellBody'>\n\
- > # end of TblColumnBody\n\
- <TblColumnF\n\
- <PgfTag `CellHeading'>\n\
- > # end of TblColumnF\n\
- > # end of TblColumn\n\
-";
-
- const string tbl_fmt_before_num_cols =
-" > # end of TblFormat\n\
-\n\
- <TblNumColumns ";
-
- const string tbl_fmt_each_col_width_begin =
- ">\n\
- <TblColumnWidth ";
-
- const string tbl_fmt_each_col_width_end = "\"";
-
- const string tbl_before_first_header1 =
- ">\n\
- <TblTitle\n\
- <TblTitleContent\n\
- <Para\n\
- <PgfTag `TableTitle'>\n\
- <Pgf\n\
- <PgfAlignment Center>\n\
- <PgfFont \n\
- <FTag `'>\n\
- <FFamily `Times'>\n\
- <FVar `Regular'>\n\
- <FWeight `Regular'>\n\
- <FAngle `Regular'>\n\
- <FPostScriptName `Times-Roman'>\n\
- <FEncoding `FrameRoman'>\n\
- <FSize 11.0 pt>\n\
- <FUnderlining FNoUnderlining>\n\
- <FOverline No>\n\
- <FStrike No>\n\
- <FChangeBar No>\n\
- <FOutline No>\n\
- <FShadow No>\n\
- <FPairKern Yes>\n\
- <FTsume No>\n\
- <FCase FAsTyped>\n\
- <FPosition FNormal>\n\
- <FDX 0.0%>\n\
- <FDY 0.0%>\n\
- <FDW 0.0%>\n\
- <FStretch 100.0%>\n\
- <FLanguage USEnglish>\n\
- <FLocked No>\n\
- <FSeparation 0>\n\
- <FColor `Black'>\n\
- > # end of PgfFont\n\
- > # end of Pgf\n\
- <PgfNumString `TABLE 1. '>\n\
- <ParaLine\n\
- <Marker\n\
- <MType 9>\n\
- <MTypeName `Cross-Ref'>\n\
- <MCurrPage `1'>\n\
- > # end of Marker\n\
- <String `";
-
- const string tbl_before_first_header2 =
- "'>\n\
- > # end of ParaLine\n\
- > # end of Para\n\
- > # end of TblTitleContent\n\
- > # end of TblTitle\n\
-\n\
- <TblH\n\
- <Row\n\
- <RowMaxHeight 14.0\">\n\
- <RowHeight 0.44444\">";
-
- const string tbl_before_each_header =
-" <Cell\n\
- <CellLRuling `Medium'>\n\
- <CellBRuling `Medium'>\n\
- <CellRRuling `Medium'>\n\
- <CellTRuling `Medium'>\n\
- <CellContent\n\
- <Para\n\
- <PgfTag `CellHeading'>\n\
- <Pgf\n\
- <PgfAlignment Center>\n\
- <PgfFont \n\
- <FTag `'>\n\
- <FFamily `Times'>\n\
- <FVar `Regular'>\n\
- <FWeight `Regular'>\n\
- <FAngle `Regular'>\n\
- <FPostScriptName `Times-Roman'>\n\
- <FEncoding `FrameRoman'>\n\
- <FSize 11.0 pt>\n\
- <FUnderlining FNoUnderlining>\n\
- <FOverline No>\n\
- <FStrike No>\n\
- <FChangeBar No>\n\
- <FOutline No>\n\
- <FShadow No>\n\
- <FPairKern Yes>\n\
- <FTsume No>\n\
- <FCase FAsTyped>\n\
- <FPosition FNormal>\n\
- <FDX 0.0%>\n\
- <FDY 0.0%>\n\
- <FDW 0.0%>\n\
- <FStretch 100.0%>\n\
- <FLanguage USEnglish>\n\
- <FLocked No>\n\
- <FSeparation 0>\n\
- <FColor `Black'>\n\
- > # end of PgfFont\n\
- >\n\
- <ParaLine\n\
- <String `";
-
- const string tbl_before_each_rot_header =
-" <Cell\n\
- <CellLRuling `Medium'>\n\
- <CellBRuling `Medium'>\n\
- <CellRRuling `Medium'>\n\
- <CellTRuling `Medium'>\n\
- <CellAngle 270>\n\
- <CellContent\n\
- <Para\n\
- <PgfTag `CellHeading'>\n\
- <ParaLine\n\
- <String `";
-
- const string tbl_after_each_header =
- "'>\n\
- > # end of ParaLine\n\
- > # end of Para\n\
- > # end of CellContent\n\
- > # end of Cell\n\
-";
-
- const string before_first_row =
-" > # end of Row\n\
- > # end of TblH\n\
-\n\
- <TblBody\n\
-";
-
- const string row_before_first_cell =
-" <Row\n\
- <RowMaxHeight 14.0\">\n\
- <RowHeight 0.22222\">";
-
- const string row_cell_before_ruling =
-" <Cell\n\
-";
-
- const string row_cell_before_contents =
-" <CellContent\n\
- <Para\n\
- <PgfTag `CellBody'>\n\
- <Pgf\n\
- <PgfAlignment Center>\n\
- <PgfFont \n\
- <FTag `'>\n\
- <FFamily `Times'>\n\
- <FVar `Regular'>\n\
- <FWeight `Regular'>\n\
- <FAngle `Regular'>\n\
- <FPostScriptName `Times-Roman'>\n\
- <FEncoding `FrameRoman'>\n\
- <FSize 11.0 pt>\n\
- <FUnderlining FNoUnderlining>\n\
- <FOverline No>\n\
- <FStrike No>\n\
- <FChangeBar No>\n\
- <FOutline No>\n\
- <FShadow No>\n\
- <FPairKern Yes>\n\
- <FTsume No>\n\
- <FCase FAsTyped>\n\
- <FPosition FNormal>\n\
- <FDX 0.0%>\n\
- <FDY 0.0%>\n\
- <FDW 0.0%>\n\
- <FStretch 100.0%>\n\
- <FLanguage USEnglish>\n\
- <FLocked No>\n\
- <FSeparation 0>\n\
- <FColor `Black'>\n\
- > # end of PgfFont\n\
- >\n\
- <ParaLine\n\
- <String `";
-
- const string row_cell_after_contents =
- "'>\n\
- > # end of ParaLine\n\
- > # end of Para\n\
- > # end of CellContent\n\
- > # end of Cell\n\
-";
-
- const string row_empty_cell =
-" <CellFill 5>\n\
- <CellColor `Cyan'>\n\
- <CellContent\n\
- <Para\n\
- <PgfTag `CellBody'>\n\
- <ParaLine\n\
- <String `'>\n\
- > # end of ParaLine\n\
- > # end of Para\n\
- > # end of CellContent\n\
- > # end of Cell\n\
-";
-
- const string row_after_last_cell =
-" > # end of Row\n\
-";
-
-
- const string mif_epilog =
-" > # end of TblBody\n\
- > # end of Tbl\n\
-> # end of Tbls\n\
-\n\
- <Para\n\
- <ParaLine\n\
- <ATbl 1>\n\
- > # end of ParaLine\n\
- > # end of Para\n\
-\n\
-# End of MIFFile\n\
-";
-
- int i, j, num_rows, num_cols;
- string row_ruling;
- string col_ruling;
-
- num_rows = sm.numStates();
- num_cols = sm.numEvents() + 1;
-
- // -- Prolog
- out << mif_prolog;
-
- // -- Table format (for each column)
- for( i = 0; i < num_cols; i++ )
- {
- out << tbl_fmt_before_col_num;
- out << i;
- out << tbl_fmt_after_col_num;
- }
-
- // -- Spell out width of each column
-
- // -- FIXME: make following constants into parameters
- const float total_table_width = 7.5; // -- Total page width = 7.5" (portrait mode)
- const float min_col_width = 0.35; // -- Min col width (for legibility)
- const float max_col_width = 0.75; // -- Max col width (for aesthetics)
- float column_width;
-
- // -- Calculate column width and clamp it within a range
- column_width = total_table_width / num_cols;
- column_width = ((column_width < min_col_width)
- ? min_col_width
- : ((column_width > max_col_width)
- ? max_col_width
- : column_width));
-
- out << tbl_fmt_before_num_cols;
- out << num_cols;
- for( i = 0; i < num_cols; i++ )
- {
- out << tbl_fmt_each_col_width_begin << column_width << tbl_fmt_each_col_width_end;
- }
-
- // -- Column headers
- out << tbl_before_first_header1;
- out << formatShorthand( sm.getShorthand() );
- out << " transitions";
- out << tbl_before_first_header2;
-
- out << tbl_before_each_header;
- out << "State";
- out << tbl_after_each_header;
-
- for( i = 0; i < sm.numEvents(); i++ )
- {
- out << tbl_before_each_rot_header;
- out << formatShorthand( sm.getEvent(i).getShorthand() );
- out << tbl_after_each_header;
- }
- out << before_first_row;
-
-
- // -- Body of table
- for( i = 0; i < num_rows; i++ )
- {
- // -- Each row
- out << row_before_first_cell;
-
- // -- Figure out ruling
- if (sm.getState(i).existPair("format")) {
- row_ruling = formatCellRuling( sm.getState(i).lookupPair("format"));
- } else {
- row_ruling = "";
- }
-
- // -- First column = state
- out << row_cell_before_ruling;
- out << row_ruling;
- out << row_cell_before_contents;
- out << formatShorthand( sm.getState(i).getShorthand() );
- out << row_cell_after_contents;
-
- // -- One column for each event
- for( j = 0; j < sm.numEvents(); j++ )
- {
- const Transition* trans_ptr = sm.getTransPtr( i, j );
-
- // -- Figure out ruling
- if (sm.getEvent(j).existPair("format")) {
- col_ruling = formatCellRuling(sm.getEvent(j).lookupPair("format"));
- } else {
- col_ruling = "";
- }
-
- out << row_cell_before_ruling;
- out << row_ruling;
- out << col_ruling;
-
- if( trans_ptr != NULL )
- {
- string actions;
- string nextState;
-
- // -- Get the actions
- actions = formatShorthand( trans_ptr->getActionShorthands() );
-
- // -- Get the next state
- // FIXME: should compare index, not the string
- if (trans_ptr->getNextStateShorthand() !=
- sm.getState(i).getShorthand() )
- {
- nextState = formatShorthand( trans_ptr->getNextStateShorthand() );
- } else
- {
- nextState = "";
- }
-
- // -- Print out "actions/next-state"
- out << row_cell_before_contents;
- out << actions;
- if ((nextState.length() != 0) && (actions.length() != 0)) {
- out << "/";
- }
- out << nextState;
- out << row_cell_after_contents;
- }
- else
- {
- out << row_empty_cell;
- }
-
- }
-
- out << row_after_last_cell;
- }
-
- // -- Epilog
- out << mif_epilog;
-
-}
-/*
-void printTBETableMIF(const StateMachine& sm, const Vector<Field>& fields, ostream& out)
-{
- const string mif_prolog1 =
-"<MIFFile 5.50> # Generated by Multifacet MIF Mungers Inc\n\
-<Tbls\n\
- <Tbl\n\
- <TblID 1>\n\
- <TblTag `Format A'>\n\
- <TblFormat\n\
-\n\
- <TblAlignment Center>\n\
-\n\
- # # <TblXColumnNum 0>\n\
- <TblXColumnRuling `Medium'>\n\
-\n\
- <TblLRuling `Medium'>\n\
- <TblRRuling `Medium'>\n\
- <TblTRuling `Medium'>\n\
- <TblBRuling `Medium'>\n\
-\n\
- <TblColumn\n\
- <TblColumnNum 0>\n\
- <TblColumnWidth 0.51\">\n\
- <TblColumnH\n\
- <PgfTag `CellHeading'>\n\
- > # end of TblColumnH\n\
- <TblColumnBody\n\
- <PgfTag `CellBody'>\n\
- > # end of TblColumnBody\n\
- <TblColumnF\n\
- <PgfTag `CellHeading'>\n\
- > # end of TblColumnF\n\
- > # end of TblColumn\n\
- <TblColumn\n\
- <TblColumnNum 1>\n\
- <TblColumnWidth 0.51\">\n\
- <TblColumnH\n\
- <PgfTag `CellHeading'>\n\
- > # end of TblColumnH\n\
- <TblColumnBody\n\
- <PgfTag `CellBody'>\n\
- > # end of TblColumnBody\n\
- <TblColumnF\n\
- <PgfTag `CellHeading'>\n\
- > # end of TblColumnF\n\
- > # end of TblColumn\n\
- > # end of TblFormat\n\
-\n\
- <TblNumColumns 2>\n\
- <TblColumnWidth 0.51\">\n\
- <TblColumnWidth 6.00\">\n\
- <TblTitle\n\
- <TblTitleContent\n\
- <Para\n\
- <PgfTag `TableTitle'>\n\
- <Pgf\n\
- <PgfAlignment Center>\n\
- <PgfFont \n\
- <FTag `'>\n\
- <FFamily `Times'>\n\
- <FVar `Regular'>\n\
- <FWeight `Regular'>\n\
- <FAngle `Regular'>\n\
- <FPostScriptName `Times-Roman'>\n\
- <FEncoding `FrameRoman'>\n\
- <FSize 11.0 pt>\n\
- <FUnderlining FNoUnderlining>\n\
- <FOverline No>\n\
- <FStrike No>\n\
- <FChangeBar No>\n\
- <FOutline No>\n\
- <FShadow No>\n\
- <FPairKern Yes>\n\
- <FTsume No>\n\
- <FCase FAsTyped>\n\
- <FPosition FNormal>\n\
- <FDX 0.0%>\n\
- <FDY 0.0%>\n\
- <FDW 0.0%>\n\
- <FStretch 100.0%>\n\
- <FLanguage USEnglish>\n\
- <FLocked No>\n\
- <FSeparation 0>\n\
- <FColor `Black'>\n\
- > # end of PgfFont\n\
- > # end of Pgf\n\
- <PgfNumString `TABLE 1. '>\n\
- <ParaLine\n\
- <Marker\n\
- <MType 9>\n\
- <MTypeName `Cross-Ref'>\n\
- <MCurrPage `1'>\n\
- > # end of Marker\n\
- <String `";
-
- const string mif_prolog2 =
- "'>\n\
- > # end of ParaLine\n\
- > # end of Para\n\
- > # end of TblTitleContent\n\
- > # end of TblTitle\n\
-\n\
- <TblH\n\
- <Row\n\
- <RowMaxHeight 14.0\">\n\
- <RowHeight 0.44444\">\n\
- <Cell\n\
- <CellLRuling `Medium'>\n\
- <CellBRuling `Medium'>\n\
- <CellRRuling `Medium'>\n\
- <CellTRuling `Medium'>\n\
- <CellContent\n\
- <Para\n\
- <PgfTag `CellHeading'>\n\
- <Pgf\n\
- <PgfAlignment Center>\n\
- <PgfFont \n\
- <FTag `'>\n\
- <FFamily `Times'>\n\
- <FVar `Regular'>\n\
- <FWeight `Regular'>\n\
- <FAngle `Regular'>\n\
- <FPostScriptName `Times-Roman'>\n\
- <FEncoding `FrameRoman'>\n\
- <FSize 11.0 pt>\n\
- <FUnderlining FNoUnderlining>\n\
- <FOverline No>\n\
- <FStrike No>\n\
- <FChangeBar No>\n\
- <FOutline No>\n\
- <FShadow No>\n\
- <FPairKern Yes>\n\
- <FTsume No>\n\
- <FCase FAsTyped>\n\
- <FPosition FNormal>\n\
- <FDX 0.0%>\n\
- <FDY 0.0%>\n\
- <FDW 0.0%>\n\
- <FStretch 100.0%>\n\
- <FLanguage USEnglish>\n\
- <FLocked No>\n\
- <FSeparation 0>\n\
- <FColor `Black'>\n\
- > # end of PgfFont\n\
- >\n\
- <ParaLine\n\
- <String `Field'>\n\
- > # end of ParaLine\n\
- > # end of Para\n\
- > # end of CellContent\n\
- > # end of Cell\n\
- <Cell\n\
- <CellLRuling `Medium'>\n\
- <CellBRuling `Medium'>\n\
- <CellRRuling `Medium'>\n\
- <CellTRuling `Medium'>\n\
- <CellContent\n\
- <Para\n\
- <PgfTag `CellHeading'>\n\
- <PgfFont \n\
- <FTag `'>\n\
- <FFamily `Times'>\n\
- <FVar `Regular'>\n\
- <FWeight `Regular'>\n\
- <FAngle `Regular'>\n\
- <FPostScriptName `Times-Roman'>\n\
- <FEncoding `FrameRoman'>\n\
- <FSize 11.0 pt>\n\
- <FUnderlining FNoUnderlining>\n\
- <FOverline No>\n\
- <FStrike No>\n\
- <FChangeBar No>\n\
- <FOutline No>\n\
- <FShadow No>\n\
- <FPairKern Yes>\n\
- <FTsume No>\n\
- <FCase FAsTyped>\n\
- <FPosition FNormal>\n\
- <FDX 0.0%>\n\
- <FDY 0.0%>\n\
- <FDW 0.0%>\n\
- <FStretch 100.0%>\n\
- <FLanguage USEnglish>\n\
- <FLocked No>\n\
- <FSeparation 0>\n\
- <FColor `Black'>\n\
- > # end of PgfFont\n\
- <ParaLine\n\
- <String `Description'>\n\
- > # end of ParaLine\n\
- > # end of Para\n\
- > # end of CellContent\n\
- > # end of Cell\n\
- > # end of Row\n\
- > # end of TblH\n\
-\n\
- <TblBody\n\
-";
-
- const string row_before_state =
-" <Row\n\
- <RowMaxHeight 14.0\">\n\
- <RowHeight 0.22222\">\n\
- <Cell\n\
- <CellContent\n\
- <Para\n\
- <PgfTag `CellBody'>\n\
- <Pgf\n\
- <PgfAlignment Center>\n\
- <PgfFont \n\
- <FTag `'>\n\
- <FFamily `Times'>\n\
- <FVar `Regular'>\n\
- <FWeight `Regular'>\n\
- <FAngle `Regular'>\n\
- <FPostScriptName `Times-Roman'>\n\
- <FEncoding `FrameRoman'>\n\
- <FSize 11.0 pt>\n\
- <FUnderlining FNoUnderlining>\n\
- <FOverline No>\n\
- <FStrike No>\n\
- <FChangeBar No>\n\
- <FOutline No>\n\
- <FShadow No>\n\
- <FPairKern Yes>\n\
- <FTsume No>\n\
- <FCase FAsTyped>\n\
- <FPosition FNormal>\n\
- <FDX 0.0%>\n\
- <FDY 0.0%>\n\
- <FDW 0.0%>\n\
- <FStretch 100.0%>\n\
- <FLanguage USEnglish>\n\
- <FLocked No>\n\
- <FSeparation 0>\n\
- <FColor `Black'>\n\
- > # end of PgfFont\n\
- >\n\
- <ParaLine\n\
- <String `";
-
- const string row_between_state_desc =
- "'>\n\
- > # end of ParaLine\n\
- > # end of Para\n\
- > # end of CellContent\n\
- > # end of Cell\n\
- <Cell\n\
- <CellContent\n\
- <Para\n\
- <PgfTag `CellBody'>\n\
- <ParaLine\n\
- <String `";
-
- const string row_after_desc =
- "'>\n\
- > # end of ParaLine\n\
- > # end of Para\n\
- > # end of CellContent\n\
- > # end of Cell\n\
- > # end of Row\n\
-";
-
- const string mif_epilog =
-" > # end of TblBody\n\
- > # end of Tbl\n\
-> # end of Tbls\n\
-\n\
- <Para\n\
- <ParaLine\n\
- <ATbl 1>\n\
- > # end of ParaLine\n\
- > # end of Para\n\
-\n\
-# End of MIFFile\n\
-";
-
- out << mif_prolog1;
- out << sm.getShorthand();
- out << " TBE";
- out << mif_prolog2;
-
- for( int i = 0; i < fields.size(); i++ ) {
- out << row_before_state;
- out << formatShorthand(fields[i].getShorthand());
- out << row_between_state_desc;
- out << fields[i].getDescription();
- out << row_after_desc;
- }
-
- out << mif_epilog;
-}
-*/
-// --
-// -- Helper function to do some shorthand formatting (kludge before we
-// -- get the tuple attributes into the state machine language.
-// -- Current convention:
-// -- - each `_' indicates a toggle between normal mode and superscript
-// -- - each escaped (using `\') character indicates a letter formatted
-// -- using the Symbol character set. \a = alpha, \b = beta, \c = chi etc.
-// -- See the FrameMaker character sets manual in the Online Manuals.
-// -- - a `!' indicates extra stuff at the end which can be ignored (used
-// -- for determining cell ruling and so on)
-// --
-string formatShorthand(const string shorthand)
-{
- string munged_shorthand = "";
- bool mode_is_normal = true;
- const string mif_superscript = "'> <Font <FPosition FSuperscript> <FLocked No> > <String `";
- const string mif_normal = "'> <Font <FPosition FNormal> <FLocked No> > <String `";
- const string mif_symbol = "'> <Font <FFamily `Symbol'> <FPostScriptName `Symbol'> <FEncoding `FrameRoman'> <FLocked No> > <String `";
- const string mif_times = "'> <Font <FFamily `Times'> <FPostScriptName `Times-Roman'> <FEncoding `FrameRoman'> <FLocked No> > <String `";
-
-
- // -- Walk over the string, processing superscript directives
- for( unsigned int i = 0; i < shorthand.length(); i++ )
- {
- if( shorthand[i] == '!' )
- {
- // -- Reached logical end of shorthand name
- break;
- }
- else if( shorthand[i] == '^' )
- {
- // -- Process super/subscript formatting
-
- mode_is_normal = !mode_is_normal;
- if( mode_is_normal )
- {
- // -- Back to normal mode
- munged_shorthand += mif_normal;
- }
- else
- {
- // -- Going to superscript mode
- munged_shorthand += mif_superscript;
- }
-
- }
- else if( shorthand[i] == '\\' )
- {
- // -- Process Symbol character set
- if( (i + 1) < shorthand.length() )
- {
- i++; // -- Proceed to next char. Yes I know that changing the loop var is ugly!
- munged_shorthand += mif_symbol;
- munged_shorthand += shorthand[i];
- munged_shorthand += mif_times;
- }
- else
- {
- // -- FIXME: Add line number info later
- cerr << "Encountered a `\\` without anything following it!" << endl;
- exit( -1 );
- }
-
- }
- else
- {
- // -- Pass on un-munged
- munged_shorthand += shorthand[i];
- }
-
- } // -- end for all characters in shorthand
-
- // -- Do any other munging
-
- // -- Return the formatted shorthand name
- return munged_shorthand;
-}
-
-
-// --
-// -- Helper function to figure out where to put rules in the table (kludge before we
-// -- get the tuple attributes into the shorthand machine language.
-// -- Current convention:
-// -- - a `!' in the shorthand indicates the beginning of ruling information
-// -- - `b' => bottom of this row is ruled
-// -- - `r' => right of this column is ruled
-// --
-string formatCellRuling( const string shorthand)
-{
- for( unsigned int i = 0; i < shorthand.length(); i++ )
- {
- if( shorthand[i] == '!' )
- {
- // -- OK, found beginning of ruling information
- for( unsigned int j = i+1; j < shorthand.length(); j++ )
- {
- if( shorthand[j] == 'b')
- {
- // -- Rule the bottom
- return "<CellBRuling `Medium'>\n";
- }
- else if( shorthand[j] == 'r')
- {
- // -- Rule the bottom
- return "<CellRRuling `Medium'>\n";
- }
-
- }
-
- // -- No ruling directives recognized, return default ruling
- return "";
- }
-
- }
-
- // -- No ruling information found, return default ruling
- return "";
-}
diff --git a/src/mem/slicc/generator/mif_gen.hh b/src/mem/slicc/generator/mif_gen.hh
deleted file mode 100644
index 6da75f748..000000000
--- a/src/mem/slicc/generator/mif_gen.hh
+++ /dev/null
@@ -1,45 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * $Id: mif_gen.hh,v 3.1 2001/12/12 01:00:35 milo Exp $
- *
- */
-
-#ifndef MIF_GEN_H
-#define MIF_GEN_H
-
-#include "mem/slicc/symbols/StateMachine.hh"
-
-void printStateTableMIF(const StateMachine& sm, ostream& out);
-void printEventTableMIF(const StateMachine& sm, ostream& out);
-void printActionTableMIF(const StateMachine& sm, ostream& out);
-void printTransitionTableMIF(const StateMachine& sm, ostream& out);
-
-#endif //MIF_GEN_H
diff --git a/src/mem/slicc/main.cc b/src/mem/slicc/main.cc
deleted file mode 100644
index 294925ee1..000000000
--- a/src/mem/slicc/main.cc
+++ /dev/null
@@ -1,246 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * $Id$
- *
- * */
-
-#include "mem/slicc/main.hh"
-#include "mem/slicc/symbols/StateMachine.hh"
-#include "mem/slicc/generator/mif_gen.hh"
-#include "mem/slicc/generator/html_gen.hh"
-#include "mem/slicc/generator/fileio.hh"
-#include "mem/slicc/ast/DeclListAST.hh"
-#include "mem/slicc/symbols/Type.hh"
-#include "mem/slicc/symbols/SymbolTable.hh"
-#include "mem/slicc/symbols/Event.hh"
-#include "mem/slicc/symbols/State.hh"
-#include "mem/slicc/symbols/Action.hh"
-#include "mem/slicc/symbols/Transition.hh"
-
-// -- Main conversion functions
-
-void printDotty(const StateMachine& sm, ostream& out);
-void printTexTable(const StateMachine& sm, ostream& out);
-
-DeclListAST* g_decl_list_ptr;
-DeclListAST* parse(string filename);
-
-int main(int argc, char *argv[])
-{
- cerr << "SLICC v0.3" << endl;
-
- if (argc < 5) {
- cerr << " Usage: generator.exec <code path> <html path> <ident> <html direction> files ... " << endl;
- exit(1);
- }
-
- // The path we should place the generated code
- string code_path(argv[1]);
- code_path += "/";
-
- // The path we should place the generated html
- string html_path(argv[2]);
- html_path += "/";
-
- string ident(argv[3]);
-
- string html_generate(argv[4]);
-
- Vector<DeclListAST*> decl_list_vec;
-
- // Parse
- cerr << "Parsing..." << endl;
- for(int i=5; i<argc; i++) {
- cerr << " " << argv[i] << endl;
- DeclListAST* decl_list_ptr = parse(argv[i]);
- decl_list_vec.insertAtBottom(decl_list_ptr);
- }
-
- // Find machines
- cerr << "Generator pass 1..." << endl;
- int size = decl_list_vec.size();
- for(int i=0; i<size; i++) {
- DeclListAST* decl_list_ptr = decl_list_vec[i];
- decl_list_ptr->findMachines();
- }
-
- // Generate Code
- cerr << "Generator pass 2..." << endl;
- for(int i=0; i<size; i++) {
- DeclListAST* decl_list_ptr = decl_list_vec[i];
- decl_list_ptr->generate();
- delete decl_list_ptr;
- }
-
- // Generate C/C++ files
- cerr << "Writing C files..." << endl;
-
- {
- // Generate the name of the protocol
- ostringstream sstr;
- sstr << "// Auto generated C++ code started by "<<__FILE__<<":"<<__LINE__<<endl;
- sstr << endl;
- sstr << "#ifndef PROTOCOL_NAME_H" << endl;
- sstr << "#define PROTOCOL_NAME_H" << endl;
- sstr << endl;
- sstr << "const char CURRENT_PROTOCOL[] = \"";
- sstr << ident << "\";\n";
- sstr << "#endif // PROTOCOL_NAME_H" << endl;
- conditionally_write_file(code_path + "/protocol_name.hh", sstr);
- }
-
- g_sym_table.writeCFiles(code_path);
-
- // Generate HTML files
- if (html_generate == "html") {
- cerr << "Writing HTML files..." << endl;
- g_sym_table.writeHTMLFiles(html_path);
- } else if (html_generate == "no_html") {
- cerr << "No HTML files generated" << endl;
- } else {
- cerr << "ERROR, unidentified html direction" << endl;
- }
-
- cerr << "Done..." << endl;
-
- // Generate MIF files
- cerr << "Writing MIF files..." << endl;
- g_sym_table.writeMIFFiles(html_path);
-
- cerr << "Done..." << endl;
-
-}
- /*
- if(!strcmp(argv[2], "parse")) {
- // Parse only
- } else if(!strcmp(argv[2], "state")) {
- printStateTableMIF(s, cout);
- } else if(!strcmp( argv[2], "event")) {
- printEventTableMIF(s, cout);
- } else if(!strcmp( argv[2], "action")) {
- printActionTableMIF(s, cout);
- } else if(!strcmp( argv[2], "transition")) {
- printTransitionTableMIF(s, cout);
- } else if(!strcmp( argv[2], "tbe")) {
- for(int i=0; i<s.numTypes(); i++) {
- if (s.getType(i).getIdent() == "TBE") {
- printTBETableMIF(s, s.getTypeFields(i), cout);
- }
- }
- } else if(!strcmp( argv[2], "dot")) {
- printDotty(s, cout);
- } else if(!strcmp( argv[2], "latex")) {
- printTexTable(s, cout);
- } else if (!strcmp( argv[2], "murphi")) {
- printMurphi(s, cout);
- } else if (!strcmp( argv[2], "html")) {
- printHTML(s);
- } else if(!strcmp( argv[2], "code")) {
- if (argc < 4) {
- cerr << "Error: Wrong number of command line parameters!" << endl;
- exit(1);
- }
- */
-
-
-void printDotty(const StateMachine& sm, ostream& out)
-{
- out << "digraph " << sm.getIdent() << " {" << endl;
- for(int i=0; i<sm.numTransitions(); i++) {
- const Transition& t = sm.getTransition(i);
- // Don't print ignored transitions
- if ((t.getActionShorthands() != "--") && (t.getActionShorthands() != "z")) {
- // if (t.getStateShorthand() != t.getNextStateShorthand()) {
- out << " " << t.getStateShorthand() << " -> ";
- out << t.getNextStateShorthand() << "[label=\"";
- out << t.getEventShorthand() << "/"
- << t.getActionShorthands() << "\"]" << endl;
- }
- }
- out << "}" << endl;
-}
-
-void printTexTable(const StateMachine& sm, ostream& out)
-{
- const Transition* trans_ptr;
- int stateIndex, eventIndex;
- string actions;
- string nextState;
-
- out << "%& latex" << endl;
- out << "\\documentclass[12pt]{article}" << endl;
- out << "\\usepackage{graphics}" << endl;
- out << "\\begin{document}" << endl;
- // out << "{\\large" << endl;
- out << "\\begin{tabular}{|l||";
- for(eventIndex=0; eventIndex < sm.numEvents(); eventIndex++) {
- out << "l";
- }
- out << "|} \\hline" << endl;
-
- for(eventIndex=0; eventIndex < sm.numEvents(); eventIndex++) {
- out << " & \\rotatebox{90}{";
- out << sm.getEvent(eventIndex).getShorthand();
- out << "}";
- }
- out << "\\\\ \\hline \\hline" << endl;
-
- for(stateIndex=0; stateIndex < sm.numStates(); stateIndex++) {
- out << sm.getState(stateIndex).getShorthand();
- for(eventIndex=0; eventIndex < sm.numEvents(); eventIndex++) {
- out << " & ";
- trans_ptr = sm.getTransPtr(stateIndex, eventIndex);
- if (trans_ptr == NULL) {
- } else {
- actions = trans_ptr->getActionShorthands();
- // FIXME: should compare index, not the string
- if (trans_ptr->getNextStateShorthand() !=
- sm.getState(stateIndex).getShorthand() ) {
- nextState = trans_ptr->getNextStateShorthand();
- } else {
- nextState = "";
- }
-
- out << actions;
- if ((nextState.length() != 0) && (actions.length() != 0)) {
- out << "/";
- }
- out << nextState;
- }
- }
- out << "\\\\" << endl;
- }
- out << "\\hline" << endl;
- out << "\\end{tabular}" << endl;
- // out << "}" << endl;
- out << "\\end{document}" << endl;
-}
-
diff --git a/src/mem/slicc/main.hh b/src/mem/slicc/main.hh
deleted file mode 100644
index a10dcca53..000000000
--- a/src/mem/slicc/main.hh
+++ /dev/null
@@ -1,48 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * main.hh
- *
- * Description:
- *
- * $Id: main.hh,v 3.2 2003/03/17 01:50:01 xu Exp $
- *
- * */
-
-#ifndef MAIN_H
-#define MAIN_H
-
-#include "mem/slicc/slicc_global.hh"
-#include "mem/slicc/ast/DeclListAST.hh"
-#include "mem/gems_common/Map.hh"
-
-extern DeclListAST* g_decl_list_ptr;
-
-#endif //MAIN_H
diff --git a/src/mem/slicc/main.py b/src/mem/slicc/main.py
new file mode 100644
index 000000000..0bc2ef37a
--- /dev/null
+++ b/src/mem/slicc/main.py
@@ -0,0 +1,108 @@
+# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
+# Copyright (c) 2009 The Hewlett-Packard Development Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+import os
+import sys
+
+from slicc.parser import SLICC
+
+usage="%prog [options] <files> ... "
+version="%prog v0.4"
+brief_copyright='''
+Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
+Copyright (c) 2009 The Hewlett-Packard Development Company
+All Rights Reserved.
+'''
+
+def nprint(format, *args):
+ pass
+
+def eprint(format, *args):
+ if args:
+ format = format % args
+
+ print >>sys.stderr, format
+
+def main(args=None):
+ import optparse
+
+ parser = optparse.OptionParser(usage=usage, version=version,
+ description=brief_copyright)
+ parser.add_option("-d", "--debug", default=False, action="store_true",
+ help="Turn on PLY debugging")
+ parser.add_option("-C", "--code-path", default="generated",
+ help="Path where C++ code output code goes")
+ parser.add_option("-H", "--html-path",
+ help="Path where html output goes")
+ parser.add_option("-F", "--print-files",
+ help="Print files that SLICC will generate")
+ parser.add_option("-q", "--quiet",
+ help="don't print messages")
+ opts,files = parser.parse_args(args=args)
+
+ if len(files) < 1:
+ parser.print_help()
+ sys.exit(2)
+
+ output = nprint if opts.quiet else eprint
+
+ output("SLICC v0.4")
+ slicc = SLICC(debug=opts.debug)
+
+ output("Parsing...")
+ for filename in slicc.load(files, verbose=True):
+ output(" %s", filename)
+
+ if opts.print_files:
+ hh, cc = slicc.files()
+ hh = sorted(hh)
+ cc = sorted(cc)
+ print 'Headers:'
+ for i in hh:
+ print ' %s' % i
+
+ print 'Sources:'
+ for i in cc:
+ print ' %s' % i
+ else:
+ output("Generator pass 1...")
+ slicc.findMachines()
+
+ output("Generator pass 2...")
+ slicc.generate()
+
+ output("Generating C++ files...")
+ slicc.writeCodeFiles(opts.code_path)
+
+ if opts.html_path:
+ nprint("Writing HTML files...")
+ slicc.writeHTMLFiles(opts.html_path)
+
+ eprint("SLICC is Done.")
+
+if __name__ == "__main__":
+ main()
diff --git a/src/mem/slicc/parser.py b/src/mem/slicc/parser.py
new file mode 100644
index 000000000..0e5ccc885
--- /dev/null
+++ b/src/mem/slicc/parser.py
@@ -0,0 +1,669 @@
+# Copyright (c) 2009 The Hewlett-Packard Development Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+# Authors: Nathan Binkert
+
+import os.path
+import re
+import sys
+
+from m5.util.grammar import Grammar, TokenError, ParseError
+
+import slicc.ast as ast
+import slicc.util as util
+from slicc.symbols import SymbolTable
+
+def read_slicc(sources):
+ if not isinstance(sources, (list,tuple)):
+ sources = [ sources ]
+
+ for source in sources:
+ for sm_file in file(source, "r"):
+ sm_file = sm_file.strip()
+ if not sm_file:
+ continue
+ if sm_file.startswith("#"):
+ continue
+ yield sm_file
+
+class SLICC(Grammar):
+ def __init__(self, **kwargs):
+ super(SLICC, self).__init__(**kwargs)
+ self.decl_list_vec = []
+ self.current_file = None
+ self.symtab = SymbolTable()
+
+ def parse(self, filename):
+ self.current_file = filename
+ f = file(filename, 'r')
+ text = f.read()
+ try:
+ decl_list = super(SLICC, self).parse(text)
+ except (TokenError, ParseError), e:
+ sys.exit("%s: %s:%d" % (e, filename, e.token.lineno))
+ self.decl_list_vec.append(decl_list)
+ self.current_file = None
+
+ def _load(self, *filenames):
+ filenames = list(filenames)
+ while filenames:
+ f = filenames.pop(0)
+ if isinstance(f, (list, tuple)):
+ filenames[0:0] = list(f)
+ continue
+
+ yield f
+ if f.endswith(".slicc"):
+ dirname,basename = os.path.split(f)
+ filenames[0:0] = [ os.path.join(dirname, x) \
+ for x in read_slicc(f)]
+ else:
+ assert f.endswith(".sm")
+ self.parse(f)
+
+ def load(self, *filenames, **kwargs):
+ verbose = kwargs.pop("verbose", False)
+ if kwargs:
+ raise TypeError
+
+ gen = self._load(*filenames)
+ if verbose:
+ return gen
+ else:
+ # Run out the generator if we don't want the verbosity
+ for foo in gen:
+ pass
+
+ def findMachines(self):
+ for decl_list in self.decl_list_vec:
+ decl_list.findMachines()
+
+ def generate(self):
+ for decl_list in self.decl_list_vec:
+ decl_list.generate()
+
+ def writeCodeFiles(self, code_path):
+ util.makeDir(code_path)
+ self.symtab.writeCodeFiles(code_path)
+
+ def writeHTMLFiles(self, code_path):
+ util.makeDir(code_path)
+ self.symtab.writeHTMLFiles(code_path)
+
+ def files(self):
+ cc = set([
+ 'ControllerFactory.cc',
+ 'MachineType.cc'])
+
+ hh = set([
+ 'ControllerFactory.hh',
+ 'MachineType.hh',
+ 'Types.hh' ])
+
+ for decl_list in self.decl_list_vec:
+ decl_list.files(hh, cc)
+
+ return hh, cc
+
+ t_ignore = '\t '
+
+ # C or C++ comment (ignore)
+ def t_c_comment(self, t):
+ r'/\*(.|\n)*?\*/'
+ t.lexer.lineno += t.value.count('\n')
+
+ def t_cpp_comment(self, t):
+ r'//.*'
+
+ # Define a rule so we can track line numbers
+ def t_newline(self, t):
+ r'\n+'
+ t.lexer.lineno += len(t.value)
+
+ reserved = {
+ 'global' : 'GLOBAL',
+ 'machine' : 'MACHINE',
+ 'in_port' : 'IN_PORT',
+ 'out_port' : 'OUT_PORT',
+ 'action' : 'ACTION',
+ 'transition' : 'TRANS',
+ 'structure' : 'STRUCT',
+ 'external_type' : 'EXTERN_TYPE',
+ 'enumeration' : 'ENUM',
+ 'peek' : 'PEEK',
+ 'enqueue' : 'ENQUEUE',
+ 'copy_head' : 'COPY_HEAD',
+ 'check_allocate' : 'CHECK_ALLOCATE',
+ 'check_stop_slots' : 'CHECK_STOP_SLOTS',
+ 'if' : 'IF',
+ 'else' : 'ELSE',
+ 'return' : 'RETURN',
+ 'THIS' : 'THIS',
+ 'CHIP' : 'CHIP',
+ 'void' : 'VOID',
+ 'new' : 'NEW',
+ }
+
+ literals = ':[]{}(),='
+
+ tokens = [ 'EQ', 'NE', 'LT', 'GT', 'LE', 'GE',
+ 'LEFTSHIFT', 'RIGHTSHIFT',
+ 'NOT', 'AND', 'OR',
+ 'PLUS', 'DASH', 'STAR', 'SLASH',
+ 'DOUBLE_COLON', 'SEMI',
+ 'ASSIGN', 'DOT',
+ 'IDENT', 'LIT_BOOL', 'FLOATNUMBER', 'NUMBER', 'STRING' ]
+ tokens += reserved.values()
+
+ t_EQ = r'=='
+ t_NE = r'!='
+ t_LT = r'<'
+ t_GT = r'>'
+ t_LE = r'<='
+ t_GE = r'>='
+ t_LEFTSHIFT = r'<<'
+ t_RIGHTSHIFT = r'>>'
+ t_NOT = r'!'
+ t_AND = r'&&'
+ t_OR = r'\|\|'
+ t_PLUS = r'\+'
+ t_DASH = r'-'
+ t_STAR = r'\*'
+ t_SLASH = r'/'
+ t_DOUBLE_COLON = r'::'
+ t_SEMI = r';'
+ t_ASSIGN = r':='
+ t_DOT = r'\.'
+
+ precedence = (
+ ('left', 'AND', 'OR'),
+ ('left', 'EQ', 'NE'),
+ ('left', 'LT', 'GT', 'LE', 'GE'),
+ ('left', 'RIGHTSHIFT', 'LEFTSHIFT'),
+ ('left', 'PLUS', 'DASH'),
+ ('left', 'STAR', 'SLASH'),
+ ('right', 'NOT', 'UMINUS'),
+ )
+
+ def t_IDENT(self, t):
+ r'[a-zA-Z_][a-zA-Z_0-9]*'
+ if t.value == 'true':
+ t.type = 'LIT_BOOL'
+ t.value = True
+ return t
+
+ if t.value == 'false':
+ t.type = 'LIT_BOOL'
+ t.value = False
+ return t
+
+ # Check for reserved words
+ t.type = self.reserved.get(t.value, 'IDENT')
+ return t
+
+ def t_FLOATNUMBER(self, t):
+ '[0-9]+[.][0-9]+'
+ try:
+ t.value = float(t.value)
+ except ValueError:
+ raise TokenError("Illegal float", t)
+ return t
+
+ def t_NUMBER(self, t):
+ r'[0-9]+'
+ try:
+ t.value = int(t.value)
+ except ValueError:
+ raise TokenError("Illegal number", t)
+ return t
+
+ def t_STRING1(self, t):
+ r'\"[^"\n]*\"'
+ t.type = 'STRING'
+ t.value = t.value[1:-1]
+ return t
+
+ def t_STRING2(self, t):
+ r"\'[^'\n]*\'"
+ t.type = 'STRING'
+ t.value = t.value[1:-1]
+ return t
+
+ def p_file(self, p):
+ "file : decls"
+ p[0] = p[1]
+
+ def p_empty(self, p):
+ "empty :"
+
+ def p_decls(self, p):
+ "decls : declsx"
+ p[0] = ast.DeclListAST(self, p[1])
+
+ def p_declsx__list(self, p):
+ "declsx : decl declsx"
+ p[0] = [ p[1] ] + p[2]
+
+ def p_declsx__none(self, p):
+ "declsx : empty"
+ p[0] = []
+
+ def p_decl__machine(self, p):
+ "decl : MACHINE '(' ident pairs ')' ':' params '{' decls '}'"
+ p[0] = ast.MachineAST(self, p[3], p[4], p[7], p[9])
+
+ def p_decl__action(self, p):
+ "decl : ACTION '(' ident pairs ')' statements"
+ p[0] = ast.ActionDeclAST(self, p[3], p[4], p[6])
+
+ def p_decl__in_port(self, p):
+ "decl : IN_PORT '(' ident ',' type ',' var pairs ')' statements"
+ p[0] = ast.InPortDeclAST(self, p[3], p[5], p[7], p[8], p[10])
+
+ def p_decl__out_port(self, p):
+ "decl : OUT_PORT '(' ident ',' type ',' var pairs ')' SEMI"
+ p[0] = ast.OutPortDeclAST(self, p[3], p[5], p[7], p[8])
+
+ def p_decl__trans0(self, p):
+ "decl : TRANS '(' idents ',' idents ',' ident pairs ')' idents"
+ p[0] = ast.TransitionDeclAST(self, p[3], p[5], p[7], p[8], p[10])
+
+ def p_decl__trans1(self, p):
+ "decl : TRANS '(' idents ',' idents pairs ')' idents"
+ p[0] = ast.TransitionDeclAST(self, p[3], p[5], None, p[6], p[8])
+
+ def p_decl__extern0(self, p):
+ "decl : EXTERN_TYPE '(' type pairs ')' SEMI"
+ p[4]["external"] = "yes"
+ p[0] = ast.TypeDeclAST(self, p[3], p[4], [])
+
+ def p_decl__extern1(self, p):
+ "decl : EXTERN_TYPE '(' type pairs ')' '{' type_methods '}'"
+ p[4]["external"] = "yes"
+ p[0] = ast.TypeDeclAST(self, p[3], p[4], p[7])
+
+ def p_decl__global(self, p):
+ "decl : GLOBAL '(' type pairs ')' '{' type_members '}'"
+ p[4]["global"] = "yes"
+ p[0] = ast.TypeDeclAST(self, p[3], p[4], p[7])
+
+ def p_decl__struct(self, p):
+ "decl : STRUCT '(' type pairs ')' '{' type_members '}'"
+ p[0] = ast.TypeDeclAST(self, p[3], p[4], p[7])
+
+ def p_decl__enum(self, p):
+ "decl : ENUM '(' type pairs ')' '{' type_enums '}'"
+ p[4]["enumeration"] = "yes"
+ p[0] = ast.EnumDeclAST(self, p[3], p[4], p[7])
+
+ def p_decl__object(self, p):
+ "decl : type ident pairs SEMI"
+ p[0] = ast.ObjDeclAST(self, p[1], p[2], p[3])
+
+ def p_decl__func_decl(self, p):
+ """decl : void ident '(' params ')' pairs SEMI
+ | type ident '(' params ')' pairs SEMI"""
+ p[0] = ast.FuncDeclAST(self, p[1], p[2], p[4], p[6], None)
+
+ def p_decl__func_def(self, p):
+ """decl : void ident '(' params ')' pairs statements
+ | type ident '(' params ')' pairs statements"""
+ p[0] = ast.FuncDeclAST(self, p[1], p[2], p[4], p[6], p[7])
+
+ # Type fields
+ def p_type_members__list(self, p):
+ "type_members : type_member type_members"
+ p[0] = [ p[1] ] + p[2]
+
+ def p_type_members__empty(self, p):
+ "type_members : empty"
+ p[0] = []
+
+ def p_type_member__1(self, p):
+ "type_member : type ident pairs SEMI"
+ p[0] = ast.TypeFieldMemberAST(self, p[1], p[2], p[3], None)
+
+ def p_type_member__2(self, p):
+ "type_member : type ident ASSIGN expr SEMI"
+ p[0] = ast.TypeFieldMemberAST(self, p[1], p[2],
+ ast.PairListAST(self), p[4])
+
+ # Methods
+ def p_type_methods__list(self, p):
+ "type_methods : type_method type_methods"
+ p[0] = [ p[1] ] + p[2]
+
+ def p_type_methods(self, p):
+ "type_methods : empty"
+ p[0] = []
+
+ def p_type_method(self, p):
+ "type_method : type_or_void ident '(' types ')' pairs SEMI"
+ p[0] = ast.TypeFieldMethodAST(self, p[1], p[2], p[4], p[6])
+
+ # Enum fields
+ def p_type_enums__list(self, p):
+ "type_enums : type_enum type_enums"
+ p[0] = [ p[1] ] + p[2]
+
+ def p_type_enums__empty(self, p):
+ "type_enums : empty"
+ p[0] = []
+
+ def p_type_enum(self, p):
+ "type_enum : ident pairs SEMI"
+ p[0] = ast.TypeFieldEnumAST(self, p[1], p[2])
+
+ # Type
+ def p_types__multiple(self, p):
+ "types : type ',' types"
+ p[0] = [ p[1] ] + p[3]
+
+ def p_types__one(self, p):
+ "types : type"
+ p[0] = [ p[1] ]
+
+ def p_types__empty(self, p):
+ "types : empty"
+ p[0] = []
+
+ def p_type(self, p):
+ "type : ident"
+ p[0] = ast.TypeAST(self, p[1])
+
+ def p_void(self, p):
+ "void : VOID"
+ p[0] = ast.TypeAST(self, p[1])
+
+ def p_type_or_void(self, p):
+ """type_or_void : type
+ | void"""
+ p[0] = p[1]
+
+ # Formal Param
+ def p_params__many(self, p):
+ "params : param ',' params"
+ p[0] = [ p[1] ] + p[3]
+
+ def p_params__one(self, p):
+ "params : param"
+ p[0] = [ p[1] ]
+
+ def p_params__none(self, p):
+ "params : empty"
+ p[0] = []
+
+ def p_param(self, p):
+ "param : type ident"
+ p[0] = ast.FormalParamAST(self, p[1], p[2])
+
+ # Idents and lists
+ def p_idents__braced(self, p):
+ "idents : '{' identx '}'"
+ p[0] = p[2]
+
+ def p_idents__bare(self, p):
+ "idents : ident"
+ p[0] = [ p[1] ]
+
+ def p_identx__multiple_1(self, p):
+ """identx : ident SEMI identx
+ | ident ',' identx"""
+ p[0] = [ p[1] ] + p[3]
+
+ def p_identx__multiple_2(self, p):
+ "identx : ident identx"
+ p[0] = [ p[1] ] + p[2]
+
+ def p_identx__single(self, p):
+ "identx : empty"
+ p[0] = [ ]
+
+ def p_ident(self, p):
+ "ident : IDENT"
+ p[0] = p[1]
+
+ # Pair and pair lists
+ def p_pairs__list(self, p):
+ "pairs : ',' pairsx"
+ p[0] = p[2]
+
+ def p_pairs__empty(self, p):
+ "pairs : empty"
+ p[0] = ast.PairListAST(self)
+
+ def p_pairsx__many(self, p):
+ "pairsx : pair ',' pairsx"
+ p[0] = p[3]
+ p[0].addPair(p[1])
+
+ def p_pairsx__one(self, p):
+ "pairsx : pair"
+ p[0] = ast.PairListAST(self)
+ p[0].addPair(p[1])
+
+ def p_pair__assign(self, p):
+ """pair : ident '=' STRING
+ | ident '=' ident"""
+ p[0] = ast.PairAST(self, p[1], p[3])
+
+ def p_pair__literal(self, p):
+ "pair : STRING"
+ p[0] = ast.PairAST(self, "short", p[1])
+
+ # Below are the rules for action descriptions
+ def p_statements__inner(self, p):
+ "statements : '{' statements_inner '}'"
+ p[0] = ast.StatementListAST(self, p[2])
+
+ def p_statements__none(self, p):
+ "statements : '{' '}'"
+ p[0] = ast.StatementListAST(self, [])
+
+ def p_statements_inner__many(self, p):
+ "statements_inner : statement statements_inner"
+ p[0] = [ p[1] ] + p[2]
+
+ def p_statements_inner__one(self, p):
+ "statements_inner : statement"
+ p[0] = [ p[1] ]
+
+ def p_exprs__multiple(self, p):
+ "exprs : expr ',' exprs"
+ p[0] = [ p[1] ] + p[3]
+
+ def p_exprs__one(self, p):
+ "exprs : expr"
+ p[0] = [ p[1] ]
+
+ def p_exprs__empty(self, p):
+ "exprs : empty"""
+ p[0] = []
+
+ def p_statement__expression(self, p):
+ "statement : expr SEMI"
+ p[0] = ast.ExprStatementAST(self, p[1])
+
+ def p_statement__assign(self, p):
+ "statement : expr ASSIGN expr SEMI"
+ p[0] = ast.AssignStatementAST(self, p[1], p[3])
+
+ def p_statement__enqueue(self, p):
+ "statement : ENQUEUE '(' var ',' type pairs ')' statements"
+ p[0] = ast.EnqueueStatementAST(self, p[3], p[5], p[6], p[8])
+
+ def p_statement__peek(self, p):
+ "statement : PEEK '(' var ',' type ')' statements"
+ p[0] = ast.PeekStatementAST(self, p[3], p[5], p[7], "peek")
+
+ def p_statement__copy_head(self, p):
+ "statement : COPY_HEAD '(' var ',' var pairs ')' SEMI"
+ p[0] = ast.CopyHeadStatementAST(self, p[3], p[5], p[6])
+
+ def p_statement__check_allocate(self, p):
+ "statement : CHECK_ALLOCATE '(' var ')' SEMI"
+ p[0] = ast.CheckAllocateStatementAST(self, p[3])
+
+ def p_statement__check_stop(self, p):
+ "statement : CHECK_STOP_SLOTS '(' var ',' STRING ',' STRING ')' SEMI"
+ p[0] = ast.CheckStopStatementAST(self, p[3], p[5], p[7])
+
+ def p_statement__return(self, p):
+ "statement : RETURN expr SEMI"
+ p[0] = ast.ReturnStatementAST(self, p[2])
+
+ def p_statement__if(self, p):
+ "statement : if_statement"
+ p[0] = p[1]
+
+ def p_if_statement__if(self, p):
+ "if_statement : IF '(' expr ')' statements"
+ p[0] = ast.IfStatementAST(self, p[3], p[5], None)
+
+ def p_if_statement__if_else(self, p):
+ "if_statement : IF '(' expr ')' statements ELSE statements"
+ p[0] = ast.IfStatementAST(self, p[3], p[5], p[7])
+
+ def p_statement__if_else_if(self, p):
+ "if_statement : IF '(' expr ')' statements ELSE if_statement"
+ p[0] = ast.IfStatementAST(self, p[3], p[5],
+ ast.StatementListAST(self, p[7]))
+
+ def p_expr__var(self, p):
+ "aexpr : var"
+ p[0] = p[1]
+
+ def p_expr__literal(self, p):
+ "aexpr : literal"
+ p[0] = p[1]
+
+ def p_expr__enumeration(self, p):
+ "aexpr : enumeration"
+ p[0] = p[1]
+
+ def p_expr__func_call(self, p):
+ "aexpr : ident '(' exprs ')'"
+ p[0] = ast.FuncCallExprAST(self, p[1], p[3])
+
+ def p_expr__new(self, p):
+ "aexpr : NEW type"
+ p[0] = ast.NewExprAST(self, p[2])
+
+ # globally access a local chip component and call a method
+ def p_expr__local_chip_method(self, p):
+ "aexpr : THIS DOT var '[' expr ']' DOT var DOT ident '(' exprs ')'"
+ p[0] = ast.LocalChipMethodAST(self, p[3], p[5], p[8], p[10], p[12])
+
+ # globally access a local chip component and access a data member
+ def p_expr__local_chip_member(self, p):
+ "aexpr : THIS DOT var '[' expr ']' DOT var DOT field"
+ p[0] = ast.LocalChipMemberAST(self, p[3], p[5], p[8], p[10])
+
+ # globally access a specified chip component and call a method
+ def p_expr__specified_chip_method(self, p):
+ "aexpr : CHIP '[' expr ']' DOT var '[' expr ']' DOT var DOT ident '(' exprs ')'"
+ p[0] = ast.SpecifiedChipMethodAST(self, p[3], p[6], p[8], p[11], p[13],
+ p[15])
+
+ # globally access a specified chip component and access a data member
+ def p_expr__specified_chip_member(self, p):
+ "aexpr : CHIP '[' expr ']' DOT var '[' expr ']' DOT var DOT field"
+ p[0] = ast.SpecifiedChipMemberAST(self, p[3], p[6], p[8], p[11], p[13])
+
+ def p_expr__member(self, p):
+ "aexpr : aexpr DOT ident"
+ p[0] = ast.MemberExprAST(self, p[1], p[3])
+
+ def p_expr__member_method_call(self, p):
+ "aexpr : aexpr DOT ident '(' exprs ')'"
+ p[0] = ast.MemberMethodCallExprAST(self, p[1], p[3], p[5])
+
+ def p_expr__member_method_call_lookup(self, p):
+ "aexpr : aexpr '[' exprs ']'"
+ p[0] = ast.MemberMethodCallExprAST(self, p[1], "lookup", p[3])
+
+ def p_expr__class_method_call(self, p):
+ "aexpr : type DOUBLE_COLON ident '(' exprs ')'"
+ p[0] = ast.ClassMethodCallExprAST(self, p[1], p[3], p[5])
+
+ def p_expr__aexpr(self, p):
+ "expr : aexpr"
+ p[0] = p[1]
+
+ def p_expr__binary_op(self, p):
+ """expr : expr STAR expr
+ | expr SLASH expr
+ | expr PLUS expr
+ | expr DASH expr
+ | expr LT expr
+ | expr GT expr
+ | expr LE expr
+ | expr GE expr
+ | expr EQ expr
+ | expr NE expr
+ | expr AND expr
+ | expr OR expr
+ | expr RIGHTSHIFT expr
+ | expr LEFTSHIFT expr"""
+ p[0] = ast.InfixOperatorExprAST(self, p[1], p[2], p[3])
+
+ # FIXME - unary not
+ def p_expr__unary_op(self, p):
+ """expr : NOT expr
+ | DASH expr %prec UMINUS"""
+ p[0] = PrefixOperatorExpr(p[1], p[2])
+
+ def p_expr__parens(self, p):
+ "aexpr : '(' expr ')'"
+ p[0] = p[2]
+
+ def p_literal__string(self, p):
+ "literal : STRING"
+ p[0] = ast.LiteralExprAST(self, p[1], "string")
+
+ def p_literal__number(self, p):
+ "literal : NUMBER"
+ p[0] = ast.LiteralExprAST(self, p[1], "int")
+
+ def p_literal__float(self, p):
+ "literal : FLOATNUMBER"
+ p[0] = ast.LiteralExprAST(self, p[1], "int")
+
+ def p_literal__bool(self, p):
+ "literal : LIT_BOOL"
+ p[0] = ast.LiteralExprAST(self, p[1], "bool")
+
+ def p_enumeration(self, p):
+ "enumeration : ident ':' ident"
+ p[0] = ast.EnumExprAST(self, ast.TypeAST(self, p[1]), p[3])
+
+ def p_var(self, p):
+ "var : ident"
+ p[0] = ast.VarExprAST(self, p[1])
+
+ def p_field(self, p):
+ "field : ident"
+ p[0] = p[1]
diff --git a/src/mem/slicc/parser/lexer.ll b/src/mem/slicc/parser/lexer.ll
deleted file mode 100644
index b2d36855b..000000000
--- a/src/mem/slicc/parser/lexer.ll
+++ /dev/null
@@ -1,125 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * $Id$
- */
-
-%{
-
-#include <assert.h>
-#include "mem/slicc/ast/ASTs.hh"
-#include "parser.hh"
-#include <string>
-
-extern "C" int yylex();
-extern "C" void yyerror();
-extern "C" int yywrap()
-{
- return 1;
-}
-
-%}
-%x CMNT
-%x IMBEDED
-%%
-
-[\t ]+ /* Ignore whitespace */
-[\n] { g_line_number++; }
-"//".*[\n] { g_line_number++; } /* C++ style comments */
-
-"/*" BEGIN CMNT;
-<CMNT>. ;
-<CMNT>\n { g_line_number++; }
-<CMNT>"*/" { BEGIN INITIAL; }
-
-true { yylval.str_ptr = new string(yytext); return LIT_BOOL; }
-false { yylval.str_ptr = new string(yytext); return LIT_BOOL; }
-global { return GLOBAL_DECL; }
-machine { return MACHINE_DECL; }
-in_port { return IN_PORT_DECL; }
-out_port { return OUT_PORT_DECL; }
-action { return ACTION_DECL; }
-transition { return TRANSITION_DECL; }
-structure { return STRUCT_DECL; }
-external_type { return EXTERN_TYPE_DECL; }
-enumeration { return ENUM_DECL; }
-peek { return PEEK; }
-enqueue { return ENQUEUE; }
-copy_head { return COPY_HEAD; }
-check_allocate { return CHECK_ALLOCATE; }
-check_stop_slots { return CHECK_STOP_SLOTS; }
-if { return IF; }
-else { return ELSE; }
-return { return RETURN; }
-THIS { return THIS; }
-CHIP { return CHIP; }
-void { yylval.str_ptr = new string(yytext); return VOID; }
-new { return NEW; }
-
-== { yylval.str_ptr = new string(yytext); return EQ; }
-!= { yylval.str_ptr = new string(yytext); return NE; }
-[<] { yylval.str_ptr = new string(yytext); return '<'; }
-[>] { yylval.str_ptr = new string(yytext); return '>'; }
-[<][<] { yylval.str_ptr = new string(yytext); return LEFTSHIFT; }
-[>][>] { yylval.str_ptr = new string(yytext); return RIGHTSHIFT; }
-[<][=] { yylval.str_ptr = new string(yytext); return LE; }
-[>][=] { yylval.str_ptr = new string(yytext); return GE; }
-[!] { yylval.str_ptr = new string(yytext); return NOT; }
-[&][&] { yylval.str_ptr = new string(yytext); return AND; }
-[|][|] { yylval.str_ptr = new string(yytext); return OR; }
-[+] { yylval.str_ptr = new string(yytext); return PLUS; }
-[-] { yylval.str_ptr = new string(yytext); return DASH; }
-[*] { yylval.str_ptr = new string(yytext); return STAR; }
-[/] { yylval.str_ptr = new string(yytext); return SLASH; }
-:: { return DOUBLE_COLON; }
-[:] { return ':'; }
-[;] { return SEMICOLON; }
-[[] { return '['; }
-[]] { return ']'; }
-[{] { return '{'; }
-[}] { return '}'; }
-[(] { return '('; }
-[)] { return ')'; }
-[,] { return ','; }
-[=] { return '='; }
-:= { return ASSIGN; }
-[.] { return DOT; }
-
-[0-9]*[.][0-9]* { yylval.str_ptr = new string(yytext); return FLOATNUMBER; }
-[0-9]* { yylval.str_ptr = new string(yytext); return NUMBER; }
-
-[a-zA-Z_][a-zA-Z_0-9]{0,50} { yylval.str_ptr = new string(yytext); return IDENT; }
-\"[^"\n]*\" { yytext[strlen(yytext)-1] = '\0'; yylval.str_ptr = new string(yytext+1); return STRING; }
-\'[^'\n]*\' { yytext[strlen(yytext)-1] = '\0'; yylval.str_ptr = new string(yytext+1); return STRING; }
-
-. { return OTHER; } /* Need so that we handle all characters */
-
-%%
-
diff --git a/src/mem/slicc/parser/parser.py b/src/mem/slicc/parser/parser.py
deleted file mode 100644
index 7fecfd273..000000000
--- a/src/mem/slicc/parser/parser.py
+++ /dev/null
@@ -1,563 +0,0 @@
-# Copyright (c) 2009 The Hewlett-Packard Development Company
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions are
-# met: redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer;
-# redistributions in binary form must reproduce the above copyright
-# notice, this list of conditions and the following disclaimer in the
-# documentation and/or other materials provided with the distribution;
-# neither the name of the copyright holders nor the names of its
-# contributors may be used to endorse or promote products derived from
-# this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-# Authors: Nathan Binkert
-
-from ply import lex, yacc
-import re
-
-t_ignore = '\t '
-
-# C or C++ comment (ignore)
-def t_c_comment(t):
- r'/\*(.|\n)*?\*/'
- t.lexer.lineno += t.value.count('\n')
-
-def t_cpp_comment(t):
- r'//.*'
- pass
-
-# Define a rule so we can track line numbers
-def t_newline(t):
- r'\n+'
- t.lexer.lineno += len(t.value)
-
-reserved = {
- 'global' : 'GLOBAL',
- 'machine' : 'MACHINE',
- 'in_port' : 'IN_PORT',
- 'out_port' : 'OUT_PORT',
- 'action' : 'ACTION',
- 'transition' : 'TRANS',
- 'structure' : 'STRUCT',
- 'external_type' : 'EXTERN_TYPE',
- 'enumeration' : 'ENUM',
- 'peek' : 'PEEK',
- 'enqueue' : 'ENQUEUE',
- 'copy_head' : 'COPY_HEAD',
- 'check_allocate' : 'CHECK_ALLOCATE',
- 'check_stop_slots' : 'CHECK_STOP_SLOTS',
- 'if' : 'IF',
- 'else' : 'ELSE',
- 'return' : 'RETURN',
- 'THIS' : 'THIS',
- 'CHIP' : 'CHIP',
- 'void' : 'VOID',
- 'new' : 'NEW',
-}
-
-literals = ':[]{}(),='
-
-tokens = [ 'EQ', 'NE', 'LT', 'GT', 'LE', 'GE',
- 'LEFTSHIFT', 'RIGHTSHIFT',
- 'NOT', 'AND', 'OR',
- 'PLUS', 'DASH', 'STAR', 'SLASH',
- 'DOUBLE_COLON', 'SEMICOLON',
- 'ASSIGN', 'DOT',
- 'IDENT', 'LIT_BOOL', 'FLOATNUMBER', 'NUMBER', 'STRING' ]
-tokens += reserved.values()
-
-t_EQ = r'=='
-t_NE = r'!='
-t_LT = r'<'
-t_GT = r'>'
-t_LE = r'<='
-t_GE = r'>='
-t_LEFTSHIFT = r'<<'
-t_RIGHTSHIFT = r'>>'
-t_NOT = r'!'
-t_AND = r'&&'
-t_OR = r'\|\|'
-t_PLUS = r'\+'
-t_DASH = r'-'
-t_STAR = r'\*'
-t_SLASH = r'/'
-t_DOUBLE_COLON = r'::'
-t_SEMICOLON = r';'
-t_ASSIGN = r':='
-t_DOT = r'\.'
-
-class TokenError(Exception):
- def __init__(self, msg, t):
- super(TokenError, self).__init__(msg)
- self.token = t
-
-class ParseError(Exception):
- def __init__(self, msg, t):
- super(ParseError, self).__init__(msg)
- self.token = t
-
-def t_error(t):
- raise TokenError("Illegal character", t)
-
-def t_IDENT(t):
- r'[a-zA-Z_][a-zA-Z_0-9]*'
- if t.value == 'true':
- t.type = 'LIT_BOOL'
- t.value = True
- return t
-
- if t.value == 'false':
- t.type = 'LIT_BOOL'
- t.value = False
- return t
-
- if t.value.startswith('LATENCY_'):
- t.type = 'LATENCY'
- return t
-
- t.type = reserved.get(t.value, 'IDENT') # Check for reserved words
- return t
-
-def t_FLOATNUMBER(t):
- '[0-9]+[.][0-9]+'
- try:
- t.value = float(t.value)
- except ValueError:
- raise TokenError("Illegal float", t)
- return t
-
-def t_NUMBER(t):
- r'[0-9]+'
- try:
- t.value = int(t.value)
- except ValueError:
- raise TokenError("Illegal number", t)
- return t
-
-def t_STRING1(t):
- r'\"[^"\n]*\"'
- t.type = 'STRING'
- return t
-
-def t_STRING2(t):
- r"\'[^'\n]*\'"
- t.type = 'STRING'
- return t
-
-
-def p_file(p):
- "file : decl_l"
- p[0] = [ x for x in p[1] if x is not None ]
-
-def p_error(t):
- raise ParseError("Syntax error", t)
-
-def p_empty(p):
- "empty :"
- pass
-
-def p_decl_l(p):
- "decl_l : decls"
- p[0] = p[1]
-
-def p_decls(p):
- """decls : decl decls
- | empty"""
- if len(p) == 3:
- p[0] = [ p[1] ] + p[2]
- elif len(p) == 2:
- p[0] = []
-
-def p_decl(p):
- """decl : d_machine
- | d_action
- | d_in_port
- | d_out_port
- | t_trans
- | d_extern
- | d_global
- | d_struct
- | d_enum
- | d_object
- | d_func_decl
- | d_func_def"""
- p[0] = p[1]
-
-def p_d_machine(p):
- """d_machine : MACHINE '(' ident pair_l ')' ':' param_l '{' decl_l '}'"""
-
- if len(p) == 9:
- decl_l = p[7]
- elif len(p) == 11:
- decl_l = p[9]
- decls = [ x for x in decl_l if x is not None ]
- p[0] = Machine(p[3], decls)
-
-def p_d_action(p):
- "d_action : ACTION '(' ident pair_l ')' statement_l"
- p[0] = Action(p[3])
-
-def p_d_in_port(p):
- "d_in_port : IN_PORT '(' ident ',' type ',' var pair_l ')' statement_l"
- p[0] = InPort(p[3])
-
-def p_d_out_port(p):
- "d_out_port : OUT_PORT '(' ident ',' type ',' var pair_l ')' SEMICOLON"
- p[0] = OutPort(p[3])
-
-def p_t_trans(p):
- """t_trans : TRANS '(' ident_l ',' ident_l ',' ident pair_l ')' ident_l
- | TRANS '(' ident_l ',' ident_l pair_l ')' ident_l"""
- p[0] = Transition("transition")
-
-def p_d_extern(p):
- """d_extern : EXTERN_TYPE '(' type pair_l ')' SEMICOLON
- | EXTERN_TYPE '(' type pair_l ')' '{' type_methods '}'"""
- p[0] = Extern(p[3])
-
-def p_d_global(p):
- "d_global : GLOBAL '(' type pair_l ')' '{' type_members '}'"
- p[0] = Global(p[3])
-
-def p_d_struct(p):
- "d_struct : STRUCT '(' type pair_l ')' '{' type_members '}'"
- p[0] = Struct(p[3])
-
-def p_d_enum(p):
- "d_enum : ENUM '(' type pair_l ')' '{' type_enums '}'"
- p[0] = Enum(p[3])
-
-def p_d_object(p):
- "d_object : type ident pair_l SEMICOLON"
- p[0] = Object(p[2])
-
-def p_d_func_decl(p):
- """d_func_decl : void ident '(' param_l ')' pair_l SEMICOLON
- | type ident '(' param_l ')' pair_l SEMICOLON"""
- pass
-
-def p_d_func_def(p):
- """d_func_def : void ident '(' param_l ')' pair_l statement_l
- | type ident '(' param_l ')' pair_l statement_l"""
- p[0] = Function(p[2])
-
-# Type fields
-def p_type_members(p):
- """type_members : type_member type_members
- | empty"""
- pass
-
-def p_type_member(p):
- """type_member : type ident pair_l SEMICOLON
- | type ident ASSIGN expr SEMICOLON"""
- pass
-
-# Methods
-def p_type_methods(p):
- """type_methods : type_method type_methods
- | empty"""
- pass
-
-def p_type_method(p):
- "type_method : type_or_void ident '(' type_l ')' pair_l SEMICOLON"
- pass
-
-# Enum fields
-def p_type_enums(p):
- """type_enums : type_enum type_enums
- | empty"""
- pass
-
-def p_type_enum(p):
- "type_enum : ident pair_l SEMICOLON"
- pass
-
-# Type
-def p_type_l(p):
- """type_l : types
- | empty"""
- pass
-
-def p_types(p):
- """types : type ',' types
- | type"""
- pass
-
-def p_type(p):
- "type : ident"
- p[0] = p[1]
-
-def p_void(p):
- "void : VOID"
- p[0] = None
-
-def p_type_or_void(p):
- """type_or_void : type
- | void"""
- p[0] = p[1]
-
-# Formal Param
-def p_param_l(p):
- """param_l : params
- | empty"""
- pass
-
-def p_params(p):
- """params : param ',' params
- | param"""
- pass
-
-def p_param(p):
- "param : type ident"
- pass
-
-# Idents and lists
-def p_ident(p):
- "ident : IDENT"
- p[0] = p[1]
-
-def p_ident_l(p):
- """ident_l : '{' idents '}'
- | ident"""
- p[0] = p[1]
-
-def p_idents(p):
- """idents : ident SEMICOLON idents
- | ident ',' idents
- | ident idents
- | empty"""
- pass
-
-# Pair and pair lists
-def p_pair_l(p):
- """pair_l : ',' pairs
- | empty"""
- if len(p) == 3:
- p[0] = p[2]
- elif len(p) == 2:
- p[0] = None
-
-def p_pairs(p):
- """pairs : pair ',' pairs
- | pair"""
- if len(p) == 4:
- p[3].append(p[1])
- p[0] = p[3]
- elif len(p) == 2:
- p[0] = [ p[1] ]
-
-def p_pair(p):
- """pair : ident '=' STRING
- | ident '=' ident
- | STRING"""
- if len(p) == 4:
- p[0] = p[1], p[3]
- elif len(p) == 2:
- p[0] = "short", p[1]
-
-# Below are the rules for action descriptions
-def p_statement_l(p):
- "statement_l : '{' statements '}'"
- pass
-
-def p_statements(p):
- """statements : statement statements
- | empty"""
- pass
-
-def p_expr_l(p):
- """expr_l : expr ',' expr_l
- | expr
- | empty"""
- pass
-
-def p_statement(p):
- """statement : expr SEMICOLON
- | expr ASSIGN expr SEMICOLON
- | ENQUEUE '(' var ',' type pair_l ')' statement_l
- | PEEK '(' var ',' type ')' statement_l
- | COPY_HEAD '(' var ',' var pair_l ')' SEMICOLON
- | CHECK_ALLOCATE '(' var ')' SEMICOLON
- | CHECK_STOP_SLOTS '(' var ',' STRING ',' STRING ')' SEMICOLON
- | if_statement
- | RETURN expr SEMICOLON"""
- pass
-
-def p_if_statement(p):
- """if_statement : IF '(' expr ')' statement_l ELSE statement_l
- | IF '(' expr ')' statement_l
- | IF '(' expr ')' statement_l ELSE if_statement"""
- pass
-
-def p_expr(p):
- """expr : var
- | literal
- | enumeration
- | ident '(' expr_l ')'
- | NEW type
- | THIS DOT var '[' expr ']' DOT var DOT ident '(' expr_l ')'
- | THIS DOT var '[' expr ']' DOT var DOT ident
- | CHIP '[' expr ']' DOT var '[' expr ']' DOT var DOT ident '(' expr_l ')'
- | CHIP '[' expr ']' DOT var '[' expr ']' DOT var DOT ident
- | expr DOT ident
- | expr DOT ident '(' expr_l ')'
- | type DOUBLE_COLON ident '(' expr_l ')'
- | expr '[' expr_l ']'
- | expr STAR expr
- | expr SLASH expr
- | expr PLUS expr
- | expr DASH expr
- | expr LT expr
- | expr GT expr
- | expr LE expr
- | expr GE expr
- | expr EQ expr
- | expr NE expr
- | expr AND expr
- | expr OR expr
- | NOT expr
- | expr RIGHTSHIFT expr
- | expr LEFTSHIFT expr
- | '(' expr ')'"""
- pass
-
-def p_literal(p):
- """literal : STRING
- | NUMBER
- | FLOATNUMBER
- | LIT_BOOL"""
- pass
-
-def p_enumeration(p):
- "enumeration : ident ':' ident"
- pass
-
-def p_var(p):
- "var : ident"
- pass
-
-lex.lex()
-yacc.yacc(write_tables=0)
-
-slicc_generated_cc = set([
- 'ControllerFactory.cc',
- 'MachineType.cc'])
-
-slicc_generated_hh = set([
- 'ControllerFactory.hh',
- 'MachineType.hh',
- 'Types.hh',
- 'protocol_name.hh' ])
-
-class Machine(object):
- def __init__(self, name, decls):
- self.name = name
- self.decls = decls
-
- def add(self, hh, cc):
- hh.add('%s_Controller.hh' % self.name)
- hh.add('%s_Profiler.hh' % self.name)
-
- cc.add('%s_Controller.cc' % self.name)
- cc.add('%s_Profiler.cc' % self.name)
- cc.add('%s_Transitions.cc' % self.name)
- cc.add('%s_Wakeup.cc' % self.name)
-
- for decl in self.decls:
- decl.add(hh, cc, self.name)
-
-class Declaration(object):
- hh = False
- cc = False
- def __init__(self, name):
- self.name = name
-
- def add(self, hh, cc, name=None):
- #print '>>>', type(self).__name__, self.name
- if name:
- name += '_'
- else:
- name = ""
- if self.hh:
- hh.add('%s%s.hh' % (name, self.name))
- if self.cc:
- cc.add('%s%s.cc' % (name, self.name))
-
-class Action(Declaration): pass
-class InPort(Declaration): pass
-class OutPort(Declaration): pass
-class Transition(Declaration): pass
-class Extern(Declaration): pass
-class Global(Declaration):
- hh = True
- cc = True
-class Struct(Declaration):
- hh = True
- cc = True
-class Enum(Declaration):
- hh = True
- cc = True
-class Object(Declaration): pass
-class Function(Declaration):
- cc = True
-
-def read_slicc(sources):
- if not isinstance(sources, (list,tuple)):
- sources = [ sources ]
-
- sm_files = []
- for source in sources:
- for sm_file in file(source, "r"):
- sm_file = sm_file.strip()
- if not sm_file:
- continue
- if sm_file.startswith("#"):
- continue
- sm_files.append(sm_file)
-
- return sm_files
-
-def scan(filenames):
- hh = slicc_generated_hh.copy()
- cc = slicc_generated_cc.copy()
-
- for filename in filenames:
- lex.lexer.lineno = 1
- try:
- print "parsing ",filename
- results = yacc.parse(file(filename, 'r').read())
- except (TokenError, ParseError), e:
- sys.exit("%s: %s:%d" % (e, filename, e.token.lineno))
-
- for result in results:
- result.add(hh, cc)
-
- return list(hh), list(cc)
-
-if __name__ == '__main__':
- import sys
-
- hh, cc = scan(read_slicc(sys.argv[1:]))
- hh.sort()
- cc.sort()
- print 'Headers:'
- for i in hh:
- print ' %s' % i
-
- print 'Sources:'
- for i in cc:
- print ' %s' % i
diff --git a/src/mem/slicc/parser/parser.yy b/src/mem/slicc/parser/parser.yy
deleted file mode 100644
index c8cef3b21..000000000
--- a/src/mem/slicc/parser/parser.yy
+++ /dev/null
@@ -1,360 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * $Id$
- *
- * */
-
-%{
-#include <string>
-#include <stdio.h>
-#include <assert.h>
-#include "mem/slicc/ast/ASTs.hh"
-#include <vector>
-
-#define YYMAXDEPTH 100000
-#define YYERROR_VERBOSE
-
-extern char* yytext;
-
-extern "C" void yyerror(char*);
-extern "C" int yylex();
-
-%}
-
-%union {
- string* str_ptr;
- Vector<string>* string_vector_ptr;
- std::vector<string*>* stdstring_vector_ptr;
-
- // Decls
- DeclAST* decl_ptr;
- DeclListAST* decl_list_ptr;
- Vector<DeclAST*>* decl_vector_ptr;
-
- // TypeField
- TypeFieldAST* type_field_ptr;
- Vector<TypeFieldAST*>* type_field_vector_ptr;
-
- // Type
- TypeAST* type_ptr;
- Vector<TypeAST*>* type_vector_ptr;
-
- // Formal Params
- FormalParamAST* formal_param_ptr;
- Vector<FormalParamAST*>* formal_param_vector_ptr;
-
- // Statements
- StatementAST* statement_ptr;
- StatementListAST* statement_list_ptr;
- Vector<StatementAST*>* statement_vector_ptr;
-
- // Pairs
- PairAST* pair_ptr;
- PairListAST* pair_list_ptr;
-
- // Expressions
- VarExprAST* var_expr_ptr;
- ExprAST* expr_ptr;
- Vector<ExprAST*>* expr_vector_ptr;
-}
-
-%type <type_ptr> type void type_or_void
-%type <type_vector_ptr> types type_list
-
- // Formal Params
-%type <formal_param_ptr> formal_param
-%type <formal_param_vector_ptr> formal_params formal_param_list
-
-%type <str_ptr> ident field
-%type <string_vector_ptr> ident_list idents
-
-%type <statement_ptr> statement if_statement
-%type <statement_list_ptr> statement_list
-%type <statement_vector_ptr> statements
-
-%type <decl_ptr> decl
-%type <decl_list_ptr> decl_list
-%type <decl_vector_ptr> decls
-
-%type <type_field_vector_ptr> type_members type_enums type_methods
-%type <type_field_ptr> type_member type_enum type_method
-
-%type <var_expr_ptr> var
-%type <expr_ptr> expr literal enumeration
-%type <expr_vector_ptr> expr_list
-
-%type <pair_ptr> pair
-%type <pair_list_ptr> pair_list pairs
-
-%token <str_ptr> IDENT STRING NUMBER FLOATNUMBER LIT_BOOL VOID
-%token <str_ptr> IMBED IMBED_TYPE
-%token CHIP THIS
-%token ASSIGN DOUBLE_COLON DOT SEMICOLON COLON
-%token GLOBAL_DECL MACHINE_DECL IN_PORT_DECL OUT_PORT_DECL
-%token PEEK ENQUEUE COPY_HEAD CHECK_ALLOCATE CHECK_STOP_SLOTS
-//%token DEQUEUE REMOVE_EARLY SKIP_EARLY PEEK_EARLY
-%token DEBUG_EXPR_TOKEN DEBUG_MSG_TOKEN
-%token ACTION_DECL TRANSITION_DECL TYPE_DECL STRUCT_DECL EXTERN_TYPE_DECL ENUM_DECL
-%token TYPE_FIELD OTHER IF ELSE RETURN NEW
-
-%token <str_ptr> EQ NE '<' '>' LE GE NOT AND OR PLUS DASH STAR SLASH RIGHTSHIFT LEFTSHIFT
-
-%left OR
-%left AND
-%nonassoc EQ NE
-%nonassoc '<' '>' GE LE
-%left PLUS DASH
-%left STAR SLASH
-%nonassoc NOT
-%nonassoc DOUBLE_COLON DOT '['
-
-%%
-
-file: decl_list { g_decl_list_ptr = $1; }
-
-decl_list: decls { $$ = new DeclListAST($1); }
-
-decls: decl decls { $2->insertAtTop($1); $$ = $2; }
- | { $$ = new Vector<DeclAST*>; }
- ;
-
-decl: MACHINE_DECL '(' ident pair_list ')' ':' formal_param_list '{' decl_list '}' { $$ = new MachineAST($3, $4, $7, $9); }
- | ACTION_DECL '(' ident pair_list ')' statement_list { $$ = new ActionDeclAST($3, $4, $6); }
- | IN_PORT_DECL '(' ident ',' type ',' var pair_list ')' statement_list { $$ = new InPortDeclAST($3, $5, $7, $8, $10); }
- | OUT_PORT_DECL '(' ident ',' type ',' var pair_list ')' SEMICOLON { $$ = new OutPortDeclAST($3, $5, $7, $8); }
- | TRANSITION_DECL '(' ident_list ',' ident_list ',' ident pair_list ')' ident_list { $$ = new TransitionDeclAST($3, $5, $7, $8, $10); }
- | TRANSITION_DECL '(' ident_list ',' ident_list pair_list ')' ident_list { $$ = new TransitionDeclAST($3, $5, NULL, $6, $8); }
- | EXTERN_TYPE_DECL '(' type pair_list ')' SEMICOLON { $4->addPair(new PairAST("external", "yes")); $$ = new TypeDeclAST($3, $4, NULL); }
- | EXTERN_TYPE_DECL '(' type pair_list ')' '{' type_methods '}' { $4->addPair(new PairAST("external", "yes")); $$ = new TypeDeclAST($3, $4, $7); }
- | GLOBAL_DECL '(' type pair_list ')' '{' type_members '}' { $4->addPair(new PairAST("global", "yes"));$$ = new TypeDeclAST($3, $4, $7); }
- | STRUCT_DECL '(' type pair_list ')' '{' type_members '}' { $$ = new TypeDeclAST($3, $4, $7); }
- | ENUM_DECL '(' type pair_list ')' '{' type_enums '}' { $4->addPair(new PairAST("enumeration", "yes")); $$ = new EnumDeclAST($3, $4, $7); }
- | type ident pair_list SEMICOLON { $$ = new ObjDeclAST($1, $2, $3); }
- | type ident '(' formal_param_list ')' pair_list SEMICOLON { $$ = new FuncDeclAST($1, $2, $4, $6, NULL); } // non-void function
- | void ident '(' formal_param_list ')' pair_list SEMICOLON { $$ = new FuncDeclAST($1, $2, $4, $6, NULL); } // void function
- | type ident '(' formal_param_list ')' pair_list statement_list { $$ = new FuncDeclAST($1, $2, $4, $6, $7); } // non-void function
- | void ident '(' formal_param_list ')' pair_list statement_list { $$ = new FuncDeclAST($1, $2, $4, $6, $7); } // void function
- ;
-
-// Type fields
-
-type_members: type_member type_members { $2->insertAtTop($1); $$ = $2; }
- | { $$ = new Vector<TypeFieldAST*>; }
- ;
-
-type_member: type ident pair_list SEMICOLON { $$ = new TypeFieldMemberAST($1, $2, $3, NULL); }
- | type ident ASSIGN expr SEMICOLON { $$ = new TypeFieldMemberAST($1, $2, new PairListAST(), $4); }
- ;
-
-// Methods
-type_methods: type_method type_methods { $2->insertAtTop($1); $$ = $2; }
- | { $$ = new Vector<TypeFieldAST*>; }
- ;
-
-type_method: type_or_void ident '(' type_list ')' pair_list SEMICOLON { $$ = new TypeFieldMethodAST($1, $2, $4, $6); }
- ;
-
-// Enum fields
-type_enums: type_enum type_enums { $2->insertAtTop($1); $$ = $2; }
- | { $$ = new Vector<TypeFieldAST*>; }
- ;
-
-type_enum: ident pair_list SEMICOLON { $$ = new TypeFieldEnumAST($1, $2); }
- ;
-
-// Type
-type_list : types { $$ = $1; }
- | { $$ = new Vector<TypeAST*>; }
- ;
-
-types : type ',' types { $3->insertAtTop($1); $$ = $3; }
- | type { $$ = new Vector<TypeAST*>; $$->insertAtTop($1); }
- ;
-
-type: ident { $$ = new TypeAST($1); }
- ;
-
-void: VOID { $$ = new TypeAST($1); }
- ;
-
-type_or_void: type { $$ = $1; }
- | void { $$ = $1; }
- ;
-
-// Formal Param
-formal_param_list : formal_params { $$ = $1; }
- | { $$ = new Vector<FormalParamAST*>; }
- ;
-
-formal_params : formal_param ',' formal_params { $3->insertAtTop($1); $$ = $3; }
- | formal_param { $$ = new Vector<FormalParamAST*>; $$->insertAtTop($1); }
- ;
-
-formal_param : type ident { $$ = new FormalParamAST($1, $2); }
- ;
-
-// Idents and lists
-ident: IDENT { $$ = $1; };
-
-ident_list: '{' idents '}' { $$ = $2; }
- | ident { $$ = new Vector<string>; $$->insertAtTop(*($1)); delete $1; }
- ;
-
-idents: ident SEMICOLON idents { $3->insertAtTop(*($1)); $$ = $3; delete $1; }
- | ident ',' idents { $3->insertAtTop(*($1)); $$ = $3; delete $1; }
- | ident idents { $2->insertAtTop(*($1)); $$ = $2; delete $1; }
- | { $$ = new Vector<string>; }
- ;
-
-// Pair and pair lists
-pair_list: ',' pairs { $$ = $2; }
- | { $$ = new PairListAST(); }
-
-pairs : pair ',' pairs { $3->addPair($1); $$ = $3; }
- | pair { $$ = new PairListAST(); $$->addPair($1); }
- ;
-
-pair : ident '=' STRING { $$ = new PairAST($1, $3); }
- | ident '=' ident { $$ = new PairAST($1, $3); }
- | STRING { $$ = new PairAST(new string("short"), $1); }
- ;
-
-// Below are the rules for action descriptions
-
-statement_list: '{' statements '}' { $$ = new StatementListAST($2); }
- ;
-
-statements: statement statements { $2->insertAtTop($1); $$ = $2; }
- | { $$ = new Vector<StatementAST*>; }
- ;
-
-expr_list: expr ',' expr_list { $3->insertAtTop($1); $$ = $3; }
- | expr { $$ = new Vector<ExprAST*>; $$->insertAtTop($1); }
- | { $$ = new Vector<ExprAST*>; }
- ;
-
-statement: expr SEMICOLON { $$ = new ExprStatementAST($1); }
- | expr ASSIGN expr SEMICOLON { $$ = new AssignStatementAST($1, $3); }
- | ENQUEUE '(' var ',' type pair_list ')' statement_list { $$ = new EnqueueStatementAST($3, $5, $6, $8); }
- | PEEK '(' var ',' type ')' statement_list { $$ = new PeekStatementAST($3, $5, $7, "peek"); }
-// | PEEK_EARLY '(' var ',' type ')' statement_list { $$ = new PeekStatementAST($3, $5, $7, "peekEarly"); }
- | COPY_HEAD '(' var ',' var pair_list ')' SEMICOLON { $$ = new CopyHeadStatementAST($3, $5, $6); }
- | CHECK_ALLOCATE '(' var ')' SEMICOLON { $$ = new CheckAllocateStatementAST($3); }
- | CHECK_STOP_SLOTS '(' var ',' STRING ',' STRING ')' SEMICOLON { $$ = new CheckStopSlotsStatementAST($3, $5, $7); }
- | if_statement { $$ = $1; }
- | RETURN expr SEMICOLON { $$ = new ReturnStatementAST($2); }
- ;
-
-if_statement: IF '(' expr ')' statement_list ELSE statement_list { $$ = new IfStatementAST($3, $5, $7); }
- | IF '(' expr ')' statement_list { $$ = new IfStatementAST($3, $5, NULL); }
- | IF '(' expr ')' statement_list ELSE if_statement { $$ = new IfStatementAST($3, $5, new StatementListAST($7)); }
- ;
-
-expr: var { $$ = $1; }
- | literal { $$ = $1; }
- | enumeration { $$ = $1; }
- | ident '(' expr_list ')' { $$ = new FuncCallExprAST($1, $3); }
- | NEW type { $$ = new NewExprAST($2); }
-
-// globally access a local chip component and call a method
- | THIS DOT var '[' expr ']' DOT var DOT ident '(' expr_list ')' { $$ = new ChipComponentAccessAST($3, $5, $8, $10, $12 ); }
-// globally access a local chip component and access a data member
- | THIS DOT var '[' expr ']' DOT var DOT field { $$ = new ChipComponentAccessAST($3, $5, $8, $10 ); }
-// globally access a specified chip component and call a method
- | CHIP '[' expr ']' DOT var '[' expr ']' DOT var DOT ident '(' expr_list ')' { $$ = new ChipComponentAccessAST($3, $6, $8, $11, $13, $15 ); }
-// globally access a specified chip component and access a data member
- | CHIP '[' expr ']' DOT var '[' expr ']' DOT var DOT field { $$ = new ChipComponentAccessAST($3, $6, $8, $11, $13 ); }
-
-
- | expr DOT field { $$ = new MemberExprAST($1, $3); }
- | expr DOT ident '(' expr_list ')' { $$ = new MethodCallExprAST($1, $3, $5); }
- | type DOUBLE_COLON ident '(' expr_list ')' { $$ = new MethodCallExprAST($1, $3, $5); }
- | expr '[' expr_list ']' { $$ = new MethodCallExprAST($1, new string("lookup"), $3); }
- | expr STAR expr { $$ = new InfixOperatorExprAST($1, $2, $3); }
- | expr SLASH expr { $$ = new InfixOperatorExprAST($1, $2, $3); }
- | expr PLUS expr { $$ = new InfixOperatorExprAST($1, $2, $3); }
- | expr DASH expr { $$ = new InfixOperatorExprAST($1, $2, $3); }
- | expr '<' expr { $$ = new InfixOperatorExprAST($1, $2, $3); }
- | expr '>' expr { $$ = new InfixOperatorExprAST($1, $2, $3); }
- | expr LE expr { $$ = new InfixOperatorExprAST($1, $2, $3); }
- | expr GE expr { $$ = new InfixOperatorExprAST($1, $2, $3); }
- | expr EQ expr { $$ = new InfixOperatorExprAST($1, $2, $3); }
- | expr NE expr { $$ = new InfixOperatorExprAST($1, $2, $3); }
- | expr AND expr { $$ = new InfixOperatorExprAST($1, $2, $3); }
- | expr OR expr { $$ = new InfixOperatorExprAST($1, $2, $3); }
- | expr RIGHTSHIFT expr { $$ = new InfixOperatorExprAST($1, $2, $3); }
- | expr LEFTSHIFT expr { $$ = new InfixOperatorExprAST($1, $2, $3); }
-// | NOT expr { $$ = NULL; } // FIXME - unary not
-// | DASH expr %prec NOT { $$ = NULL; } // FIXME - unary minus
- | '(' expr ')' { $$ = $2; }
- ;
-
-literal: STRING { $$ = new LiteralExprAST($1, "string"); }
- | NUMBER { $$ = new LiteralExprAST($1, "int"); }
- | FLOATNUMBER { $$ = new LiteralExprAST($1, "int"); }
- | LIT_BOOL { $$ = new LiteralExprAST($1, "bool"); }
- ;
-
-enumeration: ident ':' ident { $$ = new EnumExprAST(new TypeAST($1), $3); }
- ;
-
-var: ident { $$ = new VarExprAST($1); }
- ;
-
-field: ident { $$ = $1; }
- ;
-
-%%
-
-extern FILE *yyin;
-
-DeclListAST* parse(string filename)
-{
- FILE *file;
- file = fopen(filename.c_str(), "r");
- if (!file) {
- cerr << "Error: Could not open file: " << filename << endl;
- exit(1);
- }
- g_line_number = 1;
- g_file_name() = filename;
- yyin = file;
- g_decl_list_ptr = NULL;
- yyparse();
- return g_decl_list_ptr;
-}
-
-extern "C" void yyerror(char* s)
-{
- fprintf(stderr, "%s:%d: %s at %s\n", g_file_name().c_str(), g_line_number, s, yytext);
- exit(1);
-}
-
diff --git a/src/mem/slicc/slicc_global.hh b/src/mem/slicc/slicc_global.hh
deleted file mode 100644
index 40a00c9d2..000000000
--- a/src/mem/slicc/slicc_global.hh
+++ /dev/null
@@ -1,125 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef SLICC_GLOBAL_H
-#define SLICC_GLOBAL_H
-
-#include <cassert>
-
-#include "mem/gems_common/std-includes.hh"
-#include "mem/gems_common/Map.hh"
-
-typedef unsigned char uint8;
-typedef unsigned int uint32;
-typedef unsigned long long uint64;
-
-typedef signed char int8;
-typedef int int32;
-typedef long long int64;
-
-typedef long long integer_t;
-typedef unsigned long long uinteger_t;
-
-const bool ASSERT_FLAG = true;
-
-// when CHECK_RESOURCE_DEADLOCK is enabled, slicc will generate additional code
-// that works in conjuction with the resources rank value specified in the protocol
-// to detect invalid resource stalls as soon as they occur.
-const bool CHECK_INVALID_RESOURCE_STALLS = false;
-
-#undef assert
-#define assert(EXPR) ASSERT(EXPR)
-
-#define ASSERT(EXPR)\
-{\
- if (ASSERT_FLAG) {\
- if (!(EXPR)) {\
- cerr << "failed assertion '"\
- << #EXPR << "' at fn "\
- << __PRETTY_FUNCTION__ << " in "\
- << __FILE__ << ":"\
- << __LINE__ << endl;\
- if(isatty(STDERR_FILENO)) {\
- cerr << "At this point you might want to attach a debug to ";\
- cerr << "the running and get to the" << endl;\
- cerr << "crash site; otherwise press enter to continue" << endl;\
- cerr << "PID: " << getpid();\
- cerr << endl << flush; \
- char c; \
- cin.get(c); \
- }\
- abort();\
- }\
- }\
-}
-
-class State;
-class Event;
-class Symbol;
-class Var;
-
-namespace __gnu_cxx {
- template <> struct hash<State*>
- {
- size_t operator()(State* s) const { return (size_t) s; }
- };
- template <> struct hash<Event*>
- {
- size_t operator()(Event* s) const { return (size_t) s; }
- };
- template <> struct hash<Symbol*>
- {
- size_t operator()(Symbol* s) const { return (size_t) s; }
- };
- template <> struct hash<Var*>
- {
- size_t operator()(Var* s) const { return (size_t) s; }
- };
-} // namespace __gnu_cxx
-
-namespace std {
- template <> struct equal_to<Event*>
- {
- bool operator()(Event* s1, Event* s2) const { return s1 == s2; }
- };
- template <> struct equal_to<State*>
- {
- bool operator()(State* s1, State* s2) const { return s1 == s2; }
- };
- template <> struct equal_to<Symbol*>
- {
- bool operator()(Symbol* s1, Symbol* s2) const { return s1 == s2; }
- };
- template <> struct equal_to<Var*>
- {
- bool operator()(Var* s1, Var* s2) const { return s1 == s2; }
- };
-} // namespace std
-
-#endif //SLICC_GLOBAL_H
diff --git a/src/mem/slicc/symbols/Action.hh b/src/mem/slicc/symbols/Action.hh
deleted file mode 100644
index dbb0c836a..000000000
--- a/src/mem/slicc/symbols/Action.hh
+++ /dev/null
@@ -1,52 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * $Id$
- */
-
-#ifndef ACTION_H
-#define ACTION_H
-
-#include "mem/slicc/symbols/Symbol.hh"
-
-class Action : public Symbol {
-public:
- Action(string id,
- const Map<Var*, string>& resources,
- const Location& location,
- const Map<string, string>& pairs) : Symbol(id, location, pairs) { m_resources = resources; }
- const Map<Var*, string>& getResources() const { return m_resources; }
- void print(ostream& out) const { out << "[Action: " << getIdent() << "]"; }
-
-private:
- Map<Var*, string> m_resources;
-};
-
-#endif //ACTION_H
diff --git a/src/mem/slicc/symbols/Action.py b/src/mem/slicc/symbols/Action.py
new file mode 100644
index 000000000..880fab15a
--- /dev/null
+++ b/src/mem/slicc/symbols/Action.py
@@ -0,0 +1,38 @@
+# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
+# Copyright (c) 2009 The Hewlett-Packard Development Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (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 slicc.symbols.Symbol import Symbol
+
+class Action(Symbol):
+ def __init__(self, table, ident, resources, location, pairs):
+ super(Action, self).__init__(table, ident, location, pairs)
+ self.resources = resources
+
+ def __repr__(self):
+ return "[Action: %s]" % self.ident
+
+__all__ = [ "Action" ]
diff --git a/src/mem/slicc/symbols/Event.hh b/src/mem/slicc/symbols/Event.hh
deleted file mode 100644
index 40cefc982..000000000
--- a/src/mem/slicc/symbols/Event.hh
+++ /dev/null
@@ -1,45 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * $Id$
- */
-
-#ifndef EVENT_H
-#define EVENT_H
-
-#include "mem/slicc/symbols/Symbol.hh"
-
-class Event : public Symbol {
-public:
- Event(string id, const Location& location, const Map<string, string>& pairs) : Symbol(id, location, pairs) {}
- void print(ostream& out) const { out << "[Event: " << getIdent() << "]"; }
-};
-
-#endif //EVENT_H
diff --git a/src/mem/slicc/symbols/Event.py b/src/mem/slicc/symbols/Event.py
new file mode 100644
index 000000000..9ff4d8ba7
--- /dev/null
+++ b/src/mem/slicc/symbols/Event.py
@@ -0,0 +1,34 @@
+# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
+# Copyright (c) 2009 The Hewlett-Packard Development Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (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 slicc.symbols.Symbol import Symbol
+
+class Event(Symbol):
+ def __repr__(self):
+ return "[Event: %s]" % self.ident
+
+__all__ = [ "Event" ]
diff --git a/src/mem/slicc/symbols/Func.cc b/src/mem/slicc/symbols/Func.cc
deleted file mode 100644
index d29138b38..000000000
--- a/src/mem/slicc/symbols/Func.cc
+++ /dev/null
@@ -1,143 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * Func.cc
- *
- * Description: See Func.hh
- *
- * $Id$
- *
- */
-
-#include "mem/slicc/symbols/Func.hh"
-#include "mem/slicc/symbols/SymbolTable.hh"
-#include "mem/slicc/generator/fileio.hh"
-#include "mem/slicc/symbols/StateMachine.hh"
-
-Func::Func(string id, const Location& location,
- Type* type_ptr, const Vector<Type*>& param_type_vec,
- const Vector<string>& param_string_vec, string body,
- const Map<string, string>& pairs, StateMachine* machine_ptr)
- : Symbol(id, location, pairs)
-{
- m_type_ptr = type_ptr;
- m_param_type_vec = param_type_vec;
- m_param_string_vec = param_string_vec;
- m_body = body;
- m_isInternalMachineFunc = false;
-
- if (machine_ptr == NULL) {
- m_c_ident = id;
- } else if (existPair("external") || existPair("primitive")) {
- m_c_ident = id;
- } else {
- m_machineStr = machine_ptr->toString();
- m_c_ident = m_machineStr + "_" + id; // Append with machine name
- m_isInternalMachineFunc = true;
- }
-}
-
-void Func::funcPrototype(string& code) const
-{
- if (isExternal()) {
- // Do nothing
- } else {
- string return_type = m_type_ptr->cIdent();
- Type* void_type_ptr = g_sym_table.getType("void");
- if (existPair("return_by_ref") && (m_type_ptr != void_type_ptr)) {
- return_type += "&";
- }
- code += return_type + " " + cIdent() + "(";
- int size = m_param_string_vec.size();
- for(int i=0; i<size; i++) {
- // Generate code
- if (i != 0) {
- code += ", ";
- }
- code += m_param_string_vec[i];
- }
- code += ");\n";
- }
-}
-
-// This write a function of object Chip
-void Func::writeCFiles(string path)
-{
- if (isExternal()) {
- // Do nothing
- } else {
- ostringstream out;
-
- // Header
- out << "/** Auto generated C++ code started by "<<__FILE__<<":"<<__LINE__<< " */" << endl;
- out << endl;
- out << "#include \"mem/protocol/Types.hh\"" << endl;
- if (m_isInternalMachineFunc) {
- out << "#include \"mem/protocol/" << m_machineStr << "_Controller.hh\"" << endl;
- }
- out << endl;
-
- // Generate function header
- string code;
- Type* void_type_ptr = g_sym_table.getType("void");
- string return_type = m_type_ptr->cIdent();
- code += return_type;
- if (existPair("return_by_ref") && m_type_ptr != void_type_ptr) {
- code += "&";
- }
- if (!m_isInternalMachineFunc) {
- code += " Chip::" + cIdent() + "(";
- } else {
- code += " " + m_machineStr + "_Controller::" + cIdent() + "(";
- }
- int size = m_param_type_vec.size();
- for(int i=0; i<size; i++) {
- // Generate code
- if (i != 0) {
- code += ", ";
- }
- code += m_param_string_vec[i];
- }
- code += ")";
-
- // Function body
- code += "\n{\n";
- code += m_body;
- code += "}\n";
- out << code << endl;
-
- // Write it out
- conditionally_write_file(path + cIdent() + ".cc", out);
- }
-}
-
-void Func::print(ostream& out) const
-{
-}
diff --git a/src/mem/slicc/symbols/Func.hh b/src/mem/slicc/symbols/Func.hh
deleted file mode 100644
index 8f8548bb0..000000000
--- a/src/mem/slicc/symbols/Func.hh
+++ /dev/null
@@ -1,96 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * Func.hh
- *
- * Description:
- *
- * $Id$
- *
- */
-
-#ifndef FUNC_H
-#define FUNC_H
-
-#include "mem/slicc/slicc_global.hh"
-#include "mem/slicc/symbols/Type.hh"
-class StateMachine;
-
-class Func : public Symbol {
-public:
- // Constructors
- Func(string id, const Location& location,
- Type* type_ptr, const Vector<Type*>& param_type_vec, const Vector<string>& param_string_vec,
- string body, const Map<string, string>& pairs, StateMachine* machine_ptr);
-
- // Destructor
- ~Func() {}
-
- // Public Methods
- string cIdent() const { return m_c_ident; }
- const Vector<Type*>& getParamTypes() const { return m_param_type_vec; }
- Type* getReturnType() const { return m_type_ptr; }
- void writeCFiles(string path) ;
- void funcPrototype(string& code) const;
- bool isExternal() const { return existPair("external"); }
- bool isInternalMachineFunc() const { return m_isInternalMachineFunc; }
- void print(ostream& out) const;
-private:
- // Private Methods
-
- // Private copy constructor and assignment operator
- Func(const Func& obj);
- Func& operator=(const Func& obj);
-
- // Data Members (m_ prefix)
- Type* m_type_ptr;
- Vector<Type*> m_param_type_vec;
- Vector<string> m_param_string_vec;
- string m_body;
- string m_c_ident;
- string m_machineStr;
- bool m_isInternalMachineFunc;
-};
-
-// Output operator declaration
-ostream& operator<<(ostream& out, const Func& obj);
-
-// ******************* Definitions *******************
-
-// Output operator definition
-extern inline
-ostream& operator<<(ostream& out, const Func& obj)
-{
- obj.print(out);
- out << flush;
- return out;
-}
-
-#endif //FUNC_H
diff --git a/src/mem/slicc/symbols/Func.py b/src/mem/slicc/symbols/Func.py
new file mode 100644
index 000000000..5c812a96f
--- /dev/null
+++ b/src/mem/slicc/symbols/Func.py
@@ -0,0 +1,107 @@
+# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
+# Copyright (c) 2009 The Hewlett-Packard Development Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (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 slicc.symbols.Symbol import Symbol
+from slicc.symbols.Type import Type
+
+class Func(Symbol):
+ def __init__(self, table, ident, location, return_type, param_types,
+ param_strings, body, pairs, machine):
+ super(Func, self).__init__(table, ident, location, pairs)
+ self.return_type = return_type
+ self.param_types = param_types
+ self.param_strings = param_strings
+ self.body = body
+ self.isInternalMachineFunc = False
+
+ if machine is None:
+ self.c_ident = ident
+ elif "external" in self or "primitive" in self:
+ self.c_ident = ident
+ else:
+ self.machineStr = str(machine)
+ # Append with machine name
+ self.c_ident = "%s_%s" % (self.machineStr, ident)
+ self.isInternalMachineFunc = True
+
+ def __repr__(self):
+ return ""
+
+ @property
+ def prototype(self):
+ if "external" in self:
+ return ""
+
+ return_type = self.return_type.c_ident
+ void_type = self.symtab.find("void", Type)
+ if "return_by_ref" in self and self.return_type != void_type:
+ return_type += "&"
+
+ return "%s %s(%s);" % (return_type, self.c_ident,
+ ", ".join(self.param_strings))
+
+ def writeCodeFiles(self, path):
+ '''This write a function of object Chip'''
+ if "external" in self:
+ return
+
+ code = code_formatter()
+
+ # Header
+ code('''
+/** Auto generated C++ code started by $__file__:$__line__ */
+
+#include "mem/protocol/Types.hh"
+''')
+
+ if self.isInternalMachineFunc:
+ code('#include "mem/protocol/${{self.machineStr}}_Controller.hh"')
+
+ # Generate function header
+ void_type = self.symtab.find("void", Type)
+ return_type = self.return_type.c_ident
+ if "return_by_ref" in self and self.return_type != void_type:
+ return_type += "&"
+
+ if self.isInternalMachineFunc:
+ klass = "%s_Controller" % self.machineStr
+ else:
+ klass = "Chip"
+
+ params = ', '.join(self.param_strings)
+
+ code('''
+$return_type ${klass}::${{self.c_ident}}($params)
+{
+${{self.body}}
+}
+''')
+ code.write(path, "%s.cc" % self.c_ident)
+
+__all__ = [ "Func" ]
diff --git a/src/mem/slicc/symbols/State.hh b/src/mem/slicc/symbols/State.hh
deleted file mode 100644
index 39900d506..000000000
--- a/src/mem/slicc/symbols/State.hh
+++ /dev/null
@@ -1,45 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * $Id$
- */
-
-#ifndef STATE_H
-#define STATE_H
-
-#include "mem/slicc/symbols/Symbol.hh"
-
-class State : public Symbol {
-public:
- State(string id, const Location& location, const Map<string, string>& pairs) : Symbol(id, location, pairs) {}
- void print(ostream& out) const { out << "[State: " << getIdent() << "]"; }
-};
-
-#endif //STATE_H
diff --git a/src/mem/slicc/symbols/State.py b/src/mem/slicc/symbols/State.py
new file mode 100644
index 000000000..123693256
--- /dev/null
+++ b/src/mem/slicc/symbols/State.py
@@ -0,0 +1,34 @@
+# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
+# Copyright (c) 2009 The Hewlett-Packard Development Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (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 slicc.symbols.Symbol import Symbol
+
+class State(Symbol):
+ def __repr__(self):
+ return "[State: %s]" % self.ident
+
+__all__ = [ "State" ]
diff --git a/src/mem/slicc/symbols/StateMachine.cc b/src/mem/slicc/symbols/StateMachine.cc
deleted file mode 100644
index 86f92b692..000000000
--- a/src/mem/slicc/symbols/StateMachine.cc
+++ /dev/null
@@ -1,1534 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * $Id$
- *
- * */
-
-#include "mem/slicc/symbols/StateMachine.hh"
-#include "mem/slicc/generator/fileio.hh"
-#include "mem/slicc/generator/html_gen.hh"
-#include "mem/slicc/symbols/Action.hh"
-#include "mem/slicc/symbols/Event.hh"
-#include "mem/slicc/symbols/State.hh"
-#include "mem/slicc/symbols/Transition.hh"
-#include "mem/slicc/symbols/Var.hh"
-#include "mem/slicc/symbols/SymbolTable.hh"
-#include "mem/gems_common/util.hh"
-#include "mem/gems_common/Vector.hh"
-#include "mem/slicc/ast/FormalParamAST.hh"
-
-#include <set>
-
-StateMachine::StateMachine(string ident, const Location& location, const Map<string, string>& pairs, Vector<FormalParamAST*>* config_parameters)
- : Symbol(ident, location, pairs)
-{
- m_table_built = false;
- m_config_parameters = config_parameters;
-
- for (int i=0; i< m_config_parameters->size(); i++) {
- Var* var = new Var(m_config_parameters->ref(i)->getName(),
- location,
- m_config_parameters->ref(i)->getType(),
- "m_"+m_config_parameters->ref(i)->getName(),
- Map<string, string>(),
- this);
- g_sym_table.registerSym(m_config_parameters->ref(i)->getName(), var);
- }
-}
-
-StateMachine::~StateMachine()
-{
- // FIXME
- // assert(0);
-}
-
-void StateMachine::addState(State* state_ptr)
-{
- assert(m_table_built == false);
- m_state_map.add(state_ptr, m_states.size());
- m_states.insertAtBottom(state_ptr);
-}
-
-void StateMachine::addEvent(Event* event_ptr)
-{
- assert(m_table_built == false);
- m_event_map.add(event_ptr, m_events.size());
- m_events.insertAtBottom(event_ptr);
-}
-
-void StateMachine::addAction(Action* action_ptr)
-{
- assert(m_table_built == false);
-
- // Check for duplicate action
- int size = m_actions.size();
- for(int i=0; i<size; i++) {
- if (m_actions[i]->getIdent() == action_ptr->getIdent()) {
- m_actions[i]->warning("Duplicate action definition: " + m_actions[i]->getIdent());
- action_ptr->error("Duplicate action definition: " + action_ptr->getIdent());
- }
- if (m_actions[i]->getShorthand() == action_ptr->getShorthand()) {
- m_actions[i]->warning("Duplicate action shorthand: " + m_actions[i]->getIdent());
- m_actions[i]->warning(" shorthand = " + m_actions[i]->getShorthand());
- action_ptr->warning("Duplicate action shorthand: " + action_ptr->getIdent());
- action_ptr->error(" shorthand = " + action_ptr->getShorthand());
- }
- }
-
- m_actions.insertAtBottom(action_ptr);
-}
-
-void StateMachine::addTransition(Transition* trans_ptr)
-{
- assert(m_table_built == false);
- trans_ptr->checkIdents(m_states, m_events, m_actions);
- m_transitions.insertAtBottom(trans_ptr);
-}
-
-void StateMachine::addFunc(Func* func_ptr)
-{
- // register func in the symbol table
- g_sym_table.registerSym(func_ptr->toString(), func_ptr);
- m_internal_func_vec.insertAtBottom(func_ptr);
-}
-
-void StateMachine::buildTable()
-{
- assert(m_table_built == false);
- int numStates = m_states.size();
- int numEvents = m_events.size();
- int numTransitions = m_transitions.size();
- int stateIndex, eventIndex;
-
- for(stateIndex=0; stateIndex < numStates; stateIndex++) {
- m_table.insertAtBottom(Vector<Transition*>());
- for(eventIndex=0; eventIndex < numEvents; eventIndex++) {
- m_table[stateIndex].insertAtBottom(NULL);
- }
- }
-
- for(int i=0; i<numTransitions; i++) {
- Transition* trans_ptr = m_transitions[i];
-
- // Track which actions we touch so we know if we use them all --
- // really this should be done for all symbols as part of the
- // symbol table, then only trigger it for Actions, States, Events,
- // etc.
-
- Vector<Action*> actions = trans_ptr->getActions();
- for(int actionIndex=0; actionIndex < actions.size(); actionIndex++) {
- actions[actionIndex]->markUsed();
- }
-
- stateIndex = getStateIndex(trans_ptr->getStatePtr());
- eventIndex = getEventIndex(trans_ptr->getEventPtr());
- if (m_table[stateIndex][eventIndex] != NULL) {
- m_table[stateIndex][eventIndex]->warning("Duplicate transition: " + m_table[stateIndex][eventIndex]->toString());
- trans_ptr->error("Duplicate transition: " + trans_ptr->toString());
- }
- m_table[stateIndex][eventIndex] = trans_ptr;
- }
-
- // Look at all actions to make sure we used them all
- for(int actionIndex=0; actionIndex < m_actions.size(); actionIndex++) {
- Action* action_ptr = m_actions[actionIndex];
- if (!action_ptr->wasUsed()) {
- string error_msg = "Unused action: " + action_ptr->getIdent();
- if (action_ptr->existPair("desc")) {
- error_msg += ", " + action_ptr->getDescription();
- }
- action_ptr->warning(error_msg);
- }
- }
-
- m_table_built = true;
-}
-
-const Transition* StateMachine::getTransPtr(int stateIndex, int eventIndex) const
-{
- return m_table[stateIndex][eventIndex];
-}
-
-// *********************** //
-// ******* C Files ******* //
-// *********************** //
-
-void StateMachine::writeCFiles(string path)
-{
- string comp = getIdent();
- string filename;
-
- // Output the method declarations for the class declaration
- {
- ostringstream sstr;
- printControllerH(sstr, comp);
- conditionally_write_file(path + comp + "_Controller.hh", sstr);
- }
-
- // Output switch statement for transition table
- {
- ostringstream sstr;
- printCSwitch(sstr, comp);
- conditionally_write_file(path + comp + "_Transitions.cc", sstr);
- }
-
- // Output the actions for performing the actions
- {
- ostringstream sstr;
- printControllerC(sstr, comp);
- conditionally_write_file(path + comp + "_Controller.cc", sstr);
- }
-
- // Output the wakeup loop for the events
- {
- ostringstream sstr;
- printCWakeup(sstr, comp);
- conditionally_write_file(path + comp + "_Wakeup.cc", sstr);
- }
-
- // Profiling
- {
- ostringstream sstr;
- printProfilerC(sstr, comp);
- conditionally_write_file(path + comp + "_Profiler.cc", sstr);
- }
- {
- ostringstream sstr;
- printProfilerH(sstr, comp);
- conditionally_write_file(path + comp + "_Profiler.hh", sstr);
- }
-
- // Write internal func files
- for(int i=0; i<m_internal_func_vec.size(); i++) {
- m_internal_func_vec[i]->writeCFiles(path);
- }
-
-}
-
-void StateMachine::printControllerH(ostream& out, string component)
-{
-
- m_message_buffer_names.clear();
-
- out << "/** \\file " << getIdent() << ".hh" << endl;
- out << " * " << endl;
- out << " * Auto generated C++ code started by "<<__FILE__<<":"<<__LINE__<< endl;
- out << " * Created by slicc definition of Module \"" << getShorthand() << "\"" << endl;
- out << " */" << endl;
- out << endl;
- out << "#ifndef " << component << "_CONTROLLER_H" << endl;
- out << "#define " << component << "_CONTROLLER_H" << endl;
- out << endl;
- out << "#include \"mem/ruby/common/Global.hh\"" << endl;
- out << "#include \"mem/ruby/common/Consumer.hh\"" << endl;
- out << "#include \"mem/ruby/slicc_interface/AbstractController.hh\"" << endl;
- out << "#include \"mem/protocol/TransitionResult.hh\"" << endl;
- out << "#include \"mem/protocol/Types.hh\"" << endl;
- out << "#include \"mem/protocol/" << component << "_Profiler.hh\"" << endl;
-
- // include object classes
- std::set<string> seen_types;
- for(int i=0; i<numObjects(); i++) {
- Var* var = m_objs[i];
- if (seen_types.count(var->getType()->cIdent()) == 0) {
- out << "#include \"mem/protocol/" << var->getType()->cIdent() << ".hh\"" << endl;
- // out << "class " << var->getType()->cIdent() << ";" << endl;
- seen_types.insert(var->getType()->cIdent());
- }
- }
-
- out << endl;
-
- // for adding information to the protocol debug trace
- out << "extern stringstream " << component << "_" << "transitionComment;" << endl;
-
- out << "class " << component << "_Controller : public AbstractController {" << endl;
-
- /* the coherence checker needs to call isBlockExclusive() and isBlockShared()
- making the Chip a friend class is an easy way to do this for now */
- out << "#ifdef CHECK_COHERENCE" << endl;
- out << "#endif /* CHECK_COHERENCE */" << endl;
-
- out << "public:" << endl;
- // out << " " << component << "_Controller(int version, Network* net_ptr);" << endl;
- out << " " << component << "_Controller(const string & name);" << endl;
- out << " static int getNumControllers();" << endl;
- out << " void init(Network* net_ptr, const vector<string> & argv);" << endl;
- out << " MessageBuffer* getMandatoryQueue() const;" << endl;
- out << " const int & getVersion() const;" << endl;
- out << " const string toString() const;" << endl;
- out << " const string getName() const;" << endl;
- out << " const MachineType getMachineType() const;" << endl;
- out << " void print(ostream& out) const;" << endl;
- out << " void printConfig(ostream& out) const;" << endl;
- out << " void wakeup();" << endl;
- out << " void set_atomic(Address addr);" << endl;
- out << " void started_writes();" << endl;
- out << " void clear_atomic();" << endl;
- out << " void printStats(ostream& out) const { s_profiler.dumpStats(out); }" << endl;
- out << " void clearStats() { s_profiler.clearStats(); }" << endl;
- out << "private:" << endl;
-//added by SS
-// found_to_mem = 0;
- for(int i=0;i<m_config_parameters->size();i++){
- out << " int m_" << m_config_parameters->ref(i)->getName() << ";" << endl;
- }
- if (strncmp(component.c_str(), "L1Cache", 7) == 0) {
- out << " int servicing_atomic;" << endl;
- out << " bool started_receiving_writes;" << endl;
- out << " Address locked_read_request1;" << endl;
- out << " Address locked_read_request2;" << endl;
- out << " Address locked_read_request3;" << endl;
- out << " Address locked_read_request4;" << endl;
- out << " int read_counter;" << endl;
- }
- out << " int m_number_of_TBEs;" << endl;
-
- out << " TransitionResult doTransition(" << component << "_Event event, " << component
- << "_State state, const Address& addr";
- if(CHECK_INVALID_RESOURCE_STALLS) {
- out << ", int priority";
- }
- out << "); // in " << component << "_Transitions.cc" << endl;
- out << " TransitionResult doTransitionWorker(" << component << "_Event event, " << component
- << "_State state, " << component << "_State& next_state, const Address& addr";
- if(CHECK_INVALID_RESOURCE_STALLS) {
- out << ", int priority";
- }
- out << "); // in " << component << "_Transitions.cc" << endl;
- out << " string m_name;" << endl;
- out << " int m_transitions_per_cycle;" << endl;
- out << " int m_buffer_size;" << endl;
- out << " int m_recycle_latency;" << endl;
- out << " map< string, string > m_cfg;" << endl;
- out << " NodeID m_version;" << endl;
- out << " Network* m_net_ptr;" << endl;
- out << " MachineID m_machineID;" << endl;
- out << " " << component << "_Profiler s_profiler;" << endl;
- out << " static int m_num_controllers;" << endl;
-
- // internal function protypes
- out << " // Internal functions" << endl;
- for(int i=0; i<m_internal_func_vec.size(); i++) {
- Func* func = m_internal_func_vec[i];
- string proto;
- func->funcPrototype(proto);
- if (proto != "") {
- out << " " << proto;
- }
- }
-
- out << " // Actions" << endl;
- for(int i=0; i < numActions(); i++) {
- const Action& action = getAction(i);
- out << "/** \\brief " << action.getDescription() << "*/" << endl;
- out << " void " << action.getIdent() << "(const Address& addr);" << endl;
- }
-
- // the controller internal variables
- out << " // Object" << endl;
- for(int i=0; i < numObjects(); i++) {
- const Var* var = m_objs[i];
- string template_hack = "";
- if (var->existPair("template_hack")) {
- template_hack = var->lookupPair("template_hack");
- }
- out << " " << var->getType()->cIdent() << template_hack << "* m_"
- << var->cIdent() << "_ptr;" << endl;
-
- string str = "m_"+ var->cIdent() + "_ptr";
- if (var->getType()->cIdent() == "MessageBuffer")
- m_message_buffer_names.push_back(str);
-
- }
-
-
- out << "};" << endl;
- out << "#endif // " << component << "_CONTROLLER_H" << endl;
-}
-
-void StateMachine::printControllerC(ostream& out, string component)
-{
- out << "/** \\file " << getIdent() << ".cc" << endl;
- out << " * " << endl;
- out << " * Auto generated C++ code started by "<<__FILE__<<":"<<__LINE__<< endl;
- out << " * Created by slicc definition of Module \"" << getShorthand() << "\"" << endl;
- out << " */" << endl;
- out << endl;
- out << "#include \"mem/ruby/common/Global.hh\"" << endl;
- out << "#include \"mem/ruby/slicc_interface/RubySlicc_includes.hh\"" << endl;
- out << "#include \"mem/protocol/" << component << "_Controller.hh\"" << endl;
- out << "#include \"mem/protocol/" << component << "_State.hh\"" << endl;
- out << "#include \"mem/protocol/" << component << "_Event.hh\"" << endl;
- out << "#include \"mem/protocol/Types.hh\"" << endl;
- out << "#include \"mem/ruby/system/System.hh\"" << endl;
-
- // include object classes
- std::set<string> seen_types;
- for(int i=0; i<numObjects(); i++) {
- Var* var = m_objs[i];
- if (seen_types.count(var->getType()->cIdent()) == 0) {
- out << "#include \"mem/protocol/" << var->getType()->cIdent() << ".hh\"" << endl;
- seen_types.insert(var->getType()->cIdent());
- }
-
- }
-
- out << endl;
-
- out << "int " << component << "_Controller::m_num_controllers = 0;" << endl;
-
- // for adding information to the protocol debug trace
- out << "stringstream " << component << "_" << "transitionComment;" << endl;
- out << "#define APPEND_TRANSITION_COMMENT(str) (" << component << "_" << "transitionComment << str)" << endl;
-
- out << "/** \\brief constructor */" << endl;
- out << component << "_Controller::" << component
- // << "_Controller(int version, Network* net_ptr)" << endl;
- << "_Controller(const string & name)" << endl;
- out << " : m_name(name)" << endl;
- out << "{ " << endl;
- if (strncmp(component.c_str(), "L1Cache", 7) == 0) {
- out << " servicing_atomic = 0;" << endl;
- out << " started_receiving_writes = false;" << endl;
- out << " locked_read_request1 = Address(-1);" << endl;
- out << " locked_read_request2 = Address(-1);" << endl;
- out << " locked_read_request3 = Address(-1);" << endl;
- out << " locked_read_request4 = Address(-1);" << endl;
- out << " read_counter = 0;" << endl;
- }
- out << " m_num_controllers++; " << endl;
- for(int i=0; i < numObjects(); i++) {
- const Var* var = m_objs[i];
- if ( var->cIdent().find("mandatoryQueue") != string::npos)
- out << " m_" << var->cIdent() << "_ptr = new " << var->getType()->cIdent() << "();" << endl;
- }
- out << "}" << endl << endl;
-
- out << "void " << component << "_Controller::init(Network * net_ptr, const vector<string> & argv)" << endl;
- out << "{" << endl;
- out << " for (size_t i=0; i < argv.size(); i+=2) {" << endl;
-// out << " printf (\"ARG: %s = %s \\n \", argv[i].c_str(), argv[i+1].c_str());"<< endl;
-
- out << " if (argv[i] == \"version\") " << endl;
- out << " m_version = atoi(argv[i+1].c_str());" << endl;
- out << " else if (argv[i] == \"transitions_per_cycle\") " << endl;
- out << " m_transitions_per_cycle = atoi(argv[i+1].c_str());" << endl;
- out << " else if (argv[i] == \"buffer_size\") " << endl;
- out << " m_buffer_size = atoi(argv[i+1].c_str());" << endl;
-//added by SS
- out << " else if (argv[i] == \"recycle_latency\") " << endl;
- out << " m_recycle_latency = atoi(argv[i+1].c_str());" << endl;
-//added by SS --> for latency
-//for loop on latency_vector to check with argv[i] and assign the value to the related m_latency ...
- out << " else if (argv[i] == \"number_of_TBEs\") " << endl;
- out << " m_number_of_TBEs = atoi(argv[i+1].c_str());" << endl;
-
- if (m_config_parameters->size()) {
- for(int i= 0 ; i < m_config_parameters->size(); i++) {
- out << " else if (argv[i] == \"" << m_config_parameters->ref(i)->getName() << "\")" << endl;
- if (m_config_parameters->ref(i)->getTypeName() == "int")
- out << " m_" << m_config_parameters->ref(i)->getName() << "=" << "atoi(argv[i+1].c_str());" << endl;
- else
- assert(0); // only int parameters are supported right now
- // if (str == "to_mem_ctrl_latency")
- // out << " m_" << (*it)->c_str() << "=" << "atoi(argv[i+1].c_str())+(random() % 5);" << endl;
- }
- }
- out << " }" << endl;
- out << " m_net_ptr = net_ptr;" << endl;
- out << " m_machineID.type = MachineType_" << component << ";" << endl;
- out << " m_machineID.num = m_version;" << endl;
-
- // make configuration array
- out << " for (size_t i=0; i < argv.size(); i+=2) {" << endl;
- out << " if (argv[i] != \"version\") " << endl;
- out << " m_cfg[argv[i]] = argv[i+1];" << endl;
- out << " }" << endl;
-
- out << endl;
-
- // initialize objects
- out << " // Objects" << endl;
- out << " s_profiler.setVersion(m_version);" << endl;
- for(int i=0; i < numObjects(); i++) {
- const Var* var = m_objs[i];
- if (!var->existPair("network")) {
- // Not a network port object
- if (var->getType()->existPair("primitive")) {
- out << " m_" << var->cIdent() << "_ptr = new " << var->getType()->cIdent() << ";\n";
- if (var->existPair("default")) {
- out << " (*m_" << var->cIdent() << "_ptr) = " << var->lookupPair("default") << ";\n";
- }
- out << " }\n";
-
- } else {
- // Normal Object
- string template_hack = "";
- if (var->existPair("template_hack")) {
- template_hack = var->lookupPair("template_hack");
- }
-//added by SS
- string str = "";
- int found = 0;
- if (var->existPair("factory")) {
- out << " m_" << var->cIdent() << "_ptr = " << var->lookupPair("factory");
- } else {
- if ( var->cIdent().find("mandatoryQueue") == string::npos) {
-
- str = " m_" + var->cIdent() + "_ptr = new " + var->getType()->cIdent() + template_hack;
- out << str;
- if (str.find("TBETable")!=string::npos){
- found = 1;
- }
-
- if (!var->getType()->existPair("non_obj") && (!var->getType()->isEnumeration())) {
- str = "";
- if (var->existPair("constructor_hack")) {
- string constructor_hack = var->lookupPair("constructor_hack");
- str = "(" + constructor_hack + ")";
- } else {
- str = "()";
- }
- if (found)
- str = "(m_number_of_TBEs)";
- out << str;
- }
- }
- }
-
- out << ";\n";
- out << " assert(m_" << var->cIdent() << "_ptr != NULL);" << endl;
-
- if (var->existPair("default")) {
- out << " (*m_" << var->cIdent() << "_ptr) = " << var->lookupPair("default")
- << "; // Object default" << endl;
- } else if (var->getType()->hasDefault()) {
- out << " (*m_" << var->cIdent() << "_ptr) = " << var->getType()->getDefault()
- << "; // Type " << var->getType()->getIdent() << " default" << endl;
- }
-
- // Set ordering
- if (var->existPair("ordered") && !var->existPair("trigger_queue")) {
- // A buffer
- string ordered = var->lookupPair("ordered");
- out << " m_" << var->cIdent() << "_ptr->setOrdering(" << ordered << ");\n";
- }
-
- // Set randomization
- if (var->existPair("random")) {
- // A buffer
- string value = var->lookupPair("random");
- out << " m_" << var->cIdent() << "_ptr->setRandomization(" << value << ");\n";
- }
-
- // Set Priority
- if (var->getType()->isBuffer() && var->existPair("rank") && !var->existPair("trigger_queue")) {
- string rank = var->lookupPair("rank");
- out << " m_" << var->cIdent() << "_ptr->setPriority(" << rank << ");\n";
- }
- }
- } else {
- // Network port object
- string network = var->lookupPair("network");
- string ordered = var->lookupPair("ordered");
- string vnet = var->lookupPair("virtual_network");
-
- assert (var->getMachine() != NULL);
- out << " m_" << var->cIdent() << "_ptr = m_net_ptr->get"
- << network << "NetQueue(m_version+MachineType_base_number(string_to_MachineType(\""
- << var->getMachine()->getIdent() << "\")), "
- << ordered << ", " << vnet << ");\n";
- out << " assert(m_" << var->cIdent() << "_ptr != NULL);" << endl;
-
- // Set ordering
- if (var->existPair("ordered")) {
- // A buffer
- string ordered = var->lookupPair("ordered");
- out << " m_" << var->cIdent() << "_ptr->setOrdering(" << ordered << ");\n";
- }
-
- // Set randomization
- if (var->existPair("random")) {
- // A buffer
- string value = var->lookupPair("random");
- out << " m_" << var->cIdent() << "_ptr->setRandomization(" << value << ");\n";
- }
-
- // Set Priority
- if (var->existPair("rank")) {
- string rank = var->lookupPair("rank");
- out << " m_" << var->cIdent() << "_ptr->setPriority(" << rank << ");\n";
- }
-
- // Set buffer size
- if (var->getType()->isBuffer()) {
- out << " if (m_buffer_size > 0) {\n";
- out << " m_" << var->cIdent() << "_ptr->setSize(m_buffer_size);\n";
- out << " }\n";
- }
-
- // set description (may be overriden later by port def)
- out << " m_" << var->cIdent()
- << "_ptr->setDescription(\"[Version \" + int_to_string(m_version) + \", "
- << component << ", name=" << var->cIdent() << "]\");" << endl;
- out << endl;
- }
- }
-
- // Set the queue consumers
- out << endl;
- for(int i=0; i < m_in_ports.size(); i++) {
- const Var* port = m_in_ports[i];
- out << " " << port->getCode() << ".setConsumer(this);" << endl;
- }
-
- // Set the queue descriptions
- out << endl;
- for(int i=0; i < m_in_ports.size(); i++) {
- const Var* port = m_in_ports[i];
- out << " " << port->getCode()
- << ".setDescription(\"[Version \" + int_to_string(m_version) + \", "
- << component << ", " << port->toString() << "]\");" << endl;
- }
-
- // Initialize the transition profiling
- out << endl;
- for(int i=0; i<numTransitions(); i++) {
- const Transition& t = getTransition(i);
- const Vector<Action*>& action_vec = t.getActions();
- int numActions = action_vec.size();
-
- // Figure out if we stall
- bool stall = false;
- for (int i=0; i<numActions; i++) {
- if(action_vec[i]->getIdent() == "z_stall") {
- stall = true;
- }
- }
-
- // Only possible if it is not a 'z' case
- if (!stall) {
- out << " s_profiler.possibleTransition(" << component << "_State_"
- << t.getStatePtr()->getIdent() << ", " << component << "_Event_"
- << t.getEventPtr()->getIdent() << ");" << endl;
- }
- }
-
- //added by SS to initialize recycle_latency of message buffers
- std::vector<std::string>::const_iterator it;
- for ( it=m_message_buffer_names.begin() ; it != m_message_buffer_names.end(); it++ ){
- out << " "<< (*it).c_str() << "->setRecycleLatency(m_recycle_latency);" << endl;
- }
-
-
- out << "}" << endl;
-
- out << endl;
-
- bool has_mandatory_q = false;
- for(int i=0; i < m_in_ports.size(); i++) {
- if (m_in_ports[i]->getCode().find("mandatoryQueue_ptr")!= string::npos)
- has_mandatory_q = true;
- }
-
- out << "int " << component << "_Controller::getNumControllers() {" << endl;
- out << " return m_num_controllers;" << endl;
- out << "}" << endl;
-
- out << endl;
-
- out << "MessageBuffer* " << component << "_Controller::getMandatoryQueue() const {" << endl;
- if (has_mandatory_q)
- out << " return m_" << component << "_mandatoryQueue_ptr;" << endl;
- else
- out << " return NULL;" << endl;
- out << "}" << endl;
-
- out << endl;
-
- out << "const int & "<<component<<"_Controller::getVersion() const{" << endl;
- out << " return m_version;" << endl;
- out << "}";
-
- out << endl;
-
- out << "const string "<<component<<"_Controller::toString() const{" << endl;
- out << " return \"" << component<< "_Controller\";" << endl;
- out << "}";
-
- out << endl;
-
- out << "const string "<<component<<"_Controller::getName() const{" << endl;
- out << " return m_name;" << endl;
- out << "}";
-
- out << endl;
-
- out << "const MachineType "<<component<<"_Controller::getMachineType() const{" << endl;
- out << " return MachineType_" << component<< ";" << endl;
- out << "}";
-
- out << endl;
-
- out << "void " << component << "_Controller::print(ostream& out) const { out << \"[" << component
- << "_Controller \" << m_version << \"]\"; }" << endl;
-
- out << "void " << component << "_Controller::printConfig(ostream& out) const {" << endl;
- out << " out << \"" << component << "_Controller config: \" << m_name << endl;" << endl;
- out << " out << \" version: \" << m_version << endl;" << endl;
- out << " for(map< string, string >::const_iterator it = m_cfg.begin(); it != m_cfg.end(); it++) {" << endl;
- out << " out << \" \" << (*it).first << \": \" << (*it).second << endl;" << endl;
- out << " }" << endl;
- out << "}" << endl;
-
- out << endl;
- out << "// Actions" << endl;
- out << endl;
-
- for(int i=0; i < numActions(); i++) {
- const Action& action = getAction(i);
- if (action.existPair("c_code")) {
- out << "/** \\brief " << action.getDescription() << "*/" << endl;
- out << "void " << component << "_Controller::"
- << action.getIdent() << "(const Address& addr)" << endl;
- out << "{" << endl;
- out << " DEBUG_MSG(GENERATED_COMP, HighPrio,\"executing\");" << endl;
-//added by SS
-//it should point to m_latency...
-//so I should change the string output of this lookup
-
-
- string c_code_string = action.lookupPair("c_code");
-
- out << c_code_string;
-
- out << "}" << endl;
- }
- out << endl;
- }
-}
-
-void StateMachine::printCWakeup(ostream& out, string component)
-{
- out << "// Auto generated C++ code started by "<<__FILE__<<":"<<__LINE__<< endl;
- out << "// " << getIdent() << ": " << getShorthand() << endl;
- out << endl;
- out << "#include \"mem/ruby/common/Global.hh\"" << endl;
- out << "#include \"mem/ruby/slicc_interface/RubySlicc_includes.hh\"" << endl;
- out << "#include \"mem/protocol/" << component << "_Controller.hh\"" << endl;
- out << "#include \"mem/protocol/" << component << "_State.hh\"" << endl;
- out << "#include \"mem/protocol/" << component << "_Event.hh\"" << endl;
- out << "#include \"mem/protocol/Types.hh\"" << endl;
- out << "#include \"mem/ruby/system/System.hh\"" << endl;
- out << endl;
- out << "void " << component << "_Controller::wakeup()" << endl;
- out << "{" << endl;
- // out << " DEBUG_EXPR(GENERATED_COMP, MedPrio,*this);" << endl;
- // out << " DEBUG_EXPR(GENERATED_COMP, MedPrio,g_eventQueue_ptr->getTime());" << endl;
- out << endl;
- out << "int counter = 0;" << endl;
- out << " while (true) {" << endl;
- out << " // Some cases will put us into an infinite loop without this limit" << endl;
- out << " assert(counter <= m_transitions_per_cycle);" << endl;
- out << " if (counter == m_transitions_per_cycle) {" << endl;
- out << " g_system_ptr->getProfiler()->controllerBusy(m_machineID); // Count how often we're fully utilized" << endl;
- out << " g_eventQueue_ptr->scheduleEvent(this, 1); // Wakeup in another cycle and try again" << endl;
- out << " break;" << endl;
- out << " }" << endl;
-
- // InPorts
- //
- // Find the position of the mandatory queue in the vector so that we can print it out first
- int j = -1;
- if (strncmp(component.c_str(), "L1Cache", 7) == 0) {
- for(int i=0; i < m_in_ports.size(); i++) {
- const Var* port = m_in_ports[i];
- assert(port->existPair("c_code_in_port"));
- if (port->toString().find("mandatoryQueue_in") != string::npos) {
- assert (j == -1);
- j = i;
- }
- else {
- cout << port->toString() << endl << flush;
- }
- }
-
- assert(j != -1);
-
- // print out the mandatory queue here
- const Var* port = m_in_ports[j];
- assert(port->existPair("c_code_in_port"));
- out << " // "
- << component << "InPort " << port->toString()
- << endl;
- string output = port->lookupPair("c_code_in_port");
- string::size_type pos = output.find("TransitionResult result = doTransition((L1Cache_mandatory_request_type_to_event(((*in_msg_ptr)).m_Type)), L1Cache_getState(addr), addr);");
- assert(pos != string::npos);
- string atomics_string = "\n \
- if ((((*in_msg_ptr)).m_Type) == CacheRequestType_ATOMIC) { \n \
- if (servicing_atomic == 0) { \n \
- if (locked_read_request1 == Address(-1)) { \n \
- assert(read_counter == 0); \n \
- locked_read_request1 = addr; \n \
- assert(read_counter == 0); \n \
- read_counter++; \n \
- } \n \
- else if (addr == locked_read_request1) { \n \
- ; // do nothing \n\
- } \n \
- else { \n \
- assert(0); // should never be here if servicing one request at a time \n\
- } \n \
- } \n \
- else if (!started_receiving_writes) { \n \
- if (servicing_atomic == 1) { \n \
- if (locked_read_request2 == Address(-1)) { \n \
- assert(locked_read_request1 != Address(-1)); \n \
- assert(read_counter == 1); \n \
- locked_read_request2 = addr; \n \
- assert(read_counter == 1); \n \
- read_counter++; \n \
- } \n \
- else if (addr == locked_read_request2) { \n \
- ; // do nothing \n\
- } \n \
- else { \n \
- assert(0); // should never be here if servicing one request at a time \n\
- } \n \
- } \n \
- else if (servicing_atomic == 2) { \n \
- if (locked_read_request3 == Address(-1)) { \n \
- assert(locked_read_request1 != Address(-1)); \n \
- assert(locked_read_request2 != Address(-1)); \n \
- assert(read_counter == 1); \n \
- locked_read_request3 = addr; \n \
- assert(read_counter == 2); \n \
- read_counter++; \n \
- } \n \
- else if (addr == locked_read_request3) { \n \
- ; // do nothing \n\
- } \n \
- else { \n \
- assert(0); // should never be here if servicing one request at a time \n\
- } \n \
- } \n \
- else if (servicing_atomic == 3) { \n \
- if (locked_read_request4 == Address(-1)) { \n \
- assert(locked_read_request1 != Address(-1)); \n \
- assert(locked_read_request2 != Address(-1)); \n \
- assert(locked_read_request3 != Address(-1)); \n \
- assert(read_counter == 1); \n \
- locked_read_request4 = addr; \n \
- assert(read_counter == 3); \n \
- read_counter++; \n \
- } \n \
- else if (addr == locked_read_request4) { \n \
- ; // do nothing \n\
- } \n \
- else { \n \
- assert(0); // should never be here if servicing one request at a time \n\
- } \n \
- } \n \
- else { \n \
- assert(0); \n \
- } \n \
- } \n \
- } \n \
- else { \n \
- if (servicing_atomic > 0) { \n \
- // reset \n \
- servicing_atomic = 0; \n \
- read_counter = 0; \n \
- started_receiving_writes = false; \n \
- locked_read_request1 = Address(-1); \n \
- locked_read_request2 = Address(-1); \n \
- locked_read_request3 = Address(-1); \n \
- locked_read_request4 = Address(-1); \n \
- } \n \
- } \n \
- ";
- output.insert(pos, atomics_string);
- /*string foo = "// Cannot do anything with this transition, go check next doable transition (mostly likely of next port)\n";
- string::size_type next_pos = output.find(foo, pos);
- next_pos = next_pos + foo.length();
-
- assert(next_pos != string::npos);
- string complete = " }\n";
- output.insert(next_pos, complete);*/
- //out << port->lookupPair("c_code_in_port");
- out << output;
- out << endl;
- }
- for(int i=0; i < m_in_ports.size(); i++) {
- const Var* port = m_in_ports[i];
- // don't print out mandatory queue twice
- if (i != j) {
- if (strncmp(component.c_str(), "L1Cache", 7) == 0) {
- if (port->toString().find("forwardRequestNetwork_in") != string::npos) {
- out << " bool postpone = false;" << endl;
- out << " if ((((*m_L1Cache_forwardToCache_ptr)).isReady())) {" << endl;
- out << " const RequestMsg* in_msg_ptr;" << endl;
- out << " in_msg_ptr = dynamic_cast<const RequestMsg*>(((*m_L1Cache_forwardToCache_ptr)).peek());" << endl;
- out << " if ((((servicing_atomic == 1) && (locked_read_request1 == ((*in_msg_ptr)).m_Address)) || " << endl;
- out << " ((servicing_atomic == 2) && (locked_read_request1 == ((*in_msg_ptr)).m_Address || locked_read_request2 == ((*in_msg_ptr)).m_Address)) || " << endl;
- out << " ((servicing_atomic == 3) && (locked_read_request1 == ((*in_msg_ptr)).m_Address || locked_read_request2 == ((*in_msg_ptr)).m_Address || locked_read_request3 == ((*in_msg_ptr)).m_Address)) || " << endl;
- out << " ((servicing_atomic == 4) && (locked_read_request1 == ((*in_msg_ptr)).m_Address || locked_read_request2 == ((*in_msg_ptr)).m_Address || locked_read_request3 == ((*in_msg_ptr)).m_Address || locked_read_request1 == ((*in_msg_ptr)).m_Address)))) {" << endl;
-// out << " (locked_read_request2 == ((*in_msg_ptr)).m_Address) || (locked_read_request3 == ((*in_msg_ptr)).m_Address) || " << endl;
-// out << " (locked_read_request4 == ((*in_msg_ptr)).m_Address))) { " << endl;
-
- out << " postpone = true;" << endl;
- out << " }" << endl;
-
- out << " }" << endl;
- out << " if (!postpone) {" << endl;
- }
- }
- assert(port->existPair("c_code_in_port"));
- out << " // "
- << component << "InPort " << port->toString()
- << endl;
- out << port->lookupPair("c_code_in_port");
- if (strncmp(component.c_str(), "L1Cache", 7) == 0) {
- if (port->toString().find("forwardRequestNetwork_in") != string::npos) {
- out << "}" << endl;
- }
- }
- out << endl;
- }
- }
-
- out << " break; // If we got this far, we have nothing left todo" << endl;
- out << " }" << endl;
- // out << " g_eventQueue_ptr->scheduleEvent(this, 1);" << endl;
- // out << " DEBUG_NEWLINE(GENERATED_COMP, MedPrio);" << endl;
- out << "}" << endl;
- out << endl;
-
-
- // tack on two more functions
- if (strncmp(component.c_str(), "L1Cache", 7) == 0) {
- out << "void " << component << "_Controller::set_atomic(Address addr)" << endl;
- out << "{" << endl;
- out << " servicing_atomic++; " << endl;
- out << "}" << endl;
- out << "void " << component << "_Controller::started_writes()" << endl;
- out << "{" << endl;
- out << " started_receiving_writes = true; " << endl;
- out << "}" << endl;
- out << "void " << component << "_Controller::clear_atomic()" << endl;
- out << "{" << endl;
- out << " assert(servicing_atomic > 0); " << endl;
- out << " read_counter--; " << endl;
- out << " servicing_atomic--; " << endl;
- out << " if (read_counter == 0) { " << endl;
- out << " servicing_atomic = 0; " << endl;
- out << " started_receiving_writes = false; " << endl;
- out << " locked_read_request1 = Address(-1); " << endl;
- out << " locked_read_request2 = Address(-1); " << endl;
- out << " locked_read_request3 = Address(-1); " << endl;
- out << " locked_read_request4 = Address(-1); " << endl;
- out << " } " << endl;
- out << "}" << endl;
- }
- else {
- out << "void " << component << "_Controller::started_writes()" << endl;
- out << "{" << endl;
- out << " assert(0); " << endl;
- out << "}" << endl;
- out << "void " << component << "_Controller::set_atomic(Address addr)" << endl;
- out << "{" << endl;
- out << " assert(0); " << endl;
- out << "}" << endl;
-
- out << "void " << component << "_Controller::clear_atomic()" << endl;
- out << "{" << endl;
- out << " assert(0); " << endl;
- out << "}" << endl;
- }
-
-}
-
-void StateMachine::printCSwitch(ostream& out, string component)
-{
- out << "// Auto generated C++ code started by "<<__FILE__<<":"<<__LINE__<< endl;
- out << "// " << getIdent() << ": " << getShorthand() << endl;
- out << endl;
- out << "#include \"mem/ruby/common/Global.hh\"" << endl;
- out << "#include \"mem/protocol/" << component << "_Controller.hh\"" << endl;
- out << "#include \"mem/protocol/" << component << "_State.hh\"" << endl;
- out << "#include \"mem/protocol/" << component << "_Event.hh\"" << endl;
- out << "#include \"mem/protocol/Types.hh\"" << endl;
- out << "#include \"mem/ruby/system/System.hh\"" << endl;
- out << endl;
- out << "#define HASH_FUN(state, event) ((int(state)*" << component
- << "_Event_NUM)+int(event))" << endl;
- out << endl;
- out << "#define GET_TRANSITION_COMMENT() (" << component << "_" << "transitionComment.str())" << endl;
- out << "#define CLEAR_TRANSITION_COMMENT() (" << component << "_" << "transitionComment.str(\"\"))" << endl;
- out << endl;
- out << "TransitionResult " << component << "_Controller::doTransition("
- << component << "_Event event, "
- << component << "_State state, "
- << "const Address& addr" << endl;
- if(CHECK_INVALID_RESOURCE_STALLS) {
- out << ", int priority";
- }
- out << ")" << endl;
-
- out << "{" << endl;
- out << " " << component << "_State next_state = state;" << endl;
- out << endl;
- out << " DEBUG_NEWLINE(GENERATED_COMP, MedPrio);" << endl;
- out << " DEBUG_MSG(GENERATED_COMP, MedPrio,*this);" << endl;
- out << " DEBUG_EXPR(GENERATED_COMP, MedPrio,g_eventQueue_ptr->getTime());" << endl;
- out << " DEBUG_EXPR(GENERATED_COMP, MedPrio,state);" << endl;
- out << " DEBUG_EXPR(GENERATED_COMP, MedPrio,event);" << endl;
- out << " DEBUG_EXPR(GENERATED_COMP, MedPrio,addr);" << endl;
- out << endl;
- out << " TransitionResult result = doTransitionWorker(event, state, next_state, addr";
- if(CHECK_INVALID_RESOURCE_STALLS) {
- out << ", priority";
- }
- out << ");" << endl;
- out << endl;
- out << " if (result == TransitionResult_Valid) {" << endl;
- out << " DEBUG_EXPR(GENERATED_COMP, MedPrio, next_state);" << endl;
- out << " DEBUG_NEWLINE(GENERATED_COMP, MedPrio);" << endl;
- out << " s_profiler.countTransition(state, event);" << endl;
- out << " if (Debug::getProtocolTrace()) {" << endl
- << " g_system_ptr->getProfiler()->profileTransition(\"" << component
- << "\", m_version, addr, " << endl
- << " " << component << "_State_to_string(state), " << endl
- << " " << component << "_Event_to_string(event), " << endl
- << " " << component << "_State_to_string(next_state), GET_TRANSITION_COMMENT());" << endl
- << " }" << endl;
- out << " CLEAR_TRANSITION_COMMENT();" << endl;
- out << " " << component << "_setState(addr, next_state);" << endl;
- out << " " << endl;
- out << " } else if (result == TransitionResult_ResourceStall) {" << endl;
- out << " if (Debug::getProtocolTrace()) {" << endl
- << " g_system_ptr->getProfiler()->profileTransition(\"" << component
- << "\", m_version, addr, " << endl
- << " " << component << "_State_to_string(state), " << endl
- << " " << component << "_Event_to_string(event), " << endl
- << " " << component << "_State_to_string(next_state), " << endl
- << " \"Resource Stall\");" << endl
- << " }" << endl;
- out << " } else if (result == TransitionResult_ProtocolStall) {" << endl;
- out << " DEBUG_MSG(GENERATED_COMP,HighPrio,\"stalling\");" << endl
- << " DEBUG_NEWLINE(GENERATED_COMP, MedPrio);" << endl;
- out << " if (Debug::getProtocolTrace()) {" << endl
- << " g_system_ptr->getProfiler()->profileTransition(\"" << component
- << "\", m_version, addr, " << endl
- << " " << component << "_State_to_string(state), " << endl
- << " " << component << "_Event_to_string(event), " << endl
- << " " << component << "_State_to_string(next_state), " << endl
- << " \"Protocol Stall\");" << endl
- << " }" << endl
- << " }" << endl;
- out << " return result;" << endl;
- out << "}" << endl;
- out << endl;
- out << "TransitionResult " << component << "_Controller::doTransitionWorker("
- << component << "_Event event, "
- << component << "_State state, "
- << component << "_State& next_state, "
- << "const Address& addr" << endl;
- if(CHECK_INVALID_RESOURCE_STALLS) {
- out << ", int priority" << endl;
- }
- out << ")" << endl;
-
- out << "{" << endl;
- out << "" << endl;
-
- out << " switch(HASH_FUN(state, event)) {" << endl;
-
- Map<string, Vector<string> > code_map; // This map will allow suppress generating duplicate code
- Vector<string> code_vec;
-
- for(int i=0; i<numTransitions(); i++) {
- const Transition& t = getTransition(i);
- string case_string = component + "_State_" + t.getStatePtr()->getIdent()
- + ", " + component + "_Event_" + t.getEventPtr()->getIdent();
-
- string code;
-
- code += " {\n";
- // Only set next_state if it changes
- if (t.getStatePtr() != t.getNextStatePtr()) {
- code += " next_state = " + component + "_State_" + t.getNextStatePtr()->getIdent() + ";\n";
- }
-
- const Vector<Action*>& action_vec = t.getActions();
- int numActions = action_vec.size();
-
- // Check for resources
- Vector<string> code_sorter;
- const Map<Var*, string>& res = t.getResources();
- Vector<Var*> res_keys = res.keys();
- for (int i=0; i<res_keys.size(); i++) {
- string temp_code;
- if (res_keys[i]->getType()->cIdent() == "DNUCAStopTable") {
- temp_code += res.lookup(res_keys[i]);
- } else {
- temp_code += " if (!" + (res_keys[i]->getCode()) + ".areNSlotsAvailable(" + res.lookup(res_keys[i]) + ")) {\n";
- if(CHECK_INVALID_RESOURCE_STALLS) {
- // assert that the resource stall is for a resource of equal or greater priority
- temp_code += " assert(priority >= "+ (res_keys[i]->getCode()) + ".getPriority());\n";
- }
- temp_code += " return TransitionResult_ResourceStall;\n";
- temp_code += " }\n";
- }
- code_sorter.insertAtBottom(temp_code);
- }
-
- // Emit the code sequences in a sorted order. This makes the
- // output deterministic (without this the output order can vary
- // since Map's keys() on a vector of pointers is not deterministic
- code_sorter.sortVector();
- for (int i=0; i<code_sorter.size(); i++) {
- code += code_sorter[i];
- }
-
- // Figure out if we stall
- bool stall = false;
- for (int i=0; i<numActions; i++) {
- if(action_vec[i]->getIdent() == "z_stall") {
- stall = true;
- }
- }
-
- if (stall) {
- code += " return TransitionResult_ProtocolStall;\n";
- } else {
- for (int i=0; i<numActions; i++) {
- code += " " + action_vec[i]->getIdent() + "(addr);\n";
- }
- code += " return TransitionResult_Valid;\n";
- }
- code += " }\n";
-
-
- // Look to see if this transition code is unique.
- if (code_map.exist(code)) {
- code_map.lookup(code).insertAtBottom(case_string);
- } else {
- Vector<string> vec;
- vec.insertAtBottom(case_string);
- code_map.add(code, vec);
- code_vec.insertAtBottom(code);
- }
- }
-
- // Walk through all of the unique code blocks and spit out the
- // corresponding case statement elements
- for (int i=0; i<code_vec.size(); i++) {
- string code = code_vec[i];
-
- // Iterative over all the multiple transitions that share the same code
- for (int case_num=0; case_num<code_map.lookup(code).size(); case_num++) {
- string case_string = code_map.lookup(code)[case_num];
- out << " case HASH_FUN(" << case_string << "):" << endl;
- }
- out << code;
- }
-
- out << " default:" << endl;
- out << " WARN_EXPR(m_version);" << endl;
- out << " WARN_EXPR(g_eventQueue_ptr->getTime());" << endl;
- out << " WARN_EXPR(addr);" << endl;
- out << " WARN_EXPR(event);" << endl;
- out << " WARN_EXPR(state);" << endl;
- out << " ERROR_MSG(\"Invalid transition\");" << endl;
- out << " }" << endl;
- out << " return TransitionResult_Valid;" << endl;
- out << "}" << endl;
-}
-
-void StateMachine::printProfilerH(ostream& out, string component)
-{
- out << "// Auto generated C++ code started by "<<__FILE__<<":"<<__LINE__<< endl;
- out << "// " << getIdent() << ": " << getShorthand() << endl;
- out << endl;
- out << "#ifndef " << component << "_PROFILER_H" << endl;
- out << "#define " << component << "_PROFILER_H" << endl;
- out << endl;
- out << "#include \"mem/ruby/common/Global.hh\"" << endl;
- out << "#include \"mem/protocol/" << component << "_State.hh\"" << endl;
- out << "#include \"mem/protocol/" << component << "_Event.hh\"" << endl;
- out << endl;
- out << "class " << component << "_Profiler {" << endl;
- out << "public:" << endl;
- out << " " << component << "_Profiler();" << endl;
- out << " void setVersion(int version);" << endl;
- out << " void countTransition(" << component << "_State state, " << component << "_Event event);" << endl;
- out << " void possibleTransition(" << component << "_State state, " << component << "_Event event);" << endl;
- out << " void dumpStats(ostream& out) const;" << endl;
- out << " void clearStats();" << endl;
- out << "private:" << endl;
- out << " int m_counters[" << component << "_State_NUM][" << component << "_Event_NUM];" << endl;
- out << " int m_event_counters[" << component << "_Event_NUM];" << endl;
- out << " bool m_possible[" << component << "_State_NUM][" << component << "_Event_NUM];" << endl;
- out << " int m_version;" << endl;
- out << "};" << endl;
- out << "#endif // " << component << "_PROFILER_H" << endl;
-}
-
-void StateMachine::printProfilerC(ostream& out, string component)
-{
- out << "// Auto generated C++ code started by "<<__FILE__<<":"<<__LINE__<< endl;
- out << "// " << getIdent() << ": " << getShorthand() << endl;
- out << endl;
- out << "#include \"mem/protocol/" << component << "_Profiler.hh\"" << endl;
- out << endl;
-
- // Constructor
- out << component << "_Profiler::" << component << "_Profiler()" << endl;
- out << "{" << endl;
- out << " for (int state = 0; state < " << component << "_State_NUM; state++) {" << endl;
- out << " for (int event = 0; event < " << component << "_Event_NUM; event++) {" << endl;
- out << " m_possible[state][event] = false;" << endl;
- out << " m_counters[state][event] = 0;" << endl;
- out << " }" << endl;
- out << " }" << endl;
- out << " for (int event = 0; event < " << component << "_Event_NUM; event++) {" << endl;
- out << " m_event_counters[event] = 0;" << endl;
- out << " }" << endl;
- out << "}" << endl;
-
- // setVersion
- out << "void " << component << "_Profiler::setVersion(int version)" << endl;
- out << "{" << endl;
- out << " m_version = version;" << endl;
- out << "}" << endl;
-
- // Clearstats
- out << "void " << component << "_Profiler::clearStats()" << endl;
- out << "{" << endl;
- out << " for (int state = 0; state < " << component << "_State_NUM; state++) {" << endl;
- out << " for (int event = 0; event < " << component << "_Event_NUM; event++) {" << endl;
- out << " m_counters[state][event] = 0;" << endl;
- out << " }" << endl;
- out << " }" << endl;
- out << " for (int event = 0; event < " << component << "_Event_NUM; event++) {" << endl;
- out << " m_event_counters[event] = 0;" << endl;
- out << " }" << endl;
- out << "}" << endl;
-
- // Count Transition
- out << "void " << component << "_Profiler::countTransition(" << component << "_State state, " << component << "_Event event)" << endl;
- out << "{" << endl;
- out << " assert(m_possible[state][event]);" << endl;
- out << " m_counters[state][event]++;" << endl;
- out << " m_event_counters[event]++;" << endl;
- out << "}" << endl;
-
- // Possible Transition
- out << "void " << component << "_Profiler::possibleTransition(" << component << "_State state, " << component << "_Event event)" << endl;
- out << "{" << endl;
- out << " m_possible[state][event] = true;" << endl;
- out << "}" << endl;
-
- // dumpStats
- out << "void " << component << "_Profiler::dumpStats(ostream& out) const" << endl;
- out << "{" << endl;
- out << " out << \" --- " << component << " \" << m_version << \" ---\" << endl;" << endl;
- out << " out << \" - Event Counts -\" << endl;" << endl;
- out << " for (int event = 0; event < " << component << "_Event_NUM; event++) {" << endl;
- out << " int count = m_event_counters[event];" << endl;
- out << " out << (" << component << "_Event) event << \" \" << count << endl;" << endl;
- out << " }" << endl;
- out << " out << endl;" << endl;
- out << " out << \" - Transitions -\" << endl;" << endl;
- out << " for (int state = 0; state < " << component << "_State_NUM; state++) {" << endl;
- out << " for (int event = 0; event < " << component << "_Event_NUM; event++) {" << endl;
- out << " if (m_possible[state][event]) {" << endl;
- out << " int count = m_counters[state][event];" << endl;
- out << " out << (" << component << "_State) state << \" \" << (" << component << "_Event) event << \" \" << count;" << endl;
- out << " if (count == 0) {" << endl;
- out << " out << \" <-- \";" << endl;
- out << " }" << endl;
- out << " out << endl;" << endl;
- out << " }" << endl;
- out << " }" << endl;
- out << " out << endl;" << endl;
- out << " }" << endl;
- out << "}" << endl;
-}
-
-
-
-// ************************** //
-// ******* HTML Files ******* //
-// ************************** //
-
-string frameRef(string click_href, string click_target, string over_href, string over_target_num, string text)
-{
- string temp;
- temp += "<A href=\"" + click_href + "\" ";
- temp += "target=\"" + click_target + "\" ";
- string javascript = "if (parent.frames[" + over_target_num + "].location != parent.location + '" + over_href + "') { parent.frames[" + over_target_num + "].location='" + over_href + "' }";
- // string javascript = "parent." + target + ".location='" + href + "'";
- temp += "onMouseOver=\"" + javascript + "\" ";
- temp += ">" + text + "</A>";
- return temp;
-}
-
-string frameRef(string href, string target, string target_num, string text)
-{
- return frameRef(href, target, href, target_num, text);
-}
-
-
-void StateMachine::writeHTMLFiles(string path)
-{
- string filename;
- string component = getIdent();
-
- /*
- {
- ostringstream out;
- out << "<html>" << endl;
- out << "<head>" << endl;
- out << "<title>" << component << "</title>" << endl;
- out << "</head>" << endl;
- out << "<frameset rows=\"30,30,*\" frameborder=\"1\">" << endl;
- out << " <frame name=\"Status\" src=\"empty.html\" marginheight=\"1\">" << endl;
- out << " <frame name=\"Table\" src=\"" << component << "_table.html\" marginheight=\"1\">" << endl;
- out << "</frameset>" << endl;
- out << "</html>" << endl;
- conditionally_write_file(path + component + ".html", out);
- }
- */
-
- // Create table with no row hilighted
- {
- ostringstream out;
- printHTMLTransitions(out, numStates()+1);
-
- // -- Write file
- filename = component + "_table.html";
- conditionally_write_file(path + filename, out);
- }
-
- // Generate transition tables
- for(int i=0; i<numStates(); i++) {
- ostringstream out;
- printHTMLTransitions(out, i);
-
- // -- Write file
- filename = component + "_table_" + getState(i).getIdent() + ".html";
- conditionally_write_file(path + filename, out);
- }
-
- // Generate action descriptions
- for(int i=0; i<numActions(); i++) {
- ostringstream out;
- createHTMLSymbol(getAction(i), "Action", out);
-
- // -- Write file
- filename = component + "_action_" + getAction(i).getIdent() + ".html";
- conditionally_write_file(path + filename, out);
- }
-
- // Generate state descriptions
- for(int i=0; i<numStates(); i++) {
- ostringstream out;
- createHTMLSymbol(getState(i), "State", out);
-
- // -- Write file
- filename = component + "_State_" + getState(i).getIdent() + ".html";
- conditionally_write_file(path + filename, out);
- }
-
- // Generate event descriptions
- for(int i=0; i<numEvents(); i++) {
- ostringstream out;
- createHTMLSymbol(getEvent(i), "Event", out);
-
- // -- Write file
- filename = component + "_Event_" + getEvent(i).getIdent() + ".html";
- conditionally_write_file(path + filename, out);
- }
-}
-
-void StateMachine::printHTMLTransitions(ostream& out, int active_state)
-{
- // -- Prolog
- out << "<HTML><BODY link=\"blue\" vlink=\"blue\">" << endl;
-
- // -- Header
- out << "<H1 align=\"center\">" << formatHTMLShorthand(getShorthand()) << ": " << endl;
- Vector<StateMachine*> machine_vec = g_sym_table.getStateMachines();
- for (int i=0; i<machine_vec.size(); i++) {
- StateMachine* type = machine_vec[i];
- if (i != 0) {
- out << " - ";
- }
- if (type == this) {
- out << type->getIdent() << endl;
- } else {
- out << "<A target=\"Table\"href=\"" + type->getIdent() + "_table.html\">" + type->getIdent() + "</A> " << endl;
- }
- }
- out << "</H1>" << endl;
-
- // -- Table header
- out << "<TABLE border=1>" << endl;
-
- // -- Column headers
- out << "<TR>" << endl;
-
- // -- First column header
- out << " <TH> </TH>" << endl;
-
- for(int event = 0; event < numEvents(); event++ ) {
- out << " <TH bgcolor=white>";
- out << frameRef(getIdent() + "_Event_" + getEvent(event).getIdent() + ".html", "Status", "1", formatHTMLShorthand(getEvent(event).getShorthand()));
- out << "</TH>" << endl;
- }
-
- out << "</TR>" << endl;
-
- // -- Body of table
- for(int state = 0; state < numStates(); state++ ) {
- out << "<TR>" << endl;
-
- // -- Each row
- if (state == active_state) {
- out << " <TH bgcolor=yellow>";
- } else {
- out << " <TH bgcolor=white>";
- }
-
- string click_href = getIdent() + "_table_" + getState(state).getIdent() + ".html";
- string text = formatHTMLShorthand(getState(state).getShorthand());
-
- out << frameRef(click_href, "Table", getIdent() + "_State_" + getState(state).getIdent() + ".html", "1", formatHTMLShorthand(getState(state).getShorthand()));
- out << "</TH>" << endl;
-
- // -- One column for each event
- for(int event = 0; event < numEvents(); event++ ) {
- const Transition* trans_ptr = getTransPtr(state, event);
-
- if( trans_ptr != NULL ) {
- bool stall_action = false;
- string nextState;
- string actions_str;
-
- // -- Get the actions
- // actions = trans_ptr->getActionShorthands();
- const Vector<Action*> actions = trans_ptr->getActions();
- for (int action=0; action < actions.size(); action++) {
- if ((actions[action]->getIdent() == "z_stall") ||
- (actions[action]->getIdent() == "zz_recycleMandatoryQueue")) {
- stall_action = true;
- }
- actions_str += " ";
- actions_str += frameRef(getIdent() + "_action_" + actions[action]->getIdent() + ".html", "Status", "1",
- formatHTMLShorthand(actions[action]->getShorthand()));
- actions_str += "\n";
- }
-
- // -- Get the next state
- if (trans_ptr->getNextStatePtr()->getIdent() != getState(state).getIdent()) {
- string click_href = getIdent() + "_table_" + trans_ptr->getNextStatePtr()->getIdent() + ".html";
- nextState = frameRef(click_href, "Table", getIdent() + "_State_" + trans_ptr->getNextStatePtr()->getIdent() + ".html", "1",
- formatHTMLShorthand(trans_ptr->getNextStateShorthand()));
- } else {
- nextState = "";
- }
-
- // -- Print out "actions/next-state"
- if (stall_action) {
- if (state == active_state) {
- out << " <TD bgcolor=#C0C000>";
- } else {
- out << " <TD bgcolor=lightgrey>";
- }
- } else if (active_state < numStates() && (trans_ptr->getNextStatePtr()->getIdent() == getState(active_state).getIdent())) {
- out << " <TD bgcolor=aqua>";
- } else if (state == active_state) {
- out << " <TD bgcolor=yellow>";
- } else {
- out << " <TD bgcolor=white>";
- }
-
- out << actions_str;
- if ((nextState.length() != 0) && (actions_str.length() != 0)) {
- out << "/";
- }
- out << nextState;
- out << "</TD>" << endl;
- } else {
- // This is the no transition case
- if (state == active_state) {
- out << " <TD bgcolor=#C0C000>&nbsp;</TD>" << endl;
- } else {
- out << " <TD bgcolor=lightgrey>&nbsp;</TD>" << endl;
- }
- }
- }
- // -- Each row
- if (state == active_state) {
- out << " <TH bgcolor=yellow>";
- } else {
- out << " <TH bgcolor=white>";
- }
-
- click_href = getIdent() + "_table_" + getState(state).getIdent() + ".html";
- text = formatHTMLShorthand(getState(state).getShorthand());
-
- out << frameRef(click_href, "Table", getIdent() + "_State_" + getState(state).getIdent() + ".html", "1", formatHTMLShorthand(getState(state).getShorthand()));
- out << "</TH>" << endl;
-
- out << "</TR>" << endl;
- }
-
- // -- Column footer
- out << "<TR>" << endl;
- out << " <TH> </TH>" << endl;
-
- for(int i = 0; i < numEvents(); i++ ) {
- out << " <TH bgcolor=white>";
- out << frameRef(getIdent() + "_Event_" + getEvent(i).getIdent() + ".html", "Status", "1", formatHTMLShorthand(getEvent(i).getShorthand()));
- out << "</TH>" << endl;
- }
- out << "</TR>" << endl;
-
- // -- Epilog
- out << "</TABLE>" << endl;
- out << "</BODY></HTML>" << endl;
-}
-
-
diff --git a/src/mem/slicc/symbols/StateMachine.hh b/src/mem/slicc/symbols/StateMachine.hh
deleted file mode 100644
index f5f3ab073..000000000
--- a/src/mem/slicc/symbols/StateMachine.hh
+++ /dev/null
@@ -1,156 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * $Id$
- *
- * */
-
-#ifndef STATEMACHINE_H
-#define STATEMACHINE_H
-
-#include "mem/slicc/slicc_global.hh"
-#include "mem/gems_common/Vector.hh"
-#include "mem/gems_common/Map.hh"
-#include "mem/slicc/symbols/Symbol.hh"
-#include <list>
-
-using namespace std;
-
-class Transition;
-class Event;
-class State;
-class Action;
-class Var;
-class Func;
-class FormalParamAST;
-
-class StateMachine : public Symbol {
-public:
- // Constructors
- StateMachine(string ident, const Location& location, const Map<string, string>& pairs, Vector<FormalParamAST*>* config_parameters);
-
- // Destructor
- ~StateMachine();
-
- // Public Methods
-
- // Add items to the state machine
- // void setMachine(string ident, const Map<string, string>& pairs);
- void addState(State* state_ptr);
- void addEvent(Event* event_ptr);
- void addAction(Action* action_ptr);
- void addTransition(Transition* trans_ptr);
- void addInPort(Var* var) { m_in_ports.insertAtBottom(var); }
- void addFunc(Func* func);
- void addObj(Var* obj) { m_objs.insertAtBottom(obj); }
-
- // Accessors to vectors
- const State& getState(int index) const { return *m_states[index]; }
- const Event& getEvent(int index) const { return *m_events[index]; }
- const Action& getAction(int index) const { return *m_actions[index]; }
- const Transition& getTransition(int index) const { return *m_transitions[index]; }
- const Transition* getTransPtr(int stateIndex, int eventIndex) const;
- const Var& getObject(int index) const { return *m_objs[index]; }
-
- // Accessors for size of vectors
- int numStates() const { return m_states.size(); }
- int numEvents() const { return m_events.size(); }
- int numActions() const { return m_actions.size(); }
- int numTransitions() const { return m_transitions.size(); }
- int numObjects() const { return m_objs.size(); }
-
- void buildTable(); // Needs to be called before accessing the table
-
- // Code generator methods
- void writeCFiles(string path) ;
- void writeHTMLFiles(string path) ;
-
- void print(ostream& out) const { out << "[StateMachine: " << toString() << "]" << endl; }
-private:
-
- Vector<FormalParamAST*>* m_config_parameters;
-
- // Private Methods
- void checkForDuplicate(const Symbol& sym) const;
-
- int getStateIndex(State* state_ptr) const { return m_state_map.lookup(state_ptr); }
- int getEventIndex(Event* event_ptr) const { return m_event_map.lookup(event_ptr); }
-
- // Private copy constructor and assignment operator
- // StateMachine(const StateMachine& obj);
- // StateMachine& operator=(const StateMachine& obj);
-
- void printControllerH(ostream& out, string component) ;
- void printControllerC(ostream& out, string component) ;
- void printCWakeup(ostream& out, string component) ;
- void printCSwitch(ostream& out, string component) ;
- void printProfilerH(ostream& out, string component) ;
- void printProfilerC(ostream& out, string component) ;
-
- void printHTMLTransitions(ostream& out, int active_state) ;
-
- // Data Members (m_ prefix)
- Vector<State*> m_states;
- Vector<Event*> m_events;
- Vector<Action*> m_actions;
- Vector<Transition*> m_transitions;
- Vector<Func*> m_internal_func_vec;
-
- Map<State*, int> m_state_map;
- Map<Event*, int> m_event_map;
-
- Vector<Var*> m_in_ports;
-
- Vector<Var*> m_objs;
-
- // Table variables
- bool m_table_built;
- Vector<Vector<Transition*> > m_table;
-
- //added by SS
- std::vector<std::string> m_message_buffer_names;
-
-};
-
-// Output operator declaration
-ostream& operator<<(ostream& out, const StateMachine& obj);
-
-// ******************* Definitions *******************
-
-// Output operator definition
-extern inline
-ostream& operator<<(ostream& out, const StateMachine& obj)
-{
- obj.print(out);
- out << flush;
- return out;
-}
-
-#endif //STATEMACHINE_H
diff --git a/src/mem/slicc/symbols/StateMachine.py b/src/mem/slicc/symbols/StateMachine.py
new file mode 100644
index 000000000..e54d6a435
--- /dev/null
+++ b/src/mem/slicc/symbols/StateMachine.py
@@ -0,0 +1,1222 @@
+# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
+# Copyright (c) 2009 The Hewlett-Packard Development Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (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, orderdict
+
+from slicc.symbols.Symbol import Symbol
+from slicc.symbols.Var import Var
+import slicc.generate.html as html
+
+class StateMachine(Symbol):
+ def __init__(self, symtab, ident, location, pairs, config_parameters):
+ super(StateMachine, self).__init__(symtab, ident, location, pairs)
+ self.table = None
+ self.config_parameters = config_parameters
+ for param in config_parameters:
+ var = Var(symtab, param.name, location, param.type_ast.type,
+ "m_%s" % param.name, {}, self)
+ self.symtab.registerSym(param.name, var)
+
+ self.states = orderdict()
+ self.events = orderdict()
+ self.actions = orderdict()
+ self.transitions = []
+ self.in_ports = []
+ self.functions = []
+ self.objects = []
+
+ self.message_buffer_names = []
+
+ def __repr__(self):
+ return "[StateMachine: %s]" % self.ident
+
+ def addState(self, state):
+ assert self.table is None
+ self.states[state.ident] = state
+
+ def addEvent(self, event):
+ assert self.table is None
+ self.events[event.ident] = event
+
+ def addAction(self, action):
+ assert self.table is None
+
+ # Check for duplicate action
+ for other in self.actions.itervalues():
+ if action.ident == other.ident:
+ a.warning("Duplicate action definition: %s" % a.ident)
+ action.error("Duplicate action definition: %s" % action.ident)
+ if action.short == other.short:
+ other.warning("Duplicate action shorthand: %s" % other.ident)
+ other.warning(" shorthand = %s" % other.short)
+ action.warning("Duplicate action shorthand: %s" % action.ident)
+ action.error(" shorthand = %s" % action.short)
+
+ self.actions[action.ident] = action
+
+ def addTransition(self, trans):
+ assert self.table is None
+ self.transitions.append(trans)
+
+ def addInPort(self, var):
+ self.in_ports.append(var)
+
+ def addFunc(self, func):
+ # register func in the symbol table
+ self.symtab.registerSym(str(func), func)
+ self.functions.append(func)
+
+ def addObject(self, obj):
+ self.objects.append(obj)
+
+ # Needs to be called before accessing the table
+ def buildTable(self):
+ assert self.table is None
+
+ table = {}
+
+ for trans in self.transitions:
+ # Track which actions we touch so we know if we use them
+ # all -- really this should be done for all symbols as
+ # part of the symbol table, then only trigger it for
+ # Actions, States, Events, etc.
+
+ for action in trans.actions:
+ action.used = True
+
+ index = (trans.state, trans.event)
+ if index in table:
+ table[index].warning("Duplicate transition: %s" % table[index])
+ trans.error("Duplicate transition: %s" % trans)
+ table[index] = trans
+
+ # Look at all actions to make sure we used them all
+ for action in self.actions.itervalues():
+ if not action.used:
+ error_msg = "Unused action: %s" % action.ident
+ if "desc" in action:
+ error_msg += ", " + action.desc
+ action.warning(error_msg)
+ self.table = table
+
+ def writeCodeFiles(self, path):
+ self.printControllerHH(path)
+ self.printControllerCC(path)
+ self.printCSwitch(path)
+ self.printCWakeup(path)
+ self.printProfilerCC(path)
+ self.printProfilerHH(path)
+
+ for func in self.functions:
+ func.writeCodeFiles(path)
+
+ def printControllerHH(self, path):
+ '''Output the method declarations for the class declaration'''
+ code = code_formatter()
+ ident = self.ident
+ c_ident = "%s_Controller" % self.ident
+
+ self.message_buffer_names = []
+
+ code('''
+/** \\file $ident.hh
+ *
+ * Auto generated C++ code started by $__file__:$__line__
+ * Created by slicc definition of Module "${{self.short}}"
+ */
+
+#ifndef ${ident}_CONTROLLER_H
+#define ${ident}_CONTROLLER_H
+
+#include "mem/ruby/common/Global.hh"
+#include "mem/ruby/common/Consumer.hh"
+#include "mem/ruby/slicc_interface/AbstractController.hh"
+#include "mem/protocol/TransitionResult.hh"
+#include "mem/protocol/Types.hh"
+#include "mem/protocol/${ident}_Profiler.hh"
+''')
+
+ seen_types = set()
+ for var in self.objects:
+ if var.type.ident not in seen_types:
+ code('#include "mem/protocol/${{var.type.c_ident}}.hh"')
+ seen_types.add(var.type.ident)
+
+ # for adding information to the protocol debug trace
+ code('''
+extern stringstream ${ident}_transitionComment;
+
+class $c_ident : public AbstractController {
+#ifdef CHECK_COHERENCE
+#endif /* CHECK_COHERENCE */
+public:
+ $c_ident(const string & name);
+ static int getNumControllers();
+ void init(Network* net_ptr, const vector<string> & argv);
+ MessageBuffer* getMandatoryQueue() const;
+ const int & getVersion() const;
+ const string toString() const;
+ const string getName() const;
+ const MachineType getMachineType() const;
+ void print(ostream& out) const;
+ void printConfig(ostream& out) const;
+ void wakeup();
+ void set_atomic(Address addr);
+ void started_writes();
+ void clear_atomic();
+ void printStats(ostream& out) const { s_profiler.dumpStats(out); }
+ void clearStats() { s_profiler.clearStats(); }
+private:
+''')
+
+ code.indent()
+ # added by SS
+ for param in self.config_parameters:
+ code('int m_${{param.ident}};')
+
+ if self.ident == "L1Cache":
+ code('''
+int servicing_atomic;
+bool started_receiving_writes;
+Address locked_read_request1;
+Address locked_read_request2;
+Address locked_read_request3;
+Address locked_read_request4;
+int read_counter;
+''')
+
+ code('''
+int m_number_of_TBEs;
+
+TransitionResult doTransition(${ident}_Event event, ${ident}_State state, const Address& addr); // in ${ident}_Transitions.cc
+TransitionResult doTransitionWorker(${ident}_Event event, ${ident}_State state, ${ident}_State& next_state, const Address& addr); // in ${ident}_Transitions.cc
+string m_name;
+int m_transitions_per_cycle;
+int m_buffer_size;
+int m_recycle_latency;
+map< string, string > m_cfg;
+NodeID m_version;
+Network* m_net_ptr;
+MachineID m_machineID;
+${ident}_Profiler s_profiler;
+static int m_num_controllers;
+// Internal functions
+''')
+
+ for func in self.functions:
+ proto = func.prototype
+ if proto:
+ code('$proto')
+
+ code('''
+
+// Actions
+''')
+ for action in self.actions.itervalues():
+ code('/** \\brief ${{action.desc}} */')
+ code('void ${{action.ident}}(const Address& addr);')
+
+ # the controller internal variables
+ code('''
+
+// Object
+''')
+ for var in self.objects:
+ th = var.get("template_hack", "")
+ code('${{var.type.c_ident}}$th* m_${{var.c_ident}}_ptr;')
+
+ if var.type.ident == "MessageBuffer":
+ self.message_buffer_names.append("m_%s_ptr" % var.c_ident)
+
+ code.dedent()
+ code('};')
+ code('#endif // ${ident}_CONTROLLER_H')
+ code.write(path, '%s.hh' % c_ident)
+
+ def printControllerCC(self, path):
+ '''Output the actions for performing the actions'''
+
+ code = code_formatter()
+ ident = self.ident
+ c_ident = "%s_Controller" % self.ident
+
+ code('''
+/** \\file $ident.cc
+ *
+ * Auto generated C++ code started by $__file__:$__line__
+ * Created by slicc definition of Module "${{self.short}}"
+ */
+
+#include "mem/ruby/common/Global.hh"
+#include "mem/ruby/slicc_interface/RubySlicc_includes.hh"
+#include "mem/protocol/${ident}_Controller.hh"
+#include "mem/protocol/${ident}_State.hh"
+#include "mem/protocol/${ident}_Event.hh"
+#include "mem/protocol/Types.hh"
+#include "mem/ruby/system/System.hh"
+''')
+
+ # include object classes
+ seen_types = set()
+ for var in self.objects:
+ if var.type.ident not in seen_types:
+ code('#include "mem/protocol/${{var.type.c_ident}}.hh"')
+ seen_types.add(var.type.ident)
+
+ code('''
+int $c_ident::m_num_controllers = 0;
+
+stringstream ${ident}_transitionComment;
+#define APPEND_TRANSITION_COMMENT(str) (${ident}_transitionComment << str)
+/** \\brief constructor */
+$c_ident::$c_ident(const string &name)
+ : m_name(name)
+{
+''')
+ code.indent()
+ if self.ident == "L1Cache":
+ code('''
+servicing_atomic = 0;
+started_receiving_writes = false;
+locked_read_request1 = Address(-1);
+locked_read_request2 = Address(-1);
+locked_read_request3 = Address(-1);
+locked_read_request4 = Address(-1);
+read_counter = 0;
+''')
+
+ code('m_num_controllers++;')
+ for var in self.objects:
+ if var.ident.find("mandatoryQueue") >= 0:
+ code('m_${{var.c_ident}}_ptr = new ${{var.type.c_ident}}();')
+
+ code.dedent()
+ code('''
+}
+
+void $c_ident::init(Network *net_ptr, const vector<string> &argv)
+{
+ for (size_t i = 0; i < argv.size(); i += 2) {
+ if (argv[i] == "version")
+ m_version = atoi(argv[i+1].c_str());
+ else if (argv[i] == "transitions_per_cycle")
+ m_transitions_per_cycle = atoi(argv[i+1].c_str());
+ else if (argv[i] == "buffer_size")
+ m_buffer_size = atoi(argv[i+1].c_str());
+ else if (argv[i] == "recycle_latency")
+ m_recycle_latency = atoi(argv[i+1].c_str());
+ else if (argv[i] == "number_of_TBEs")
+ m_number_of_TBEs = atoi(argv[i+1].c_str());
+''')
+
+ code.indent()
+ code.indent()
+ for param in self.config_parameters:
+ code('else if (argv[i] == "${{param.name}}")')
+ if param.type_ast.type.ident == "int":
+ code(' m_${{param.name}} = atoi(argv[i+1].c_str());')
+ else:
+ self.error("only int parameters are supported right now")
+ code.dedent()
+ code.dedent()
+ code('''
+ }
+
+ m_net_ptr = net_ptr;
+ m_machineID.type = MachineType_${ident};
+ m_machineID.num = m_version;
+ for (size_t i = 0; i < argv.size(); i += 2) {
+ if (argv[i] != "version")
+ m_cfg[argv[i]] = argv[i+1];
+ }
+
+ // Objects
+ s_profiler.setVersion(m_version);
+''')
+
+ code.indent()
+ for var in self.objects:
+ vtype = var.type
+ vid = "m_%s_ptr" % var.c_ident
+ if "network" not in var:
+ # Not a network port object
+ if "primitive" in vtype:
+ code('$vid = new ${{vtype.c_ident}};')
+ if "default" in var:
+ code('(*$vid) = ${{var["default"]}};')
+ else:
+ # Normal Object
+ # added by SS
+ if "factory" in var:
+ code('$vid = ${{var["factory"]}};')
+ elif var.ident.find("mandatoryQueue") < 0:
+ th = var.get("template_hack", "")
+ expr = "%s = new %s%s" % (vid, vtype.c_ident, th)
+
+ args = ""
+ if "non_obj" not in vtype and not vtype.isEnumeration:
+ if expr.find("TBETable") >= 0:
+ args = "m_number_of_TBEs"
+ else:
+ args = var.get("constructor_hack", "")
+ args = "(%s)" % args
+
+ code('$expr$args;')
+ else:
+ code(';')
+
+ code('assert($vid != NULL);')
+
+ if "default" in var:
+ code('(*$vid) = ${{var["default"]}}; // Object default')
+ elif "default" in vtype:
+ code('(*$vid) = ${{vtype["default"]}}; // Type ${{vtype.ident}} default')
+
+ # Set ordering
+ if "ordered" in var and "trigger_queue" not in var:
+ # A buffer
+ code('$vid->setOrdering(${{var["ordered"]}});')
+
+ # Set randomization
+ if "random" in var:
+ # A buffer
+ code('$vid->setRandomization(${{var["random"]}});')
+
+ # Set Priority
+ if vtype.isBuffer and \
+ "rank" in var and "trigger_queue" not in var:
+ code('$vid->setPriority(${{var["rank"]}});')
+ else:
+ # Network port object
+ network = var["network"]
+ ordered = var["ordered"]
+ vnet = var["virtual_network"]
+
+ assert var.machine is not None
+ code('''
+$vid = m_net_ptr->get${network}NetQueue(m_version+MachineType_base_number(string_to_MachineType("${{var.machine.ident}}")), $ordered, $vnet);
+''')
+
+ code('assert($vid != NULL);')
+
+ # Set ordering
+ if "ordered" in var:
+ # A buffer
+ code('$vid->setOrdering(${{var["ordered"]}});')
+
+ # Set randomization
+ if "random" in var:
+ # A buffer
+ code('$vid->setRandomization(${{var["random"]}})')
+
+ # Set Priority
+ if "rank" in var:
+ code('$vid->setPriority(${{var["rank"]}})')
+
+ # Set buffer size
+ if vtype.isBuffer:
+ code('''
+if (m_buffer_size > 0) {
+ $vid->setSize(m_buffer_size);
+}
+''')
+
+ # set description (may be overriden later by port def)
+ code('$vid->setDescription("[Version " + int_to_string(m_version) + ", ${ident}, name=${{var.c_ident}}]");')
+
+ # Set the queue consumers
+ code.insert_newline()
+ for port in self.in_ports:
+ code('${{port.code}}.setConsumer(this);')
+
+ # Set the queue descriptions
+ code.insert_newline()
+ for port in self.in_ports:
+ code('${{port.code}}.setDescription("[Version " + int_to_string(m_version) + ", $ident, $port]");')
+
+ # Initialize the transition profiling
+ code.insert_newline()
+ for trans in self.transitions:
+ # Figure out if we stall
+ stall = False
+ for action in trans.actions:
+ if action.ident == "z_stall":
+ stall = True
+
+ # Only possible if it is not a 'z' case
+ if not stall:
+ state = "%s_State_%s" % (self.ident, trans.state.ident)
+ event = "%s_Event_%s" % (self.ident, trans.event.ident)
+ code('s_profiler.possibleTransition($state, $event);')
+
+ # added by SS to initialize recycle_latency of message buffers
+ for buf in self.message_buffer_names:
+ code("$buf->setRecycleLatency(m_recycle_latency);")
+
+ code.dedent()
+ code('}')
+
+ has_mandatory_q = False
+ for port in self.in_ports:
+ if port.code.find("mandatoryQueue_ptr") >= 0:
+ has_mandatory_q = True
+
+ if has_mandatory_q:
+ mq_ident = "m_%s_mandatoryQueue_ptr" % self.ident
+ else:
+ mq_ident = "NULL"
+
+ code('''
+int $c_ident::getNumControllers() {
+ return m_num_controllers;
+}
+
+MessageBuffer* $c_ident::getMandatoryQueue() const {
+ return $mq_ident;
+}
+
+const int & $c_ident::getVersion() const{
+ return m_version;
+}
+
+const string $c_ident::toString() const{
+ return "$c_ident";
+}
+
+const string $c_ident::getName() const{
+ return m_name;
+}
+const MachineType $c_ident::getMachineType() const{
+ return MachineType_${ident};
+}
+
+void $c_ident::print(ostream& out) const { out << "[$c_ident " << m_version << "]"; }
+
+void $c_ident::printConfig(ostream& out) const {
+ out << "$c_ident config: " << m_name << endl;
+ out << " version: " << m_version << endl;
+ for (map<string, string>::const_iterator it = m_cfg.begin(); it != m_cfg.end(); it++) {
+ out << " " << (*it).first << ": " << (*it).second << endl;
+ }
+}
+
+// Actions
+''')
+
+ for action in self.actions.itervalues():
+ if "c_code" not in action:
+ continue
+
+ code('''
+/** \\brief ${{action.desc}} */
+void $c_ident::${{action.ident}}(const Address& addr)
+{
+ DEBUG_MSG(GENERATED_COMP, HighPrio, "executing");
+ ${{action["c_code"]}}
+}
+
+''')
+ code.write(path, "%s.cc" % c_ident)
+
+ def printCWakeup(self, path):
+ '''Output the wakeup loop for the events'''
+
+ code = code_formatter()
+ ident = self.ident
+
+ code('''
+// Auto generated C++ code started by $__file__:$__line__
+// ${ident}: ${{self.short}}
+
+#include "mem/ruby/common/Global.hh"
+#include "mem/ruby/slicc_interface/RubySlicc_includes.hh"
+#include "mem/protocol/${ident}_Controller.hh"
+#include "mem/protocol/${ident}_State.hh"
+#include "mem/protocol/${ident}_Event.hh"
+#include "mem/protocol/Types.hh"
+#include "mem/ruby/system/System.hh"
+
+void ${ident}_Controller::wakeup()
+{
+
+ int counter = 0;
+ while (true) {
+ // Some cases will put us into an infinite loop without this limit
+ assert(counter <= m_transitions_per_cycle);
+ if (counter == m_transitions_per_cycle) {
+ g_system_ptr->getProfiler()->controllerBusy(m_machineID); // Count how often we\'re fully utilized
+ g_eventQueue_ptr->scheduleEvent(this, 1); // Wakeup in another cycle and try again
+ break;
+ }
+''')
+
+ code.indent()
+ code.indent()
+
+ # InPorts
+ #
+ # Find the position of the mandatory queue in the vector so
+ # that we can print it out first
+
+ mandatory_q = None
+ if self.ident == "L1Cache":
+ for i,port in enumerate(self.in_ports):
+ assert "c_code_in_port" in port
+ if str(port).find("mandatoryQueue_in") >= 0:
+ assert mandatory_q is None
+ mandatory_q = port
+
+ assert mandatory_q is not None
+
+ # print out the mandatory queue here
+ port = mandatory_q
+ code('// ${ident}InPort $port')
+ output = port["c_code_in_port"]
+
+ pos = output.find("TransitionResult result = doTransition((L1Cache_mandatory_request_type_to_event(((*in_msg_ptr)).m_Type)), L1Cache_getState(addr), addr);")
+ assert pos >= 0
+ atomics_string = '''
+if ((((*in_msg_ptr)).m_Type) == CacheRequestType_ATOMIC) {
+ if (servicing_atomic == 0) {
+ if (locked_read_request1 == Address(-1)) {
+ assert(read_counter == 0);
+ locked_read_request1 = addr;
+ assert(read_counter == 0);
+ read_counter++;
+ }
+ else if (addr == locked_read_request1) {
+ ; // do nothing
+ }
+ else {
+ assert(0); // should never be here if servicing one request at a time
+ }
+ }
+ else if (!started_receiving_writes) {
+ if (servicing_atomic == 1) {
+ if (locked_read_request2 == Address(-1)) {
+ assert(locked_read_request1 != Address(-1));
+ assert(read_counter == 1);
+ locked_read_request2 = addr;
+ assert(read_counter == 1);
+ read_counter++;
+ }
+ else if (addr == locked_read_request2) {
+ ; // do nothing
+ }
+ else {
+ assert(0); // should never be here if servicing one request at a time
+ }
+ }
+ else if (servicing_atomic == 2) {
+ if (locked_read_request3 == Address(-1)) {
+ assert(locked_read_request1 != Address(-1));
+ assert(locked_read_request2 != Address(-1));
+ assert(read_counter == 1);
+ locked_read_request3 = addr;
+ assert(read_counter == 2);
+ read_counter++;
+ }
+ else if (addr == locked_read_request3) {
+ ; // do nothing
+ }
+ else {
+ assert(0); // should never be here if servicing one request at a time
+ }
+ }
+ else if (servicing_atomic == 3) {
+ if (locked_read_request4 == Address(-1)) {
+ assert(locked_read_request1 != Address(-1));
+ assert(locked_read_request2 != Address(-1));
+ assert(locked_read_request3 != Address(-1));
+ assert(read_counter == 1);
+ locked_read_request4 = addr;
+ assert(read_counter == 3);
+ read_counter++;
+ }
+ else if (addr == locked_read_request4) {
+ ; // do nothing
+ }
+ else {
+ assert(0); // should never be here if servicing one request at a time
+ }
+ }
+ else {
+ assert(0);
+ }
+ }
+}
+else {
+ if (servicing_atomic > 0) {
+ // reset
+ servicing_atomic = 0;
+ read_counter = 0;
+ started_receiving_writes = false;
+ locked_read_request1 = Address(-1);
+ locked_read_request2 = Address(-1);
+ locked_read_request3 = Address(-1);
+ locked_read_request4 = Address(-1);
+ }
+}
+'''
+
+ output = output[:pos] + atomics_string + output[pos:]
+ code('$output')
+
+ for port in self.in_ports:
+ # don't print out mandatory queue twice
+ if port == mandatory_q:
+ continue
+
+ if ident == "L1Cache":
+ if str(port).find("forwardRequestNetwork_in") >= 0:
+ code('''
+bool postpone = false;
+if ((((*m_L1Cache_forwardToCache_ptr)).isReady())) {
+ const RequestMsg* in_msg_ptr;
+ in_msg_ptr = dynamic_cast<const RequestMsg*>(((*m_L1Cache_forwardToCache_ptr)).peek());
+ if ((((servicing_atomic == 1) && (locked_read_request1 == ((*in_msg_ptr)).m_Address)) ||
+ ((servicing_atomic == 2) && (locked_read_request1 == ((*in_msg_ptr)).m_Address || locked_read_request2 == ((*in_msg_ptr)).m_Address)) ||
+ ((servicing_atomic == 3) && (locked_read_request1 == ((*in_msg_ptr)).m_Address || locked_read_request2 == ((*in_msg_ptr)).m_Address || locked_read_request3 == ((*in_msg_ptr)).m_Address)) ||
+ ((servicing_atomic == 4) && (locked_read_request1 == ((*in_msg_ptr)).m_Address || locked_read_request2 == ((*in_msg_ptr)).m_Address || locked_read_request3 == ((*in_msg_ptr)).m_Address || locked_read_request1 == ((*in_msg_ptr)).m_Address)))) {
+ postpone = true;
+ }
+}
+if (!postpone) {
+''')
+ code.indent()
+ code('// ${ident}InPort $port')
+ code('${{port["c_code_in_port"]}}')
+ code.dedent()
+
+ if ident == "L1Cache":
+ if str(port).find("forwardRequestNetwork_in") >= 0:
+ code.dedent()
+ code('}')
+ code.indent()
+ code('')
+
+ code.dedent()
+ code.dedent()
+ code('''
+ break; // If we got this far, we have nothing left todo
+ }
+}
+''')
+
+ if self.ident == "L1Cache":
+ code('''
+void ${ident}_Controller::set_atomic(Address addr)
+{
+ servicing_atomic++;
+}
+
+void ${ident}_Controller::started_writes()
+{
+ started_receiving_writes = true;
+}
+
+void ${ident}_Controller::clear_atomic()
+{
+ assert(servicing_atomic > 0);
+ read_counter--;
+ servicing_atomic--;
+ if (read_counter == 0) {
+ servicing_atomic = 0;
+ started_receiving_writes = false;
+ locked_read_request1 = Address(-1);
+ locked_read_request2 = Address(-1);
+ locked_read_request3 = Address(-1);
+ locked_read_request4 = Address(-1);
+ }
+}
+''')
+ else:
+ code('''
+void ${ident}_Controller::started_writes()
+{
+ assert(0);
+}
+
+void ${ident}_Controller::set_atomic(Address addr)
+{
+ assert(0);
+}
+
+void ${ident}_Controller::clear_atomic()
+{
+ assert(0);
+}
+''')
+
+
+ code.write(path, "%s_Wakeup.cc" % self.ident)
+
+ def printCSwitch(self, path):
+ '''Output switch statement for transition table'''
+
+ code = code_formatter()
+ ident = self.ident
+
+ code('''
+// Auto generated C++ code started by $__file__:$__line__
+// ${ident}: ${{self.short}}
+
+#include "mem/ruby/common/Global.hh"
+#include "mem/protocol/${ident}_Controller.hh"
+#include "mem/protocol/${ident}_State.hh"
+#include "mem/protocol/${ident}_Event.hh"
+#include "mem/protocol/Types.hh"
+#include "mem/ruby/system/System.hh"
+
+#define HASH_FUN(state, event) ((int(state)*${ident}_Event_NUM)+int(event))
+
+#define GET_TRANSITION_COMMENT() (${ident}_transitionComment.str())
+#define CLEAR_TRANSITION_COMMENT() (${ident}_transitionComment.str(""))
+
+TransitionResult ${ident}_Controller::doTransition(${ident}_Event event, ${ident}_State state, const Address& addr
+)
+{
+ ${ident}_State next_state = state;
+
+ DEBUG_NEWLINE(GENERATED_COMP, MedPrio);
+ DEBUG_MSG(GENERATED_COMP, MedPrio, *this);
+ DEBUG_EXPR(GENERATED_COMP, MedPrio, g_eventQueue_ptr->getTime());
+ DEBUG_EXPR(GENERATED_COMP, MedPrio,state);
+ DEBUG_EXPR(GENERATED_COMP, MedPrio,event);
+ DEBUG_EXPR(GENERATED_COMP, MedPrio,addr);
+
+ TransitionResult result = doTransitionWorker(event, state, next_state, addr);
+
+ if (result == TransitionResult_Valid) {
+ DEBUG_EXPR(GENERATED_COMP, MedPrio, next_state);
+ DEBUG_NEWLINE(GENERATED_COMP, MedPrio);
+ s_profiler.countTransition(state, event);
+ if (Debug::getProtocolTrace()) {
+ g_system_ptr->getProfiler()->profileTransition("${ident}", m_version, addr,
+ ${ident}_State_to_string(state),
+ ${ident}_Event_to_string(event),
+ ${ident}_State_to_string(next_state), GET_TRANSITION_COMMENT());
+ }
+ CLEAR_TRANSITION_COMMENT();
+ ${ident}_setState(addr, next_state);
+
+ } else if (result == TransitionResult_ResourceStall) {
+ if (Debug::getProtocolTrace()) {
+ g_system_ptr->getProfiler()->profileTransition("${ident}", m_version, addr,
+ ${ident}_State_to_string(state),
+ ${ident}_Event_to_string(event),
+ ${ident}_State_to_string(next_state),
+ "Resource Stall");
+ }
+ } else if (result == TransitionResult_ProtocolStall) {
+ DEBUG_MSG(GENERATED_COMP, HighPrio, "stalling");
+ DEBUG_NEWLINE(GENERATED_COMP, MedPrio);
+ if (Debug::getProtocolTrace()) {
+ g_system_ptr->getProfiler()->profileTransition("${ident}", m_version, addr,
+ ${ident}_State_to_string(state),
+ ${ident}_Event_to_string(event),
+ ${ident}_State_to_string(next_state),
+ "Protocol Stall");
+ }
+ }
+
+ return result;
+}
+
+TransitionResult ${ident}_Controller::doTransitionWorker(${ident}_Event event, ${ident}_State state, ${ident}_State& next_state, const Address& addr
+)
+{
+ switch(HASH_FUN(state, event)) {
+''')
+
+ # This map will allow suppress generating duplicate code
+ cases = orderdict()
+
+ for trans in self.transitions:
+ case_string = "%s_State_%s, %s_Event_%s" % \
+ (self.ident, trans.state.ident, self.ident, trans.event.ident)
+
+ case = code_formatter()
+ # Only set next_state if it changes
+ if trans.state != trans.nextState:
+ ns_ident = trans.nextState.ident
+ case('next_state = ${ident}_State_${ns_ident};')
+
+ actions = trans.actions
+
+ # Check for resources
+ case_sorter = []
+ res = trans.resources
+ for key,val in res.iteritems():
+ if key.type.ident != "DNUCAStopTable":
+ val = '''
+if (!%s.areNSlotsAvailable(%s)) {
+ return TransitionResult_ResourceStall;
+}
+''' % (key.code, val)
+ case_sorter.append(val)
+
+
+ # Emit the code sequences in a sorted order. This makes the
+ # output deterministic (without this the output order can vary
+ # since Map's keys() on a vector of pointers is not deterministic
+ for c in sorted(case_sorter):
+ case("$c")
+
+ # Figure out if we stall
+ stall = False
+ for action in actions:
+ if action.ident == "z_stall":
+ stall = True
+ break
+
+ if stall:
+ case('return TransitionResult_ProtocolStall;')
+ else:
+ for action in actions:
+ case('${{action.ident}}(addr);')
+ case('return TransitionResult_Valid;')
+
+ case = str(case)
+
+ # Look to see if this transition code is unique.
+ if case not in cases:
+ cases[case] = []
+
+ cases[case].append(case_string)
+
+ # Walk through all of the unique code blocks and spit out the
+ # corresponding case statement elements
+ for case,transitions in cases.iteritems():
+ # Iterative over all the multiple transitions that share
+ # the same code
+ for trans in transitions:
+ code(' case HASH_FUN($trans):')
+ code(' {')
+ code(' $case')
+ code(' }')
+
+ code('''
+ default:
+ WARN_EXPR(m_version);
+ WARN_EXPR(g_eventQueue_ptr->getTime());
+ WARN_EXPR(addr);
+ WARN_EXPR(event);
+ WARN_EXPR(state);
+ ERROR_MSG(\"Invalid transition\");
+ }
+ return TransitionResult_Valid;
+}
+''')
+ code.write(path, "%s_Transitions.cc" % self.ident)
+
+ def printProfilerHH(self, path):
+ code = code_formatter()
+ ident = self.ident
+
+ code('''
+// Auto generated C++ code started by $__file__:$__line__
+// ${ident}: ${{self.short}}
+
+#ifndef ${ident}_PROFILER_H
+#define ${ident}_PROFILER_H
+
+#include "mem/ruby/common/Global.hh"
+#include "mem/protocol/${ident}_State.hh"
+#include "mem/protocol/${ident}_Event.hh"
+
+class ${ident}_Profiler {
+ public:
+ ${ident}_Profiler();
+ void setVersion(int version);
+ void countTransition(${ident}_State state, ${ident}_Event event);
+ void possibleTransition(${ident}_State state, ${ident}_Event event);
+ void dumpStats(ostream& out) const;
+ void clearStats();
+
+ private:
+ int m_counters[${ident}_State_NUM][${ident}_Event_NUM];
+ int m_event_counters[${ident}_Event_NUM];
+ bool m_possible[${ident}_State_NUM][${ident}_Event_NUM];
+ int m_version;
+};
+
+#endif // ${ident}_PROFILER_H
+''')
+ code.write(path, "%s_Profiler.hh" % self.ident)
+
+ def printProfilerCC(self, path):
+ code = code_formatter()
+ ident = self.ident
+
+ code('''
+// Auto generated C++ code started by $__file__:$__line__
+// ${ident}: ${{self.short}}
+
+#include "mem/protocol/${ident}_Profiler.hh"
+
+${ident}_Profiler::${ident}_Profiler()
+{
+ for (int state = 0; state < ${ident}_State_NUM; state++) {
+ for (int event = 0; event < ${ident}_Event_NUM; event++) {
+ m_possible[state][event] = false;
+ m_counters[state][event] = 0;
+ }
+ }
+ for (int event = 0; event < ${ident}_Event_NUM; event++) {
+ m_event_counters[event] = 0;
+ }
+}
+void ${ident}_Profiler::setVersion(int version)
+{
+ m_version = version;
+}
+void ${ident}_Profiler::clearStats()
+{
+ for (int state = 0; state < ${ident}_State_NUM; state++) {
+ for (int event = 0; event < ${ident}_Event_NUM; event++) {
+ m_counters[state][event] = 0;
+ }
+ }
+
+ for (int event = 0; event < ${ident}_Event_NUM; event++) {
+ m_event_counters[event] = 0;
+ }
+}
+void ${ident}_Profiler::countTransition(${ident}_State state, ${ident}_Event event)
+{
+ assert(m_possible[state][event]);
+ m_counters[state][event]++;
+ m_event_counters[event]++;
+}
+void ${ident}_Profiler::possibleTransition(${ident}_State state, ${ident}_Event event)
+{
+ m_possible[state][event] = true;
+}
+void ${ident}_Profiler::dumpStats(ostream& out) const
+{
+ out << " --- ${ident} " << m_version << " ---" << endl;
+ out << " - Event Counts -" << endl;
+ for (int event = 0; event < ${ident}_Event_NUM; event++) {
+ int count = m_event_counters[event];
+ out << (${ident}_Event) event << " " << count << endl;
+ }
+ out << endl;
+ out << " - Transitions -" << endl;
+ for (int state = 0; state < ${ident}_State_NUM; state++) {
+ for (int event = 0; event < ${ident}_Event_NUM; event++) {
+ if (m_possible[state][event]) {
+ int count = m_counters[state][event];
+ out << (${ident}_State) state << " " << (${ident}_Event) event << " " << count;
+ if (count == 0) {
+ out << " <-- ";
+ }
+ out << endl;
+ }
+ }
+ out << endl;
+ }
+}
+''')
+ code.write(path, "%s_Profiler.cc" % self.ident)
+
+ # **************************
+ # ******* HTML Files *******
+ # **************************
+ def frameRef(self, click_href, click_target, over_href, over_target_num,
+ text):
+ code = code_formatter(fix_newlines=False)
+ code("""<A href=\"$click_href\" target=\"$click_target\" onMouseOver=\"if (parent.frames[$over_target_num].location != parent.location + '$over_href') { parent.frames[$over_target_num].location='$over_href' }\" >${{html.formatShorthand(text)}}</A>""")
+ return str(code)
+
+ def writeHTMLFiles(self, path):
+ # Create table with no row hilighted
+ self.printHTMLTransitions(path, None)
+
+ # Generate transition tables
+ for state in self.states.itervalues():
+ self.printHTMLTransitions(path, state)
+
+ # Generate action descriptions
+ for action in self.actions.itervalues():
+ name = "%s_action_%s.html" % (self.ident, action.ident)
+ code = html.createSymbol(action, "Action")
+ code.write(path, name)
+
+ # Generate state descriptions
+ for state in self.states.itervalues():
+ name = "%s_State_%s.html" % (self.ident, state.ident)
+ code = html.createSymbol(state, "State")
+ code.write(path, name)
+
+ # Generate event descriptions
+ for event in self.events.itervalues():
+ name = "%s_Event_%s.html" % (self.ident, event.ident)
+ code = html.createSymbol(event, "Event")
+ code.write(path, name)
+
+ def printHTMLTransitions(self, path, active_state):
+ code = code_formatter()
+
+ code('''
+<HTML><BODY link="blue" vlink="blue">
+
+<H1 align="center">${{html.formatShorthand(self.short)}}:
+''')
+ code.indent()
+ for i,machine in enumerate(self.symtab.getAllType(StateMachine)):
+ mid = machine.ident
+ if i != 0:
+ extra = " - "
+ else:
+ extra = ""
+ if machine == self:
+ code('$extra$mid')
+ else:
+ code('$extra<A target="Table" href="${mid}_table.html">$mid</A>')
+ code.dedent()
+
+ code("""
+</H1>
+
+<TABLE border=1>
+<TR>
+ <TH> </TH>
+""")
+
+ for event in self.events.itervalues():
+ href = "%s_Event_%s.html" % (self.ident, event.ident)
+ ref = self.frameRef(href, "Status", href, "1", event.short)
+ code('<TH bgcolor=white>$ref</TH>')
+
+ code('</TR>')
+ # -- Body of table
+ for state in self.states.itervalues():
+ # -- Each row
+ if state == active_state:
+ color = "yellow"
+ else:
+ color = "white"
+
+ click = "%s_table_%s.html" % (self.ident, state.ident)
+ over = "%s_State_%s.html" % (self.ident, state.ident)
+ text = html.formatShorthand(state.short)
+ ref = self.frameRef(click, "Table", over, "1", state.short)
+ code('''
+<TR>
+ <TH bgcolor=$color>$ref</TH>
+''')
+
+ # -- One column for each event
+ for event in self.events.itervalues():
+ trans = self.table.get((state,event), None)
+ if trans is None:
+ # This is the no transition case
+ if state == active_state:
+ color = "#C0C000"
+ else:
+ color = "lightgrey"
+
+ code('<TD bgcolor=$color>&nbsp;</TD>')
+ continue
+
+ next = trans.nextState
+ stall_action = False
+
+ # -- Get the actions
+ for action in trans.actions:
+ if action.ident == "z_stall" or \
+ action.ident == "zz_recycleMandatoryQueue":
+ stall_action = True
+
+ # -- Print out "actions/next-state"
+ if stall_action:
+ if state == active_state:
+ color = "#C0C000"
+ else:
+ color = "lightgrey"
+
+ elif active_state and next.ident == active_state.ident:
+ color = "aqua"
+ elif state == active_state:
+ color = "yellow"
+ else:
+ color = "white"
+
+ fix = code.nofix()
+ code('<TD bgcolor=$color>')
+ for action in trans.actions:
+ href = "%s_action_%s.html" % (self.ident, action.ident)
+ ref = self.frameRef(href, "Status", href, "1",
+ action.short)
+ code(' $ref\n')
+ if next != state:
+ if trans.actions:
+ code('/')
+ click = "%s_table_%s.html" % (self.ident, next.ident)
+ over = "%s_State_%s.html" % (self.ident, next.ident)
+ ref = self.frameRef(click, "Table", over, "1", next.short)
+ code("$ref")
+ code("</TD>\n")
+ code.fix(fix)
+
+ # -- Each row
+ if state == active_state:
+ color = "yellow"
+ else:
+ color = "white"
+
+ click = "%s_table_%s.html" % (self.ident, state.ident)
+ over = "%s_State_%s.html" % (self.ident, state.ident)
+ ref = self.frameRef(click, "Table", over, "1", state.short)
+ code('''
+ <TH bgcolor=$color>$ref</TH>
+</TR>
+''')
+ code('''
+<TR>
+ <TH> </TH>
+''')
+
+ for event in self.events.itervalues():
+ href = "%s_Event_%s.html" % (self.ident, event.ident)
+ ref = self.frameRef(href, "Status", href, "1", event.short)
+ code('<TH bgcolor=white>$ref</TH>')
+ code('''
+</TR>
+</TABLE>
+</BODY></HTML>
+''')
+
+
+ if active_state:
+ name = "%s_table_%s.html" % (self.ident, active_state.ident)
+ else:
+ name = "%s_table.html" % self.ident
+ code.write(path, name)
+
+__all__ = [ "StateMachine" ]
diff --git a/src/mem/slicc/symbols/Symbol.cc b/src/mem/slicc/symbols/Symbol.cc
deleted file mode 100644
index 25af5ad47..000000000
--- a/src/mem/slicc/symbols/Symbol.cc
+++ /dev/null
@@ -1,72 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * $Id$
- *
- */
-
-#include "mem/slicc/symbols/Symbol.hh"
-
-Symbol::Symbol(string id, const Location& location, const Map<string, string>& pairs)
-{
- m_id = id;
- m_location = location;
- m_pairs = pairs;
- if (!existPair("short")) {
- addPair("short", m_id);
- }
- m_used = false;
-}
-
-Symbol::Symbol(string id, const Location& location)
-{
- m_id = id;
- m_location = location;
- if (!existPair("short")) {
- addPair("short", m_id);
- }
- m_used = false;
-}
-
-const string& Symbol::lookupPair(const string& key) const
-{
- if (!existPair(key)) {
- error("Value for pair '" + key + "' missing.");
- }
- return m_pairs.lookup(key);
-}
-
-void Symbol::addPair(const string& key, const string& value)
-{
- if (existPair(key)) {
- warning("Pair key '" + key + "' re-defined. new: '" + value + "' old: '" + lookupPair(key) + "'");
- }
- m_pairs.add(key, value);
-}
diff --git a/src/mem/slicc/symbols/Symbol.hh b/src/mem/slicc/symbols/Symbol.hh
deleted file mode 100644
index 4a1c5e44e..000000000
--- a/src/mem/slicc/symbols/Symbol.hh
+++ /dev/null
@@ -1,100 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * $Id$
- */
-
-#ifndef SYMBOL_H
-#define SYMBOL_H
-
-#include "mem/slicc/slicc_global.hh"
-#include "mem/gems_common/Map.hh"
-#include "mem/slicc/ast/Location.hh"
-
-class Symbol {
-public:
- // Constructors
- Symbol(string id, const Location& location, const Map<string, string>& pairs);
- Symbol(string id, const Location& location);
- // Destructor
- virtual ~Symbol() { }
-
- // Public Methods
- void error(string err_msg) const { m_location.error(err_msg); }
- void warning(string err_msg) const { m_location.warning(err_msg); }
- const Location& getLocation() const { return m_location; }
-
- const string& toString() const { return m_id; }
-
- const string& getIdent() const { return m_id; }
- const string& getShorthand() const { return lookupPair("short"); }
- const string& getDescription() const { return lookupPair("desc"); }
-
- void markUsed() { m_used = true; }
- bool wasUsed() { return m_used; }
-
- bool existPair(const string& key) const { return m_pairs.exist(key); }
- const string& lookupPair(const string& key) const;
- void addPair(const string& key, const string& value);
-
- // virtual string getCode() const = 0;
- virtual void writeCFiles(string path) {}
- virtual void writeHTMLFiles(string path) {}
- virtual void print(ostream& out) const { out << "[Symbol: " << getIdent() << "]"; }
-
-private:
- // Private Methods
-
- // Private copy constructor and assignment operator
- // Symbol(const Symbol& obj);
- // Symbol& operator=(const Symbol& obj);
-
- // Data Members (m_ prefix)
- string m_id;
- Map<string, string> m_pairs;
- Location m_location;
- bool m_used;
-};
-
-// Output operator declaration
-ostream& operator<<(ostream& out, const Symbol& obj);
-
-// ******************* Definitions *******************
-
-// Output operator definition
-extern inline
-ostream& operator<<(ostream& out, const Symbol& obj)
-{
- obj.print(out);
- out << flush;
- return out;
-}
-
-#endif //SYMBOL_H
diff --git a/src/mem/slicc/symbols/Symbol.py b/src/mem/slicc/symbols/Symbol.py
new file mode 100644
index 000000000..b394fda44
--- /dev/null
+++ b/src/mem/slicc/symbols/Symbol.py
@@ -0,0 +1,78 @@
+# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
+# Copyright (c) 2009 The Hewlett-Packard Development Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (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 slicc.util import PairContainer
+
+class Symbol(PairContainer):
+ def __init__(self, symtab, ident, location, pairs=None):
+ super(Symbol, self).__init__()
+
+ from slicc.util import Location
+ from slicc.symbols import SymbolTable
+ if not isinstance(symtab, SymbolTable): raise AttributeError
+ if not isinstance(ident, str): raise AttributeError
+ if not isinstance(location, Location): raise AttributeError
+
+ self.symtab = symtab
+ self.ident = ident
+ self.location = location
+ if pairs:
+ self.pairs.update(getattr(pairs, "pairs", pairs))
+ if "short" not in self:
+ self["short"] = self.ident
+ self.used = False
+
+ def __repr__(self):
+ return "[Symbol: %s]" % self.ident
+
+ def __str__(self):
+ return str(self.ident)
+
+ def __setitem__(self, key, value):
+ if key in self.pairs:
+ self.warning("Pair key '%s' re-defined. new: '%s' old: '%s'",
+ key, value, self.pairs[key])
+ super(Symbol, self).__setitem__(key, value)
+
+ @property
+ def short(self):
+ return self["short"]
+
+ @property
+ def desc(self):
+ return self["desc"]
+
+ def error(self, message, *args):
+ self.location.error(message, *args)
+
+ def warning(self, message, *args):
+ self.location.warning(message, *args)
+
+ def writeHTMLFiles(self, path):
+ pass
+
+__all__ = [ "Symbol" ]
diff --git a/src/mem/slicc/symbols/SymbolTable.cc b/src/mem/slicc/symbols/SymbolTable.cc
deleted file mode 100644
index 8af3685f8..000000000
--- a/src/mem/slicc/symbols/SymbolTable.cc
+++ /dev/null
@@ -1,327 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * SymbolTable.cc
- *
- * Description: See SymbolTable.hh
- *
- * $Id$
- *
- * */
-
-#include "mem/slicc/symbols/SymbolTable.hh"
-#include "mem/slicc/generator/fileio.hh"
-#include "mem/slicc/generator/html_gen.hh"
-#include "mem/slicc/generator/mif_gen.hh"
-#include "mem/slicc/symbols/Action.hh"
-
-SymbolTable g_sym_table;
-
-SymbolTable::SymbolTable()
-{
- m_sym_map_vec.setSize(1);
- m_depth = 0;
-
- {
- Map<string, string> pairs;
- pairs.add("enumeration", "yes");
- newSym(new Type("MachineType", Location(), pairs));
- }
-
- {
- Map<string, string> pairs;
- pairs.add("primitive", "yes");
- pairs.add("external", "yes");
- newSym(new Type("void", Location(), pairs));
- }
-}
-
-SymbolTable::~SymbolTable()
-{
- int size = m_sym_vec.size();
- for(int i=0; i<size; i++) {
- delete m_sym_vec[i];
- }
-}
-
-void SymbolTable::newSym(Symbol* sym_ptr)
-{
- registerSym(sym_ptr->toString(), sym_ptr);
- m_sym_vec.insertAtBottom(sym_ptr); // Holder for the allocated Sym objects.
-}
-
-void SymbolTable::newMachComponentSym(Symbol* sym_ptr)
-{
- // used to cheat-- that is, access components in other machines
- StateMachine* mach_ptr = getStateMachine("current_machine");
- if (mach_ptr != NULL) {
- m_machine_component_map_vec.lookup(mach_ptr->toString()).add(sym_ptr->toString(), sym_ptr);
- }
-}
-
-Var* SymbolTable::getMachComponentVar(string mach, string ident)
-{
- Symbol* s = m_machine_component_map_vec.lookup(mach).lookup(ident);
- return dynamic_cast<Var*>(s);
-}
-
-
-void SymbolTable::registerSym(string id, Symbol* sym_ptr)
-{
-
- // Check for redeclaration (in the current frame only)
- if (m_sym_map_vec[m_depth].exist(id)) {
- sym_ptr->error("Symbol '" + id + "' redeclared in same scope.");
- }
- // FIXME - warn on masking of a declaration in a previous frame
- m_sym_map_vec[m_depth].add(id, sym_ptr);
-}
-
-void SymbolTable::registerGlobalSym(string id, Symbol* sym_ptr)
-{
- // Check for redeclaration (global frame only)
- if (m_sym_map_vec[0].exist(id)) {
- sym_ptr->error("Global symbol '" + id + "' redeclared in global scope.");
- }
- m_sym_map_vec[0].add(id, sym_ptr);
-}
-
-Symbol* SymbolTable::getSym(string ident) const
-{
- for (int i=m_depth; i>=0; i--) {
- if (m_sym_map_vec[i].exist(ident)) {
- return m_sym_map_vec[i].lookup(ident);
- }
- }
- return NULL;
-}
-
-void SymbolTable::newCurrentMachine(StateMachine* sym_ptr)
-{
- registerGlobalSym(sym_ptr->toString(), sym_ptr);
- registerSym("current_machine", sym_ptr);
- m_sym_vec.insertAtBottom(sym_ptr); // Holder for the allocated Sym objects.
-
- Map<string, Symbol*> m;
- m_machine_component_map_vec.add(sym_ptr->toString(),m);
-
-}
-
-Type* SymbolTable::getType(string ident) const
-{
- return dynamic_cast<Type*>(getSym(ident));
-}
-
-Var* SymbolTable::getVar(string ident) const
-{
- return dynamic_cast<Var*>(getSym(ident));
-}
-
-Func* SymbolTable::getFunc(string ident) const
-{
- return dynamic_cast<Func*>(getSym(ident));
-}
-
-StateMachine* SymbolTable::getStateMachine(string ident) const
-{
- return dynamic_cast<StateMachine*>(getSym(ident));
-}
-
-void SymbolTable::pushFrame()
-{
- m_depth++;
- m_sym_map_vec.expand(1);
- m_sym_map_vec[m_depth].clear();
-}
-
-void SymbolTable::popFrame()
-{
- m_depth--;
- assert(m_depth >= 0);
- m_sym_map_vec.expand(-1);
-}
-
-void SymbolTable::writeCFiles(string path) const
-{
- int size = m_sym_vec.size();
- {
- // Write the Types.hh include file for the types
- ostringstream sstr;
- sstr << "/** Auto generated C++ code started by "<<__FILE__<<":"<<__LINE__<< " */" << endl;
- sstr << endl;
- sstr << "#include \"mem/ruby/slicc_interface/RubySlicc_includes.hh\"" << endl;
- for(int i=0; i<size; i++) {
- Type* type = dynamic_cast<Type*>(m_sym_vec[i]);
- if (type != NULL && !type->isPrimitive()) {
- sstr << "#include \"mem/protocol/" << type->cIdent() << ".hh" << "\"" << endl;
- }
- }
- conditionally_write_file(path + "/Types.hh", sstr);
- }
-
- // Write all the symbols
- for(int i=0; i<size; i++) {
- m_sym_vec[i]->writeCFiles(path + '/');
- }
-
- writeControllerFactory(path);
-}
-
-void SymbolTable::writeControllerFactory(string path) const
-{
- ostringstream sstr;
- int size = m_sym_vec.size();
-
- sstr << "/** \\file ControllerFactory.hh " << endl;
- sstr << " * Auto generatred C++ code started by " << __FILE__ << ":" << __LINE__ << endl;
- sstr << " */" << endl << endl;
-
- sstr << "#ifndef CONTROLLERFACTORY_H" << endl;
- sstr << "#define CONTROLLERFACTORY_H" << endl;
- sstr << endl;
-
- Vector< string > controller_types;
-
- // includes
- sstr << "#include <string>" << endl;
- sstr << "class Network;" << endl;
- sstr << "class AbstractController;" << endl;
- sstr << endl;
-
- sstr << "class ControllerFactory {" << endl;
- sstr << "public:" << endl;
- sstr << " static AbstractController* createController(const std::string & controller_type, const std::string & name);" << endl;
- sstr << "};" << endl;
- sstr << endl;
-
- sstr << "#endif // CONTROLLERFACTORY_H" << endl;
- conditionally_write_file(path + "/ControllerFactory.hh", sstr);
-
- // ControllerFactory.cc file
-
- sstr.str("");
-
- sstr << "/** \\file ControllerFactory.cc " << endl;
- sstr << " * Auto generatred C++ code started by " << __FILE__ << ":" << __LINE__ << endl;
- sstr << " */" << endl << endl;
-
- // includes
- sstr << "#include \"mem/protocol/ControllerFactory.hh\"" << endl;
- sstr << "#include \"mem/ruby/slicc_interface/AbstractController.hh\"" << endl;
- sstr << "#include \"mem/protocol/MachineType.hh\"" << endl;
- for(int i=0; i<size; i++) {
- StateMachine* machine = dynamic_cast<StateMachine*>(m_sym_vec[i]);
- if (machine != NULL) {
- sstr << "#include \"mem/protocol/" << machine->getIdent() << "_Controller.hh\"" << endl;
- controller_types.insertAtBottom(machine->getIdent());
- }
- }
- sstr << endl;
-
- sstr << "AbstractController* ControllerFactory::createController(const std::string & controller_type, const std::string & name) {" << endl;
- for (int i=0;i<controller_types.size();i++) {
- sstr << " if (controller_type == \"" << controller_types[i] << "\")" << endl;
- sstr << " return new " << controller_types[i] << "_Controller(name);" << endl;
- }
- sstr << " assert(0); // invalid controller type" << endl;
- sstr << " return NULL;" << endl;
- sstr << "}" << endl;
- conditionally_write_file(path + "/ControllerFactory.cc", sstr);
-}
-
-Vector<StateMachine*> SymbolTable::getStateMachines() const
-{
- Vector<StateMachine*> machine_vec;
- int size = m_sym_vec.size();
- for(int i=0; i<size; i++) {
- StateMachine* type = dynamic_cast<StateMachine*>(m_sym_vec[i]);
- if (type != NULL) {
- machine_vec.insertAtBottom(type);
- }
- }
- return machine_vec;
-}
-
-void SymbolTable::writeHTMLFiles(string path) const
-{
- // Create index.html
- {
- ostringstream out;
- createHTMLindex(path, out);
- conditionally_write_file(path + "index.html", out);
- }
-
- // Create empty.html
- {
- ostringstream out;
- out << "<HTML></HTML>";
- conditionally_write_file(path + "empty.html", out);
- }
-
- // Write all the symbols
- int size = m_sym_vec.size();
- for(int i=0; i<size; i++) {
- m_sym_vec[i]->writeHTMLFiles(path);
- }
-}
-
-void write_file(string filename, ostringstream& sstr)
-{
- ofstream out;
-
- out.open(filename.c_str());
- out << sstr.str();
- out.close();
-}
-
-void SymbolTable::writeMIFFiles(string path) const
-{
- int size = m_sym_vec.size();
- for(int i=0; i<size; i++) {
- ostringstream states, events, actions, transitions;
- StateMachine* machine = dynamic_cast<StateMachine*>(m_sym_vec[i]);
- if (machine != NULL) {
- printStateTableMIF(*machine, states);
- write_file(path + machine->getIdent() + "_states.mif", states);
- printEventTableMIF(*machine, events);
- write_file(path + machine->getIdent() + "_events.mif", events);
- printActionTableMIF(*machine, actions);
- write_file(path + machine->getIdent() + "_actions.mif", actions);
- printTransitionTableMIF(*machine, transitions);
- write_file(path + machine->getIdent() + "_transitions.mif", transitions);
- }
- }
-}
-
-
-void SymbolTable::print(ostream& out) const
-{
- out << "[SymbolTable]"; // FIXME
-}
diff --git a/src/mem/slicc/symbols/SymbolTable.hh b/src/mem/slicc/symbols/SymbolTable.hh
deleted file mode 100644
index 90d3f48c3..000000000
--- a/src/mem/slicc/symbols/SymbolTable.hh
+++ /dev/null
@@ -1,121 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * SymbolTable.hh
- *
- * Description:
- *
- * $Id$
- *
- * */
-
-#ifndef SYMBOLTABLE_H
-#define SYMBOLTABLE_H
-
-#include "mem/slicc/slicc_global.hh"
-#include "mem/gems_common/Map.hh"
-#include "mem/gems_common/Vector.hh"
-
-#include "mem/slicc/symbols/Symbol.hh"
-#include "mem/slicc/symbols/Type.hh"
-#include "mem/slicc/symbols/Var.hh"
-#include "mem/slicc/symbols/Func.hh"
-#include "mem/slicc/symbols/StateMachine.hh"
-
-class SymbolTable;
-
-extern SymbolTable g_sym_table;
-
-class SymbolTable {
-public:
- // Constructors
- SymbolTable();
-
- // Destructor
- ~SymbolTable();
-
- // Public Methods
- void newSym(Symbol* sym_ptr);
- void registerSym(string id, Symbol* sym_ptr);
- Symbol* getSym(string id) const;
-
- // used to cheat-- that is, access components in other machines
- void newMachComponentSym(Symbol* sym_ptr);
- Var* getMachComponentVar(string mach, string ident);
-
- void newCurrentMachine(StateMachine* machine_ptr);
- StateMachine* getStateMachine(string ident) const;
- StateMachine* getStateMachine() const { return getStateMachine("current_machine"); }
- Type* getType(string ident) const;
-
- Var* getVar(string ident) const;
- Func* getFunc(string ident) const;
-
- void pushFrame();
- void popFrame();
-
- Vector<StateMachine*> getStateMachines() const;
-
- void writeCFiles(string path) const;
- void writeHTMLFiles(string path) const;
- void writeMIFFiles(string path) const;
-
- void print(ostream& out) const;
-private:
- // Private Methods
- void registerGlobalSym(string id, Symbol* sym_ptr);
- void writeControllerFactory(string path) const;
-
- // Private copy constructor and assignment operator
- SymbolTable(const SymbolTable& obj);
- SymbolTable& operator=(const SymbolTable& obj);
-
- // Data Members (m_ prefix)
- Vector<Symbol*> m_sym_vec;
- Vector<Map<string, Symbol*> > m_sym_map_vec;
- Map<string, Map<string, Symbol*> > m_machine_component_map_vec;
- int m_depth;
-};
-
-// Output operator declaration
-ostream& operator<<(ostream& out, const SymbolTable& obj);
-
-// ******************* Definitions *******************
-
-// Output operator definition
-extern inline
-ostream& operator<<(ostream& out, const SymbolTable& obj)
-{
- obj.print(out);
- out << flush;
- return out;
-}
-
-#endif //SYMBOLTABLE_H
diff --git a/src/mem/slicc/symbols/SymbolTable.py b/src/mem/slicc/symbols/SymbolTable.py
new file mode 100644
index 000000000..17d7dfad3
--- /dev/null
+++ b/src/mem/slicc/symbols/SymbolTable.py
@@ -0,0 +1,218 @@
+# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
+# Copyright (c) 2009 The Hewlett-Packard Development Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (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 slicc.generate import html
+from slicc.symbols.StateMachine import StateMachine
+from slicc.symbols.Type import Type
+from slicc.util import Location
+
+class SymbolTable(object):
+ def __init__(self):
+ self.sym_vec = []
+ 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)
+ self.newSymbol(void)
+
+ def __repr__(self):
+ return "[SymbolTable]" # FIXME
+
+ def newSymbol(self, sym):
+ self.registerSym(str(sym), sym)
+ self.sym_vec.append(sym)
+
+ def registerSym(self, id, sym):
+ # Check for redeclaration (in the current frame only)
+ if id in self.sym_map_vec[-1]:
+ sym.error("Symbol '%s' redeclared in same scope.", id)
+
+ # FIXME - warn on masking of a declaration in a previous frame
+ self.sym_map_vec[-1][id] = sym
+
+ def find(self, ident, types=None):
+ for sym_map in reversed(self.sym_map_vec):
+ try:
+ symbol = sym_map[ident]
+ except KeyError:
+ continue
+
+ if types is not None:
+ assert isinstance(symbol, types)
+
+ return symbol
+
+ return None
+
+ def newMachComponentSym(self, symbol):
+ # used to cheat-- that is, access components in other machines
+ machine = self.find("current_machine", StateMachine)
+ if machine:
+ self.machine_components[str(machine)][str(symbol)] = symbol
+
+ def newCurrentMachine(self, sym):
+ self.registerGlobalSym(str(sym), sym)
+ self.registerSym("current_machine", sym)
+ self.sym_vec.append(sym)
+
+ self.machine_components[str(sym)] = {}
+
+ @property
+ def state_machine(self):
+ return self.find("current_machine", StateMachine)
+
+ def pushFrame(self):
+ self.sym_map_vec.append({})
+
+ def popFrame(self):
+ assert len(self.sym_map_vec) > 0
+ self.sym_map_vec.pop()
+
+ def registerGlobalSym(self, ident, symbol):
+ # Check for redeclaration (global frame only)
+ if ident in self.sym_map_vec[0]:
+ symbol.error("Symbol '%s' redeclared in global scope." % ident)
+
+ self.sym_map_vec[0][ident] = symbol
+
+ def getAllType(self, type):
+ for symbol in self.sym_vec:
+ if isinstance(symbol, type):
+ yield symbol
+
+ def writeCodeFiles(self, path):
+ code = code_formatter()
+ code('''
+/** Auto generated C++ code started by $__file__:$__line__ */
+
+#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"')
+
+ code.write(path, "Types.hh")
+
+ for symbol in self.sym_vec:
+ symbol.writeCodeFiles(path)
+
+ self.writeControllerFactory(path)
+
+ def writeControllerFactory(self, path):
+ code = code_formatter()
+
+ code('''
+/** \\file ControllerFactory.hh
+ * Auto generatred C++ code started by $__file__:$__line__
+ */
+
+#ifndef CONTROLLERFACTORY_H
+#define CONTROLLERFACTORY_H
+
+#include <string>
+class Network;
+class AbstractController;
+
+class ControllerFactory {
+ public:
+ static AbstractController *createController(const std::string &controller_type, const std::string &name);
+};
+#endif // CONTROLLERFACTORY_H''')
+ code.write(path, "ControllerFactory.hh")
+
+ code = code_formatter()
+ code('''
+/** \\file ControllerFactory.cc
+ * Auto generatred C++ code started by $__file__:$__line__
+ */
+
+#include "mem/protocol/ControllerFactory.hh"
+#include "mem/ruby/slicc_interface/AbstractController.hh"
+#include "mem/protocol/MachineType.hh"
+''')
+
+ controller_types = []
+ for symbol in self.getAllType(StateMachine):
+ code('#include "mem/protocol/${{symbol.ident}}_Controller.hh"')
+ controller_types.append(symbol.ident)
+
+ code('''
+AbstractController *ControllerFactory::createController(const std::string &controller_type, const std::string &name) {
+''')
+
+ for ct in controller_types:
+ code('''
+ if (controller_type == "$ct")
+ return new ${ct}_Controller(name);
+''')
+
+ code('''
+ assert(0); // invalid controller type
+ return NULL;
+}
+''')
+ code.write(path, "ControllerFactory.cc")
+
+ def writeHTMLFiles(self, path):
+ machines = list(self.getAllType(StateMachine))
+ if len(machines) > 1:
+ name = "%s_table.html" % machines[0].ident
+ else:
+ name = "empty.html"
+
+ code = code_formatter()
+ code('''
+<html>
+<head>
+<title>$path</title>
+</head>
+<frameset rows="*,30">
+ <frame name="Table" src="$name">
+ <frame name="Status" src="empty.html">
+</frameset>
+</html>
+''')
+ code.write(path, "index.html")
+
+ code = code_formatter()
+ code("<HTML></HTML>")
+ code.write(path, "empty.html")
+
+ for symbol in self.sym_vec:
+ symbol.writeHTMLFiles(path)
+
+__all__ = [ "SymbolTable" ]
diff --git a/src/mem/slicc/symbols/Transition.cc b/src/mem/slicc/symbols/Transition.cc
deleted file mode 100644
index d6d348166..000000000
--- a/src/mem/slicc/symbols/Transition.cc
+++ /dev/null
@@ -1,173 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * $Id$
- *
- * */
-
-#include "mem/slicc/symbols/Transition.hh"
-#include "mem/slicc/symbols/State.hh"
-#include "mem/slicc/symbols/Event.hh"
-#include "mem/slicc/symbols/Action.hh"
-#include "mem/gems_common/util.hh"
-#include "mem/slicc/symbols/Var.hh"
-
-Transition::Transition(string state, string event, string nextState,
- const Vector<string>& actionList,
- const Location& location,
- const Map<string, string>& pairMap)
- : Symbol(state + "|" + event, location, pairMap)
-{
- m_state = state;
- m_event = event;
- m_nextState = nextState;
- m_actionList = actionList;
-
- // Ptrs are undefined at this point
- m_statePtr = NULL;
- m_eventPtr = NULL;
- m_nextStatePtr = NULL;
- m_actionPtrsValid = false;
-}
-
-void Transition::checkIdents(const Vector<State*>& states,
- const Vector<Event*>& events,
- const Vector<Action*>& actions)
-{
- m_statePtr = findIndex(states, m_state);
- m_eventPtr = findIndex(events, m_event);
- m_nextStatePtr = findIndex(states, m_nextState);
-
- for(int i=0; i < m_actionList.size(); i++) {
- Action* action_ptr = findIndex(actions, m_actionList[i]);
- int size = action_ptr->getResources().keys().size();
- for (int j=0; j < size; j++) {
- Var* var_ptr = action_ptr->getResources().keys()[j];
- if (var_ptr->getType()->cIdent() != "DNUCAStopTable") {
- int num = atoi((action_ptr->getResources().lookup(var_ptr)).c_str());
- if (m_resources.exist(var_ptr)) {
- num += atoi((m_resources.lookup(var_ptr)).c_str());
- }
- m_resources.add(var_ptr, int_to_string(num));
- } else {
- m_resources.add(var_ptr, action_ptr->getResources().lookup(var_ptr));
- }
- }
- m_actionPtrs.insertAtBottom(action_ptr);
- }
- m_actionPtrsValid = true;
-}
-
-const string& Transition::getStateShorthand() const
-{
- assert(m_statePtr != NULL);
- return m_statePtr->getShorthand();
-}
-
-const string& Transition::getEventShorthand() const
-{
- assert(m_eventPtr != NULL);
- return m_eventPtr->getShorthand();
-}
-
-const string& Transition::getNextStateShorthand() const
-{
- assert(m_nextStatePtr != NULL);
- return m_nextStatePtr->getShorthand();
-}
-
-string Transition::getActionShorthands() const
-{
- assert(m_actionPtrsValid);
- string str;
- int numActions = m_actionPtrs.size();
- for (int i=0; i<numActions; i++) {
- str += m_actionPtrs[i]->getShorthand();
- }
- return str;
-}
-
-void Transition::print(ostream& out) const
-{
- out << "[Transition: ";
- out << "(" << m_state;
- if (m_statePtr != NULL) {
- out << ":" << *m_statePtr;
- }
- out << ", " << m_event;
- if (m_eventPtr != NULL) {
- out << ":" << *m_eventPtr;
- }
- out << ") -> ";
- out << m_nextState;
- if (m_nextStatePtr != NULL) {
- out << ":" << *m_nextStatePtr;
- }
- out << ", ";
- out << m_actionList;
- out << "]";
-}
-
-Event* Transition::findIndex(const Vector<Event*>& vec, string ident)
-{
- int size = vec.size();
- for(int i=0; i<size; i++) {
- if (ident == vec[i]->getIdent()) {
- return vec[i];
- }
- }
- error("Event not found: " + ident);
- return NULL;
-}
-
-State* Transition::findIndex(const Vector<State*>& vec, string ident)
-{
- int size = vec.size();
- for(int i=0; i<size; i++) {
- if (ident == vec[i]->getIdent()) {
- return vec[i];
- }
- }
- error("State not found: " + ident);
- return NULL;
-}
-
-Action* Transition::findIndex(const Vector<Action*>& vec, string ident)
-{
- int size = vec.size();
- for(int i=0; i<size; i++) {
- if (ident == vec[i]->getIdent()) {
- return vec[i];
- }
- }
- error("Action not found: " + ident);
- return NULL;
-}
-
diff --git a/src/mem/slicc/symbols/Transition.hh b/src/mem/slicc/symbols/Transition.hh
deleted file mode 100644
index 75d6da4e9..000000000
--- a/src/mem/slicc/symbols/Transition.hh
+++ /dev/null
@@ -1,120 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * Transition.hh
- *
- * Description:
- *
- * $Id$
- *
- * */
-
-#ifndef TRANSITION_H
-#define TRANSITION_H
-
-#include "mem/slicc/slicc_global.hh"
-#include "mem/gems_common/Vector.hh"
-#include "mem/slicc/symbols/Symbol.hh"
-
-class State;
-class Event;
-class Action;
-class Var;
-
-class Transition : public Symbol {
-public:
- // Constructors
- Transition(string state, string event, string nextState,
- const Vector<string>& actionList,
- const Location& location,
- const Map<string, string>& pairMap);
- // Destructor
- ~Transition() { }
-
- // Public Methods
- State* getStatePtr() const { assert(m_statePtr != NULL); return m_statePtr; }
- Event* getEventPtr() const { assert(m_eventPtr != NULL); return m_eventPtr; }
- State* getNextStatePtr() const { assert(m_nextStatePtr != NULL); return m_nextStatePtr; }
-
- // int getStateIndex() const { assert(m_statePtr != NULL); return m_statePtr->getIndex(); }
- // int getEventIndex() const { assert(m_eventPtr != NULL); return m_eventPtr->getIndex(); }
- // int getNextStateIndex() const { assert(m_nextStatePtr != NULL); return m_nextStatePtr->getIndex(); }
- void checkIdents(const Vector<State*>& states,
- const Vector<Event*>& events,
- const Vector<Action*>& actions);
-
- const string& getStateShorthand() const;
- const string& getEventShorthand() const;
- const string& getNextStateShorthand() const;
- string getActionShorthands() const;
- const Vector<Action*>& getActions() const { assert(m_actionPtrsValid); return m_actionPtrs; }
- const Map<Var*, string>& getResources() const { assert(m_actionPtrsValid); return m_resources; }
-
- void print(ostream& out) const;
-
- // Default copy constructor and assignment operator
- // Transition(const Transition& obj);
- // Transition& operator=(const Transition& obj);
-private:
- // Private Methods
- Event* findIndex(const Vector<Event*>& vec, string ident);
- State* findIndex(const Vector<State*>& vec, string ident);
- Action* findIndex(const Vector<Action*>& vec, string ident);
-
- // Data Members (m_ prefix)
- string m_state;
- string m_event;
- string m_nextState;
-
- State* m_statePtr;
- Event* m_eventPtr;
- State* m_nextStatePtr;
-
- Vector<string> m_actionList;
- Vector<Action*> m_actionPtrs;
- Map<Var*, string> m_resources;
- bool m_actionPtrsValid;
-};
-
-// Output operator declaration
-ostream& operator<<(ostream& out, const Transition& obj);
-
-// ******************* Definitions *******************
-
-// Output operator definition
-extern inline
-ostream& operator<<(ostream& out, const Transition& obj)
-{
- obj.print(out);
- out << flush;
- return out;
-}
-
-#endif //TRANSITION_H
diff --git a/src/mem/slicc/symbols/Transition.py b/src/mem/slicc/symbols/Transition.py
new file mode 100644
index 000000000..1bf09048a
--- /dev/null
+++ b/src/mem/slicc/symbols/Transition.py
@@ -0,0 +1,61 @@
+# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
+# Copyright (c) 2009 The Hewlett-Packard Development Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (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 slicc.symbols.Symbol import Symbol
+
+class Transition(Symbol):
+ def __init__(self, table, machine, state, event, nextState, actions,
+ location, pairs):
+ ident = "%s|%s" % (state, event)
+ super(Transition, self).__init__(table, ident, location, pairs)
+
+ self.state = machine.states[state]
+ self.event = machine.events[event]
+ self.nextState = machine.states[nextState]
+ self.actions = [ machine.actions[a] for a in actions ]
+ self.resources = {}
+
+ for action in self.actions:
+ for var,value in action.resources.iteritems():
+ if var.type.ident != "DNUCAStopTable":
+ num = int(value)
+ if var in self.resources:
+ num += int(value)
+ self.resources[var] = str(num)
+ else:
+ self.resources[var] = value
+
+ def __repr__(self):
+ return "[Transition: (%r, %r) -> %r, %r]" % \
+ (self.state, self.event, self.nextState, self.actions)
+
+ def getActionShorthands(self):
+ assert self.actions
+
+ return ''.join(a.short for a in self.actions)
+
+__all__ = [ "Transition" ]
diff --git a/src/mem/slicc/symbols/Type.cc b/src/mem/slicc/symbols/Type.cc
deleted file mode 100644
index 5afe53423..000000000
--- a/src/mem/slicc/symbols/Type.cc
+++ /dev/null
@@ -1,779 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * Type.cc
- *
- * Description: See Type.hh
- *
- * $Id$
- * */
-
-#include "mem/slicc/symbols/Type.hh"
-#include "mem/slicc/generator/fileio.hh"
-#include "mem/gems_common/Map.hh"
-#include "mem/slicc/symbols/StateMachine.hh"
-
-Type::Type(string id, const Location& location,
- const Map<string, string>& pairs,
- StateMachine* machine_ptr)
- : Symbol(id, location, pairs)
-{
- if (machine_ptr == NULL) {
- m_c_id = id;
- } else if (isExternal() || isPrimitive()) {
- if (existPair("external_name")) {
- m_c_id = lookupPair("external_name");
- } else {
- m_c_id = id;
- }
- } else {
- m_c_id = machine_ptr->toString() + "_" + id; // Append with machine name
- }
-
- if(existPair("desc")){
- m_desc = lookupPair("desc");
- } else {
- m_desc = "No description avaliable";
- }
-
- // check for interface that this Type implements
- if(existPair("interface")) {
- string interface = lookupPair("interface");
- if(interface == "Message" || interface == "NetworkMessage") {
- addPair("message", "yes");
- }
- if(interface == "NetworkMessage") {
- addPair("networkmessage", "yes");
- }
- }
-
- // FIXME - all of the following id comparisons are fragile hacks
- if ((getIdent() == "CacheMemory") || (getIdent() == "NewCacheMemory") ||
- (getIdent() == "TLCCacheMemory") || (getIdent() == "DNUCACacheMemory") ||
- (getIdent() == "DNUCABankCacheMemory") || (getIdent() == "L2BankCacheMemory") ||
- (getIdent() == "CompressedCacheMemory") || (getIdent() == "PrefetchCacheMemory")) {
- addPair("cache", "yes");
- }
-
- if ((getIdent() == "TBETable") || (getIdent() == "DNUCATBETable") || (getIdent() == "DNUCAStopTable")) {
- addPair("tbe", "yes");
- }
-
- if ((getIdent() == "NewTBETable")) {
- addPair("newtbe", "yes");
- }
-
- if ((getIdent() == "TimerTable")) {
- addPair("timer", "yes");
- }
-
- if ((getIdent() == "DirectoryMemory")) {
- addPair("dir", "yes");
- }
-
- if ((getIdent() == "PersistentTable")) {
- addPair("persistent", "yes");
- }
-
- if ((getIdent() == "Prefetcher")) {
- addPair("prefetcher", "yes");
- }
-
- if ((getIdent() == "DNUCA_Movement")) {
- addPair("mover", "yes");
- }
-
- if (id == "MachineType") {
- m_isMachineType = true;
- } else {
- m_isMachineType = false;
- }
-}
-
-// Return false on error
-bool Type::dataMemberAdd(string id, Type* type_ptr, Map<string, string>& pairs,
- string* init_code)
-{
- if (dataMemberExist(id)) {
- return false; // Error
- } else {
- m_data_member_map.add(id, type_ptr);
- m_data_member_ident_vec.insertAtBottom(id);
- m_data_member_type_vec.insertAtBottom(type_ptr);
- m_data_member_pairs_vec.insertAtBottom(pairs);
- m_data_member_init_code_vec.insertAtBottom(init_code);
- }
-
- return true;
-}
-
-string Type::methodId(string name,
- const Vector<Type*>& param_type_vec)
-{
- string paramStr = "";
- for (int i = 0; i < param_type_vec.size(); i++) {
- paramStr += "_"+param_type_vec[i]->cIdent();
- }
- return name+paramStr;
-}
-
-bool Type::methodAdd(string name,
- Type* return_type_ptr,
- const Vector<Type*>& param_type_vec)
-{
- string id = methodId(name, param_type_vec);
- if (methodExist(id)) {
- return false; // Error
- } else {
- m_method_return_type_map.add(id, return_type_ptr);
- m_method_param_type_map.add(id, param_type_vec);
- return true;
- }
-}
-
-bool Type::enumAdd(string id, Map<string, string> pairs_map)
-{
- if (enumExist(id)) {
- return false;
- } else {
- m_enum_map.add(id, true);
- m_enum_vec.insertAtBottom(id);
- m_enum_pairs.insertAtBottom(pairs_map);
-
- // Add default
- if (!existPair("default")) {
- addPair("default", cIdent()+"_NUM");
- }
-
- return true;
- }
-}
-
-void Type::writeCFiles(string path)
-{
- if (isExternal()) {
- // Do nothing
- } else if (isEnumeration()) {
- printEnumH(path);
- printEnumC(path);
- } else { // User defined structs and messages
- printTypeH(path);
- printTypeC(path);
- }
-}
-
-void Type::printTypeH(string path) const
-{
- ostringstream out;
- int size = m_data_member_type_vec.size();
- string type_name = cIdent(); // Identifier for the type in C
-
- // Header
- out << "/** \\file " << type_name << ".hh" << endl;
- out << " * " << endl;
- out << " * Auto generated C++ code started by "<<__FILE__<<":"<<__LINE__<< endl;
- out << " */" << endl;
- out << endl;
- out << "#ifndef " << type_name << "_H" << endl;
- out << "#define " << type_name << "_H" << endl;
- out << endl;
-
- // Include all of the #includes needed
- out << "#include \"mem/ruby/common/Global.hh\"" << endl;
- out << "#include \"mem/gems_common/Allocator.hh\"" << endl;
- for (int i=0; i < size; i++) {
- Type* type = m_data_member_type_vec[i];
- if (!type->isPrimitive()) {
- out << "#include \"mem/protocol/" << type->cIdent() << ".hh" << "\"" << endl;
- }
- }
- string interface = "";
- if(existPair("interface")) {
- interface = lookupPair("interface");
- out << "#include \"mem/protocol/" << interface << ".hh\"" << endl;
- }
-
- // Class definition
- out << "class " << type_name;
-
- if(interface != "") {
- out << " : public " << interface ;
- }
-
- out << " {" << endl;
- out << "public:" << endl;
-
- // ******** Default constructor ********
-
- out << " " << type_name << "() " << endl;
-
- // Call superclass constructor
- if (interface != "") {
- out << " : " << interface << "()" << endl;
- }
-
- out << " {" << endl;
-
- if(!isGlobal()) {
- for (int i=0; i < size; i++) {
-
- Type* type_ptr = m_data_member_type_vec[i];
- string id = m_data_member_ident_vec[i];
- if (m_data_member_pairs_vec[i].exist("default")) {
- // look for default value
- string default_value = m_data_member_pairs_vec[i].lookup("default");
- out << " m_" << id << " = " << default_value << "; // default for this field " << endl;
- } else if (type_ptr->hasDefault()) {
- // Look for the type default
- string default_value = type_ptr->getDefault();
- out << " m_" << id << " = " << default_value << "; // default value of " << type_ptr->cIdent() << endl;
- } else {
- out << " // m_" << id << " has no default" << endl;
- }
- }
- } // end of if(!isGlobal())
- out << " }" << endl;
-
- // ******** Default destructor ********
- out << " ";
- out << "~" << type_name << "() { };" << endl;
-
- // ******** Full init constructor ********
- if(! isGlobal()) {
- out << " " << type_name << "(";
-
- for (int i=0; i < size; i++) {
- if (i != 0) {
- out << ", ";
- }
- Type* type = m_data_member_type_vec[i];
- string id = m_data_member_ident_vec[i];
- out << "const " << type->cIdent() << "& local_" << id;
- }
-
- if (isMessage()) {
- out << ", const unsigned local_proc_id" << flush;
- }
-
- out << ")" << endl;
-
- // Call superclass constructor
- if (interface != "") {
- out << " : " << interface << "()" << endl;
- }
-
- out << " {" << endl;
- for (int i=0; i < size; i++) {
- Type* type_ptr = m_data_member_type_vec[i];
- string id = m_data_member_ident_vec[i];
- out << " m_" << id << " = local_" << id << ";" << endl;
- if (m_data_member_pairs_vec[i].exist("nextLineCallHack")) {
- string next_line_value = m_data_member_pairs_vec[i].lookup("nextLineCallHack");
- out << " m_" << id << next_line_value << ";" << endl;
- }
- }
- if (isMessage()) {
- out << " proc_id = local_proc_id;" << endl << flush;
- }
- out << " }" << endl;
- } // end of if(!isGlobal())
-
- // create a static factory method
- if (interface != "") {
- out << " static " << interface << "* create() {" << endl;
- out << " return new " << type_name << "(); " << endl;
- out << " }" << endl;
- }
-
- // bobba -
- //******** Partial init constructor ********
- //** Constructor needs only the first n-1 data members for init
- //** HACK to create objects with partially specified data members
- //** Need to get rid of this and use hierarchy instead
-// if(! isGlobal()) {
-// out << " " << type_name << "(";
-
-// for (int i=0; i < size-1; i++) {
-// if (i != 0) {
-// out << ", ";
-// }
-// Type* type = m_data_member_type_vec[i];
-// string id = m_data_member_ident_vec[i];
-// out << "const " << type->cIdent() << "& local_" << id;
-// }
-// out << ")" << endl;
-
-// // Call superclass constructor
-// if (interface != "") {
-// out << " : " << interface << "()" << endl;
-// }
-
-// out << " {" << endl;
-// for (int i=0; i < size-1; i++) {
-// Type* type_ptr = m_data_member_type_vec[i];
-// string id = m_data_member_ident_vec[i];
-// out << " m_" << id << " = local_" << id << ";" << endl;
-// if (m_data_member_pairs_vec[i].exist("nextLineCallHack")) {
-// string next_line_value = m_data_member_pairs_vec[i].lookup("nextLineCallHack");
-// out << " m_" << id << next_line_value << ";" << endl;
-// }
-
-// }
-// out << " }" << endl;
-// } // end of if(!isGlobal())
-
- // ******** Message member functions ********
- // FIXME: those should be moved into slicc file, slicc should support more of
- // the c++ class inheritance
-
- if (isMessage()) {
- out << " Message* clone() const { checkAllocator(); return s_allocator_ptr->allocate(*this); }" << endl;
- out << " void destroy() { checkAllocator(); s_allocator_ptr->deallocate(this); }" << endl;
- out << " static Allocator<" << type_name << ">* s_allocator_ptr;" << endl;
- out << " static void checkAllocator() { if (s_allocator_ptr == NULL) { s_allocator_ptr = new Allocator<" << type_name << ">; }}" << endl;
- }
-
- if(!isGlobal()) {
- // const Get methods for each field
- out << " // Const accessors methods for each field" << endl;
- for (int i=0; i < size; i++) {
- Type* type_ptr = m_data_member_type_vec[i];
- string type = type_ptr->cIdent();
- string id = m_data_member_ident_vec[i];
- out << "/** \\brief Const accessor method for " << id << " field." << endl;
- out << " * \\return " << id << " field" << endl;
- out << " */" << endl;
- out << " const " << type << "& get" << id
- << "() const { return m_" << id << "; }" << endl;
- }
-
- out << endl;
-
- // Non-const Get methods for each field
- out << " // Non const Accessors methods for each field" << endl;
- for (int i=0; i < size; i++) {
- Type* type_ptr = m_data_member_type_vec[i];
- string type = type_ptr->cIdent();
- string id = m_data_member_ident_vec[i];
- out << "/** \\brief Non-const accessor method for " << id << " field." << endl;
- out << " * \\return " << id << " field" << endl;
- out << " */" << endl;
- out << " " << type << "& get" << id
- << "() { return m_" << id << "; }" << endl;
- }
-
- out << endl;
-
- // Set methods for each field
- out << " // Mutator methods for each field" << endl;
- for (int i=0; i < size; i++) {
- Type* type_ptr = m_data_member_type_vec[i];
- string type = type_ptr->cIdent();
- string id = m_data_member_ident_vec[i];
- out << "/** \\brief Mutator method for " << id << " field */" << endl;
- out << " void set" << id << "(const " << type << "& local_"
- << id << ") { m_" << id << " = local_" << id << "; }" << endl;
- }
-
- out << endl;
- } // end of if(!isGlobal())
-
- out << " void print(ostream& out) const;" << endl;
- out << "//private:" << endl;
-
- // Data members for each field
- for (int i=0; i < size; i++) {
- if (!m_data_member_pairs_vec[i].exist("abstract")) {
- out << " ";
- // global structure
- if(isGlobal()) out << "static const ";
-
- Type* type = m_data_member_type_vec[i];
- string id = m_data_member_ident_vec[i];
- out << type->cIdent() << " m_" << id;
-
- // init value
- string* init_code = m_data_member_init_code_vec[i];
- if(init_code) {
- // only global structure can have init value here
- assert(isGlobal());
- out << " = " << *init_code << " ";
- }
- out << ";";
- if (m_data_member_pairs_vec[i].exist("desc")) {
- string desc = m_data_member_pairs_vec[i].lookup("desc");
- out << " /**< " << desc << "*/";
- }
- out << endl;
- }
- }
-
- if (isMessage()) {
- out << " unsigned proc_id;" << endl << flush;
- }
-
- out << "};" << endl; // End class
-
- out << "// Output operator declaration" << endl;
- out << "ostream& operator<<(ostream& out, const " << type_name << "& obj);" << endl;
- out << endl;
- out << "// Output operator definition" << endl;
- out << "extern inline" << endl;
- out << "ostream& operator<<(ostream& out, const " << type_name << "& obj)" << endl;
- out << "{" << endl;
- out << " obj.print(out);" << endl;
- out << " out << flush;" << endl;
- out << " return out;" << endl;
- out << "}" << endl;
- out << endl;
- out << "#endif // " << type_name << "_H" << endl;
-
- // Write it out
- conditionally_write_file(path + type_name + ".hh", out);
-}
-
-void Type::printTypeC(string path) const
-{
- ostringstream out;
- int size = m_data_member_type_vec.size();
- string type_name = cIdent(); // Identifier for the type in C
-
- // Header
- out << "/** \\file " << type_name << ".cc" << endl;
- out << " * " << endl;
- out << " * Auto generated C++ code started by "<<__FILE__<<":"<<__LINE__<< endl;
- out << " */" << endl;
- out << endl;
- out << "#include \"mem/protocol/" << type_name << ".hh\"" << endl;
- out << endl;
- if (isMessage()) {
- out << "Allocator<" << type_name << ">* " << type_name << "::s_allocator_ptr = NULL;" << endl;
- }
- out << "/** \\brief Print the state of this object */" << endl;
- out << "void " << type_name << "::print(ostream& out) const" << endl;
- out << "{" << endl;
- out << " out << \"[" << type_name << ": \";" << endl;
-
- // For each field
- for (int i=0; i < size; i++) {
- string id = m_data_member_ident_vec[i];
- out << " out << \"" << id << "=\" << m_" << id << " << \" \";" << endl;
- }
-
- if (isMessage()) {
- out << " out << \"" << "Time" << "=\" << getTime()" << " << \" \";" << endl;
- }
-
- // Trailer
- out << " out << \"]\";" << endl;
- out << "}" << endl;
-
- // Write it out
- conditionally_write_file(path + type_name + ".cc", out);
-}
-
-void Type::printEnumH(string path) const
-{
- ostringstream out;
- int size = m_enum_vec.size();
- string type_name = cIdent(); // Identifier for the type in C
- string type_desc = desc();
-
- // Header
- out << "/** \\file " << type_name << ".hh" << endl;
- out << " * " << endl;
- out << " * Auto generated C++ code started by "<<__FILE__<<":"<<__LINE__<< endl;
- out << " */" << endl;
-
- out << "#ifndef " << type_name << "_H" << endl;
- out << "#define " << type_name << "_H" << endl;
- out << endl;
- // Include all of the #includes needed
- out << "#include \"mem/ruby/common/Global.hh\"" << endl;
- out << endl;
-
- // Class definition
- out << "/** \\enum " << type_name << endl;
- out << " * \\brief " << type_desc << endl;
- out << " */" << endl;
- out << "enum " << type_name << " {" << endl;
-
- out << " " << type_name << "_FIRST," << endl;
-
- // For each field
- for(int i = 0; i < size; i++ ) {
- string id = m_enum_vec[i];
- string description;
- if(m_enum_pairs[i].exist("desc")){
- description = m_enum_pairs[i].lookup("desc");
- } else {
- description = "No description avaliable";
- }
- if (i == 0) {
- out << " " << type_name << "_" << id << " = " << type_name << "_FIRST, /**< " << description << " */" << endl;
- }
- else {
- out << " " << type_name << "_" << id << ", /**< " << description << " */" << endl;
- }
- }
- out << " " << type_name << "_NUM" << endl;
- out << "};" << endl;
-
- // Code to convert from a string to the enumeration
- out << type_name << " string_to_" << type_name << "(const string& str);" << endl;
-
- // Code to convert state to a string
- out << "string " << type_name << "_to_string(const " << type_name << "& obj);" << endl;
-
- // Code to increment an enumeration type
- out << type_name << " &operator++( " << type_name << " &e);" << endl;
-
- // MachineType hack used to set the base component id for each Machine
- if (m_isMachineType) {
- out << "int " << type_name << "_base_level(const " << type_name << "& obj);" << endl;
- out << "MachineType " << type_name << "_from_base_level(int);" << endl;
- out << "int " << type_name << "_base_number(const " << type_name << "& obj);" << endl;
- out << "int " << type_name << "_base_count(const " << type_name << "& obj);" << endl;
- // out << "int " << type_name << "_chip_count(const " << type_name << "& obj, int chipID);" << endl;
-
- for(int i = 0; i < size; i++ ) {
- string id = m_enum_vec[i];
- out << "#define MACHINETYPE_" << id << " 1" << endl;
- }
- cout << endl;
- }
-
- // Trailer
- out << "ostream& operator<<(ostream& out, const " << type_name << "& obj);" << endl;
- out << endl;
- out << "#endif // " << type_name << "_H" << endl;
-
- // Write the file
- conditionally_write_file(path + type_name + ".hh", out);
-}
-
-void Type::printEnumC(string path) const
-{
- ostringstream out;
- int size = m_enum_vec.size();
- string type_name = cIdent(); // Identifier for the type in C
-
- // Header
- out << "/** \\file " << type_name << ".hh" << endl;
- out << " * " << endl;
- out << " * Auto generated C++ code started by "<<__FILE__<<":"<<__LINE__<< endl;
- out << " */" << endl;
-
- out << endl;
- out << "#include \"mem/protocol/" << type_name << ".hh\"" << endl;
- if (m_isMachineType) {
- out << "#include \"mem/protocol/ControllerFactory.hh\"" << endl;
- for( int i = 0; i<size; i++ ) {
- out << "#include \"mem/protocol/" << m_enum_vec[i] << "_Controller.hh\"" << endl;
- }
- out << endl;
- }
- out << endl;
-
- // Code for output operator
- out << "ostream& operator<<(ostream& out, const " << type_name << "& obj)" << endl;
- out << "{" << endl;
- out << " out << " << type_name << "_to_string(obj);" << endl;
- out << " out << flush;" << endl;
- out << " return out;" << endl;
- out << "}" << endl;
-
- // Code to convert state to a string
- out << endl;
- out << "string " << type_name << "_to_string(const " << type_name << "& obj)" << endl;
- out << "{" << endl;
- out << " switch(obj) {" << endl;
-
- // For each field
- for( int i = 0; i<size; i++ ) {
- out << " case " << type_name << "_" << m_enum_vec[i] << ":" << endl;
- out << " return \"" << m_enum_vec[i] << "\";" << endl;
- }
-
- // Trailer
- out << " default:" << endl;
- out << " ERROR_MSG(\"Invalid range for type " << type_name << "\");" << endl;
- out << " return \"\";" << endl;
- out << " }" << endl;
- out << "}" << endl;
-
- // Code to convert from a string to the enumeration
- out << endl;
- out << type_name << " string_to_" << type_name << "(const string& str)" << endl;
- out << "{" << endl;
- out << " if (false) {" << endl;
-
- // For each field
- for( int i = 0; i<size; i++ ) {
- out << " } else if (str == \"" << m_enum_vec[i] << "\") {" << endl;
- out << " return " << type_name << "_" << m_enum_vec[i] << ";" << endl;
- }
-
- out << " } else {" << endl;
- out << " WARN_EXPR(str);" << endl;
- out << " ERROR_MSG(\"Invalid string conversion for type " << type_name << "\");" << endl;
- out << " }" << endl;
- out << "}" << endl;
-
- // Code to increment an enumeration type
- out << endl;
- out << type_name << "& operator++( " << type_name << "& e) {" << endl;
- out << " assert(e < " << type_name << "_NUM);" << endl;
- out << " return e = " << type_name << "(e+1);" << endl;
- out << "}" << endl;
-
- // MachineType hack used to set the base level and number of components for each Machine
- if (m_isMachineType) {
- out << endl;
- out << "/** \\brief returns the base vector index for each machine type to be used by NetDest " << endl;
- out << " * " << endl;
- out << " * \\return the base vector index for each machine type to be used by NetDest" << endl;
- out << " * \\see NetDest.hh" << endl;
- out << " */" << endl;
- out << "int " << type_name << "_base_level(const " << type_name << "& obj)" << endl;
- out << "{" << endl;
- out << " switch(obj) {" << endl;
-
- // For each field
- Vector < string > MachineNames;
- for( int i = 0; i<size; i++ ) {
- out << " case " << type_name << "_" << m_enum_vec[i] << ":" << endl;
- out << " return " << MachineNames.size() << ";" << endl;
- MachineNames.insertAtBottom(m_enum_vec[i]);
- }
-
- // total num
- out << " case " << type_name << "_NUM:" << endl;
- out << " return " << MachineNames.size() << ";" << endl;
-
- // Trailer
- out << " default:" << endl;
- out << " ERROR_MSG(\"Invalid range for type " << type_name << "\");" << endl;
- out << " return -1;" << endl;
- out << " }" << endl;
- out << "}" << endl;
-
- out << "/** \\brief returns the machine type for each base vector index used by NetDest" << endl;
- out << " * " << endl;
- out << " * \\return the MachineTYpe" << endl;
- out << " */" << endl;
- out << "MachineType " << type_name << "_from_base_level(int type)" << endl;
- out << "{" << endl;
- out << " switch(type) {" << endl;
-
- // For each field
- MachineNames.clear();
- for( int i = 0; i<size; i++ ) {
- out << " case " << MachineNames.size() << ":" << endl;
- out << " return " << type_name << "_" << m_enum_vec[i] << ";" << endl;
- MachineNames.insertAtBottom(m_enum_vec[i]);
- }
-
- // Trailer
- out << " default:" << endl;
- out << " ERROR_MSG(\"Invalid range for type " << type_name << "\");" << endl;
- out << " return MachineType_NUM;" << endl;
- out << " }" << endl;
- out << "}" << endl;
-
-
- out << endl;
- out << "/** \\brief The return value indicates the number of components created" << endl;
- out << " * before a particular machine's components" << endl;
- out << " * " << endl;
- out << " * \\return the base number of components for each machine" << endl;
- out << " */" << endl;
- out << "int " << type_name << "_base_number(const " << type_name << "& obj)" << endl;
- out << "{" << endl;
- out << " switch(obj) {" << endl;
-
- // For each field
- MachineNames.clear();
- for( int i = 0; i<size; i++ ) {
- out << " case " << type_name << "_" << m_enum_vec[i] << ":" << endl;
- out << " return 0";
- for ( int m = 0; m<MachineNames.size(); m++) {
- out << "+ " << MachineNames[m] << "_Controller::getNumControllers()";
- }
- out << ";" << endl;
- MachineNames.insertAtBottom(m_enum_vec[i]);
- }
-
- // total num
- out << " case " << type_name << "_NUM:" << endl;
- out << " return 0";
- for ( int m = 0; m<MachineNames.size(); m++) {
- out << "+ " << MachineNames[m] << "_Controller::getNumControllers()";
- }
- out << ";" << endl;
-
- // Trailer
- out << " default:" << endl;
- out << " ERROR_MSG(\"Invalid range for type " << type_name << "\");" << endl;
- out << " return -1;" << endl;
- out << " }" << endl;
- out << "}" << endl;
-
-
- out << endl;
- out << "/** \\brief returns the total number of components for each machine" << endl;
- out << " * \\return the total number of components for each machine" << endl;
- out << " */" << endl;
- out << "int " << type_name << "_base_count(const " << type_name << "& obj)" << endl;
- out << "{" << endl;
- out << " switch(obj) {" << endl;
-
- // For each field
- for( int i = 0; i<size; i++ ) {
- out << " case " << type_name << "_" << m_enum_vec[i] << ":" << endl;
- out << " return " << m_enum_vec[i] << "_Controller::getNumControllers();" << endl;
- }
-
- // total num
- out << " case " << type_name << "_NUM:" << endl;
- // Trailer
- out << " default:" << endl;
- out << " ERROR_MSG(\"Invalid range for type " << type_name << "\");" << endl;
- out << " return -1;" << endl;
- out << " }" << endl;
- out << "}" << endl;
-
- out << endl;
-
- }
-
- // Write the file
- conditionally_write_file(path + type_name + ".cc", out);
-}
diff --git a/src/mem/slicc/symbols/Type.hh b/src/mem/slicc/symbols/Type.hh
deleted file mode 100644
index 07d661d3c..000000000
--- a/src/mem/slicc/symbols/Type.hh
+++ /dev/null
@@ -1,155 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * Type.hh
- *
- * Description:
- *
- * $Id$
- *
- * */
-
-#ifndef TYPE_H
-#define TYPE_H
-
-#include "mem/slicc/slicc_global.hh"
-#include "mem/gems_common/Map.hh"
-#include "mem/slicc/symbols/Symbol.hh"
-
-class StateMachine;
-
-class Type : public Symbol {
-public:
- // Constructors
- Type(string id, const Location& location,
- const Map<string, string>& pairs,
- StateMachine* machine_ptr = NULL);
-
- // Destructor
- ~Type() {}
-
- // Public Methods
- string cIdent() const { return m_c_id; }
- string desc() const { return m_desc; }
-
- bool isPrimitive() const { return existPair("primitive"); }
- bool isNetworkMessage() const { return existPair("networkmessage"); }
- bool isMessage() const { return existPair("message"); }
- bool isBuffer() const { return existPair("buffer"); }
- bool isInPort() const { return existPair("inport"); }
- bool isOutPort() const { return existPair("outport"); }
- bool isEnumeration() const { return existPair("enumeration"); }
- bool isExternal() const { return existPair("external"); }
- bool isGlobal() const { return existPair("global"); }
- bool isInterface() const { return existPair("interface"); }
-
- // The data members of this type - only valid for messages and SLICC
- // declared structures
- // Return false on error
- bool dataMemberAdd(string id, Type* type_ptr, Map<string, string>& pairs,
- string* init_code);
- bool dataMemberExist(string id) const { return m_data_member_map.exist(id); }
- Type* dataMemberType(string id) const { return m_data_member_map.lookup(id); }
-
- // The methods of this type - only valid for external types
- // Return false on error
- bool methodAdd(string name, Type* return_type_ptr, const Vector<Type*>& param_type_vec);
- bool methodExist(string id) const { return m_method_return_type_map.exist(id); }
-
- string methodId(string name, const Vector<Type*>& param_type_vec);
- Type* methodReturnType(string id) const { return m_method_return_type_map.lookup(id); }
- const Vector<Type*>& methodParamType(string id) const { return m_method_param_type_map.lookup(id); }
-
- // The enumeration idents of this type - only valid for enums
- // Return false on error
- bool enumAdd(string id, Map<string, string> pairs);
- bool enumExist(string id) const { return m_enum_map.exist(id); }
-
- // Write the C output files
- void writeCFiles(string path) ;
-
- bool hasDefault() const { return existPair("default"); }
- string getDefault() const { return lookupPair("default"); }
-
- void print(ostream& out) const {}
-private:
- // Private Methods
-
- void printTypeH(string path) const;
- void printTypeC(string path) const;
- void printEnumC(string path) const;
- void printEnumH(string path) const;
-
- // Private copy constructor and assignment operator
- Type(const Type& obj);
- Type& operator=(const Type& obj);
-
- // Data Members (m_ prefix)
- string m_c_id;
- string m_desc;
-
- // Data Members
- Map<string, Type*> m_data_member_map;
- Vector<string> m_data_member_ident_vec;
- Vector<Type*> m_data_member_type_vec;
- Vector<Map<string, string> > m_data_member_pairs_vec;
- Vector<string*> m_data_member_init_code_vec;
- // Needs pairs here
-
- // Methods
- Map<string, Type*> m_method_return_type_map;
- Map<string, Vector<Type*> > m_method_param_type_map;
- // Needs pairs here
-
- // Enum
- Map<string, bool> m_enum_map;
- Vector<string> m_enum_vec;
- Vector< Map < string, string > > m_enum_pairs;
-
- // MachineType Hack
- bool m_isMachineType;
-
-};
-
-// Output operator declaration
-ostream& operator<<(ostream& out, const Type& obj);
-
-// ******************* Definitions *******************
-
-// Output operator definition
-extern inline
-ostream& operator<<(ostream& out, const Type& obj)
-{
- obj.print(out);
- out << flush;
- return out;
-}
-
-#endif //TYPE_H
diff --git a/src/mem/slicc/symbols/Type.py b/src/mem/slicc/symbols/Type.py
new file mode 100644
index 000000000..2541296dc
--- /dev/null
+++ b/src/mem/slicc/symbols/Type.py
@@ -0,0 +1,650 @@
+# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
+# Copyright (c) 2009 The Hewlett-Packard Development Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (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, orderdict
+
+from slicc.util import PairContainer
+from slicc.symbols.Symbol import Symbol
+
+class DataMember(PairContainer):
+ def __init__(self, ident, type, pairs, init_code):
+ super(DataMember, self).__init__(pairs)
+ self.ident = ident
+ self.type = type
+ self.init_code = init_code
+
+class Enumeration(PairContainer):
+ def __init__(self, ident, pairs):
+ super(Enumeration, self).__init__(pairs)
+ self.ident = ident
+
+class Method(object):
+ def __init__(self, return_type, param_types):
+ self.return_type = return_type
+ self.param_types = param_types
+
+class Type(Symbol):
+ def __init__(self, table, ident, location, pairs, machine=None):
+ super(Type, self).__init__(table, ident, location, pairs)
+ self.c_ident = ident
+ if machine:
+ if self.isExternal or self.isPrimitive:
+ if "external_name" in self:
+ self.c_ident = self["external_name"]
+ else:
+ # Append with machine name
+ self.c_ident = "%s_%s" % (machine, ident)
+
+ self.pairs.setdefault("desc", "No description avaliable")
+
+ # check for interface that this Type implements
+ if "interface" in self:
+ interface = self["interface"]
+ if interface in ("Message", "NetworkMessage"):
+ self["message"] = "yes"
+ if interface == "NetworkMessage":
+ self["networkmessage"] = "yes"
+
+ # FIXME - all of the following id comparisons are fragile hacks
+ if self.ident in ("CacheMemory", "NewCacheMemory",
+ "TLCCacheMemory", "DNUCACacheMemory",
+ "DNUCABankCacheMemory", "L2BankCacheMemory",
+ "CompressedCacheMemory", "PrefetchCacheMemory"):
+ self["cache"] = "yes"
+
+ if self.ident in ("TBETable", "DNUCATBETable", "DNUCAStopTable"):
+ self["tbe"] = "yes"
+
+ if self.ident == "NewTBETable":
+ self["newtbe"] = "yes"
+
+ if self.ident == "TimerTable":
+ self["timer"] = "yes"
+
+ if self.ident == "DirectoryMemory":
+ self["dir"] = "yes"
+
+ if self.ident == "PersistentTable":
+ self["persistent"] = "yes"
+
+ if self.ident == "Prefetcher":
+ self["prefetcher"] = "yes"
+
+ if self.ident == "DNUCA_Movement":
+ self["mover"] = "yes"
+
+ self.isMachineType = (ident == "MachineType")
+
+ self.data_members = orderdict()
+
+ # Methods
+ self.methods = {}
+
+ # Enums
+ self.enums = orderdict()
+
+ @property
+ def isPrimitive(self):
+ return "primitive" in self
+ @property
+ def isNetworkMessage(self):
+ return "networkmessage" in self
+ @property
+ def isMessage(self):
+ return "message" in self
+ @property
+ def isBuffer(self):
+ return "buffer" in self
+ @property
+ def isInPort(self):
+ return "inport" in self
+ @property
+ def isOutPort(self):
+ return "outport" in self
+ @property
+ def isEnumeration(self):
+ return "enumeration" in self
+ @property
+ def isExternal(self):
+ return "external" in self
+ @property
+ def isGlobal(self):
+ return "global" in self
+ @property
+ def isInterface(self):
+ return "interface" in self
+
+ # Return false on error
+ def dataMemberAdd(self, ident, type, pairs, init_code):
+ if ident in self.data_members:
+ return False
+
+ member = DataMember(ident, type, pairs, init_code)
+ self.data_members[ident] = member
+
+ return True
+
+ def dataMemberType(self, ident):
+ return self.data_members[ident].type
+
+ def methodId(self, name, param_type_vec):
+ return '_'.join([name] + [ pt.c_ident for pt in param_type_vec ])
+
+ def methodAdd(self, name, return_type, param_type_vec):
+ ident = self.methodId(name, param_type_vec)
+ if ident in self.methods:
+ return False
+
+ self.methods[ident] = Method(return_type, param_type_vec)
+ return True
+
+ def enumAdd(self, ident, pairs):
+ if ident in self.enums:
+ return False
+
+ self.enums[ident] = Enumeration(ident, pairs)
+
+ # Add default
+ if "default" not in self:
+ self["default"] = "%s_NUM" % self.c_ident
+
+ return True
+
+ def writeCodeFiles(self, path):
+ if self.isExternal:
+ # Do nothing
+ pass
+ elif self.isEnumeration:
+ self.printEnumHH(path)
+ self.printEnumCC(path)
+ else:
+ # User defined structs and messages
+ self.printTypeHH(path)
+ self.printTypeCC(path)
+
+ def printTypeHH(self, path):
+ code = code_formatter()
+ code('''
+/** \\file ${{self.c_ident}}.hh
+ *
+ *
+ * Auto generated C++ code started by $__file__:$__line__
+ */
+
+#ifndef ${{self.c_ident}}_H
+#define ${{self.c_ident}}_H
+
+#include "mem/ruby/common/Global.hh"
+#include "mem/gems_common/Allocator.hh"
+''')
+
+ for dm in self.data_members.values():
+ if not dm.type.isPrimitive:
+ code('#include "mem/protocol/$0.hh"', dm.type.c_ident)
+
+ parent = ""
+ if "interface" in self:
+ code('#include "mem/protocol/$0.hh"', self["interface"])
+ parent = " : public %s" % self["interface"]
+
+ code('''
+$klass ${{self.c_ident}}$parent {
+ public:
+ ${{self.c_ident}}()
+''', klass="class")
+
+ # Call superclass constructor
+ if "interface" in self:
+ code(' : ${{self["interface"]}}()')
+
+ code.indent()
+ code("{")
+ if not self.isGlobal:
+ code.indent()
+ for dm in self.data_members.values():
+ ident = dm.ident
+ if "default" in dm:
+ # look for default value
+ code('m_$ident = ${{dm["default"]}}; // default for this field')
+ elif "default" in dm.type:
+ # Look for the type default
+ tid = dm.type.c_ident
+ code('m_$ident = ${{dm.type["default"]}}; // default value of $tid')
+ else:
+ code('// m_$ident has no default')
+ code.dedent()
+ code('}')
+
+ # ******** Default destructor ********
+ code('~${{self.c_ident}}() { };')
+
+ # ******** Full init constructor ********
+ if not self.isGlobal:
+ params = [ 'const %s& local_%s' % (dm.type.c_ident, dm.ident) \
+ for dm in self.data_members.itervalues() ]
+
+ if self.isMessage:
+ params.append('const unsigned local_proc_id')
+
+ params = ', '.join(params)
+ code('${{self.c_ident}}($params)')
+
+ # Call superclass constructor
+ if "interface" in self:
+ code(' : ${{self["interface"]}}()')
+
+ code('{')
+ code.indent()
+ for dm in self.data_members.values():
+ code('m_${{dm.ident}} = local_${{dm.ident}};')
+ if "nextLineCallHack" in dm:
+ code('m_${{dm.ident}}${{dm["nextLineCallHack"]}};')
+
+ if self.isMessage:
+ code('proc_id = local_proc_id;')
+
+ code.dedent()
+ code('}')
+
+ # create a static factory method
+ if "interface" in self:
+ code('''
+static ${{self["interface"]}}* create() {
+ return new ${{self.c_ident}}();
+}
+''')
+
+ # ******** Message member functions ********
+ # FIXME: those should be moved into slicc file, slicc should
+ # support more of the c++ class inheritance
+
+ if self.isMessage:
+ code('''
+Message* clone() const { checkAllocator(); return s_allocator_ptr->allocate(*this); }
+void destroy() { checkAllocator(); s_allocator_ptr->deallocate(this); }
+static Allocator<${{self.c_ident}}>* s_allocator_ptr;
+static void checkAllocator() { if (s_allocator_ptr == NULL) { s_allocator_ptr = new Allocator<${{self.c_ident}}>; }}
+''')
+
+ if not self.isGlobal:
+ # const Get methods for each field
+ code('// Const accessors methods for each field')
+ for dm in self.data_members.values():
+ code('''
+/** \\brief Const accessor method for ${{dm.ident}} field.
+ * \\return ${{dm.ident}} field
+ */
+const ${{dm.type.c_ident}}& get${{dm.ident}}() const { return m_${{dm.ident}}; }
+''')
+
+ # Non-const Get methods for each field
+ code('// Non const Accessors methods for each field')
+ for dm in self.data_members.values():
+ code('''
+/** \\brief Non-const accessor method for ${{dm.ident}} field.
+ * \\return ${{dm.ident}} field
+ */
+${{dm.type.c_ident}}& get${{dm.ident}}() { return m_${{dm.ident}}; }
+''')
+
+ #Set methods for each field
+ code('// Mutator methods for each field')
+ for dm in self.data_members.values():
+ code('''
+/** \\brief Mutator method for ${{dm.ident}} field */
+void set${{dm.ident}}(const ${{dm.type.c_ident}}& local_${{dm.ident}}) { m_${{dm.ident}} = local_${{dm.ident}}; }
+''')
+
+ code('void print(ostream& out) const;')
+ code.dedent()
+ code(' //private:')
+ code.indent()
+
+ # Data members for each field
+ for dm in self.data_members.values():
+ if "abstract" not in dm:
+ const = ""
+ init = ""
+
+ # global structure
+ if self.isGlobal:
+ const = "static const "
+
+ # init value
+ if dm.init_code:
+ # only global structure can have init value here
+ assert self.isGlobal
+ init = " = %s" % (dm.init_code)
+
+ desc = ""
+ if "desc" in dm:
+ desc = '/**< %s */' % dm["desc"]
+
+ code('$const${{dm.type.c_ident}} m_${{dm.ident}}$init; $desc')
+
+ if self.isMessage:
+ code('unsigned proc_id;')
+
+ code.dedent()
+ code('};')
+
+ code('''
+// Output operator declaration
+ostream& operator<<(ostream& out, const ${{self.c_ident}}& obj);
+
+// Output operator definition
+extern inline
+ostream& operator<<(ostream& out, const ${{self.c_ident}}& obj)
+{
+ obj.print(out);
+ out << flush;
+ return out;
+}
+
+#endif // ${{self.c_ident}}_H
+''')
+
+ code.write(path, "%s.hh" % self.c_ident)
+
+ def printTypeCC(self, path):
+ code = code_formatter()
+
+ code('''
+/** \\file ${{self.c_ident}}.cc
+ *
+ * Auto generated C++ code started by $__file__:$__line__
+ */
+
+#include "mem/protocol/${{self.c_ident}}.hh"
+''')
+
+ if self.isMessage:
+ code('Allocator<${{self.c_ident}}>* ${{self.c_ident}}::s_allocator_ptr = NULL;')
+ code('''
+/** \\brief Print the state of this object */
+void ${{self.c_ident}}::print(ostream& out) const
+{
+ out << "[${{self.c_ident}}: ";
+''')
+
+ # For each field
+ code.indent()
+ for dm in self.data_members.values():
+ code('out << "${{dm.ident}} = " << m_${{dm.ident}} << " ";''')
+
+ if self.isMessage:
+ code('out << "Time = " << getTime() << " ";')
+ code.dedent()
+
+ # Trailer
+ code('''
+ out << "]";
+}''')
+
+ code.write(path, "%s.cc" % self.c_ident)
+
+ def printEnumHH(self, path):
+ code = code_formatter()
+ code('''
+/** \\file ${{self.c_ident}}.hh
+ *
+ * Auto generated C++ code started by $__file__:$__line__
+ */
+#ifndef ${{self.c_ident}}_H
+#define ${{self.c_ident}}_H
+
+#include "mem/ruby/common/Global.hh"
+
+/** \\enum ${{self.c_ident}}
+ * \\brief ${{self.desc}}
+ */
+enum ${{self.c_ident}} {
+ ${{self.c_ident}}_FIRST,
+''')
+
+ code.indent()
+ # For each field
+ for i,(ident,enum) in enumerate(self.enums.iteritems()):
+ desc = enum.get("desc", "No description avaliable")
+ init = ' = %s_FIRST' % self.c_ident if i == 0 else ''
+
+ code('${{self.c_ident}}_${{enum.ident}}$init, /**< $desc */')
+ code.dedent()
+ code('''
+ ${{self.c_ident}}_NUM
+};
+${{self.c_ident}} string_to_${{self.c_ident}}(const string& str);
+string ${{self.c_ident}}_to_string(const ${{self.c_ident}}& obj);
+${{self.c_ident}} &operator++(${{self.c_ident}} &e);
+''')
+
+ # MachineType hack used to set the base component id for each Machine
+ if self.isMachineType:
+ code('''
+int ${{self.c_ident}}_base_level(const ${{self.c_ident}}& obj);
+MachineType ${{self.c_ident}}_from_base_level(int);
+int ${{self.c_ident}}_base_number(const ${{self.c_ident}}& obj);
+int ${{self.c_ident}}_base_count(const ${{self.c_ident}}& obj);
+''')
+
+ for enum in self.enums.itervalues():
+ code('#define MACHINETYPE_${{enum.ident}} 1')
+
+ # Trailer
+ code('''
+ostream& operator<<(ostream& out, const ${{self.c_ident}}& obj);
+
+#endif // ${{self.c_ident}}_H
+''')
+
+ code.write(path, "%s.hh" % self.c_ident)
+
+ def printEnumCC(self, path):
+ code = code_formatter()
+ code('''
+/** \\file ${{self.c_ident}}.hh
+ *
+ * Auto generated C++ code started by $__file__:$__line__
+ */
+
+#include "mem/protocol/${{self.c_ident}}.hh"
+
+''')
+
+ if self.isMachineType:
+ code('#include "mem/protocol/ControllerFactory.hh"')
+ for enum in self.enums.itervalues():
+ code('#include "mem/protocol/${{enum.ident}}_Controller.hh"')
+
+ code('''
+ostream& operator<<(ostream& out, const ${{self.c_ident}}& obj)
+{
+ out << ${{self.c_ident}}_to_string(obj);
+ out << flush;
+ return out;
+}
+
+string ${{self.c_ident}}_to_string(const ${{self.c_ident}}& obj)
+{
+ switch(obj) {
+''')
+
+ # For each field
+ code.indent()
+ for enum in self.enums.itervalues():
+ code(' case ${{self.c_ident}}_${{enum.ident}}:')
+ code(' return "${{enum.ident}}";')
+ code.dedent()
+
+ # Trailer
+ code('''
+ default:
+ ERROR_MSG("Invalid range for type ${{self.c_ident}}");
+ return "";
+ }
+}
+
+${{self.c_ident}} string_to_${{self.c_ident}}(const string& str)
+{
+''')
+
+ # For each field
+ code.indent()
+ code("if (false) {")
+ start = "} else "
+ for enum in self.enums.itervalues():
+ code('${start}if (str == "${{enum.ident}}") {')
+ code(' return ${{self.c_ident}}_${{enum.ident}};')
+ code.dedent()
+
+ code('''
+ } else {
+ WARN_EXPR(str);
+ ERROR_MSG("Invalid string conversion for type ${{self.c_ident}}");
+ }
+}
+
+${{self.c_ident}}& operator++(${{self.c_ident}}& e) {
+ assert(e < ${{self.c_ident}}_NUM);
+ return e = ${{self.c_ident}}(e+1);
+}
+''')
+
+ # MachineType hack used to set the base level and number of
+ # components for each Machine
+ if self.isMachineType:
+ code('''
+/** \\brief returns the base vector index for each machine type to be used by NetDest
+ *
+ * \\return the base vector index for each machine type to be used by NetDest
+ * \\see NetDest.hh
+ */
+int ${{self.c_ident}}_base_level(const ${{self.c_ident}}& obj)
+{
+ switch(obj) {
+''')
+
+ # For each field
+ code.indent()
+ for i,enum in enumerate(self.enums.itervalues()):
+ code(' case ${{self.c_ident}}_${{enum.ident}}:')
+ code(' return $i;')
+ code.dedent()
+
+ # total num
+ code('''
+ case ${{self.c_ident}}_NUM:
+ return ${{len(self.enums)}};
+
+ default:
+ ERROR_MSG("Invalid range for type ${{self.c_ident}}");
+ return -1;
+ }
+}
+
+/** \\brief returns the machine type for each base vector index used by NetDest
+ *
+ * \\return the MachineTYpe
+ */
+MachineType ${{self.c_ident}}_from_base_level(int type)
+{
+ switch(type) {
+''')
+
+ # For each field
+ code.indent()
+ for i,enum in enumerate(self.enums.itervalues()):
+ code(' case $i:')
+ code(' return ${{self.c_ident}}_${{enum.ident}};')
+ code.dedent()
+
+ # Trailer
+ code('''
+ default:
+ ERROR_MSG("Invalid range for type ${{self.c_ident}}");
+ return MachineType_NUM;
+ }
+}
+
+/** \\brief The return value indicates the number of components created
+ * before a particular machine\'s components
+ *
+ * \\return the base number of components for each machine
+ */
+int ${{self.c_ident}}_base_number(const ${{self.c_ident}}& obj)
+{
+ int base = 0;
+ switch(obj) {
+''')
+
+ # For each field
+ code.indent()
+ code(' case ${{self.c_ident}}_NUM:')
+ for enum in reversed(self.enums.values()):
+ code(' base += ${{enum.ident}}_Controller::getNumControllers();')
+ code(' case ${{self.c_ident}}_${{enum.ident}}:')
+ code(' break;')
+ code.dedent()
+
+ code('''
+ default:
+ ERROR_MSG("Invalid range for type ${{self.c_ident}}");
+ return -1;
+ }
+
+ return base;
+}
+
+/** \\brief returns the total number of components for each machine
+ * \\return the total number of components for each machine
+ */
+int ${{self.c_ident}}_base_count(const ${{self.c_ident}}& obj)
+{
+ switch(obj) {
+''')
+
+ # For each field
+ for enum in self.enums.itervalues():
+ code('''
+ case ${{self.c_ident}}_${{enum.ident}}:
+ return ${{enum.ident}}_Controller::getNumControllers();
+''')
+
+ # total num
+ code('''
+ case ${{self.c_ident}}_NUM:
+ default:
+ ERROR_MSG("Invalid range for type ${{self.c_ident}}");
+ return -1;
+ }
+}
+''')
+
+ # Write the file
+ code.write(path, "%s.cc" % self.c_ident)
+
+__all__ = [ "Type" ]
diff --git a/src/mem/slicc/symbols/Var.cc b/src/mem/slicc/symbols/Var.cc
deleted file mode 100644
index a6e8dfd55..000000000
--- a/src/mem/slicc/symbols/Var.cc
+++ /dev/null
@@ -1,57 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * $Id$
- *
- * */
-
-#include "mem/slicc/symbols/Var.hh"
-#include "mem/slicc/symbols/StateMachine.hh"
-
-Var::Var(string id, const Location& location,
- Type* type_ptr, string code,
- const Map<string, string>& pairs,
- StateMachine* machine_ptr) : Symbol(id, location, pairs)
-{
- if (machine_ptr == NULL) {
- m_c_id = id;
- } else {
- m_c_id = machine_ptr->toString() + "_" + id; // Append with machine name
- }
-
- m_machine_ptr = machine_ptr;
- m_type_ptr = type_ptr;
- m_code = code;
-}
-
-void Var::print(ostream& out) const
-{
- out << "[Var id: " << m_c_id << "]" << endl;
-}
diff --git a/src/mem/slicc/symbols/Var.hh b/src/mem/slicc/symbols/Var.hh
deleted file mode 100644
index 4cb504296..000000000
--- a/src/mem/slicc/symbols/Var.hh
+++ /dev/null
@@ -1,98 +0,0 @@
-
-/*
- * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * Var.hh
- *
- * Description:
- *
- * $Id$
- *
- * */
-
-#ifndef VAR_H
-#define VAR_H
-
-#include "mem/slicc/slicc_global.hh"
-#include "mem/slicc/symbols/Symbol.hh"
-#include "mem/slicc/symbols/Type.hh"
-
-class StateMachine;
-
-class Var : public Symbol {
-public:
- // Constructors
- Var(string id, const Location& location,
- Type* type_ptr, string code,
- const Map<string, string>& pairs,
- StateMachine* machine_ptr = NULL);
-
- // Var(string id, const Location& location,
- // Type* type_ptr, string code) : Symbol(id, location) { m_type_ptr = type_ptr; m_code = code; }
-
- // Destructor
- ~Var() {}
-
- // Public Methods
- string cIdent() const { return m_c_id; }
- void writeCFiles(string path) {}
- string getCode() const { return m_code; }
- Type* getType() const { return m_type_ptr; }
- StateMachine* getMachine() const { return m_machine_ptr; }
-
- void print(ostream& out) const;
-private:
- // Private Methods
-
- // Private copy constructor and assignment operator
- Var(const Var& obj);
- Var& operator=(const Var& obj);
-
- // Data Members (m_ prefix)
- string m_c_id;
- Type* m_type_ptr;
- string m_code;
- StateMachine* m_machine_ptr;
-};
-
-// Output operator declaration
-ostream& operator<<(ostream& out, const Var& obj);
-
-// ******************* Definitions *******************
-
-// Output operator definition
-extern inline
-ostream& operator<<(ostream& out, const Var& obj)
-{
- obj.print(out);
- out << flush;
- return out;
-}
-
-#endif //VAR_H
diff --git a/src/mem/slicc/symbols/Var.py b/src/mem/slicc/symbols/Var.py
new file mode 100644
index 000000000..87a101f65
--- /dev/null
+++ b/src/mem/slicc/symbols/Var.py
@@ -0,0 +1,50 @@
+# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
+# Copyright (c) 2009 The Hewlett-Packard Development Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (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 slicc.symbols.Symbol import Symbol
+
+class Var(Symbol):
+ def __init__(self, symtab, ident, location, type, code, pairs,
+ machine=None):
+ super(Var, self).__init__(symtab, ident, location, pairs)
+
+ if machine:
+ self.c_ident = "%s_%s" % (machine, ident)
+ else:
+ self.c_ident = ident
+
+ self.machine = machine
+ self.type = type
+ self.code = code
+
+ def __repr__(self):
+ return "[Var id: %s]" % (self.c_ident)
+
+ def writeCodeFiles(self, path):
+ pass
+
+__all__ = [ "Var" ]
diff --git a/src/mem/slicc/symbols/__init__.py b/src/mem/slicc/symbols/__init__.py
new file mode 100644
index 000000000..43388a5fe
--- /dev/null
+++ b/src/mem/slicc/symbols/__init__.py
@@ -0,0 +1,38 @@
+# Copyright (c) 2009 The Hewlett-Packard Development Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+# Authors: Nathan Binkert
+
+from slicc.symbols.Action import Action
+from slicc.symbols.Event import Event
+from slicc.symbols.Func import Func
+from slicc.symbols.State import State
+from slicc.symbols.StateMachine import StateMachine
+from slicc.symbols.Symbol import Symbol
+from slicc.symbols.SymbolTable import SymbolTable
+from slicc.symbols.Transition import Transition
+from slicc.symbols.Type import Type
+from slicc.symbols.Var import Var
diff --git a/src/mem/slicc/util.py b/src/mem/slicc/util.py
new file mode 100644
index 000000000..abadc3e30
--- /dev/null
+++ b/src/mem/slicc/util.py
@@ -0,0 +1,75 @@
+# Copyright (c) 2009 The Hewlett-Packard Development Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+import os
+import sys
+
+def makeDir(path):
+ if os.path.exists(path):
+ if not os.path.isdir(path):
+ raise AttributeError, "%s exists but is not directory" % path
+ else:
+ os.mkdir(path)
+
+class PairContainer(object):
+ def __init__(self, pairs=None):
+ self.pairs = {}
+ if pairs:
+ self.pairs.update(pairs)
+
+ def __contains__(self, item):
+ return item in self.pairs
+
+ def __getitem__(self, item):
+ return self.pairs[item]
+
+ def __setitem__(self, item, value):
+ self.pairs[item] = value
+
+ def get(self, item, failobj=None):
+ return self.pairs.get(item, failobj)
+
+class Location(object):
+ def __init__(self, filename, lineno):
+ self.filename = filename
+ self.lineno = lineno
+
+ def __str__(self):
+ return '%s:%d' % (os.path.basename(self.filename), self.lineno)
+
+ def warning(self, message, *args):
+ if args:
+ message = message % args
+ #raise Exception, "%s: Warning: %s" % (self, message)
+ print >>sys.stderr, "%s: Warning: %s" % (self, message)
+
+ def error(self, message, *args):
+ if args:
+ message = message % args
+ raise Exception, "%s: Error: %s" % (self, message)
+ sys.exit("\n%s: Error: %s" % (self, message))
+
+__all__ = [ 'makeDir', 'PairContainer', 'Location' ]
diff --git a/util/slicc b/util/slicc
new file mode 100755
index 000000000..07bd73ffa
--- /dev/null
+++ b/util/slicc
@@ -0,0 +1,38 @@
+#!/usr/bin/env python
+# Copyright (c) 2009 The Hewlett-Packard Development Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+if __name__ == "__main__":
+ import sys
+ from os.path import dirname, join
+
+ base = dirname(__file__)
+ sys.path.insert(1, join(base, "../src/mem"))
+ sys.path.insert(1, join(base, "../src/python"))
+ sys.path.insert(1, join(base, "../ext/ply"))
+
+ import slicc.main
+ slicc.main.main()