17839Snilay@cs.wisc.edu# 27839Snilay@cs.wisc.edu# Copyright (c) 2011 Mark D. Hill and David A. Wood 37839Snilay@cs.wisc.edu# All rights reserved. 47839Snilay@cs.wisc.edu# 57839Snilay@cs.wisc.edu# Redistribution and use in source and binary forms, with or without 67839Snilay@cs.wisc.edu# modification, are permitted provided that the following conditions are 77839Snilay@cs.wisc.edu# met: redistributions of source code must retain the above copyright 87839Snilay@cs.wisc.edu# notice, this list of conditions and the following disclaimer; 97839Snilay@cs.wisc.edu# redistributions in binary form must reproduce the above copyright 107839Snilay@cs.wisc.edu# notice, this list of conditions and the following disclaimer in the 117839Snilay@cs.wisc.edu# documentation and/or other materials provided with the distribution; 127839Snilay@cs.wisc.edu# neither the name of the copyright holders nor the names of its 137839Snilay@cs.wisc.edu# contributors may be used to endorse or promote products derived from 147839Snilay@cs.wisc.edu# this software without specific prior written permission. 157839Snilay@cs.wisc.edu# 167839Snilay@cs.wisc.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 177839Snilay@cs.wisc.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 187839Snilay@cs.wisc.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 197839Snilay@cs.wisc.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 207839Snilay@cs.wisc.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 217839Snilay@cs.wisc.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 227839Snilay@cs.wisc.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 237839Snilay@cs.wisc.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 247839Snilay@cs.wisc.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 257839Snilay@cs.wisc.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 267839Snilay@cs.wisc.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 277839Snilay@cs.wisc.edu# 287839Snilay@cs.wisc.edu 297839Snilay@cs.wisc.edufrom slicc.ast.ExprAST import ExprAST 307839Snilay@cs.wisc.edufrom slicc.symbols import Type 317839Snilay@cs.wisc.edu 327839Snilay@cs.wisc.educlass IsValidPtrExprAST(ExprAST): 337839Snilay@cs.wisc.edu def __init__(self, slicc, variable, flag): 347839Snilay@cs.wisc.edu super(IsValidPtrExprAST, self).__init__(slicc) 357839Snilay@cs.wisc.edu self.variable = variable 367839Snilay@cs.wisc.edu self.flag = flag 377839Snilay@cs.wisc.edu 387839Snilay@cs.wisc.edu def __repr__(self): 397839Snilay@cs.wisc.edu return "[IsValidPtrExprAST: %r]" % self.variable 407839Snilay@cs.wisc.edu 417839Snilay@cs.wisc.edu def generate(self, code): 427839Snilay@cs.wisc.edu # Make sure the variable is valid 437839Snilay@cs.wisc.edu fix = code.nofix() 447839Snilay@cs.wisc.edu code("(") 457839Snilay@cs.wisc.edu var_type, var_code = self.variable.inline(True); 467839Snilay@cs.wisc.edu if self.flag: 478192SLisa.Hsu@amd.com code("${var_code} != NULL)") 487839Snilay@cs.wisc.edu else: 498192SLisa.Hsu@amd.com code("${var_code} == NULL)") 507839Snilay@cs.wisc.edu code.fix(fix) 517839Snilay@cs.wisc.edu type = self.symtab.find("bool", Type) 527839Snilay@cs.wisc.edu return type 53