File 2242-hipe-Pattern-matching-compilation-of-binaries-and-bi.patch of Package erlang

From 34c83a54c3ef6c1a5e2657d4fa3f91622e9b58aa Mon Sep 17 00:00:00 2001
From: Kostis Sagonas <kostis@it.uu.se>
Date: Wed, 15 Jun 2016 00:22:36 +0200
Subject: [PATCH] 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.
---
 lib/hipe/cerl/cerl_pmatch.erl | 28 ++++++++++++----------------
 1 file changed, 12 insertions(+), 16 deletions(-)

diff --git a/lib/hipe/cerl/cerl_pmatch.erl b/lib/hipe/cerl/cerl_pmatch.erl
index 594f2bf..ca27fff 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()
 
-- 
2.1.4

openSUSE Build Service is sponsored by