aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorKostis Sagonas <[email protected]>2016-06-15 00:22:36 +0200
committerKostis Sagonas <[email protected]>2016-06-15 00:22:36 +0200
commit34c83a54c3ef6c1a5e2657d4fa3f91622e9b58aa (patch)
treeb5d9b4eb397971a55920f4cd1ab8d32fa83d31a7 /lib
parent481ac2a246c53c29033648ae5adda2c215fcc924 (diff)
downloadotp-34c83a54c3ef6c1a5e2657d4fa3f91622e9b58aa.tar.gz
otp-34c83a54c3ef6c1a5e2657d4fa3f91622e9b58aa.tar.bz2
otp-34c83a54c3ef6c1a5e2657d4fa3f91622e9b58aa.zip
hipe: Pattern matching compilation of binaries and bistrings
The Core Erlang pattern matching compiler was written long ago, at a time when binaries and bistrings did not really exist in Erlang. This patch, taken from the code of CutEr where it's used for more than a year now, extends the transformation for pattern matching compilation to also include binaries and bistrings. Some code that was found erroneous and causes errors when compiling the transformed code to native code was also taken out while at it. Thanks to @aggelgian for most of the changes in the code.
Diffstat (limited to 'lib')
-rw-r--r--lib/hipe/cerl/cerl_pmatch.erl28
1 files changed, 12 insertions, 16 deletions
diff --git a/lib/hipe/cerl/cerl_pmatch.erl b/lib/hipe/cerl/cerl_pmatch.erl
index 594f2bf81c..ca27fff1dd 100644
--- a/lib/hipe/cerl/cerl_pmatch.erl
+++ b/lib/hipe/cerl/cerl_pmatch.erl
@@ -231,12 +231,9 @@ match_typegroup(T, V, Vs, Gs, Else, Env) ->
Else, Env),
typetest_clause(T, V, Body, Env).
-match_congroup({?binary_id, Segs}, Vs, Cs, _Else, Env) ->
- Ref = get_unique(),
- Guard = cerl:c_primop(cerl:c_atom(set_label), [cerl:c_int(Ref)]),
- NewElse = cerl:c_primop(cerl:c_atom(goto_label), [cerl:c_int(Ref)]),
- Body = match(Vs, Cs, NewElse, Env),
- cerl:c_clause([make_pat(?binary_id, Segs)], Guard, Body);
+match_congroup({?binary_id, Segs}, Vs, Cs, Else, Env) ->
+ Body = match(Vs, Cs, Else, Env),
+ cerl:c_clause([make_pat(?binary_id, Segs)], Body);
match_congroup({D, A}, Vs, Cs, Else, Env) ->
Vs1 = new_vars(A, Env),
@@ -415,6 +412,15 @@ make_let(Vs, A, B) ->
expr(E, Env) ->
case cerl:type(E) of
+ binary ->
+ Es = expr_list(cerl:binary_segments(E), Env),
+ cerl:update_c_binary(E, Es);
+ bitstr ->
+ V = expr(cerl:bitstr_val(E), Env),
+ Sz = expr(cerl:bitstr_size(E), Env),
+ Unit = expr(cerl:bitstr_unit(E), Env),
+ Type = expr(cerl:bitstr_type(E), Env),
+ cerl:update_c_bitstr(E, V, Sz, Unit, Type, cerl:bitstr_flags(E));
literal ->
E;
var ->
@@ -584,16 +590,6 @@ is_simple(E) ->
end.
-get_unique() ->
- case get(unique_label) of
- undefined ->
- put(unique_label, 1),
- 0;
- N ->
- put(unique_label, N+1),
- N
- end.
-
%% ---------------------------------------------------------------------
%% Abstract datatype: environment()