Minor refactoring of op instruction handling

This commit is contained in:
Ulf Norell 2019-04-26 12:16:17 +02:00
parent 3c6e06e99a
commit c419b105bf

View File

@ -39,28 +39,56 @@
-define(i(X), {immediate, X}). -define(i(X), {immediate, X}).
-define(a, {stack, 0}). -define(a, {stack, 0}).
-define(IsBinOp(Op), -define(IsOp(Op), (
(Op =:= 'ADD' orelse Op =:= 'STORE' orelse
Op =:= 'SUB' orelse Op =:= 'ADD' orelse
Op =:= 'MUL' orelse Op =:= 'SUB' orelse
Op =:= 'DIV' orelse Op =:= 'MUL' orelse
Op =:= 'MOD' orelse Op =:= 'DIV' orelse
Op =:= 'POW' orelse Op =:= 'MOD' orelse
Op =:= 'LT' orelse Op =:= 'POW' orelse
Op =:= 'GT' orelse Op =:= 'LT' orelse
Op =:= 'EQ' orelse Op =:= 'GT' orelse
Op =:= 'ELT' orelse Op =:= 'EQ' orelse
Op =:= 'EGT' orelse Op =:= 'ELT' orelse
Op =:= 'NEQ' orelse Op =:= 'EGT' orelse
Op =:= 'AND' orelse Op =:= 'NEQ' orelse
Op =:= 'OR' orelse Op =:= 'AND' orelse
Op =:= 'ELEMENT' orelse Op =:= 'OR' orelse
Op =:= 'NOT' orelse
Op =:= 'ELEMENT' orelse
Op =:= 'MAP_EMPTY' orelse
Op =:= 'MAP_LOOKUP' orelse
Op =:= 'MAP_LOOKUPD' orelse
Op =:= 'MAP_UPDATE' orelse
Op =:= 'MAP_DELETE' orelse
Op =:= 'MAP_MEMBER' orelse
Op =:= 'MAP_FROM_LIST' orelse
Op =:= 'NIL' orelse
Op =:= 'IS_NIL' orelse
Op =:= 'CONS' orelse
Op =:= 'HD' orelse
Op =:= 'TL' orelse
Op =:= 'LENGTH' orelse
Op =:= 'STR_EQ' orelse
Op =:= 'STR_JOIN' orelse
Op =:= 'INT_TO_STR' orelse
Op =:= 'ADDR_TO_STR' orelse
Op =:= 'STR_REVERSE' orelse
Op =:= 'INT_TO_ADDR' orelse
Op =:= 'VARIANT_TEST' orelse
Op =:= 'VARIANT_ELEMENT' orelse Op =:= 'VARIANT_ELEMENT' orelse
Op =:= 'CONS')). Op =:= 'BITS_NONE' orelse
Op =:= 'BITS_ALL' orelse
-define(IsUnOp(Op), Op =:= 'BITS_ALL_N' orelse
(Op =:= 'HD' orelse Op =:= 'BITS_SET' orelse
Op =:= 'TL')). Op =:= 'BITS_CLEAR' orelse
Op =:= 'BITS_TEST' orelse
Op =:= 'BITS_SUM' orelse
Op =:= 'BITS_OR' orelse
Op =:= 'BITS_AND' orelse
Op =:= 'BITS_DIFF' orelse
false)).
-record(env, { vars = [], locals = [], tailpos = true }). -record(env, { vars = [], locals = [], tailpos = true }).
@ -786,16 +814,13 @@ r_write_to_dead_var({i, Ann, I}, Code) ->
end; end;
r_write_to_dead_var(_, _) -> false. r_write_to_dead_var(_, _) -> false.
op_view({Op, R, A, B}) when ?IsBinOp(Op) -> op_view(T) when is_tuple(T) ->
{Op, R, [A, B]}; case tuple_to_list(T) of
op_view({Op, R, A}) when ?IsUnOp(Op); Op == 'STORE' -> [Op, R | As] when ?IsOp(Op) ->
{Op, R, [A]}; {Op, R, As};
op_view({Op, R, A, B, C}) when Op == 'SETELEMENT' -> _ -> false
{Op, R, [A, B, C]}; end;
op_view({Op, R}) when Op == 'NIL' -> op_view(_) -> false.
{Op, R, []};
op_view(_) ->
false.
from_op_view(Op, R, As) -> list_to_tuple([Op, R | As]). from_op_view(Op, R, As) -> list_to_tuple([Op, R | As]).