1# Copyright (c) 2021-2022 Huawei Device Co., Ltd.
2# Licensed under the Apache License, Version 2.0 (the "License");
3# you may not use this file except in compliance with the License.
4# You may obtain a copy of the License at
5# http://www.apache.org/licenses/LICENSE-2.0
6# Unless required by applicable law or agreed to in writing, software
7# distributed under the License is distributed on an "AS IS" BASIS,
8# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9# See the License for the specific language governing permissions and
10# limitations under the License.
11
12import("//arkcompiler/runtime_core/ark_config.gni")
13
14config("arkassembler_public_config") {
15  include_dirs = [
16    "$ark_root/assembler",
17    "$target_gen_dir",
18    "$target_gen_dir/include",
19    "$root_gen_dir/libpandabase",
20    "$ark_root/plugins/ecmascript/assembler",
21  ]
22
23  defines = [ "PANDA_WITH_ECMASCRIPT" ]
24}
25
26libarkassembler_sources = [
27  "$target_gen_dir/function_collect_string.cpp",
28  "$target_gen_dir/ins_to_string.cpp",
29  "annotation.cpp",
30  "assembly-emitter.cpp",
31  "assembly-ins.cpp",
32  "assembly-parser.cpp",
33  "assembly-program.cpp",
34  "assembly-type.cpp",
35  "context.cpp",
36  "extensions/ecmascript_meta.cpp",
37  "extensions/extensions.cpp",
38  "lexer.cpp",
39  "meta.cpp",
40]
41
42libarkassembler_configs = [
43  "$ark_root:ark_config",
44  ":arkassembler_public_config",
45  "$ark_root/libpandabase:arkbase_public_config",
46  "$ark_root/libpandafile:arkfile_public_config",
47]
48
49plugin_deps = []
50foreach(plugin, enabled_plugins) {
51  print("add assembler plugin: $plugin")
52  plugin_dir = "$ark_root/plugins/$plugin"
53  libarkassembler_configs += [ "$plugin_dir:assembler" ]
54  plugin_deps += [ "$plugin_dir:assembler_deps" ]
55
56  source_files = read_file("$plugin_dir/subproject_sources.gn", "scope")
57  if (defined(source_files.srcs_assembler_path)) {
58    source_file = "$plugin_dir/${source_files.srcs_assembler_path}"
59    src_scope = read_file(source_file, "scope")
60    foreach(src, src_scope.srcs) {
61      libarkassembler_sources += [ "$plugin_dir/assembler/$src" ]
62    }
63    src_scope = {
64    }
65  }
66  source_files = []
67}
68
69ohos_static_library("libarkassembler_static") {
70  sources = libarkassembler_sources
71
72  public_configs = libarkassembler_configs
73
74  deps = [
75    ":ark_asm_meta_gen_h",
76    ":ark_asm_register_extensions_h",
77    ":isa_gen_libarkassembler_function_collect_string_cpp",
78    ":isa_gen_libarkassembler_ins_create_api_h",
79    ":isa_gen_libarkassembler_ins_emit_h",
80    ":isa_gen_libarkassembler_ins_to_string_cpp",
81    ":isa_gen_libarkassembler_isa_h",
82    ":isa_gen_libarkassembler_opcode_parsing_h",
83    ":isa_gen_libarkassembler_operand_types_print_h",
84    "$ark_root/libpandabase:libarkbase_static",
85    "$ark_root/libpandafile:libarkfile_static",
86  ]
87
88  external_deps = [ sdk_libc_secshared_dep ]
89
90  deps += plugin_deps
91
92  part_name = "runtime_core"
93  subsystem_name = "arkcompiler"
94}
95
96ohos_shared_library("libarkassembler") {
97  stack_protector_ret = false
98  deps = [ ":libarkassembler_static" ]
99
100  if (!is_standard_system) {
101    relative_install_dir = "ark"
102  }
103  output_extension = "so"
104  if (is_mingw) {
105    output_extension = "dll"
106  }
107
108  part_name = "runtime_core"
109  subsystem_name = "arkcompiler"
110}
111
112ohos_source_set("libarkassembler_frontend_set_static") {
113  sources = libarkassembler_sources
114
115  public_configs = libarkassembler_configs
116
117  deps = [
118    ":ark_asm_meta_gen_h",
119    ":ark_asm_register_extensions_h",
120    ":isa_gen_libarkassembler_function_collect_string_cpp",
121    ":isa_gen_libarkassembler_ins_create_api_h",
122    ":isa_gen_libarkassembler_ins_emit_h",
123    ":isa_gen_libarkassembler_ins_to_string_cpp",
124    ":isa_gen_libarkassembler_isa_h",
125    ":isa_gen_libarkassembler_opcode_parsing_h",
126    ":isa_gen_libarkassembler_operand_types_print_h",
127    "$ark_root/libpandabase:libarkbase_frontend_static",
128    "$ark_root/libpandafile:libarkfile_frontend_static",
129  ]
130
131  if (is_arkui_x) {
132    deps += [ "$ark_third_party_root/bounds_checking_function:libsec_static" ]
133  } else {
134    external_deps = [ sdk_libc_secshared_dep ]
135  }
136
137  deps += plugin_deps
138
139  part_name = "runtime_core"
140  subsystem_name = "arkcompiler"
141}
142
143ohos_static_library("libarkassembler_frontend_static") {
144  stack_protector_ret = false
145  deps = [ ":libarkassembler_frontend_set_static" ]
146
147  part_name = "runtime_core"
148  subsystem_name = "arkcompiler"
149}
150
151# ark_asm_static is a legcay component for ts2abc and is no longer valid
152ohos_source_set("ark_asm_static") {
153  sources = [ "pandasm.cpp" ]
154
155  include_dirs = [
156    "$target_gen_dir",
157    "$root_gen_dir/libpandabase",
158  ]
159
160  public_configs = [
161    ":arkassembler_public_config",
162    "$ark_root:ark_config",
163    "$ark_root/libpandabase:arkbase_public_config",
164    "$ark_root/libpandafile:arkfile_public_config",
165  ]
166
167  deps = [
168    ":libarkassembler_frontend_static",
169    "$ark_root/libpandabase:libarkbase_frontend_static",
170    "$ark_root/libpandafile:libarkfile_frontend_static",
171  ]
172
173  external_deps = [ sdk_libc_secshared_dep ]
174
175  libs = platform_libs
176  if (!is_mac && !is_mingw) {
177    ldflags = platform_ldflags
178  }
179
180  part_name = "runtime_core"
181  subsystem_name = "arkcompiler"
182}
183
184ark_isa_gen("isa_gen_libarkassembler") {
185  template_files = [
186    "isa.h.erb",
187    "function_collect_string.cpp.erb",
188    "ins_emit.h.erb",
189    "ins_to_string.cpp.erb",
190    "ins_create_api.h.erb",
191    "opcode_parsing.h.erb",
192    "operand_types_print.h.erb",
193  ]
194  sources = "templates"
195  destination = "$target_gen_dir"
196  requires = [
197    "asm_isapi.rb",
198    "../libpandafile/pandafile_isapi.rb",
199  ]
200}
201
202ark_gen_file("ark_asm_meta_gen_h") {
203  template_file = "templates/meta_gen.cpp.erb"
204  data_file = "metadata.yaml"
205  requires = [ "asm_metadata.rb" ]
206  output_file = "$target_gen_dir/meta_gen.h"
207}
208
209ark_gen_file("ark_asm_register_extensions_h") {
210  extra_dependencies = [ "$ark_root:concat_plugins_yamls" ]
211  template_file = "extensions/register_extensions.h.erb"
212  data_file = "$target_gen_dir/../plugin_options.yaml"
213  requires = [ "$ark_root/templates/plugin_options.rb" ]
214  output_file = "$target_gen_dir/register_extensions.h"
215}
216