slicc: Pure python implementation of slicc.

This is simply a translation of the C++ slicc into python with very minimal
reorganization of the code.  The output can be verified as nearly identical
by doing a "diff -wBur".

Slicc can easily be run manually by using util/slicc
This commit is contained in:
Nathan Binkert 2009-09-22 18:12:39 -07:00
parent 30d5d95b6a
commit 2278363015
178 changed files with 6516 additions and 15232 deletions

View file

@ -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()
print "SLICC Generator pass 2..."
slicc.generate()
print "SLICC writing C++ files..."
slicc.writeCodeFiles(pdir)
print "SLICC writing HTML files..."
slicc.writeHTMLFiles(hdir)
slicc_builder = Builder(action=slicc_action, emitter=slicc_emitter)
protocol = env['PROTOCOL']
sources = [ protocol_dir.File("RubySlicc_interfaces.slicc"),
protocol_dir.File("%s.slicc" % protocol) ]
execfile(slicc_dir.File('parser/parser.py').srcnode().abspath)
sm_files = read_slicc([s.srcnode().abspath for s in sources])
sm_files = [ protocol_dir.File(f) for f in sm_files ]
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_bin = slicc_dir.File("slicc")
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)

View file

@ -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') ])

25
src/mem/slicc/__init__.py Normal file
View file

@ -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.

View file

@ -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"

View file

@ -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

63
src/mem/slicc/ast/AST.py Normal file
View file

@ -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

View file

@ -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

View file

@ -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 << "]";
}

View file

@ -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

View file

@ -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)

View file

@ -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 << "]";
}

View file

@ -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

View file

@ -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)

View file

@ -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 << "]";
}

View file

@ -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

View file

@ -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)

View file

@ -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 << "]";
}

View file

@ -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

View file

@ -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)

View file

@ -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 << "]";
}

View file

@ -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

View file

@ -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)

View file

@ -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 << "]";
}

View file

@ -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

View file

@ -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)

View file

@ -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"

View file

@ -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

View file

@ -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

View file

@ -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 << "]";
}

View file

@ -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

View file

@ -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()

View file

@ -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 << "]";
}

View file

@ -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

View file

@ -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)

View file

@ -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() << "]";
}

View file

@ -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

View file

@ -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)

View file

@ -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 << "]";
}

View file

@ -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

View file

@ -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

View file

@ -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"

View file

@ -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

View file

@ -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

View file

@ -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 << "]";
}

View file

@ -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

View file

@ -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)

View file

@ -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;
}

View file

@ -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

View file

@ -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)

View file

@ -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 << "]";
}

View file

@ -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

View file

@ -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

View file

@ -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 << "]";
}

View file

@ -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

View file

@ -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)

View file

@ -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 << "]";
}

View file

@ -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

View file

@ -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)

View file

@ -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 << "]";
}

View file

@ -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

View file

@ -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)

View file

@ -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 << "]";
}

View file

@ -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

View file

@ -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)

View file

@ -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;
}

View file

@ -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

View file

@ -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

View file

@ -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;
}

View file

@ -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

View file

@ -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 << "]";
}

View file

@ -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

View file

@ -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()

View file

@ -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 << "]";
}

View file

@ -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

View file

@ -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

View file

@ -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 << "]";
}

View file

@ -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

View file

@ -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" ]

View file

@ -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;
}

View file

@ -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

View file

@ -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

View file

@ -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 << "]";
}

View file

@ -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

View file

@ -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)

View file

@ -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 << "]";
}

View file

@ -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

View file

@ -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)

View file

@ -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;
}

View file

@ -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

View file

@ -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)

View file

@ -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();
}

View file

@ -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

View file

@ -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

View file

@ -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
<< "]";
}

View file

@ -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

View file

@ -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)

View file

@ -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 << "]";
}

View file

@ -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

View file

@ -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)

View file

@ -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;
}

Some files were not shown because too many files have changed in this diff Show more