IsValidPtrExprAST.py revision 7839
15361Srstrong@cs.ucsd.edu# 24486Sbinkertn@umich.edu# Copyright (c) 2011 Mark D. Hill and David A. Wood 34486Sbinkertn@umich.edu# All rights reserved. 44486Sbinkertn@umich.edu# 54486Sbinkertn@umich.edu# Redistribution and use in source and binary forms, with or without 64486Sbinkertn@umich.edu# modification, are permitted provided that the following conditions are 74486Sbinkertn@umich.edu# met: redistributions of source code must retain the above copyright 84486Sbinkertn@umich.edu# notice, this list of conditions and the following disclaimer; 94486Sbinkertn@umich.edu# redistributions in binary form must reproduce the above copyright 104486Sbinkertn@umich.edu# notice, this list of conditions and the following disclaimer in the 114486Sbinkertn@umich.edu# documentation and/or other materials provided with the distribution; 124486Sbinkertn@umich.edu# 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.edu 293102SN/Afrom slicc.ast.ExprAST import ExprAST 303102SN/Afrom slicc.symbols import Type 313102SN/A 324486Sbinkertn@umich.educlass IsValidPtrExprAST(ExprAST): 331692SN/A def __init__(self, slicc, variable, flag): 341366SN/A super(IsValidPtrExprAST, self).__init__(slicc) 351310SN/A self.variable = variable 369338SAndreas.Sandberg@arm.com self.flag = flag 375154Sgblack@eecs.umich.edu 385514SMichael.Adler@intel.com def __repr__(self): 395514SMichael.Adler@intel.com return "[IsValidPtrExprAST: %r]" % self.variable 402378SN/A 415154Sgblack@eecs.umich.edu def generate(self, code): 421310SN/A # Make sure the variable is valid 439110Ssteve.reinhardt@amd.com fix = code.nofix() 449110Ssteve.reinhardt@amd.com code("(") 459110Ssteve.reinhardt@amd.com var_type, var_code = self.variable.inline(True); 469110Ssteve.reinhardt@amd.com var_code_str = str(var_code).replace('*','') 471692SN/A if self.flag: 481366SN/A code("${var_code_str} != NULL)") 499338SAndreas.Sandberg@arm.com else: 501898SN/A code("${var_code_str} == NULL)") 511310SN/A code.fix(fix) 524597Sbinkertn@umich.edu type = self.symtab.find("bool", Type) 533669SN/A return type 543066SN/A