def __init__(self, id, label='empty', have_code=True, is_expr=False, is_exit=False, pos=None, is_fabricated=False): if pos: label = "%s_%s" % (label, error.format_pos(pos).rstrip(": ")) super(ControlBlock, self).__init__(body=[], label=label) self.id = id self.children = set() self.parents = set() self.positions = set() self.stats = [] self.gen = {} self.bound = set() # Same as i_input/i_output but for reaching defs with sets self.input = set() self.output = set() self.i_input = 0 self.i_output = 0 self.i_gen = 0 self.i_kill = 0 self.i_state = 0 self.is_expr = is_expr self.is_exit = is_exit self.have_code = have_code # TODO: Make these bits # Set of blocks that dominate this block self.dominators = set() # Set of blocks where our dominance stops self.dominance_frontier = set() # SSA Φ locations. Maps Variables to a list of (basic_block, definition) # There can be only one reaching definition, since each variable is # assigned only once self.phis = {} self.phi_nodes = [] # Promotions at the end of the block to have a consistent promoted # Φ type at one of our children. self.promotions = {} # (renamed_var_name, dst_type) -> promotion_node # LLVM entry and exit blocks. The entry block is the block before the # body is evaluated, the exit block the block after the body is # evaluated. self.exit_block = None self.phi_block = None self.exit_block = None self.promotions = set() self.symtab = None self.is_fabricated = is_fabricated # If set to True, branch from the previous basic block to this basic # block self.branch_here = False
def _trap(self, body, node): if node.exc_msg and node.print_on_trap: pos = error.format_pos(node) msg = '%s: %s%%s' % (node.exc_type, pos) format = nodes.const(msg, c_string_type) print_msg = self.function_cache.call('printf', format, node.exc_msg) body.append(print_msg) trap = nodes.LLVMIntrinsicNode(signature=void(), args=[], func_name='TRAP') body.append(trap)
def _trap(self, body, node): if node.exc_msg and node.print_on_trap: pos = error.format_pos(node) if node.exception_type: exc_type = '%s: ' % node.exception_type.__name__ else: exc_type = '' msg = '%s%s%%s' % (exc_type, pos) format = nodes.const(msg, c_string_type) print_msg = self.function_cache.call('printf', format, node.exc_msg) body.append(print_msg) trap = nodes.LLVMIntrinsicNode(signature=void(), args=[], func_name='TRAP') body.append(trap)
def visit_Name(self, node): if (is_obj(node.type) and isinstance(node.ctx, ast.Load) and getattr(node, 'cf_maybe_null', False)): # Check for unbound objects and raise UnboundLocalError if so value = nodes.LLVMValueRefNode(Py_uintptr_t, None) node.loaded_name = value exc_msg = node.variable.name if hasattr(node, 'lineno'): exc_msg = '%s%s' % (error.format_pos(node), exc_msg) check_unbound = nodes.CheckErrorNode( value, badval=nodes.const(0, Py_uintptr_t), exc_type=UnboundLocalError, exc_msg=exc_msg) node.check_unbound = self.visit(check_unbound) return node
def visit_Name(self, node): if (is_obj(node.type) and isinstance(node.ctx, ast.Load) and getattr(node, 'cf_maybe_null', False)): # Check for unbound objects and raise UnboundLocalError if so value = nodes.LLVMValueRefNode(Py_uintptr_t, None) node.loaded_name = value exc_msg = node.variable.name if hasattr(node, 'lineno'): exc_msg = '%s%s' % (error.format_pos(node), exc_msg) check_unbound = nodes.CheckErrorNode(value, badval=nodes.const( 0, Py_uintptr_t), exc_type=UnboundLocalError, exc_msg=exc_msg) node.check_unbound = self.visit(check_unbound) return node
def _trap(self, body, node): if node.exc_msg and node.print_on_trap: pos = error.format_pos(node) if node.exception_type: exc_type = '%s: ' % node.exception_type.__name__ else: exc_type = '' msg = '%s%s%%s' % (exc_type, pos) format = nodes.const(msg, c_string_type) print_msg = function_util.external_call(self.context, self.llvm_module, 'printf', args=[format, node.exc_msg]) body.append(print_msg) trap = nodes.LLVMIntrinsicNode(signature=void(), args=[], func_name='TRAP') body.append(trap)
def _trap(self, node): body = [] if node.exc_msg and node.print_on_trap: pos = error.format_pos(node) if node.exception_type: exc_type = '%s: ' % node.exception_type.__name__ else: exc_type = '' msg = '%s%s%%s' % (exc_type, pos) format = nodes.const(msg, c_string_type) print_msg = function_util.external_call( self.context, self.llvm_module, 'printf', args=[format, node.exc_msg]) body.append(print_msg) trap = nodes.LLVMIntrinsicNode(signature=void(), args=[], func_name='TRAP') return body + [trap]
def warn_unreachable(node): if hasattr(node, 'lineno'): print "Warning, unreachable code at %s" % error.format_pos(node).rstrip(': ')
def warning(node, message): # printing allows us to test the code print "Warning %s%s" % (error.format_pos(node), message)
def format_msg_simple(type, node, message): return "%s %s%s\n" % (type, error.format_pos(node), message)
def warn_unreachable(node): "Generate a warning for unreachable code" if hasattr(node, 'lineno'): print("Warning, unreachable code at %s\n" % error.format_pos(node).rstrip(': '))
def format_msg_simple(type, node, message): "Issue a warning" # printing allows us to test the code return "%s %s%s\n" % (type, error.format_pos(node), message)