diff --git a/assembler/BUILD.gn b/assembler/BUILD.gn index 44970dda749e214bfff329fda8b3e298ac785960..c2e5a7c2357657baad103ec3572fbd36f8c72716 100644 --- a/assembler/BUILD.gn +++ b/assembler/BUILD.gn @@ -29,6 +29,7 @@ config("arkassembler_public_config") { libarkassembler_sources = [ "$target_gen_dir/ins_to_string.cpp", + "$target_gen_dir/meta_gen.cpp", "annotation.cpp", "assembly-emitter.cpp", "assembly-ins.cpp", @@ -59,7 +60,7 @@ source_set("libarkassembler_static") { public_configs = libarkassembler_configs deps = [ - ":ark_asm_meta_gen_h", + ":ark_asm_meta_gen_cpp", ":ark_asm_register_extensions_h", ":isa_gen_libarkassembler_ins_create_api_h", ":isa_gen_libarkassembler_ins_emit_h", @@ -94,7 +95,7 @@ source_set("libarkassembler_frontend_set_static") { public_configs = libarkassembler_configs deps = [ - ":ark_asm_meta_gen_h", + ":ark_asm_meta_gen_cpp", ":ark_asm_register_extensions_h", ":isa_gen_libarkassembler_ins_create_api_h", ":isa_gen_libarkassembler_ins_emit_h", @@ -118,9 +119,7 @@ ohos_static_library("libarkassembler_frontend_static") { source_set("ark_asm_static") { sources = [ "pandasm.cpp" ] - include_dirs = [ - "$target_gen_dir", - ] + include_dirs = [ "$target_gen_dir" ] public_configs = [ sdk_libc_secshared_config, @@ -167,11 +166,11 @@ ark_isa_gen("isa_gen_libarkassembler") { ] } -ark_gen_file("ark_asm_meta_gen_h") { +ark_gen_file("ark_asm_meta_gen_cpp") { template_file = "templates/meta_gen.cpp.erb" data_file = "metadata.yaml" requires = [ "asm_metadata.rb" ] - output_file = "$target_gen_dir/meta_gen.h" + output_file = "$target_gen_dir/meta_gen.cpp" } ark_gen_file("ark_asm_register_extensions_h") { diff --git a/assembler/CMakeLists.txt b/assembler/CMakeLists.txt index 6575250f0f37b873cda827bf98b77f27abd6a7dd..03b80c63c319c82c7ab1f197a21641cc30352fa6 100644 --- a/assembler/CMakeLists.txt +++ b/assembler/CMakeLists.txt @@ -14,12 +14,8 @@ cmake_minimum_required(VERSION 3.3.2 FATAL_ERROR) project(assembler CXX) -panda_add_executable(ark_asm pandasm.cpp) - -set(PANDASM_BIN_TESTS ${CMAKE_CURRENT_BINARY_DIR}/tests) -file(MAKE_DIRECTORY "${PANDASM_BIN_TESTS}") - panda_isa_gen( + TARGET_NAME assembly_isa_gen TEMPLATES "isa.h.erb" "ins_emit.h.erb" @@ -32,63 +28,100 @@ panda_isa_gen( "${PANDA_ROOT}/libpandafile/pandafile_isapi.rb" ) -set(SOURCES - lexer.cpp +# NB! For explanations, see panda_add_assembly_metadata. +function(panda_add_assembler_dependencies ARG_TARGET) + add_dependencies(${ARG_TARGET} assembly_isa_gen profiling_gen) + target_link_libraries(${ARG_TARGET} arkbase arkfile) +endfunction() + +# Add metadata parser (either core or language-specific). +# Basically this is a work-around for +# https://gitlab.kitware.com/cmake/cmake/-/issues/18399, +# which can be completely removed when we fully adopt +# cmake 3.20+. panda_add_assembler_dependencies is used +# to propagate proper dependencies of the main assembler +# target to the aux target created by this function. In +# this particular case, generator expressions were not +# used because we also depend on some code generation, so +# looks like this is a bit ugly, but most reliable solution. +function(panda_add_assembly_metadata) + set(prefix ARG) + set(noValues) + set(singleValues TARGET DATAFILE OUTPUT) + set(multiValues) + cmake_parse_arguments("${prefix}" + "${noValues}" + "${singleValues}" + "${multiValues}" + ${ARGN}) + + set_source_files_properties(${ARG_OUTPUT} PROPERTIES GENERATED 1) + panda_gen_file( + REQUIRES ${PANDA_ROOT}/assembler/asm_metadata.rb + TEMPLATE ${PANDA_ROOT}/assembler/templates/meta_gen.cpp.erb + DATAFILE ${ARG_DATAFILE} + OUTPUTFILE ${ARG_OUTPUT} + ) + add_library(${ARG_TARGET} OBJECT ${ARG_OUTPUT}) + set_target_properties(${ARG_TARGET} PROPERTIES POSITION_INDEPENDENT_CODE ON) + target_include_directories(${ARG_TARGET} PRIVATE + $ + ) + panda_add_assembler_dependencies(${ARG_TARGET}) + add_dependencies(arkassembler ${ARG_TARGET}) + target_sources(arkassembler PRIVATE $) + + # FIXME(igelhaus): Test fuzzers prior to merging + if (PANDA_ENABLE_AFL AND TARGET arkassembler_fuzz) + add_dependencies(arkassembler_fuzz ${ARG_TARGET}) + target_sources(arkassembler_fuzz PRIVATE $) + endif() +endfunction() + +add_library(arkassembler ${PANDA_DEFAULT_LIB_TYPE} annotation.cpp assembly-emitter.cpp + assembly-ins.cpp assembly-parser.cpp assembly-program.cpp assembly-type.cpp - assembly-ins.cpp context.cpp - meta.cpp - ins_to_string.cpp extensions/extensions.cpp + ins_to_string.cpp + lexer.cpp + meta.cpp ) - -set(META_GEN_H ${CMAKE_CURRENT_BINARY_DIR}/meta_gen.h) -panda_gen_file( +panda_add_assembler_dependencies(arkassembler) +panda_add_assembly_metadata( + TARGET arkassembler_metadata DATAFILE ${CMAKE_CURRENT_SOURCE_DIR}/metadata.yaml - TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/templates/meta_gen.cpp.erb - OUTPUTFILE ${META_GEN_H} - REQUIRES ${CMAKE_CURRENT_SOURCE_DIR}/asm_metadata.rb -) -add_custom_target(meta_gen_h DEPENDS ${META_GEN_H}) - -add_library(arkassembler ${PANDA_DEFAULT_LIB_TYPE} ${SOURCES}) -add_dependencies(arkassembler - isa_gen_assembler - arkfile - meta_gen_h - profiling_gen + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/meta_gen.cpp ) target_include_directories(arkassembler PUBLIC - ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_BINARY_DIR}/libpandabase - ${PANDA_ROOT} + ${CMAKE_CURRENT_BINARY_DIR} + # TODO(chernykhsergey): Remove the path to the binary dir + # when build system for profiling is fixed. ${CMAKE_BINARY_DIR} ) -target_link_libraries(arkassembler arkfile) -target_link_libraries(ark_asm arkassembler arkbase) +panda_add_executable(ark_asm pandasm.cpp) +target_link_libraries(ark_asm arkassembler) if(PANDA_WITH_BYTECODE_OPTIMIZER) target_link_libraries(ark_asm arkbytecodeopt) endif() -include_directories(${PANDA_ROOT}/libpandabase/) -include_directories(${CMAKE_BINARY_DIR}/libpandafile/include/) - +file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tests) panda_add_gtest( NAME assembler_tests SOURCES - tests/lexer_test.cpp - tests/parser_test.cpp tests/emitter_test.cpp + tests/lexer_test.cpp tests/mangling_tests.cpp + tests/parser_test.cpp LIBRARIES - arkbase arkassembler + arkassembler SANITIZERS ${PANDA_SANITIZERS_LIST} ) diff --git a/assembler/meta.cpp b/assembler/meta.cpp index a03bf14a8ffcb664bc7a1bd40c1c2a90c4010271..609d913223c1df69577fc6fabb434dc8dcbf8344 100644 --- a/assembler/meta.cpp +++ b/assembler/meta.cpp @@ -507,6 +507,4 @@ std::optional FieldMetadata::StoreValue(std::string_view attrib return {}; } -#include - } // namespace panda::pandasm diff --git a/assembler/templates/meta_gen.cpp.erb b/assembler/templates/meta_gen.cpp.erb index 0013fbe32b7ecec4d139df001ccf0287b0108c8e..f7f194d534f82451545306227dcf32976a54c4e9 100644 --- a/assembler/templates/meta_gen.cpp.erb +++ b/assembler/templates/meta_gen.cpp.erb @@ -13,6 +13,17 @@ * limitations under the License. */ +% unless Metadata.language.empty? +#include <<%= Metadata.language.downcase %>_meta.h> + +namespace panda::pandasm::extensions::<%= Metadata.language.downcase %> { +% else +#include "meta.h" + +namespace panda::pandasm { +% end + +// NOLINTBEGIN(readability-function-size) % Metadata::item_types.each do |item_type| std::optional @@ -26,6 +37,8 @@ std::optional } % end +// NOLINTEND(readability-function-size) + % % Metadata::item_types.each do |item_type| void <%= MetadataGen::class_name(item_type) %>::SetFlags(<%= MetadataGen::flags_arg_list(item_type, true).join(', ') %>) { @@ -45,3 +58,9 @@ void <%= MetadataGen::class_name(item_type) %>::RemoveFlags(<%= MetadataGen::fla } % end + +% unless Metadata.language.empty? +} // namespace panda::pandasm::extensions::<%= Metadata.language.downcase %> +% else +} // namespace panda::pandasm +% end diff --git a/plugins/ets/assembler/CMakeLists.txt b/plugins/ets/assembler/CMakeLists.txt index 61c9241d7299bf1b0b8e9305430e5f12b6c63a9c..3917c2055082dc160b96e9f69bab8c775953e04a 100644 --- a/plugins/ets/assembler/CMakeLists.txt +++ b/plugins/ets/assembler/CMakeLists.txt @@ -12,22 +12,10 @@ # limitations under the License. set(EXTENSION_DIR ${PANDA_ETS_PLUGIN_SOURCE}/assembler/extension) - -target_sources(arkassembler PRIVATE ${EXTENSION_DIR}/ets_meta.cpp) target_include_directories(arkassembler PUBLIC ${EXTENSION_DIR}) -set(ETS_META_GEN_H ${PANDA_BINARY_ROOT}/assembler/ets_meta_gen.h) -panda_gen_file( - DATAFILE ${PANDA_ETS_PLUGIN_SOURCE}/assembler/extension/metadata.yaml - TEMPLATE ${PANDA_ROOT}/assembler/templates/meta_gen.cpp.erb - OUTPUTFILE ${ETS_META_GEN_H} - REQUIRES ${PANDA_ROOT}/assembler/asm_metadata.rb +panda_add_assembly_metadata( + TARGET ets_asm_metadata + DATAFILE ${EXTENSION_DIR}/metadata.yaml + OUTPUT ${PANDA_BINARY_ROOT}/assembler/ets_meta_gen.cpp ) -add_custom_target(ets_meta_gen_h DEPENDS ${ETS_META_GEN_H}) -add_dependencies(arkassembler ets_meta_gen_h) - -if (PANDA_ENABLE_AFL) - target_sources(arkassembler_fuzz PRIVATE ${EXTENSION_DIR}/ets_meta.cpp) - target_include_directories(arkassembler_fuzz PUBLIC ${EXTENSION_DIR}) - add_dependencies(arkassembler_fuzz ets_meta_gen_h) -endif() diff --git a/plugins/ets/assembler/extension/ets_meta.cpp b/plugins/ets/assembler/extension/ets_meta.cpp deleted file mode 100644 index e1186ad32ad5d660d388b90b33c79eaaff258a2a..0000000000000000000000000000000000000000 --- a/plugins/ets/assembler/extension/ets_meta.cpp +++ /dev/null @@ -1,22 +0,0 @@ -/** - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * 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. - */ - -#include "ets_meta.h" - -namespace panda::pandasm::extensions::ets { - -#include - -} // namespace panda::pandasm::extensions::ets diff --git a/plugins/plugins.gni b/plugins/plugins.gni index 3d335a3c5bb8c996270fbdc2f5618096796c1b58..43d790e317db7e711f4133f127bd242c400317f3 100644 --- a/plugins/plugins.gni +++ b/plugins/plugins.gni @@ -68,7 +68,8 @@ foreach(plugin, ark_enabled_plugins) { _plugin_vars = read_file("$_plugin_dir/plugin.gn", "scope") if (defined(_plugin_vars.enable_bytecode_optimizer)) { - plugin_enable_bytecode_optimizer = plugin_enable_bytecode_optimizer || _plugin_vars.enable_bytecode_optimizer + plugin_enable_bytecode_optimizer = plugin_enable_bytecode_optimizer || + _plugin_vars.enable_bytecode_optimizer } plugin_ark_host_linux_tools_packages += @@ -113,14 +114,25 @@ foreach(plugin, ark_enabled_plugins) { } } + # NB! Current scenario for adding plugin-specific source files + # distinguishes between "normal" files (srcs_$COMPONENT) and + # auto-generated files (srcs_$COMPONENT_gen). For normal + # sources, the absolute path to plugin is added implicitly. + # Auto-generated sources are added as is because + # currently they are retrieved with get_label_info, + # which already returns an absolute path. + # Whether srcs_$COMPONENT or srcs_$COMPONENT_gen or both + # should be supported by a specific $COMPONENT, is deemed + # upon actual needs. + if (defined(_plugin_vars.srcs_disassembler)) { foreach(src, _plugin_vars.srcs_disassembler) { plugin_arkdisassembler_sources += [ "$_plugin_dir/$src" ] } } - if (defined(_plugin_vars.srcs_assembler)) { - foreach(src, _plugin_vars.srcs_assembler) { - plugin_libarkassembler_sources += [ "$_plugin_dir/$src" ] + if (defined(_plugin_vars.srcs_assembler_gen)) { + foreach(src, _plugin_vars.srcs_assembler_gen) { + plugin_libarkassembler_sources += [ src ] } } if (defined(_plugin_vars.srcs_bytecode_optimizer)) { diff --git a/runtime/tests/class_linker_test_extension.h b/runtime/tests/class_linker_test_extension.h index d1bc85d347d1ad261f0ecb1fe82169d2b944e50d..e3939602eb8dcf079c8313f2dd504e092a380137 100644 --- a/runtime/tests/class_linker_test_extension.h +++ b/runtime/tests/class_linker_test_extension.h @@ -24,12 +24,15 @@ namespace panda::test { class ClassLinkerTestExtension : public ClassLinkerExtension { public: + NO_COPY_SEMANTIC(ClassLinkerTestExtension); + NO_MOVE_SEMANTIC(ClassLinkerTestExtension); + ClassLinkerTestExtension(ManagedThread *thread, panda_file::SourceLang lang) : ClassLinkerExtension(lang), thread_(thread) { } - ~ClassLinkerTestExtension() + ~ClassLinkerTestExtension() override { FreeLoadedClasses(); } @@ -95,12 +98,12 @@ public: RemoveCreatedClass(klass); } - bool InitializeClass(Class *) override + bool InitializeClass(Class * /* klass */) override { return true; } - const void *GetNativeEntryPointFor(panda::Method *) const override + const void *GetNativeEntryPointFor(panda::Method * /* method */) const override { return nullptr; }