00001 #!/bin/python 00002 # -*- coding: utf-8 -*- 00003 # Copyright (c) 2009, Fixstars Corporation 00004 # All rights reserved. 00005 # 00006 # Redistribution and use in source and binary forms, with or without modification, 00007 # are permitted provided that the following conditions are met: 00008 # 00009 # * Redistributions of source code must retain the above copyright notice, 00010 # this list of conditions and the following disclaimer. 00011 # 00012 # * Redistributions in binary form must reproduce the above copyright notice, 00013 # this list of conditions and the following disclaimer in the documentation 00014 # and/or other materials provided with the distribution. 00015 # 00016 # * Neither the name of Fixstars Corporation nor the names of its contributors 00017 # may be used to endorse or promote products derived from this software 00018 # without specific prior written permission. 00019 # 00020 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 00021 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00022 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 00023 # IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 00024 # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00025 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00026 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 00027 # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00028 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 00029 # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00030 00031 ''' 00032 ループ脱出条件 00033 ''' 00034 00035 import ctrump 00036 00037 def build_bound_expr(builder, exit_info): 00038 b = exit_info.bound 00039 return builder.expr(b) 00040 00041 # returns (var, loop_entry_definition, incr) 00042 def get_loop_counter(e): 00043 return (e.inductive, e.iv_loop_entry_value, e.incr) 00044 00045 # returns var and append decl to decls when that is required 00046 def build_bound_var(builder, decls, exit_info, name, init): 00047 if exit_info.bound == ctrump.EXPR_VARREF: 00048 return exit_info.bound.var 00049 else: 00050 n = '%s_%s'%(str(name), str(exit_info.inductive.name)) 00051 decls.append(builder.decl(exit_info.bound.type, n, init = init)) 00052 return builder.scope[n]