Merge pull request #80 from aeternity/fix-basic-block-bug

Fix bug in basic block generation
This commit is contained in:
Ulf Norell 2019-06-03 10:35:18 +02:00 committed by GitHub
commit 4f612650e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1361,7 +1361,7 @@ tweak_returns(['RETURN' | Code = [{'ABORT', _} | _]]) -> Code;
tweak_returns(Code) -> Code.
%% -- Split basic blocks at CALL instructions --
%% Calls can only return to a new basic block.
%% Calls can only return to a new basic block. Also splits at JUMPIF instructions.
split_calls({Ref, Code}) ->
split_calls(Ref, Code, [], []).
@ -1370,7 +1370,8 @@ split_calls(Ref, [], Acc, Blocks) ->
lists:reverse([{Ref, lists:reverse(Acc)} | Blocks]);
split_calls(Ref, [I | Code], Acc, Blocks) when element(1, I) == 'CALL';
element(1, I) == 'CALL_R';
element(1, I) == 'CALL_GR' ->
element(1, I) == 'CALL_GR';
element(1, I) == 'jumpif' ->
split_calls(make_ref(), Code, [], [{Ref, lists:reverse([I | Acc])} | Blocks]);
split_calls(Ref, [I | Code], Acc, Blocks) ->
split_calls(Ref, Code, [I | Acc], Blocks).