ExprStatementAST.py revision 6657
112109SRekai.GonzalezAlberquilla@arm.com# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
212109SRekai.GonzalezAlberquilla@arm.com# Copyright (c) 2009 The Hewlett-Packard Development Company
312109SRekai.GonzalezAlberquilla@arm.com# All rights reserved.
412109SRekai.GonzalezAlberquilla@arm.com#
512109SRekai.GonzalezAlberquilla@arm.com# Redistribution and use in source and binary forms, with or without
612109SRekai.GonzalezAlberquilla@arm.com# modification, are permitted provided that the following conditions are
712109SRekai.GonzalezAlberquilla@arm.com# met: redistributions of source code must retain the above copyright
812109SRekai.GonzalezAlberquilla@arm.com# notice, this list of conditions and the following disclaimer;
912109SRekai.GonzalezAlberquilla@arm.com# redistributions in binary form must reproduce the above copyright
1012109SRekai.GonzalezAlberquilla@arm.com# notice, this list of conditions and the following disclaimer in the
1112109SRekai.GonzalezAlberquilla@arm.com# documentation and/or other materials provided with the distribution;
1212109SRekai.GonzalezAlberquilla@arm.com# neither the name of the copyright holders nor the names of its
134486Sbinkertn@umich.edu# contributors may be used to endorse or promote products derived from
144486Sbinkertn@umich.edu# this software without specific prior written permission.
154486Sbinkertn@umich.edu#
164486Sbinkertn@umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
174486Sbinkertn@umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
184486Sbinkertn@umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
194486Sbinkertn@umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
204486Sbinkertn@umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
214486Sbinkertn@umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
224486Sbinkertn@umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
234486Sbinkertn@umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
244486Sbinkertn@umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
254486Sbinkertn@umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
264486Sbinkertn@umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
274486Sbinkertn@umich.edu
284486Sbinkertn@umich.edufrom m5.util import code_formatter
294486Sbinkertn@umich.edu
304486Sbinkertn@umich.edufrom slicc.ast.StatementAST import StatementAST
314486Sbinkertn@umich.edufrom slicc.symbols import Type
324486Sbinkertn@umich.edu
334486Sbinkertn@umich.educlass ExprStatementAST(StatementAST):
344486Sbinkertn@umich.edu    def __init__(self, slicc, expr):
354486Sbinkertn@umich.edu        super(ExprStatementAST, self).__init__(slicc)
364486Sbinkertn@umich.edu        self.expr = expr
374486Sbinkertn@umich.edu
384486Sbinkertn@umich.edu    def __repr__(self):
394486Sbinkertn@umich.edu        return "[ExprStatementAST: %s]" % (self.expr)
404486Sbinkertn@umich.edu
4112563Sgabeblack@google.com    def generate(self, code, return_type):
4212563Sgabeblack@google.com        actual_type,rcode = self.expr.inline(True)
436654Snate@binkert.org        code("$rcode;")
443102SN/A
453102SN/A        # The return type must be void
461681SN/A        if actual_type != self.symtab.find("void", Type):
473223SN/A            self.expr.error("Non-void return must not be ignored, " + \
488887Sgeoffrey.blake@arm.com                            "return type is '%s'", actual_type.ident)
4910785Sgope@wisc.edu
504486Sbinkertn@umich.edu    def findResources(self, resources):
512817SN/A        self.expr.findResources(resources)
522817SN/A
539341SAndreas.Sandberg@arm.com