Permalink
Browse files

Finally block adjustments.

  • Loading branch information...
1 parent 598e77b commit c6f37aa676997f5a2263ea72b8e9be147dae34a4 @whitequark committed Aug 19, 2012
@@ -21,11 +21,17 @@ def transform(code, body)
exc_block.target_labels << exc.target_offset
- exc_block.cti.children <<
- AST::Node.new(:catch,
- [ (exc.exception.to_astlet if exc.exception),
- exc.variable.to_astlet,
- exc.target_offset ])
+ if exc.variable
+ exc_block.cti.children <<
+ AST::Node.new(:catch,
+ [ (exc.exception.to_astlet if exc.exception),
+ exc.variable.to_astlet,
+ exc.target_offset ])
+ else
+ exc_block.cti.children <<
+ AST::Node.new(:finally,
+ [ exc.target_offset ])
+ end
end
# Handle nested exception handling blocks.
@@ -84,8 +90,11 @@ def transform(code, body)
next_offset = next_opcode.offset if next_opcode
case opcode
- when ABC::FunctionReturnOpcode, ABC::AS3Throw
- cutoff(nil, [nil])
+ when ABC::FunctionReturnOpcode
+ cutoff(nil, [ nil ])
+
+ when ABC::AS3Throw
+ cutoff(opcode, [ ])
when ABC::AS3Jump
@jumps.add(opcode.target_offset)
@@ -425,6 +425,12 @@ def extended_block(block, stopgap=nil, loop_stack=[], nesting=0, upper_exc=nil,
end
block = out_root
+ elsif block.cti.type == :throw
+ log nesting, "ends with throw"
+
+ append_instructions(block, current_nodes, true)
+
+ block = nil
else
log nesting, "is a conditional"
@@ -664,9 +670,9 @@ def check_nonlocal_loop(loop_stack, block)
end
end
- def append_instructions(block, nodes)
+ def append_instructions(block, nodes, cti=false)
block.insns.each do |insn|
- next if insn.equal? block.cti
+ next if insn.equal?(block.cti) && !cti
nodes << insn
end
end
@@ -22,7 +22,9 @@ def transform(cfg)
block = worklist.first
worklist.delete block
- if loops.include? block
+ if block.cti && block.cti.type == :throw
+ dead_ends.add block
+ elsif loops.include? block
back_edged, sources = block.sources.partition do |source|
dom[source].include? block
end

0 comments on commit c6f37aa

Please sign in to comment.