ObjDeclAST.py revision 6657
1955SN/A# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
2955SN/A# Copyright (c) 2009 The Hewlett-Packard Development Company
31762SN/A# All rights reserved.
4955SN/A#
5955SN/A# Redistribution and use in source and binary forms, with or without
6955SN/A# modification, are permitted provided that the following conditions are
7955SN/A# met: redistributions of source code must retain the above copyright
8955SN/A# notice, this list of conditions and the following disclaimer;
9955SN/A# redistributions in binary form must reproduce the above copyright
10955SN/A# notice, this list of conditions and the following disclaimer in the
11955SN/A# documentation and/or other materials provided with the distribution;
12955SN/A# neither the name of the copyright holders nor the names of its
13955SN/A# contributors may be used to endorse or promote products derived from
14955SN/A# this software without specific prior written permission.
15955SN/A#
16955SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17955SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18955SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19955SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20955SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21955SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22955SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23955SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24955SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25955SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26955SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27955SN/A
282665Ssaidi@eecs.umich.edufrom slicc.ast.DeclAST import DeclAST
294762Snate@binkert.orgfrom slicc.symbols import Var
30955SN/A
315522Snate@binkert.orgclass ObjDeclAST(DeclAST):
326143Snate@binkert.org    def __init__(self, slicc, type_ast, ident, pairs):
334762Snate@binkert.org        super(ObjDeclAST, self).__init__(slicc, pairs)
345522Snate@binkert.org
35955SN/A        self.type_ast = type_ast
365522Snate@binkert.org        self.ident = ident
37955SN/A
385522Snate@binkert.org    def __repr__(self):
394202Sbinkertn@umich.edu        return "[ObjDecl: %r]" % self.ident
405742Snate@binkert.org
41955SN/A    def generate(self):
424381Sbinkertn@umich.edu        machineComponentSym = False
434381Sbinkertn@umich.edu
448334Snate@binkert.org        self["chip_object"] = "yes"
45955SN/A
46955SN/A        if "hack" in self:
474202Sbinkertn@umich.edu            warning("'hack=' is now deprecated")
48955SN/A
494382Sbinkertn@umich.edu        if "network" in self and "virtual_network" not in self:
504382Sbinkertn@umich.edu            self.error("Network queues require a 'virtual_network' attribute")
514382Sbinkertn@umich.edu
526654Snate@binkert.org        type = self.type_ast.type
535517Snate@binkert.org        if type.isBuffer and "ordered" not in self:
548614Sgblack@eecs.umich.edu            self.error("Buffer object decls require an 'ordered' attribute")
557674Snate@binkert.org
566143Snate@binkert.org        if "ordered" in self:
576143Snate@binkert.org            value = self["ordered"]
586143Snate@binkert.org
598233Snate@binkert.org            if value not in ("true", "false"):
608233Snate@binkert.org                self.error("The 'ordered' attribute is '%s' " + \
618233Snate@binkert.org                           "must be 'true' or 'false'.", value)
628233Snate@binkert.org
638233Snate@binkert.org        if "random" in self:
648334Snate@binkert.org            value = self["random"]
658334Snate@binkert.org            if value not in ("true", "false"):
6610453SAndrew.Bardsley@arm.com                self.error("The 'random' attribute is '%s' " + \
6710453SAndrew.Bardsley@arm.com                           "must be 'true' or 'false'.", value)
688233Snate@binkert.org
698233Snate@binkert.org        machine = self.symtab.state_machine
708233Snate@binkert.org
718233Snate@binkert.org        # FIXME : should all use accessors here to avoid public member
728233Snate@binkert.org        # variables
738233Snate@binkert.org        if self.ident == "id":
746143Snate@binkert.org            c_code = "m_chip_ptr.getID()"
758233Snate@binkert.org        elif self.ident == "version":
768233Snate@binkert.org            c_code = "m_version"
778233Snate@binkert.org        elif self.ident == "machineID":
786143Snate@binkert.org            c_code = "m_machineID"
796143Snate@binkert.org        elif machine:
806143Snate@binkert.org            c_code = "(*m_%s_%s_ptr)" % (machine.ident, self.ident)
8111308Santhony.gutierrez@amd.com        else:
828233Snate@binkert.org            c_code = "(*m_%s_ptr)" % (self.ident)
838233Snate@binkert.org
848233Snate@binkert.org        v = Var(self.symtab, self.ident, self.location, type, c_code,
856143Snate@binkert.org                self.pairs, machine)
868233Snate@binkert.org
878233Snate@binkert.org        if machine:
888233Snate@binkert.org            machine.addObject(v)
898233Snate@binkert.org
906143Snate@binkert.org        self.symtab.newSymbol(v)
916143Snate@binkert.org
926143Snate@binkert.org        # used to cheat-- that is, access components in other machines
934762Snate@binkert.org        if machineComponentSym:
946143Snate@binkert.org            self.symtab.newMachComponentSym(v)
958233Snate@binkert.org