diff options
author | Björn Gustavsson <[email protected]> | 2017-09-01 13:12:51 +0200 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2017-09-04 15:46:43 +0200 |
commit | 86298264166f9d1b5e2e4c13bcd4db7c9d8d0ca1 (patch) | |
tree | 50d42a8d7590c9c5654cfbe5f2b47fa12f98050f /erts/emulator/utils/beam_makeops | |
parent | cc39ad3445291c15a7f8460f892c115b4125be9e (diff) | |
download | otp-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-x | erts/emulator/utils/beam_makeops | 27 |
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 { |