diff options
author | Sverker Eriksson <sverker@erlang.org> | 2022-02-10 21:04:23 +0100 |
---|---|---|
committer | Sverker Eriksson <sverker@erlang.org> | 2022-04-26 19:53:00 +0200 |
commit | 6770378539ff9eb48f562579ca0132537a1faa44 (patch) | |
tree | eecd49623e23a7a1b85539a880406f2a27fea913 | |
parent | ee8872b0f2528985306e8b2299920eb445a0c30f (diff) | |
download | erlang-6770378539ff9eb48f562579ca0132537a1faa44.tar.gz |
erts: Generate beam_asm_global.hpp with perl
instead of C preprocessor macros, to improve the ability for
(IDE supported) code browsing.
-rw-r--r-- | erts/emulator/Makefile.in | 5 | ||||
-rw-r--r-- | erts/emulator/beam/jit/arm/beam_asm.hpp | 143 | ||||
-rw-r--r-- | erts/emulator/beam/jit/arm/beam_asm_global.cpp | 17 | ||||
-rw-r--r-- | erts/emulator/beam/jit/arm/beam_asm_global.hpp.pl | 216 | ||||
-rw-r--r-- | erts/emulator/beam/jit/x86/beam_asm.hpp | 134 | ||||
-rw-r--r-- | erts/emulator/beam/jit/x86/beam_asm_global.cpp | 17 | ||||
-rwxr-xr-x | erts/emulator/beam/jit/x86/beam_asm_global.hpp.pl | 206 |
7 files changed, 433 insertions, 305 deletions
diff --git a/erts/emulator/Makefile.in b/erts/emulator/Makefile.in index fa331e003a..e9e7951517 100644 --- a/erts/emulator/Makefile.in +++ b/erts/emulator/Makefile.in @@ -595,6 +595,11 @@ $(TTF_DIR)/OPCODES-GENERATED: $(OPCODE_TABLES) utils/beam_makeops -emulator $(OPCODE_TABLES) && echo $? >$(TTF_DIR)/OPCODES-GENERATED GENERATE += $(TTF_DIR)/OPCODES-GENERATED +ifeq ($(FLAVOR),jit) +$(TTF_DIR)/beam_asm_global.hpp: beam/jit/$(JIT_ARCH)/beam_asm_global.hpp.pl + $(gen_verbose)LANG=C $(PERL) $< > $@ +GENERATE += $(TTF_DIR)/beam_asm_global.hpp +endif # bif and atom table ATOMS= beam/atom.names diff --git a/erts/emulator/beam/jit/arm/beam_asm.hpp b/erts/emulator/beam/jit/arm/beam_asm.hpp index 82646641fd..23437f8002 100644 --- a/erts/emulator/beam/jit/arm/beam_asm.hpp +++ b/erts/emulator/beam/jit/arm/beam_asm.hpp @@ -816,148 +816,7 @@ public: } }; -class BeamGlobalAssembler : public BeamAssembler { - typedef void (BeamGlobalAssembler::*emitFptr)(void); - typedef void (*fptr)(void); - - /* Please keep this in alphabetical order. */ -#define BEAM_GLOBAL_FUNCS(_) \ - _(apply_fun_shared) \ - _(arith_compare_shared) \ - _(bif_nif_epilogue) \ - _(bif_export_trap) \ - _(bif_bit_size_body) \ - _(bif_bit_size_guard) \ - _(bif_byte_size_body) \ - _(bif_byte_size_guard) \ - _(bif_element_body_shared) \ - _(bif_element_guard_shared) \ - _(bif_is_eq_exact_shared) \ - _(bif_is_ne_exact_shared) \ - _(bif_tuple_size_body) \ - _(bif_tuple_size_guard) \ - _(bs_add_guard_shared) \ - _(bs_add_body_shared) \ - _(bs_bit_size_shared) \ - _(bs_create_bin_error_shared) \ - _(bs_get_tail_shared) \ - _(bs_size_check_shared) \ - _(call_bif_shared) \ - _(call_light_bif_shared) \ - _(call_nif_yield_helper) \ - _(catch_end_shared) \ - _(call_nif_early) \ - _(call_nif_shared) \ - _(check_float_error) \ - _(debug_bp) \ - _(dispatch_bif) \ - _(dispatch_nif) \ - _(dispatch_return) \ - _(dispatch_save_calls) \ - _(export_trampoline) \ - _(fconv_shared) \ - _(handle_and_error) \ - _(handle_call_fun_error) \ - _(handle_element_error_shared) \ - _(handle_hd_error) \ - _(handle_map_size_error) \ - _(handle_not_error) \ - _(handle_or_error) \ - _(handle_tl_error) \ - _(garbage_collect) \ - _(generic_bp_global) \ - _(generic_bp_local) \ - _(i_band_body_shared) \ - _(i_bnot_body_shared) \ - _(i_bnot_guard_shared) \ - _(i_bor_body_shared) \ - _(i_bif_body_shared) \ - _(i_bif_guard_shared) \ - _(i_breakpoint_trampoline_shared) \ - _(i_bsr_body_shared) \ - _(i_bsl_body_shared) \ - _(i_get_map_element_shared) \ - _(i_get_map_element_hash_shared) \ - _(i_func_info_shared) \ - _(i_length_guard_shared) \ - _(i_length_body_shared) \ - _(i_loop_rec_shared) \ - _(i_new_small_map_lit_shared) \ - _(i_test_yield_shared) \ - _(i_bxor_body_shared) \ - _(int_div_rem_body_shared) \ - _(int_div_rem_guard_shared) \ - _(internal_hash_helper) \ - _(minus_body_shared) \ - _(new_map_shared) \ - _(update_map_assoc_shared) \ - _(unloaded_fun) \ - _(plus_body_shared) \ - _(process_exit) \ - _(process_main) \ - _(raise_exception) \ - _(raise_exception_shared) \ - _(times_body_shared) \ - _(times_guard_shared) \ - _(unary_minus_body_shared) \ - _(update_map_exact_guard_shared) \ - _(update_map_exact_body_shared) - -/* Labels exported from within process_main */ -#define PROCESS_MAIN_LABELS(_) \ - _(context_switch) \ - _(context_switch_simplified) \ - _(do_schedule) - -#define DECL_ENUM(NAME) NAME, - - enum GlobalLabels : uint32_t { - BEAM_GLOBAL_FUNCS(DECL_ENUM) PROCESS_MAIN_LABELS(DECL_ENUM) - }; -#undef DECL_ENUM - - static const std::map<GlobalLabels, const std::string> labelNames; - static const std::map<GlobalLabels, emitFptr> emitPtrs; - std::unordered_map<GlobalLabels, Label> labels; - std::unordered_map<GlobalLabels, fptr> ptrs; - -#define DECL_FUNC(NAME) void emit_##NAME(void); - - BEAM_GLOBAL_FUNCS(DECL_FUNC); -#undef DECL_FUNC - - template<typename T> - void emit_bitwise_fallback_body(T(*func_ptr), const ErtsCodeMFA *mfa); - - void emit_i_length_common(Label fail, int state_size); - - void emit_raise_badarg(const ErtsCodeMFA *mfa); - - void emit_bif_bit_size_helper(Label fail); - void emit_bif_byte_size_helper(Label fail); - void emit_bif_element_helper(Label fail); - void emit_bif_tuple_size_helper(Label fail); - - void emit_flatmap_get_element(); - void emit_hashmap_get_element(); - -public: - BeamGlobalAssembler(JitAllocator *allocator); - - void (*get(GlobalLabels lbl))(void) { - ASSERT(ptrs[lbl]); - return ptrs[lbl]; - } - -#define GET_CODE(NAME) \ - void (*get_##NAME(void))() { \ - return get(NAME); \ - } - - BEAM_GLOBAL_FUNCS(GET_CODE) - PROCESS_MAIN_LABELS(GET_CODE) -#undef GET_CODE -}; +#include "beam_asm_global.hpp" class BeamModuleAssembler : public BeamAssembler { typedef unsigned BeamLabel; diff --git a/erts/emulator/beam/jit/arm/beam_asm_global.cpp b/erts/emulator/beam/jit/arm/beam_asm_global.cpp index 0defce9ee2..0c824e0484 100644 --- a/erts/emulator/beam/jit/arm/beam_asm_global.cpp +++ b/erts/emulator/beam/jit/arm/beam_asm_global.cpp @@ -18,7 +18,9 @@ * %CopyrightEnd% */ +#define ERTS_BEAM_ASM_GLOBAL_WANT_STATIC_DEFS #include "beam_asm.hpp" +#undef ERTS_BEAM_ASM_GLOBAL_WANT_STATIC_DEFS using namespace asmjit; @@ -28,21 +30,6 @@ extern "C" #include "beam_common.h" } -#define STRINGIFY_(X) #X -#define STRINGIFY(X) STRINGIFY_(X) - -#define DECL_EMIT(NAME) {NAME, &BeamGlobalAssembler::emit_##NAME}, -const std::map<BeamGlobalAssembler::GlobalLabels, BeamGlobalAssembler::emitFptr> - BeamGlobalAssembler::emitPtrs = {BEAM_GLOBAL_FUNCS(DECL_EMIT)}; -#undef DECL_EMIT - -#define DECL_LABEL_NAME(NAME) {NAME, STRINGIFY(NAME)}, - -const std::map<BeamGlobalAssembler::GlobalLabels, const std::string> - BeamGlobalAssembler::labelNames = {BEAM_GLOBAL_FUNCS( - DECL_LABEL_NAME) PROCESS_MAIN_LABELS(DECL_LABEL_NAME)}; -#undef DECL_LABEL_NAME - BeamGlobalAssembler::BeamGlobalAssembler(JitAllocator *allocator) : BeamAssembler("beam_asm_global") { labels.reserve(emitPtrs.size()); diff --git a/erts/emulator/beam/jit/arm/beam_asm_global.hpp.pl b/erts/emulator/beam/jit/arm/beam_asm_global.hpp.pl new file mode 100644 index 0000000000..f42d16e853 --- /dev/null +++ b/erts/emulator/beam/jit/arm/beam_asm_global.hpp.pl @@ -0,0 +1,216 @@ +#!/usr/bin/env perl -W +# +# %CopyrightBegin% +# +# Copyright Ericsson AB 2022. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# %CopyrightEnd% +# +use strict; + +# Please keep the names in the list in alphabetical order. +my @beam_global_funcs = qw( + apply_fun_shared + arith_compare_shared + bif_nif_epilogue + bif_export_trap + bif_bit_size_body + bif_bit_size_guard + bif_byte_size_body + bif_byte_size_guard + bif_element_body_shared + bif_element_guard_shared + bif_is_eq_exact_shared + bif_is_ne_exact_shared + bif_tuple_size_body + bif_tuple_size_guard + bs_add_guard_shared + bs_add_body_shared + bs_bit_size_shared + bs_create_bin_error_shared + bs_get_tail_shared + bs_size_check_shared + call_bif_shared + call_light_bif_shared + call_nif_yield_helper + catch_end_shared + call_nif_early + call_nif_shared + check_float_error + debug_bp + dispatch_bif + dispatch_nif + dispatch_return + dispatch_save_calls + export_trampoline + fconv_shared + handle_and_error + handle_call_fun_error + handle_element_error_shared + handle_hd_error + handle_map_size_error + handle_not_error + handle_or_error + handle_tl_error + garbage_collect + generic_bp_global + generic_bp_local + i_band_body_shared + i_bnot_body_shared + i_bnot_guard_shared + i_bor_body_shared + i_bif_body_shared + i_bif_guard_shared + i_breakpoint_trampoline_shared + i_bsr_body_shared + i_bsl_body_shared + i_func_info_shared + i_get_map_element_shared + i_get_map_element_hash_shared + i_length_guard_shared + i_length_body_shared + i_loop_rec_shared + i_new_small_map_lit_shared + i_test_yield_shared + i_bxor_body_shared + int_div_rem_body_shared + int_div_rem_guard_shared + internal_hash_helper + minus_body_shared + new_map_shared + update_map_assoc_shared + unloaded_fun + plus_body_shared + process_exit + process_main + raise_exception + raise_exception_shared + times_body_shared + times_guard_shared + unary_minus_body_shared + update_map_exact_guard_shared + update_map_exact_body_shared + ); + + +# Labels exported from within process_main +my @process_main_labels = qw( + context_switch + context_switch_simplified + do_schedule + ); + +my $decl_enums = + gen_list(' %s,', @beam_global_funcs, '', @process_main_labels); + +my $decl_emit_funcs = + gen_list(' void emit_%s(void);', @beam_global_funcs); + +my $decl_get_funcs = + gen_list(' void (*get_%s(void))() { return get(%s); }', + @beam_global_funcs, '', @process_main_labels); + +my $decl_emitPtrs = + gen_list(' {%s, &BeamGlobalAssembler::emit_%s},', @beam_global_funcs); + +my $decl_label_names = + gen_list(' {%s, "%s"},', @beam_global_funcs, '', @process_main_labels); + +sub gen_list { + my ($format, @strings) = @_; + my $out = ''; + foreach my $str (@strings) { + if ($str eq '') { + $out .= "\n"; + } + else { + my $subst = $format; + $subst =~ s/%s/$str/g; + $out .= "$subst\n"; + } + } + $out; +} + + +my $this_source_file = __FILE__; + +print <<END_OF_FILE; +/* + * Warning: Do not edit this file. + * Auto-generated by $this_source_file. + */ + +#ifndef _BEAM_ASM_GLOBAL_HPP +#define _BEAM_ASM_GLOBAL_HPP + + +class BeamGlobalAssembler : public BeamAssembler { + typedef void (BeamGlobalAssembler::*emitFptr)(void); + typedef void (*fptr)(void); + + enum GlobalLabels : uint32_t { +$decl_enums + }; + + static const std::map<GlobalLabels, const std::string> labelNames; + static const std::map<GlobalLabels, emitFptr> emitPtrs; + std::unordered_map<GlobalLabels, Label> labels; + std::unordered_map<GlobalLabels, fptr> ptrs; + +$decl_emit_funcs + + template<typename T> + void emit_bitwise_fallback_body(T(*func_ptr), const ErtsCodeMFA *mfa); + + void emit_i_length_common(Label fail, int state_size); + + void emit_raise_badarg(const ErtsCodeMFA *mfa); + + void emit_bif_bit_size_helper(Label fail); + void emit_bif_byte_size_helper(Label fail); + void emit_bif_element_helper(Label fail); + void emit_bif_tuple_size_helper(Label fail); + + void emit_flatmap_get_element(); + void emit_hashmap_get_element(); + +public: + BeamGlobalAssembler(JitAllocator *allocator); + + void (*get(GlobalLabels lbl))(void) { + ASSERT(ptrs[lbl]); + return ptrs[lbl]; + } + +$decl_get_funcs +}; + +#ifdef ERTS_BEAM_ASM_GLOBAL_WANT_STATIC_DEFS + +const std::map<BeamGlobalAssembler::GlobalLabels, BeamGlobalAssembler::emitFptr> +BeamGlobalAssembler::emitPtrs = { +$decl_emitPtrs +}; + +const std::map<BeamGlobalAssembler::GlobalLabels, const std::string> +BeamGlobalAssembler::labelNames = { +$decl_label_names +}; + +#endif /* ERTS_BEAM_ASM_GLOBAL_WANT_STATIC_DEFS */ + +#endif /* !_BEAM_ASM_GLOBAL_HPP */ +END_OF_FILE diff --git a/erts/emulator/beam/jit/x86/beam_asm.hpp b/erts/emulator/beam/jit/x86/beam_asm.hpp index a769c4fb41..cd353714ef 100644 --- a/erts/emulator/beam/jit/x86/beam_asm.hpp +++ b/erts/emulator/beam/jit/x86/beam_asm.hpp @@ -902,139 +902,7 @@ public: }; }; -class BeamGlobalAssembler : public BeamAssembler { - typedef void (BeamGlobalAssembler::*emitFptr)(void); - typedef void (*fptr)(void); - - /* Please keep this in alphabetical order. */ -#define BEAM_GLOBAL_FUNCS(_) \ - _(apply_fun_shared) \ - _(arith_compare_shared) \ - _(arith_eq_shared) \ - _(bif_nif_epilogue) \ - _(bif_element_shared) \ - _(bif_export_trap) \ - _(bs_add_shared) \ - _(bs_create_bin_error_shared) \ - _(bs_size_check_shared) \ - _(bs_fixed_integer_shared) \ - _(bs_get_tail_shared) \ - _(call_bif_shared) \ - _(call_light_bif_shared) \ - _(call_nif_early) \ - _(call_nif_shared) \ - _(call_nif_yield_helper) \ - _(catch_end_shared) \ - _(check_float_error) \ - _(dispatch_bif) \ - _(dispatch_nif) \ - _(dispatch_return) \ - _(dispatch_save_calls) \ - _(export_trampoline) \ - _(garbage_collect) \ - _(generic_bp_global) \ - _(generic_bp_local) \ - _(debug_bp) \ - _(fconv_shared) \ - _(handle_call_fun_error) \ - _(handle_element_error) \ - _(handle_hd_error) \ - _(i_band_body_shared) \ - _(i_band_guard_shared) \ - _(i_bif_body_shared) \ - _(i_bif_guard_shared) \ - _(i_bor_body_shared) \ - _(i_bor_guard_shared) \ - _(i_bnot_body_shared) \ - _(i_bnot_guard_shared) \ - _(i_bsl_guard_shared) \ - _(i_bsl_body_shared) \ - _(i_bsr_guard_shared) \ - _(i_bsr_body_shared) \ - _(i_bxor_body_shared) \ - _(i_bxor_guard_shared) \ - _(i_func_info_shared) \ - _(i_get_map_element_shared) \ - _(i_get_map_element_hash_shared) \ - _(i_load_nif_shared) \ - _(i_length_guard_shared) \ - _(i_length_body_shared) \ - _(i_loop_rec_shared) \ - _(i_new_small_map_lit_shared) \ - _(i_test_yield_shared) \ - _(increment_body_shared) \ - _(int_div_rem_body_shared) \ - _(int_div_rem_guard_shared) \ - _(internal_hash_helper) \ - _(minus_body_shared) \ - _(minus_guard_shared) \ - _(new_map_shared) \ - _(plus_body_shared) \ - _(plus_guard_shared) \ - _(process_exit) \ - _(process_main) \ - _(raise_exception) \ - _(raise_exception_shared) \ - _(times_body_shared) \ - _(times_guard_shared) \ - _(unary_minus_body_shared) \ - _(unary_minus_guard_shared) \ - _(unloaded_fun) \ - _(update_map_assoc_shared) \ - _(update_map_exact_guard_shared) \ - _(update_map_exact_body_shared) - -/* Labels exported from within process_main */ -#define PROCESS_MAIN_LABELS(_) \ - _(context_switch) \ - _(context_switch_simplified) \ - _(do_schedule) - -#define DECL_ENUM(NAME) NAME, - - enum GlobalLabels : uint32_t { - BEAM_GLOBAL_FUNCS(DECL_ENUM) PROCESS_MAIN_LABELS(DECL_ENUM) - }; -#undef DECL_ENUM - - static const std::map<GlobalLabels, const std::string> labelNames; - static const std::map<GlobalLabels, emitFptr> emitPtrs; - std::unordered_map<GlobalLabels, Label> labels; - std::unordered_map<GlobalLabels, fptr> ptrs; - -#define DECL_FUNC(NAME) void emit_##NAME(void); - - BEAM_GLOBAL_FUNCS(DECL_FUNC); -#undef DECL_FUNC - - template<typename T> - void emit_bitwise_fallback_body(T(*func_ptr), const ErtsCodeMFA *mfa); - - template<typename T> - void emit_bitwise_fallback_guard(T(*func_ptr)); - - x86::Mem emit_i_length_common(Label fail, int state_size); - - void emit_flatmap_get_element(); - void emit_hashmap_get_element(); - -public: - BeamGlobalAssembler(JitAllocator *allocator); - - void (*get(GlobalLabels lbl))(void) { - ASSERT(ptrs[lbl]); - return ptrs[lbl]; - } - -#define GET_CODE(NAME) \ - void (*get_##NAME(void))() { \ - return get(NAME); \ - } - - BEAM_GLOBAL_FUNCS(GET_CODE) - PROCESS_MAIN_LABELS(GET_CODE) -#undef GET_CODE -}; +#include "beam_asm_global.hpp" class BeamModuleAssembler : public BeamAssembler { typedef unsigned BeamLabel; diff --git a/erts/emulator/beam/jit/x86/beam_asm_global.cpp b/erts/emulator/beam/jit/x86/beam_asm_global.cpp index 1d2037fb4a..f0058ecc8f 100644 --- a/erts/emulator/beam/jit/x86/beam_asm_global.cpp +++ b/erts/emulator/beam/jit/x86/beam_asm_global.cpp @@ -18,7 +18,9 @@ * %CopyrightEnd% */ +#define ERTS_BEAM_ASM_GLOBAL_WANT_STATIC_DEFS #include "beam_asm.hpp" +#undef ERTS_BEAM_ASM_GLOBAL_WANT_STATIC_DEFS using namespace asmjit; @@ -28,21 +30,6 @@ extern "C" #include "beam_common.h" } -#define STRINGIFY_(X) #X -#define STRINGIFY(X) STRINGIFY_(X) - -#define DECL_EMIT(NAME) {NAME, &BeamGlobalAssembler::emit_##NAME}, -const std::map<BeamGlobalAssembler::GlobalLabels, BeamGlobalAssembler::emitFptr> - BeamGlobalAssembler::emitPtrs = {BEAM_GLOBAL_FUNCS(DECL_EMIT)}; -#undef DECL_EMIT - -#define DECL_LABEL_NAME(NAME) {NAME, STRINGIFY(NAME)}, - -const std::map<BeamGlobalAssembler::GlobalLabels, const std::string> - BeamGlobalAssembler::labelNames = {BEAM_GLOBAL_FUNCS( - DECL_LABEL_NAME) PROCESS_MAIN_LABELS(DECL_LABEL_NAME)}; -#undef DECL_LABEL_NAME - BeamGlobalAssembler::BeamGlobalAssembler(JitAllocator *allocator) : BeamAssembler("beam_asm_global") { labels.reserve(emitPtrs.size()); diff --git a/erts/emulator/beam/jit/x86/beam_asm_global.hpp.pl b/erts/emulator/beam/jit/x86/beam_asm_global.hpp.pl new file mode 100755 index 0000000000..9ea270c4f4 --- /dev/null +++ b/erts/emulator/beam/jit/x86/beam_asm_global.hpp.pl @@ -0,0 +1,206 @@ +#!/usr/bin/env perl -W +# +# %CopyrightBegin% +# +# Copyright Ericsson AB 2022. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# %CopyrightEnd% +# +use strict; + +# Please keep the names in the list in alphabetical order. +my @beam_global_funcs = qw( + apply_fun_shared + arith_compare_shared + arith_eq_shared + bif_nif_epilogue + bif_element_shared + bif_export_trap + bs_add_shared + bs_create_bin_error_shared + bs_size_check_shared + bs_fixed_integer_shared + bs_get_tail_shared + call_bif_shared + call_light_bif_shared + call_nif_early + call_nif_shared + call_nif_yield_helper + catch_end_shared + check_float_error + dispatch_bif + dispatch_nif + dispatch_return + dispatch_save_calls + export_trampoline + garbage_collect + generic_bp_global + generic_bp_local + debug_bp + fconv_shared + handle_call_fun_error + handle_element_error + handle_hd_error + i_band_body_shared + i_band_guard_shared + i_bif_body_shared + i_bif_guard_shared + i_bor_body_shared + i_bor_guard_shared + i_bnot_body_shared + i_bnot_guard_shared + i_bsl_guard_shared + i_bsl_body_shared + i_bsr_guard_shared + i_bsr_body_shared + i_bxor_body_shared + i_bxor_guard_shared + i_func_info_shared + i_get_map_element_shared + i_get_map_element_hash_shared + i_load_nif_shared + i_length_guard_shared + i_length_body_shared + i_loop_rec_shared + i_new_small_map_lit_shared + i_test_yield_shared + increment_body_shared + int_div_rem_body_shared + int_div_rem_guard_shared + internal_hash_helper + minus_body_shared + minus_guard_shared + new_map_shared + plus_body_shared + plus_guard_shared + process_exit + process_main + raise_exception + raise_exception_shared + times_body_shared + times_guard_shared + unary_minus_body_shared + unary_minus_guard_shared + unloaded_fun + update_map_assoc_shared + update_map_exact_guard_shared + update_map_exact_body_shared + ); + +# Labels exported from within process_main +my @process_main_labels = qw( + context_switch + context_switch_simplified + do_schedule + ); + +my $decl_enums = + gen_list(' %s,', @beam_global_funcs, '', @process_main_labels); + +my $decl_emit_funcs = + gen_list(' void emit_%s(void);', @beam_global_funcs); + +my $decl_get_funcs = + gen_list(' void (*get_%s(void))() { return get(%s); }', + @beam_global_funcs, '', @process_main_labels); + +my $decl_emitPtrs = + gen_list(' {%s, &BeamGlobalAssembler::emit_%s},', @beam_global_funcs); + +my $decl_label_names = + gen_list(' {%s, "%s"},', @beam_global_funcs, '', @process_main_labels); + +sub gen_list { + my ($format, @strings) = @_; + my $out = ''; + foreach my $str (@strings) { + if ($str eq '') { + $out .= "\n"; + } + else { + my $subst = $format; + $subst =~ s/%s/$str/g; + $out .= "$subst\n"; + } + } + $out; +} + + +my $this_source_file = __FILE__; + +print <<END_OF_FILE; +/* + * Warning: Do not edit this file. + * Auto-generated by $this_source_file. + */ + +#ifndef _BEAM_ASM_GLOBAL_HPP +#define _BEAM_ASM_GLOBAL_HPP + + +class BeamGlobalAssembler : public BeamAssembler { + typedef void (BeamGlobalAssembler::*emitFptr)(void); + typedef void (*fptr)(void); + + enum GlobalLabels : uint32_t { +$decl_enums + }; + + static const std::map<GlobalLabels, const std::string> labelNames; + static const std::map<GlobalLabels, emitFptr> emitPtrs; + std::unordered_map<GlobalLabels, Label> labels; + std::unordered_map<GlobalLabels, fptr> ptrs; + +$decl_emit_funcs + + template<typename T> + void emit_bitwise_fallback_body(T(*func_ptr), const ErtsCodeMFA *mfa); + + template<typename T> + void emit_bitwise_fallback_guard(T(*func_ptr)); + + x86::Mem emit_i_length_common(Label fail, int state_size); + + void emit_flatmap_get_element(); + void emit_hashmap_get_element(); + +public: + BeamGlobalAssembler(JitAllocator *allocator); + + void (*get(GlobalLabels lbl))(void) { + ASSERT(ptrs[lbl]); + return ptrs[lbl]; + } + +$decl_get_funcs +}; + +#ifdef ERTS_BEAM_ASM_GLOBAL_WANT_STATIC_DEFS + +const std::map<BeamGlobalAssembler::GlobalLabels, BeamGlobalAssembler::emitFptr> +BeamGlobalAssembler::emitPtrs = { +$decl_emitPtrs +}; + +const std::map<BeamGlobalAssembler::GlobalLabels, const std::string> +BeamGlobalAssembler::labelNames = { +$decl_label_names +}; + +#endif /* ERTS_BEAM_ASM_GLOBAL_WANT_STATIC_DEFS */ + +#endif /* !_BEAM_ASM_GLOBAL_HPP */ +END_OF_FILE |