aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator/utils/beam_makeops
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2017-09-01 13:12:51 +0200
committerBjörn Gustavsson <[email protected]>2017-09-04 15:46:43 +0200
commit86298264166f9d1b5e2e4c13bcd4db7c9d8d0ca1 (patch)
tree50d42a8d7590c9c5654cfbe5f2b47fa12f98050f /erts/emulator/utils/beam_makeops
parentcc39ad3445291c15a7f8460f892c115b4125be9e (diff)
downloadotp-86298264166f9d1b5e2e4c13bcd4db7c9d8d0ca1.tar.gz
otp-86298264166f9d1b5e2e4c13bcd4db7c9d8d0ca1.tar.bz2
otp-86298264166f9d1b5e2e4c13bcd4db7c9d8d0ca1.zip
Try to avoid generating unecessary do/while wrappers
Make the generated code easier to read.
Diffstat (limited to 'erts/emulator/utils/beam_makeops')
-rwxr-xr-xerts/emulator/utils/beam_makeops27
1 files changed, 26 insertions, 1 deletions
diff --git a/erts/emulator/utils/beam_makeops b/erts/emulator/utils/beam_makeops
index bcc92472d4..38754e67a1 100755
--- a/erts/emulator/utils/beam_makeops
+++ b/erts/emulator/utils/beam_makeops
@@ -1451,7 +1451,32 @@ sub expand_macro {
warn $@;
die "... from the body of $name at $where\n";
}
- ("do {\n$body\n} while (0)",$rest);
+ $body = "do {\n$body\n} while (0)"
+ if needs_do_wrapper($body);
+ ($body,$rest);
+}
+
+# Conservative heuristic to determine whether a do { ... } while(0)
+# wrapper is needed.
+sub needs_do_wrapper {
+ local $_ = shift;
+
+ s@^//[|][^\n]*\n@@;
+ s@^\s*@@s;
+ s@^/[*].*[*]/\s*@@s;
+ return 1 if /^(Eterm|Uint|Sint|int|unsigned)/; # Definitely needed.
+ return 0 if /^do/;
+ return 0 if /^SET_I/;
+ return 0 if /^SET_CP/;
+ return 0 if /^ERTS_NO_FPE_CHECK_INIT/;
+ return 0 if /^ASSERT/;
+ return 0 if /^DTRACE/;
+ return 0 if /^[A-Za-z_]*\s*=/;
+ return 0 if /^c_p->/;
+ return 0 if /^[A-Z_]*SWAPOUT/;
+ return 0 if /^if\s*[(]/;
+ return 0 if /^goto\b/;
+ return 1; # Not sure, say that it is needed.
}
sub do_pack {