• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "ecmascript/js_runtime_options.h"
17 
18 #include <cerrno>
19 #include <cstdlib>
20 #include <iostream>
21 #include <getopt.h>
22 
23 #include "ecmascript/compiler/aot_file/an_file_data_manager.h"
24 #include "ecmascript/compiler/ecma_opcode_des.h"
25 
26 namespace panda::ecmascript {
27 const std::string PUBLIC_API COMMON_HELP_HEAD_MSG =
28     "Usage: jsvm  <option>  <filename.abc>\n"
29     "\n"
30     "Options:\n";
31 
32 const std::string PUBLIC_API COMPILER_HELP_HEAD_MSG =
33     "Usage: ark_aot_compiler  <option>  --aot-file=<filename>  <filename.abc>\n"
34     "\n"
35     "Options:\n";
36 
37 const std::string PUBLIC_API STUB_HELP_HEAD_MSG =
38     "Usage: ark_stub_compiler <option>\n"
39     "\n"
40     "Options:\n";
41 
42 const std::string PUBLIC_API HELP_OPTION_MSG =
43     "--aot-file:                           Path (file suffix not needed) to AOT output file. Default: 'aot_file'\n"
44     "--ark-properties:                     Set ark properties\n"
45     "--ark-bundle-name:                    Set ark bundle name\n"
46     "--asm-interpreter:                    Enable asm interpreter. Default: 'true'\n"
47     "--asm-opcode-disable-range:           Opcode range when asm interpreter is enabled.\n"
48     "--builtins-lazy:                     Load some builtins function later.This option is only valid in workervm.\n"
49     "--compiler-log:                       Log Option For aot compiler and stub compiler,\n"
50     "                                      'none': no log,\n"
51     "                                      'allllircirasm' or 'all012': print all log for all methods,\n"
52     "                                      'allcir' or 'all0': print IR info for all methods,\n"
53     "                                      'allllir' or 'all1': print llir info for all methods,\n"
54     "                                      'allasm' or 'all2': print asm log for all methods,\n"
55     "                                      'alltype' or 'all3': print type infer log for all methods,\n"
56     "                                      'cerllircirasm' or 'cer0112': print all log for certain method defined "
57                                            "in 'mlist-for-log',\n"
58     "                                      'cercir' or 'cer0': print IR for methods in 'mlist-for-log',\n"
59     "                                      'cerasm' or 'cer2': print log for methods in 'mlist-for-log',\n"
60     "                                      Default: 'none'\n"
61     "--compiler-log-methods:               Specific method list for compiler log, only used when compiler-log. "
62                                            "Default: 'none'\n"
63     "--compiler-type-threshold:            enable to skip methods whose type is no more than threshold. Default: -1\n"
64     "--compiler-log-snapshot:              Enable to print snapshot information. Default: 'false'\n"
65     "--compiler-log-time:                  Enable to print pass compiler time. Default: 'false'\n"
66     "--enable-ark-tools:                   Enable ark tools to debug. Default: 'false'\n"
67     "--open-ark-tools:                     Open ark tools to return specific implementation. Default: 'false'\n"
68     "--pgo-trace:                          Enable pgo trace for JS runtime. Default: 'false'\n"
69     "--compiler-trace-bc:                  Enable tracing bytecode for aot runtime. Default: 'false'\n"
70     "--compiler-trace-deopt:               Enable tracing deopt for aot runtime. Default: 'false'\n"
71     "--compiler-trace-inline:              Enable tracing inline function for aot runtime. Default: 'false'\n"
72     "--compiler-trace-value-numbering:     Enable tracing value numbering for aot runtime. Default: 'false'\n"
73     "--compiler-max-inline-bytecodes       Set max bytecodes count which aot function can be inlined. Default: '25'\n"
74     "--compiler-deopt-threshold:           Set max count which aot function can occur deoptimization. Default: '10'\n"
75     "--compiler-device-state               Compiler device state for aot. Check device screen state. Default: 'false'\n"
76     "--compiler-stress-deopt:              Enable stress deopt for aot compiler. Default: 'false'\n"
77     "--compiler-opt-code-profiler:         Enable opt code Bytecode Statistics for aot runtime. Default: 'false'\n"
78     "--compiler-opt-bc-range:              Range list for EcmaOpCode range Example '1:2,5:8'\n"
79     "--compiler-opt-bc-range-help:         Range list for EcmaOpCode range help. Default: 'false''\n"
80     "--enable-force-gc:                    Enable force gc when allocating object. Default: 'true'\n"
81     "--enable-eden-gc:                     Enable eden gc. Default: 'false'\n"
82     "--force-shared-gc-frequency:          How frequency force shared gc . Default: '1'\n"
83     "--enable-ic:                          Switch of inline cache. Default: 'true'\n"
84     "--enable-runtime-stat:                Enable statistics of runtime state. Default: 'false'\n"
85     "--compiler-opt-array-bounds-check-elimination: Enable Index Check elimination. Default: 'true'\n"
86     "--compiler-opt-constant-folding:      Enable constant folding. Default: 'true'\n"
87     "--compiler-opt-type-lowering:         Enable all type optimization pass for aot compiler. Default: 'true'\n"
88     "--compiler-opt-early-elimination:     Enable EarlyElimination for aot compiler. Default: 'true'\n"
89     "--compiler-opt-later-elimination:     Enable LaterElimination for aot compiler. Default: 'true'\n"
90     "--compiler-opt-string:                Enable string optimization pass for aot compiler. Default: 'true'\n"
91     "--compiler-opt-value-numbering:       Enable ValueNumbering for aot compiler. Default: 'true'\n"
92     "--compiler-empty-catch-function:      Enable function with empty-catch for aot compiler: Default: 'false'\n"
93     "--compiler-opt-inlining:              Enable inlining function for aot compiler: Default: 'true'\n"
94     "--compiler-opt-pgotype:               Enable pgo type for aot compiler: Default: 'true'\n"
95     "--compiler-opt-track-field:           Enable track field for aot compiler: Default: 'false'\n"
96     "--entry-point:                        Full name of entrypoint function. Default: '_GLOBAL::func_main_0'\n"
97     "--force-full-gc:                      If true trigger full gc, else trigger semi and old gc. Default: 'true'\n"
98     "--framework-abc-file:                 Snapshot file. Default: 'strip.native.min.abc'\n"
99     "--gc-long-paused-time:                Set gc's longPauseTime in millisecond. Default: '40'\n"
100     "--gc-thread-num:                      Set gc thread number. Default: '7'\n"
101     "--heap-size-limit:                    Max heap size (MB). Default: '512'\n"
102     "--help:                               Print this message and exit\n"
103     "--icu-data-path:                      Path to generated icu data file. Default: 'default'\n"
104     "--enable-worker:                      Whether is worker vm. Default: 'false'\n"
105     "--log-level:                          Log level: ['debug', 'info', 'warning', 'error', 'fatal'].\n"
106     "--log-components:                     Enable logs from specified components: ['all', 'gc', 'ecma','interpreter',\n"
107     "                                      'debugger', 'compiler', 'builtins', 'trace', 'jit', 'baselinejit', 'all']. \n"
108     "                                      Default: 'all'\n"
109     "--log-debug:                          Enable debug or above logs for components: ['all', 'gc', 'ecma',\n"
110     "                                      'interpreter', 'debugger', 'compiler', 'builtins', 'trace', 'jit',\n"
111     "                                      'baselinejit', 'all']. Default: 'all'\n"
112     "--log-error:                          Enable error log for components: ['all', 'gc', 'ecma',\n"
113     "                                      'interpreter', 'debugger', 'compiler', 'builtins', 'trace', 'jit',\n"
114     "                                      'baselinejit', 'all']. Default: 'all'\n"
115     "--log-fatal:                          Enable fatal log for components: ['all', 'gc', 'ecma',\n"
116     "                                      'interpreter', 'debugger', 'compiler', 'builtins', 'trace', 'jit',\n"
117     "                                      'baselinejit', 'all']. Default: 'all'\n"
118     "--log-info:                           Enable info log for components: ['all', 'gc', 'ecma',\n"
119     "                                      'interpreter', 'debugger', 'compiler', 'builtins', 'trace', 'jit',\n"
120     "                                      'baselinejit', 'all']. Default: 'all'\n"
121     "--log-warning:                        Enable warning log for components: ['all', 'gc', 'ecma',\n"
122     "                                      'interpreter', 'debugger', 'compiler', 'trace', 'jit', \n"
123     "                                      'baselinejit', 'builtins', 'all']. Default: 'all'\n"
124     "--compiler-opt-max-method:            Enable aot compiler to skip method larger than limit (KB). Default: '32'\n"
125     "--compiler-module-methods:            The number of max compiled methods in a module. Default: '100'\n"
126     "--max-unmovable-space:                Set max unmovable space capacity\n"
127     "--merge-abc:                          ABC file is merge abc. Default: 'false'\n"
128     "--compiler-opt-level:                 Optimization level configuration of aot compiler. Default: '3'\n"
129     "--options:                            Print compiler and runtime options\n"
130     "--serializer-buffer-size-limit:       Max serializer buffer size used by the VM in Byte. Default size is 2GB\n"
131     "--snapshot-file:                      Snapshot file. Default: '/system/etc/snapshot'\n"
132     "--startup-time:                       Print the start time of command execution. Default: 'false'\n"
133     "--stub-file:                          Path of file includes common stubs module compiled by stub compiler. "
134                                            "Default: 'stub.an'\n"
135     "--enable-pgo-profiler:                Enable pgo profiler to sample jsfunction call and output to file. "
136                                            "Default: 'false'\n"
137     "--enable-elements-kind:               Enable elementsKind sampling and usage. Default: 'false'\n"
138     "--compiler-pgo-hotness-threshold:     Set hotness threshold for pgo in aot compiler. Default: '2'\n"
139     "--compiler-pgo-profiler-path:         The pgo file output dir or the pgo file dir of AOT compiler. Default: ''\n"
140     "--compiler-pgo-save-min-interval:     Set the minimum time interval for automatically saving profile, "
141                                            "Unit seconds. Default: '30s'\n"
142     "--compiler-baseline-pgo:              Enable compile the baseline Ap file. "
143                                            "Default: 'false'\n"
144     "--compiler-target-triple:             CPU triple for aot compiler or stub compiler. \n"
145     "                                      values: ['x86_64-unknown-linux-gnu', 'arm-unknown-linux-gnu', \n"
146     "                                      'aarch64-unknown-linux-gnu'], Default: 'x86_64-unknown-linux-gnu'\n"
147     "--enable-print-execute-time:          Enable print execute panda file spent time\n"
148     "--compiler-verify-vtable:             Verify vtable result for aot compiler. Default: 'false'\n"
149     "--compiler-select-methods             Compiler selected methods for aot. Only work in full compiling mode\n"
150     "                                      Format:--compile-methods=record1:m1,m2,record2:m3\n"
151     "--compiler-skip-methods               Compiler skpped methods for aot. Only work in full compiling mode\n"
152     "                                      Format:--compile-skip-methods=record1:m1,m2,record2:m3\n"
153     "--target-compiler-mode                The compilation mode at the device side, including partial, full and none."
154     "                                      Default: ''\n"
155     "--hap-path(Deprecated)                The path of the app hap. Default: ''\n"
156     "--hap-abc-offset(Deprecated)          The offset of the abc file in app hap. Default: '0'\n"
157     "--hap-abc-size(Deprecated)            The size of the abc file in app hap. Default: '0'\n"
158     "--compiler-fast-compile               Disable some time-consuming pass. Default: 'true'\n"
159     "--compiler-no-check                   Enable remove checks for aot compiler. Default: 'false'\n"
160     "--compiler-pipeline-host-aot          Enable pipeline host aot compiler. Default: 'false'\n"
161     "--compiler-opt-loop-peeling:          Enable loop peeling for aot compiler: Default: 'false'\n"
162     "--compiler-pkg-info                   Specify the package json info for ark aot compiler\n"
163     "--compiler-external-pkg-info          Specify the external package json info for ark aot compiler\n"
164     "--compiler-enable-external-pkg        Enable compile with external package for ark aot compiler\n"
165     "--compiler-enable-lexenv-specialization: Enable replace ldlexvar with specific values: Default: 'true'\n"
166     "--compiler-enable-native-inline:      Enable inline native function: Default: 'false'\n"
167     "--compiler-enable-lowering-builtin:   Enable lowering global object: Default: 'false'\n"
168     "--compiler-opt-array-onheap-check:    Enable TypedArray on heap check for aot compiler: Default: 'false'\n"
169     "--compiler-enable-litecg:             Enable LiteCG: Default: 'false'\n"
170     "--compiler-enable-jit:                Enable jit: Default: 'false'\n"
171     "--compiler-enable-osr:                Enable osr: Default: 'false'\n"
172     "--compiler-enable-framework-aot:      Enable frame aot: Default: 'true'\n"
173     "--compiler-jit-hotness-threshold:     Set hotness threshold for jit. Default: '2'\n"
174     "--compiler-jit-call-threshold:        Set call threshold for jit. Default: '0'\n"
175     "--compiler-osr-hotness-threshold:     Set hotness threshold for osr. Default: '2'\n"
176     "--compiler-force-jit-compile-main:    Enable jit compile main function: Default: 'false'\n"
177     "--compiler-trace-jit:                 Enable trace jit: Default: 'false'\n"
178     "--compiler-enable-jit-pgo:            Enable jit pgo: Default: 'true'\n"
179     "--compiler-typed-op-profiler:         Enable Typed Opcode Statistics for aot runtime. Default: 'false'\n"
180     "--compiler-opt-branch-profiling:      Enable branch profiling for aot compiler. Default: 'true'\n"
181     "--test-assert:                        Set Assert Model. Default: 'false'\n"
182     "--compiler-methods-range:             Enable aot compiler to compile only in-range methods."
183     "                                      Default: '0:4294967295'\n"
184     "--compiler-codegen-options:           Compile options passed to codegen. Default: ''\n\n"
185     "--compiler-opt-escape-analysis:       Enable escape analysis for aot compiler. Default: 'true'\n"
186     "--compiler-trace-escape-analysis:     Enable tracing escape analysis for aot compiler. Default: 'false'\n"
187     "--compiler-opt-induction-variable:    Enable induciton variable analysis for aot compiler. Default: 'false'\n"
188     "--compiler-trace-induction-variable:  Enable tracing induction variable for aot compiler. Default: 'false'\n"
189     "--compiler-memory-analysis:           Enable memory analysis for aot compiler. Default: 'true'\n"
190     "--compiler-enable-jit-fast-compile:   Enable jit fast compile. Default: 'false'\n"
191     "--compiler-enable-jitfort:            Enable jit fort memory space. Default: 'false'\n"
192     "--compiler-codesign-disable:          Disable codesign for jit fort. Default: 'true'\n"
193     "--compiler-enable-async-copytofort:   Enable jit fort allocation and code copy in Jit thread. Default: 'true'\n"
194     "--compiler-pgo-force-dump:            Enable pgo dump not interrupted by GC. Default: 'true'\n"
195     "--async-load-abc:                     Enable asynchronous load abc. Default: 'true'\n"
196     "--async-load-abc-test:                Enable asynchronous load abc test. Default: 'false'\n"
197     "--compiler-enable-concurrent:         Enable concurrent compile(only support in ark_stub_compiler).\n"
198     "--compiler-opt-frame-state-elimination: Enable frame state elimination. Default: 'true'\n"
199     "                                      Default: 'true'\n\n";
200 
ParseCommand(const int argc,const char ** argv)201 bool JSRuntimeOptions::ParseCommand(const int argc, const char **argv)
202 {
203     const struct option longOptions[] = {
204         {"aot-file", required_argument, nullptr, OPTION_AOT_FILE},
205         {"ark-properties", required_argument, nullptr, OPTION_ARK_PROPERTIES},
206         {"ark-bundleName", required_argument, nullptr, OPTION_ARK_BUNDLENAME},
207         {"asm-interpreter", required_argument, nullptr, OPTION_ENABLE_ASM_INTERPRETER},
208         {"asm-opcode-disable-range", required_argument, nullptr, OPTION_ASM_OPCODE_DISABLE_RANGE},
209         {"builtins-lazy", required_argument, nullptr, OPTION_ENABLE_BUILTINS_LAZY},
210         {"compiler-log", required_argument, nullptr, OPTION_COMPILER_LOG_OPT},
211         {"compiler-log-methods", required_argument, nullptr, OPTION_COMPILER_LOG_METHODS},
212         {"compiler-log-snapshot", required_argument, nullptr, OPTION_COMPILER_LOG_SNAPSHOT},
213         {"compiler-log-time", required_argument, nullptr, OPTION_COMPILER_LOG_TIME},
214         {"compiler-type-threshold", required_argument, nullptr, OPTION_COMPILER_TYPE_THRESHOLD},
215         {"enable-ark-tools", required_argument, nullptr, OPTION_ENABLE_ARK_TOOLS},
216         {"open-ark-tools", required_argument, nullptr, OPTION_OPEN_ARK_TOOLS},
217         {"pgo-trace", required_argument, nullptr, OPTION_PGO_TRACE},
218         {"compiler-trace-bc", required_argument, nullptr, OPTION_COMPILER_TRACE_BC},
219         {"compiler-trace-deopt", required_argument, nullptr, OPTION_COMPILER_TRACE_DEOPT},
220         {"compiler-trace-inline", required_argument, nullptr, OPTION_COMPILER_TRACE_INLINE},
221         {"compiler-trace-value-numbering", required_argument, nullptr, OPTION_COMPILER_TRACE_VALUE_NUMBERING},
222         {"compiler-trace-instruction-combine", required_argument, nullptr, OPTION_COMPILER_TRACE_INSTRUCTION_COMBINE},
223         {"compiler-max-inline-bytecodes", required_argument, nullptr, OPTION_COMPILER_MAX_INLINE_BYTECODES},
224         {"compiler-deopt-threshold", required_argument, nullptr, OPTION_COMPILER_DEOPT_THRESHOLD},
225         {"compiler-device-state", required_argument, nullptr, OPTION_COMPILER_DEVICE_STATE},
226         {"compiler-stress-deopt", required_argument, nullptr, OPTION_COMPILER_STRESS_DEOPT},
227         {"compiler-opt-code-profiler", required_argument, nullptr, OPTION_COMPILER_OPT_CODE_PROFILER},
228         {"compiler-opt-bc-range", required_argument, nullptr, OPTION_COMPILER_OPT_BC_RANGE},
229         {"compiler-opt-bc-range-help", required_argument, nullptr, OPTION_COMPILER_OPT_BC_RANGE_HELP},
230         {"enable-force-gc", required_argument, nullptr, OPTION_ENABLE_FORCE_GC},
231         {"enable-eden-gc", required_argument, nullptr, OPTION_ENABLE_EDEN_GC},
232         {"enable-ic", required_argument, nullptr, OPTION_ENABLE_IC},
233         {"enable-runtime-stat", required_argument, nullptr, OPTION_ENABLE_RUNTIME_STAT},
234         {"compiler-opt-constant-folding", required_argument, nullptr, OPTION_COMPILER_OPT_CONSTANT_FOLDING},
235         {"compiler-opt-array-bounds-check-elimination", required_argument, nullptr,
236             OPTION_COMPILER_OPT_ARRAY_BOUNDS_CHECK_ELIMINATION},
237         {"compiler-opt-type-lowering", required_argument, nullptr, OPTION_COMPILER_OPT_TYPE_LOWERING},
238         {"compiler-opt-early-elimination", required_argument, nullptr, OPTION_COMPILER_OPT_EARLY_ELIMINATION},
239         {"compiler-opt-later-elimination", required_argument, nullptr, OPTION_COMPILER_OPT_LATER_ELIMINATION},
240         {"compiler-opt-instr-combine", required_argument, nullptr, OPTION_COMPILER_OPT_INSTRUCTIONE_COMBINE},
241         {"compiler-opt-string", required_argument, nullptr, OPTION_COMPILER_OPT_STRING},
242         {"compiler-opt-value-numbering", required_argument, nullptr, OPTION_COMPILER_OPT_VALUE_NUMBERING},
243         {"compiler-opt-new-value-numbering", required_argument, nullptr, OPTION_COMPILER_OPT_NEW_VALUE_NUMBERING},
244         {"compiler-opt-inlining", required_argument, nullptr, OPTION_COMPILER_OPT_INLINING},
245         {"compiler-empty-catch-function", required_argument, nullptr, OPTION_COMPILER_EMPTY_CATCH_FUNCTION},
246         {"compiler-opt-pgotype", required_argument, nullptr, OPTION_COMPILER_OPT_PGOTYPE},
247         {"compiler-opt-track-field", required_argument, nullptr, OPTION_COMPILER_OPT_TRACK_FIELD},
248         {"entry-point", required_argument, nullptr, OPTION_ENTRY_POINT},
249         {"force-full-gc", required_argument, nullptr, OPTION_FORCE_FULL_GC},
250         {"force-shared-gc-frequency", required_argument, nullptr, OPTION_ENABLE_FORCE_SHARED_GC_FREQUENCY},
251         {"gc-thread-num", required_argument, nullptr, OPTION_GC_THREADNUM},
252         {"heap-size-limit", required_argument, nullptr, OPTION_HEAP_SIZE_LIMIT},
253         {"help", no_argument, nullptr, OPTION_HELP},
254         {"icu-data-path", required_argument, nullptr, OPTION_ICU_DATA_PATH},
255         {"enable-worker", required_argument, nullptr, OPTION_ENABLE_WORKER},
256         {"log-components", required_argument, nullptr, OPTION_LOG_COMPONENTS},
257         {"log-debug", required_argument, nullptr, OPTION_LOG_DEBUG},
258         {"log-error", required_argument, nullptr, OPTION_LOG_ERROR},
259         {"log-fatal", required_argument, nullptr, OPTION_LOG_FATAL},
260         {"log-info", required_argument, nullptr, OPTION_LOG_INFO},
261         {"log-level", required_argument, nullptr, OPTION_LOG_LEVEL},
262         {"log-warning", required_argument, nullptr, OPTION_LOG_WARNING},
263         {"gc-long-paused-time", required_argument, nullptr, OPTION_GC_LONG_PAUSED_TIME},
264         {"compiler-opt-max-method", required_argument, nullptr, OPTION_COMPILER_OPT_MAX_METHOD},
265         {"compiler-module-methods", required_argument, nullptr, OPTION_COMPILER_MODULE_METHODS},
266         {"max-unmovable-space", required_argument, nullptr, OPTION_MAX_UNMOVABLE_SPACE},
267         {"merge-abc", required_argument, nullptr, OPTION_MERGE_ABC},
268         {"enable-context", required_argument, nullptr, OPTION_ENABLE_CONTEXT},
269         {"compiler-opt-level", required_argument, nullptr, OPTION_ASM_OPT_LEVEL},
270         {"reloc-mode", required_argument, nullptr, OPTION_RELOCATION_MODE},
271         {"serializer-buffer-size-limit", required_argument, nullptr, OPTION_SERIALIZER_BUFFER_SIZE_LIMIT},
272         {"startup-time", required_argument, nullptr, OPTION_STARTUP_TIME},
273         {"stub-file", required_argument, nullptr, OPTION_STUB_FILE},
274         {"compiler-target-triple", required_argument, nullptr, OPTION_COMPILER_TARGET_TRIPLE},
275         {"enable-print-execute-time", required_argument, nullptr, OPTION_PRINT_EXECUTE_TIME},
276         {"enable-pgo-profiler", required_argument, nullptr, OPTION_ENABLE_PGO_PROFILER},
277         {"enable-elements-kind", required_argument, nullptr, OPTION_ENABLE_ELEMENTSKIND},
278         {"compiler-pgo-profiler-path", required_argument, nullptr, OPTION_COMPILER_PGO_PROFILER_PATH},
279         {"compiler-pgo-hotness-threshold", required_argument, nullptr, OPTION_COMPILER_PGO_HOTNESS_THRESHOLD},
280         {"compiler-pgo-save-min-interval", required_argument, nullptr, OPTION_COMPILER_PGO_SAVE_MIN_INTERVAL},
281         {"compiler-baseline-pgo", required_argument, nullptr, OPTION_COMPILER_BASELINE_PGO},
282         {"compiler-verify-vtable", required_argument, nullptr, OPTION_COMPILER_VERIFY_VTABLE},
283         {"compiler-select-methods", required_argument, nullptr, OPTION_COMPILER_SELECT_METHODS},
284         {"compiler-skip-methods", required_argument, nullptr, OPTION_COMPILER_SKIP_METHODS},
285         {"target-compiler-mode", required_argument, nullptr, OPTION_TARGET_COMPILER_MODE},
286         {"hap-path", required_argument, nullptr, OPTION_HAP_PATH},
287         {"hap-abc-offset", required_argument, nullptr, OPTION_HAP_ABC_OFFSET},
288         {"hap-abc-size", required_argument, nullptr, OPTION_HAP_ABC_SIZE},
289         {"compiler-no-check", required_argument, nullptr, OPTION_COMPILER_NOCHECK},
290         {"compiler-pipeline-host-aot", required_argument, nullptr, OPTION_COMPILER_PIPELINE_HOST_AOT},
291         {"compiler-fast-compile", required_argument, nullptr, OPTION_FAST_AOT_COMPILE_MODE},
292         {"compiler-opt-loop-peeling", required_argument, nullptr, OPTION_COMPILER_OPT_LOOP_PEELING},
293         {"compiler-opt-array-onheap-check", required_argument, nullptr, OPTION_COMPILER_OPT_ON_HEAP_CHECK},
294         {"compiler-pkg-info", required_argument, nullptr, OPTION_COMPILER_PKG_INFO},
295         {"compiler-external-pkg-info", required_argument, nullptr, OPTION_COMPILER_EXTERNAL_PKG_INFO},
296         {"compiler-enable-external-pkg", required_argument, nullptr, OPTION_COMPILER_ENABLE_EXTERNAL_PKG},
297         {"compiler-framework-abc-path", required_argument, nullptr, OPTION_COMPILER_FRAMEWORK_ABC_PATH},
298         {"compiler-enable-lexenv-specialization", required_argument, nullptr,
299             OPTION_COMPILER_ENABLE_LEXENV_SPECIALIZATION},
300         {"compiler-enable-native-inline", required_argument, nullptr, OPTION_COMPILER_ENABLE_NATIVE_INLINE},
301         {"compiler-enable-lowering-builtin", required_argument, nullptr, OPTION_COMPILER_ENABLE_LOWERING_BUILTIN},
302         {"compiler-enable-litecg", required_argument, nullptr, OPTION_COMPILER_ENABLE_LITECG},
303         {"compiler-enable-jit", required_argument, nullptr, OPTION_COMPILER_ENABLE_JIT},
304         {"compiler-enable-osr", required_argument, nullptr, OPTION_COMPILER_ENABLE_OSR},
305         {"compiler-trace-jit", required_argument, nullptr, OPTION_COMPILER_TRACE_JIT},
306         {"compiler-jit-hotness-threshold", required_argument, nullptr, OPTION_COMPILER_JIT_HOTNESS_THRESHOLD},
307         {"compiler-jit-call-threshold", required_argument, nullptr, OPTION_COMPILER_JIT_CALL_THRESHOLD},
308         {"compiler-osr-hotness-threshold", required_argument, nullptr, OPTION_COMPILER_OSR_HOTNESS_THRESHOLD},
309         {"compiler-force-jit-compile-main", required_argument, nullptr, OPTION_COMPILER_FORCE_JIT_COMPILE_MAIN},
310         {"compiler-enable-jit-pgo", required_argument, nullptr, OPTION_COMPILER_ENABLE_JIT_PGO},
311         {"compiler-enable-aot-pgo", required_argument, nullptr, OPTION_COMPILER_ENABLE_AOT_PGO},
312         {"compiler-enable-framework-aot", required_argument, nullptr, OPTION_COMPILER_ENABLE_FRAMEWORK_AOT},
313         {"compiler-enable-profile-dump", required_argument, nullptr, OPTION_COMPILER_ENABLE_PROPFILE_DUMP},
314         {"compiler-typed-op-profiler", required_argument, nullptr, OPTION_COMPILER_TYPED_OP_PROFILER},
315         {"compiler-opt-branch-profiling", required_argument, nullptr, OPTION_COMPILER_OPT_BRANCH_PROFILING},
316         {"test-assert", required_argument, nullptr, OPTION_TEST_ASSERT},
317         {"compiler-methods-range", required_argument, nullptr, OPTION_COMPILER_METHODS_RANGE},
318         {"compiler-codegen-options", required_argument, nullptr, OPTION_COMPILER_CODEGEN_OPT},
319         {"compiler-opt-escape-analysis", required_argument, nullptr, OPTION_COMPILER_OPT_ESCAPE_ANALYSIS},
320         {"compiler-trace-escape-analysis", required_argument, nullptr, OPTION_COMPILER_TRACE_ESCAPE_ANALYSIS},
321         {"compiler-opt-induction-variable", required_argument, nullptr, OPTION_COMPILER_OPT_INDUCTION_VARIABLE},
322         {"compiler-trace-induction-variable", required_argument, nullptr, OPTION_COMPILER_TRACE_INDUCTION_VARIABLE},
323         {"compiler-memory-analysis", required_argument, nullptr, OPTION_COMPILER_MEMORY_ANALYSIS},
324         {"compiler-check-pgo-version", required_argument, nullptr, OPTION_COMPILER_CHECK_PGO_VERSION},
325         {"compiler-enable-baselinejit", required_argument, nullptr, OPTION_COMPILER_ENABLE_BASELINEJIT},
326         {"compiler-baselinejit-hotness-threshold", required_argument, nullptr, OPTION_COMPILER_BASELINEJIT_HOTNESS_THRESHOLD},
327         {"compiler-force-baselinejit-compile-main", required_argument, nullptr, OPTION_COMPILER_FORCE_BASELINEJIT_COMPILE_MAIN},
328         {"compiler-enable-jit-fast-compile", required_argument, nullptr, OPTION_COMPILER_ENABLE_JIT_FAST_COMPILE},
329         {"compiler-enable-jitfort", required_argument, nullptr, OPTION_ENABLE_JITFORT},
330         {"compiler-codesign-disable", required_argument, nullptr, OPTION_CODESIGN_DISABLE},
331         {"compiler-enable-async-copytofort", required_argument, nullptr, OPTION_ENABLE_ASYNC_COPYTOFORT},
332         {"compiler-pgo-force-dump", required_argument, nullptr, OPTION_COMPILER_PGO_FORCE_DUMP},
333         {"async-load-abc", required_argument, nullptr, OPTION_ASYNC_LOAD_ABC},
334         {"async-load-abc-test", required_argument, nullptr, OPTION_ASYNC_LOAD_ABC_TEST},
335         {"compiler-enable-concurrent", required_argument, nullptr, OPTION_COMPILER_ENABLE_CONCURRENT},
336         {"compiler-opt-frame-state-elimination", required_argument, nullptr,
337             OPTION_COMPILER_OPT_FRAME_STATE_ELIMINATION},
338         {nullptr, 0, nullptr, 0},
339     };
340 
341     int index = 0;
342     opterr = 0;
343     bool ret = false;
344     int option = 0;
345     arg_list_t argListStr;
346     uint32_t argUint32 = 0;
347     uint64_t argUInt64 = 0;
348     int argInt = 0;
349     bool argBool = false;
350     double argDouble = 0.0;
351     static std::string COLON = ":";
352 
353     if (argc <= 1) {
354         return true;
355     }
356 
357     while (true) {
358         option = getopt_long_only(argc, const_cast<char **>(argv), "", longOptions, &index);
359         LOG_ECMA(INFO) << "option: " << option << ", optopt: " << optopt << ", optind: " << optind;
360 
361         if (optind <= 0 || optind > argc) {
362             return false;
363         }
364 
365         if (option == -1) {
366             return true;
367         }
368 
369         // unknown option or required_argument option has no argument
370         if (option == OPTION_DEFAULT) {
371             ret = SetDefaultValue(const_cast<char *>(argv[optind - 1]));
372             if (ret) {
373                 continue;
374             } else {
375                 return ret;
376             }
377         }
378 
379         WasSet(option);
380         switch (option) {
381             case OPTION_AOT_FILE:
382                 SetAOTOutputFile(optarg);
383                 ecmascript::AnFileDataManager::GetInstance()->SetEnable(true);
384                 break;
385             case OPTION_ARK_PROPERTIES:
386                 ret = ParseIntParam("ark-properties", &argInt);
387                 if (ret) {
388                     SetArkProperties(argInt);
389                 } else {
390                     return false;
391                 }
392                 break;
393             case OPTION_ARK_BUNDLENAME:
394                 SetArkBundleName(optarg);
395                 break;
396             case OPTION_ENABLE_ASM_INTERPRETER:
397                 ret = ParseBoolParam(&argBool);
398                 if (ret) {
399                     SetEnableAsmInterpreter(argBool);
400                 } else {
401                     return false;
402                 }
403                 break;
404             case OPTION_ASM_OPCODE_DISABLE_RANGE:
405                 SetAsmOpcodeDisableRange(optarg);
406                 break;
407             case OPTION_ENABLE_BUILTINS_LAZY:
408                 ret = ParseBoolParam(&argBool);
409                 if (ret) {
410                     SetEnableBuiltinsLazy(argBool);
411                 } else {
412                     return false;
413                 }
414                 break;
415             case OPTION_COMPILER_LOG_OPT:
416                 SetCompilerLogOption(optarg);
417                 break;
418             case OPTION_COMPILER_LOG_SNAPSHOT:
419                 ret = ParseBoolParam(&argBool);
420                 if (ret) {
421                     SetCompilerLogSnapshot(argBool);
422                 } else {
423                     return false;
424                 }
425                 break;
426             case OPTION_COMPILER_LOG_TIME:
427                 ret = ParseBoolParam(&argBool);
428                 if (ret) {
429                     SetCompilerLogTime(argBool);
430                 } else {
431                     return false;
432                 }
433                 break;
434             case OPTION_ENABLE_ARK_TOOLS:
435                 ret = ParseBoolParam(&argBool);
436                 if (ret) {
437                     SetEnableArkTools(argBool);
438                 } else {
439                     return false;
440                 }
441                 break;
442             case OPTION_OPEN_ARK_TOOLS:
443                 ret = ParseBoolParam(&argBool);
444                 if (ret) {
445                     SetOpenArkTools(argBool);
446                 } else {
447                     return false;
448                 }
449                 break;
450             case OPTION_PGO_TRACE:
451                 ret = ParseBoolParam(&argBool);
452                 if (ret) {
453                     SetPGOTrace(argBool);
454                 } else {
455                     return false;
456                 }
457                 break;
458             case OPTION_COMPILER_TRACE_BC:
459                 ret = ParseBoolParam(&argBool);
460                 if (ret) {
461                     SetTraceBc(argBool);
462                 } else {
463                     return false;
464                 }
465                 break;
466             case OPTION_COMPILER_TRACE_DEOPT:
467                 ret = ParseBoolParam(&argBool);
468                 if (ret) {
469                     SetTraceDeopt(argBool);
470                 } else {
471                     return false;
472                 }
473                 break;
474             case OPTION_COMPILER_TRACE_INLINE:
475                 ret = ParseBoolParam(&argBool);
476                 if (ret) {
477                     SetTraceInline(argBool);
478                 } else {
479                     return false;
480                 }
481                 break;
482             case OPTION_COMPILER_TRACE_VALUE_NUMBERING:
483                 ret = ParseBoolParam(&argBool);
484                 if (ret) {
485                     SetTraceValueNumbering(argBool);
486                 } else {
487                     return false;
488                 }
489                 break;
490             case OPTION_COMPILER_TRACE_INSTRUCTION_COMBINE:
491                 ret = ParseBoolParam(&argBool);
492                 if (ret) {
493                     SetTraceInstructionCombine(argBool);
494                 } else {
495                     return false;
496                 }
497                 break;
498             case OPTION_COMPILER_MAX_INLINE_BYTECODES:
499                 ret = ParseUint32Param("max-inline-bytecodes", &argUint32);
500                 if (ret) {
501                     SetMaxInlineBytecodes(argUint32);
502                 } else {
503                     return false;
504                 }
505                 break;
506             case OPTION_COMPILER_DEOPT_THRESHOLD:
507                 ret = ParseUint32Param("deopt-threshol", &argUint32);
508                 if (ret) {
509                     SetDeoptThreshold(argUint32);
510                 } else {
511                     return false;
512                 }
513                 break;
514             case OPTION_COMPILER_DEVICE_STATE:
515                 ret = ParseBoolParam(&argBool);
516                 if (ret) {
517                     SetDeviceState(argBool);
518                 } else {
519                     return false;
520                 }
521                 break;
522             case OPTION_COMPILER_STRESS_DEOPT:
523                 ret = ParseBoolParam(&argBool);
524                 if (ret) {
525                     SetStressDeopt(argBool);
526                 } else {
527                     return false;
528                 }
529                 break;
530             case OPTION_COMPILER_OPT_CODE_PROFILER:
531                 ret = ParseBoolParam(&argBool);
532                 if (ret) {
533                     SetOptCodeProfiler(argBool);
534                 } else {
535                     return false;
536                 }
537                 break;
538             case OPTION_COMPILER_OPT_BC_RANGE:
539                 SetOptCodeRange(optarg);
540                 break;
541             case OPTION_COMPILER_OPT_BC_RANGE_HELP:
542                 ret = ParseBoolParam(&argBool);
543                 if (ret) {
544                     std::string helpInfo = kungfu::GetHelpForEcmaCodeListForRange();
545                     LOG_COMPILER(ERROR) << helpInfo.c_str();
546                     exit(1);
547                 }
548                 break;
549             case OPTION_ENABLE_FORCE_GC:
550                 ret = ParseBoolParam(&argBool);
551                 if (ret) {
552                     SetEnableForceGC(argBool);
553                 } else {
554                     return false;
555                 }
556                 break;
557             case OPTION_ENABLE_EDEN_GC:
558                 ret = ParseBoolParam(&argBool);
559                 if (ret) {
560                     SetEnableEdenGC(argBool);
561                 } else {
562                     return false;
563                 }
564                 break;
565             case OPTION_FORCE_FULL_GC:
566                 ret = ParseBoolParam(&argBool);
567                 if (ret) {
568                     SetForceFullGC(argBool);
569                 } else {
570                     return false;
571                 }
572                 break;
573             case OPTION_ENABLE_FORCE_SHARED_GC_FREQUENCY:
574                 ret = ParseUint32Param("force-shared-gc-frequency", &argUint32);
575                 if (ret) {
576                     SetForceSharedGCFrequency(argUint32);
577                 } else {
578                     return false;
579                 }
580                 break;
581             case OPTION_ENABLE_IC:
582                 ret = ParseBoolParam(&argBool);
583                 if (ret) {
584                     SetEnableIC(argBool);
585                 } else {
586                     return false;
587                 }
588                 break;
589             case OPTION_ENABLE_RUNTIME_STAT:
590                 ret = ParseBoolParam(&argBool);
591                 if (ret) {
592                     SetEnableRuntimeStat(argBool);
593                 } else {
594                     return false;
595                 }
596                 break;
597             case OPTION_GC_THREADNUM:
598                 ret = ParseUint32Param("gc-thread-num", &argUint32);
599                 if (ret) {
600                     SetGcThreadNum(argUint32);
601                 } else {
602                     return false;
603                 }
604                 break;
605             case OPTION_HEAP_SIZE_LIMIT:
606                 ret = ParseUint32Param("heap-size-limit", &argUint32);
607                 if (ret) {
608                     SetHeapSizeLimit(argUint32);
609                 } else {
610                     return false;
611                 }
612                 break;
613             case OPTION_HELP:
614                 return false;
615             case OPTION_ICU_DATA_PATH:
616                 SetIcuDataPath(optarg);
617                 break;
618             case OPTION_ENABLE_WORKER:
619                 ret = ParseBoolParam(&argBool);
620                 if (ret) {
621                     SetIsWorker(argBool);
622                 } else {
623                     return false;
624                 }
625                 break;
626             case OPTION_LOG_COMPONENTS:
627                 ParseListArgParam(optarg, &argListStr, COLON);
628                 SetLogComponents(argListStr);
629                 break;
630             case OPTION_LOG_DEBUG:
631                 ParseListArgParam(optarg, &argListStr, COLON);
632                 SetLogDebug(argListStr);
633                 break;
634             case OPTION_LOG_ERROR:
635                 ParseListArgParam(optarg, &argListStr, COLON);
636                 SetLogError(argListStr);
637                 break;
638             case OPTION_LOG_FATAL:
639                 ParseListArgParam(optarg, &argListStr, COLON);
640                 SetLogFatal(argListStr);
641                 break;
642             case OPTION_LOG_INFO:
643                 ParseListArgParam(optarg, &argListStr, COLON);
644                 SetLogInfo(argListStr);
645                 break;
646             case OPTION_LOG_LEVEL:
647                 SetLogLevel(optarg);
648                 break;
649             case OPTION_LOG_WARNING:
650                 ParseListArgParam(optarg, &argListStr, COLON);
651                 SetLogWarning(argListStr);
652                 break;
653             case OPTION_GC_LONG_PAUSED_TIME:
654                 ret = ParseUint32Param("gc-long-paused-time", &argUint32);
655                 if (ret) {
656                     SetLongPauseTime(argUint32);
657                 } else {
658                     return false;
659                 }
660                 break;
661             case OPTION_COMPILER_OPT_MAX_METHOD:
662                 ret = ParseUint32Param("compiler-opt-max-method", &argUint32);
663                 if (ret) {
664                     SetMaxAotMethodSize(argUint32);
665                 } else {
666                     return false;
667                 }
668                 break;
669             case OPTION_COMPILER_MODULE_METHODS:
670                 ret = ParseUint32Param("compiler-module-methods", &argUint32);
671                 if (!ret) {
672                     return false;
673                 }
674                 SetCompilerModuleMethods(argUint32);
675                 break;
676             case OPTION_COMPILER_TYPE_THRESHOLD:
677                 ret = ParseDoubleParam("compiler-type-threshold", &argDouble);
678                 if (ret) {
679                     SetTypeThreshold(argDouble);
680                 } else {
681                     return false;
682                 }
683                 break;
684             case OPTION_MAX_UNMOVABLE_SPACE:
685                 ret = ParseUint32Param("max-unmovable-space", &argUint32);
686                 if (ret) {
687                     SetMaxNonmovableSpaceCapacity(argUint32);
688                 } else {
689                     return false;
690                 }
691                 break;
692             case OPTION_COMPILER_LOG_METHODS:
693                 SetMethodsListForLog(optarg);
694                 break;
695             case OPTION_ASM_OPT_LEVEL:
696                 ret = ParseUint32Param("compiler-opt-level", &argUint32);
697                 if (ret) {
698                     SetOptLevel(argUint32);
699                 } else {
700                     return false;
701                 }
702                 break;
703             case OPTION_PRINT_EXECUTE_TIME:
704                 ret = ParseBoolParam(&argBool);
705                 if (ret) {
706                     SetEnablePrintExecuteTime(argBool);
707                 } else {
708                     return false;
709                 }
710                 break;
711             case OPTION_ENABLE_PGO_PROFILER:
712                 ret = ParseBoolParam(&argBool);
713                 if (ret) {
714                     SetEnablePGOProfiler(argBool);
715                 } else {
716                     return false;
717                 }
718                 break;
719             case OPTION_ENABLE_ELEMENTSKIND:
720                 ret = ParseBoolParam(&argBool);
721                 if (ret) {
722                     SetEnableElementsKind(argBool);
723                 } else {
724                     return false;
725                 }
726                 break;
727             case OPTION_COMPILER_PGO_PROFILER_PATH:
728                 if (*optarg == '\0') {
729                     return false;
730                 }
731                 SetPGOProfilerPath(optarg);
732                 break;
733             case OPTION_COMPILER_PGO_HOTNESS_THRESHOLD:
734                 ret = ParseUint32Param("pgo-hotness-threshold", &argUint32);
735                 if (ret) {
736                     SetPGOHotnessThreshold(argUint32);
737                 } else {
738                     return false;
739                 }
740                 break;
741             case OPTION_COMPILER_PGO_SAVE_MIN_INTERVAL:
742                 ret = ParseUint32Param("compiler-pgo-save-min-interval", &argUint32);
743                 if (ret) {
744                     SetPGOSaveMinInterval(argUint32);
745                 } else {
746                     return false;
747                 }
748                 break;
749             case OPTION_COMPILER_BASELINE_PGO:
750                 ret = ParseBoolParam(&argBool);
751                 if (ret) {
752                     SetEnableBaselinePgo(argBool);
753                 } else {
754                     return false;
755                 }
756                 break;
757             case OPTION_RELOCATION_MODE:
758                 ret = ParseUint32Param("reloc-mode", &argUint32);
759                 if (ret) {
760                     SetRelocMode(argUint32);
761                 } else {
762                     return false;
763                 }
764                 break;
765             case OPTION_SERIALIZER_BUFFER_SIZE_LIMIT:
766                 ret = ParseUint64Param("serializer-buffer-size-limit", &argUInt64);
767                 if (ret) {
768                     SetSerializerBufferSizeLimit(argUInt64);
769                 } else {
770                     return false;
771                 }
772                 break;
773             case OPTION_STARTUP_TIME:
774                 ret = ParseBoolParam(&argBool);
775                 if (ret) {
776                     SetStartupTime(argBool);
777                 } else {
778                     return false;
779                 }
780                 break;
781             case OPTION_STUB_FILE:
782                 SetStubFile(optarg);
783                 break;
784             case OPTION_COMPILER_TARGET_TRIPLE:
785                 SetTargetTriple(optarg);
786                 break;
787             case OPTION_ENTRY_POINT:
788                 SetEntryPoint(optarg);
789                 break;
790             case OPTION_MERGE_ABC:
791                 ret = ParseBoolParam(&argBool);
792                 if (ret) {
793                     SetMergeAbc(argBool);
794                 } else {
795                     return false;
796                 }
797                 break;
798             case OPTION_ENABLE_CONTEXT:
799                 ret = ParseBoolParam(&argBool);
800                 if (ret) {
801                     SetEnableContext(argBool);
802                 } else {
803                     return false;
804                 }
805                 break;
806             case OPTION_COMPILER_OPT_TYPE_LOWERING:
807                 ret = ParseBoolParam(&argBool);
808                 if (ret) {
809                     SetEnableTypeLowering(argBool);
810                 } else {
811                     return false;
812                 }
813                 break;
814             case OPTION_COMPILER_OPT_ARRAY_BOUNDS_CHECK_ELIMINATION:
815                 ret = ParseBoolParam(&argBool);
816                 if (ret) {
817                     SetEnableArrayBoundsCheckElimination(argBool);
818                 } else {
819                     return false;
820                 }
821                 break;
822             case OPTION_COMPILER_OPT_FRAME_STATE_ELIMINATION:
823                 ret = ParseBoolParam(&argBool);
824                 if (ret) {
825                     SetEnableFrameStateElimination(argBool);
826                 } else {
827                     return false;
828                 }
829                 break;
830             case OPTION_COMPILER_OPT_EARLY_ELIMINATION:
831                 ret = ParseBoolParam(&argBool);
832                 if (ret) {
833                     SetEnableEarlyElimination(argBool);
834                 } else {
835                     return false;
836                 }
837                 break;
838             case OPTION_COMPILER_OPT_LATER_ELIMINATION:
839                 ret = ParseBoolParam(&argBool);
840                 if (ret) {
841                     SetEnableLaterElimination(argBool);
842                 } else {
843                     return false;
844                 }
845                 break;
846             case OPTION_COMPILER_EMPTY_CATCH_FUNCTION:
847                 ret = ParseBoolParam(&argBool);
848                 if (ret) {
849                     SetEnableEmptyCatchFunction(argBool);
850                 } else {
851                     return false;
852                 }
853                 break;
854             case OPTION_COMPILER_OPT_INSTRUCTIONE_COMBINE:
855                 ret = ParseBoolParam(&argBool);
856                 if (ret) {
857                     SetEnableInstrcutionCombine(argBool);
858                 } else {
859                     return false;
860                 }
861                 break;
862             case OPTION_COMPILER_OPT_STRING:
863                 ret = ParseBoolParam(&argBool);
864                 if (ret) {
865                     SetEnableOptString(argBool);
866                 } else {
867                     return false;
868                 }
869                 break;
870             case OPTION_COMPILER_OPT_VALUE_NUMBERING:
871                 ret = ParseBoolParam(&argBool);
872                 if (ret) {
873                     SetEnableValueNumbering(argBool);
874                 } else {
875                     return false;
876                 }
877                 break;
878             case OPTION_COMPILER_OPT_NEW_VALUE_NUMBERING:
879                 ret = ParseBoolParam(&argBool);
880                 if (ret) {
881                     SetEnableNewValueNumbering(argBool);
882                 } else {
883                     return false;
884                 }
885                 break;
886             case OPTION_COMPILER_OPT_INLINING:
887                 ret = ParseBoolParam(&argBool);
888                 if (ret) {
889                     SetEnableOptInlining(argBool);
890                 } else {
891                     return false;
892                 }
893                 break;
894             case OPTION_COMPILER_OPT_PGOTYPE:
895                 ret = ParseBoolParam(&argBool);
896                 if (ret) {
897                     SetEnableOptPGOType(argBool);
898                 } else {
899                     return false;
900                 }
901                 break;
902             case OPTION_COMPILER_OPT_TRACK_FIELD:
903                 ret = ParseBoolParam(&argBool);
904                 if (ret) {
905                     SetEnableOptTrackField(argBool);
906                 } else {
907                     return false;
908                 }
909                 break;
910             case OPTION_COMPILER_VERIFY_VTABLE:
911                 ret = ParseBoolParam(&argBool);
912                 if (ret) {
913                     SetVerifyVTable(argBool);
914                 } else {
915                     return false;
916                 }
917                 break;
918             case OPTION_COMPILER_SELECT_METHODS:
919                 SetCompilerSelectMethods(optarg);
920                 break;
921             case OPTION_COMPILER_SKIP_METHODS:
922                 SetCompilerSkipMethods(optarg);
923                 break;
924             case OPTION_TARGET_COMPILER_MODE:
925                 SetTargetCompilerMode(optarg);
926                 break;
927             case OPTION_COMPILER_FRAMEWORK_ABC_PATH:
928                 SetCompilerFrameworkAbcPath(optarg);
929                 break;
930             case OPTION_HAP_PATH:
931                 SetHapPath(optarg);
932                 break;
933             case OPTION_HAP_ABC_OFFSET:
934                 ret = ParseUint32Param("hap-abc-offset", &argUint32);
935                 if (!ret) {
936                     return false;
937                 }
938                 SetHapAbcOffset(argUint32);
939                 break;
940             case OPTION_HAP_ABC_SIZE:
941                 ret = ParseUint32Param("hap-abc-size", &argUint32);
942                 if (!ret) {
943                     return false;
944                 }
945                 SetHapAbcSize(argUint32);
946                 break;
947             case OPTION_COMPILER_NOCHECK:
948                 ret = ParseBoolParam(&argBool);
949                 if (!ret) {
950                     return false;
951                 }
952                 SetCompilerNoCheck(argBool);
953                 break;
954             case OPTION_COMPILER_PIPELINE_HOST_AOT:
955                 ret = ParseBoolParam(&argBool);
956                 if (!ret) {
957                     return false;
958                 }
959                 SetCompilerPipelineHostAOT(argBool);
960                 break;
961             case OPTION_FAST_AOT_COMPILE_MODE:
962                 ret = ParseBoolParam(&argBool);
963                 if (!ret) {
964                     return false;
965                 }
966                 SetFastAOTCompileMode(argBool);
967                 break;
968             case OPTION_COMPILER_OPT_CONSTANT_FOLDING:
969                 ret = ParseBoolParam(&argBool);
970                 if (ret) {
971                     SetEnableOptConstantFolding(argBool);
972                 } else {
973                     return false;
974                 }
975                 break;
976             case OPTION_COMPILER_OPT_LOOP_PEELING:
977                 ret = ParseBoolParam(&argBool);
978                 if (ret) {
979                     SetEnableOptLoopPeeling(argBool);
980                 } else {
981                     return false;
982                 }
983                 break;
984             case OPTION_COMPILER_OPT_ON_HEAP_CHECK:
985                 ret = ParseBoolParam(&argBool);
986                 if (ret) {
987                     SetEnableOptOnHeapCheck(argBool);
988                 } else {
989                     return false;
990                 }
991                 break;
992             case OPTION_COMPILER_PKG_INFO:
993                 SetCompilerPkgJsonInfo(optarg);
994                 break;
995             case OPTION_COMPILER_EXTERNAL_PKG_INFO:
996                 SetCompilerExternalPkgJsonInfo(optarg);
997                 break;
998             case OPTION_COMPILER_ENABLE_EXTERNAL_PKG:
999                 ret = ParseBoolParam(&argBool);
1000                 if (ret) {
1001                     SetCompilerEnableExternalPkg(argBool);
1002                 } else {
1003                     return false;
1004                 }
1005                 break;
1006             case OPTION_COMPILER_ENABLE_LEXENV_SPECIALIZATION:
1007                 ret = ParseBoolParam(&argBool);
1008                 if (ret) {
1009                     SetEnableLexenvSpecialization(argBool);
1010                 } else {
1011                     return false;
1012                 }
1013                 break;
1014             case OPTION_COMPILER_ENABLE_NATIVE_INLINE:
1015                 ret = ParseBoolParam(&argBool);
1016                 if (ret) {
1017                     SetEnableNativeInline(argBool);
1018                 } else {
1019                     return false;
1020                 }
1021                 break;
1022             case OPTION_COMPILER_ENABLE_LOWERING_BUILTIN:
1023                 ret = ParseBoolParam(&argBool);
1024                 if (ret) {
1025                     SetEnableLoweringBuiltin(argBool);
1026                 } else {
1027                     return false;
1028                 }
1029                 break;
1030             case OPTION_COMPILER_ENABLE_LITECG:
1031                 ret = ParseBoolParam(&argBool);
1032                 if (ret) {
1033                     SetCompilerEnableLiteCG(argBool);
1034                 } else {
1035                     return false;
1036                 }
1037                 break;
1038             case OPTION_COMPILER_ENABLE_JIT:
1039                 ret = ParseBoolParam(&argBool);
1040                 if (ret) {
1041                     SetEnableJIT(argBool);
1042                 } else {
1043                     return false;
1044                 }
1045                 break;
1046             case OPTION_COMPILER_ENABLE_OSR:
1047                 ret = ParseBoolParam(&argBool);
1048                 if (ret) {
1049                     SetEnableOSR(argBool);
1050                 } else {
1051                     return false;
1052                 }
1053                 break;
1054             case OPTION_COMPILER_JIT_HOTNESS_THRESHOLD:
1055                 ret = ParseUint32Param("compiler-jit-hotness-threshold", &argUint32);
1056                 if (ret) {
1057                     uint16_t val = argUint32 > std::numeric_limits<uint16_t>::max() ?
1058                         std::numeric_limits<uint16_t>::max() : static_cast<uint16_t>(argUint32);
1059                     SetJitHotnessThreshold(val);
1060                 } else {
1061                     return false;
1062                 }
1063                 break;
1064             case OPTION_COMPILER_JIT_CALL_THRESHOLD:
1065                 ret = ParseUint32Param("compiler-jit-call-threshold", &argUint32);
1066                 if (ret) {
1067                     uint8_t val =  argUint32 > std::numeric_limits<uint8_t>::max() ?
1068                         std::numeric_limits<uint8_t>::max() : static_cast<uint8_t>(argUint32);
1069                     SetJitCallThreshold(val);
1070                 } else {
1071                     return false;
1072                 }
1073                 break;
1074             case OPTION_COMPILER_OSR_HOTNESS_THRESHOLD:
1075                 ret = ParseUint32Param("compiler-osr-hotness-threshold", &argUint32);
1076                 if (ret) {
1077                     uint16_t val = argUint32 > std::numeric_limits<uint16_t>::max() ?
1078                         std::numeric_limits<uint16_t>::max() : static_cast<uint16_t>(argUint32);
1079                     SetOsrHotnessThreshold(val);
1080                 } else {
1081                     return false;
1082                 }
1083                 break;
1084             case OPTION_COMPILER_FORCE_JIT_COMPILE_MAIN:
1085                 ret = ParseBoolParam(&argBool);
1086                 if (ret) {
1087                     SetForceJitCompileMain(argBool);
1088                 } else {
1089                     return false;
1090                 }
1091                 break;
1092             case OPTION_COMPILER_TRACE_JIT:
1093                 ret = ParseBoolParam(&argBool);
1094                 if (ret) {
1095                     SetTraceJIT(argBool);
1096                 } else {
1097                     return false;
1098                 }
1099                 break;
1100             case OPTION_COMPILER_TYPED_OP_PROFILER:
1101                 ret = ParseBoolParam(&argBool);
1102                 if (ret) {
1103                     SetTypedOpProfiler(argBool);
1104                 } else {
1105                     return false;
1106                 }
1107                 break;
1108             case OPTION_COMPILER_OPT_BRANCH_PROFILING:
1109                 ret = ParseBoolParam(&argBool);
1110                 if (ret) {
1111                     SetEnableBranchProfiling(argBool);
1112                 } else {
1113                     return false;
1114                 }
1115                 break;
1116             case OPTION_COMPILER_ENABLE_JIT_PGO:
1117                 ret = ParseBoolParam(&argBool);
1118                 if (ret) {
1119                     SetEnableJITPGO(argBool);
1120                 } else {
1121                     return false;
1122                 }
1123                 break;
1124             case OPTION_COMPILER_ENABLE_PROPFILE_DUMP:
1125                 ret = ParseBoolParam(&argBool);
1126                 if (ret) {
1127                     SetEnableProfileDump(argBool);
1128                 } else {
1129                     return false;
1130                 }
1131                 break;
1132             case OPTION_COMPILER_ENABLE_AOT_PGO:
1133                 ret = ParseBoolParam(&argBool);
1134                 if (ret) {
1135                     SetEnableAOTPGO(argBool);
1136                 } else {
1137                     return false;
1138                 }
1139                 break;
1140             case OPTION_COMPILER_ENABLE_FRAMEWORK_AOT:
1141                 ret = ParseBoolParam(&argBool);
1142                 if (ret) {
1143                     SetEnableFrameworkAOT(argBool);
1144                 } else {
1145                     return false;
1146                 }
1147                 break;
1148             case OPTION_COMPILER_ENABLE_BASELINEJIT:
1149                 ret = ParseBoolParam(&argBool);
1150                 if (ret) {
1151                     SetEnableBaselineJIT(argBool);
1152                 } else {
1153                     return false;
1154                 }
1155                 break;
1156             case OPTION_COMPILER_METHODS_RANGE:
1157                 ParseListArgParam(optarg, &argListStr, COLON);
1158                 SetCompilerMethodsRange(&argListStr);
1159                 break;
1160             case OPTION_COMPILER_CODEGEN_OPT:
1161                 ParseListArgParam(optarg, &argListStr, " ");
1162                 SetCompilerCodegenOptions(argListStr);
1163                 break;
1164             case OPTION_TEST_ASSERT:
1165                 ret = ParseBoolParam(&argBool);
1166                 if (ret) {
1167                     SetTestAssert(argBool);
1168                 } else {
1169                     return false;
1170                 }
1171                 break;
1172             case OPTION_COMPILER_OPT_ESCAPE_ANALYSIS:
1173                 ret = ParseBoolParam(&argBool);
1174                 if (ret) {
1175                     SetEnableEscapeAnalysis(argBool);
1176                 } else {
1177                     return false;
1178                 }
1179                 break;
1180             case OPTION_COMPILER_TRACE_ESCAPE_ANALYSIS:
1181                 ret = ParseBoolParam(&argBool);
1182                 if (ret) {
1183                     SetEnableTraceEscapeAnalysis(argBool);
1184                 } else {
1185                     return false;
1186                 }
1187                 break;
1188             case OPTION_COMPILER_OPT_INDUCTION_VARIABLE:
1189                 ret = ParseBoolParam(&argBool);
1190                 if (ret) {
1191                     SetEnableInductionVariableAnalysis(argBool);
1192                 } else {
1193                     return false;
1194                 }
1195                 break;
1196             case OPTION_COMPILER_TRACE_INDUCTION_VARIABLE:
1197                 ret = ParseBoolParam(&argBool);
1198                 if (ret) {
1199                     SetEnableTraceInductionVariableAnalysis(argBool);
1200                 } else {
1201                     return false;
1202                 }
1203                 break;
1204             case OPTION_COMPILER_BASELINEJIT_HOTNESS_THRESHOLD:
1205                 ret = ParseUint32Param("compiler-baselinejit-hotness-threshold", &argUint32);
1206                 if (ret) {
1207                     uint16_t val = argUint32 > std::numeric_limits<uint16_t>::max() ?
1208                         std::numeric_limits<uint16_t>::max() : static_cast<uint16_t>(argUint32);
1209                     SetBaselineJitHotnessThreshold(val);
1210                 } else {
1211                     return false;
1212                 }
1213                 break;
1214             case OPTION_COMPILER_CHECK_PGO_VERSION:
1215                 ret = ParseBoolParam(&argBool);
1216                 if (ret) {
1217                     SetCheckPgoVersion(argBool);
1218                 } else {
1219                     return false;
1220                 }
1221                 break;
1222             case OPTION_COMPILER_FORCE_BASELINEJIT_COMPILE_MAIN:
1223                 ret = ParseBoolParam(&argBool);
1224                 if (ret) {
1225                     SetForceBaselineCompileMain(argBool);
1226                 } else {
1227                     return false;
1228                 }
1229                 break;
1230             case OPTION_COMPILER_ENABLE_JIT_FAST_COMPILE:
1231                 ret = ParseBoolParam(&argBool);
1232                 if (ret) {
1233                     SetEnableJitFastCompile(argBool);
1234                 } else {
1235                     return false;
1236                 }
1237                 break;
1238             case OPTION_ASYNC_LOAD_ABC:
1239                 ret = ParseBoolParam(&argBool);
1240                 if (ret) {
1241                     SetAsyncLoadAbc(argBool);
1242                 } else {
1243                     return false;
1244                 }
1245                 break;
1246             case OPTION_ASYNC_LOAD_ABC_TEST:
1247                 ret = ParseBoolParam(&argBool);
1248                 if (ret) {
1249                     SetAsyncLoadAbcTest(argBool);
1250                 } else {
1251                     return false;
1252                 }
1253                 break;
1254             case OPTION_ENABLE_JITFORT:
1255                 ret = ParseBoolParam(&argBool);
1256                 if (ret) {
1257                     SetEnableJitFort(argBool);
1258                 } else {
1259                     return false;
1260                 }
1261                 break;
1262             case OPTION_CODESIGN_DISABLE:
1263                 ret = ParseBoolParam(&argBool);
1264                 if (ret) {
1265                     SetDisableCodeSign(argBool);
1266                 } else {
1267                     return false;
1268                 }
1269                 break;
1270             case OPTION_ENABLE_ASYNC_COPYTOFORT:
1271                 ret = ParseBoolParam(&argBool);
1272                 if (ret) {
1273                     SetEnableAsyncCopyToFort(argBool);
1274                 } else {
1275                     return false;
1276                 }
1277                 break;
1278             case OPTION_COMPILER_ENABLE_CONCURRENT:
1279                 ret = ParseBoolParam(&argBool);
1280                 if (ret) {
1281                     SetConcurrentCompile(argBool);
1282                 } else {
1283                     return false;
1284                 }
1285                 break;
1286             case OPTION_COMPILER_PGO_FORCE_DUMP:
1287                 ret = ParseBoolParam(&argBool);
1288                 if (ret) {
1289                     SetPgoForceDump(argBool);
1290                 } else {
1291                     return false;
1292                 }
1293                 break;
1294             default:
1295                 LOG_ECMA(ERROR) << "Invalid option\n";
1296                 return false;
1297         }
1298     }
1299 }
1300 
SetDefaultValue(char * argv)1301 bool JSRuntimeOptions::SetDefaultValue(char* argv)
1302 {
1303     WasSet(optopt);
1304 
1305     if (optopt == OPTION_DEFAULT) { // unknown option
1306         LOG_ECMA(ERROR) << " Invalid option \"" << argv << "\"";
1307         return false;
1308     }
1309 
1310     if (optopt >= OPTION_LAST) { // unknown argument
1311         LOG_ECMA(ERROR) << "getopt: \"" << argv <<"\" argument has invalid parameter value \n";
1312         return false;
1313     }
1314     return true;
1315 }
1316 
ParseBoolParam(bool * argBool)1317 bool JSRuntimeOptions::ParseBoolParam(bool* argBool)
1318 {
1319     if ((strcmp(optarg, "false") == 0) || (strcmp(optarg, "0") == 0)) {
1320         *argBool = false;
1321     } else {
1322         *argBool = true;
1323     }
1324     return true;
1325 }
1326 
ParseDoubleParam(const std::string & option,double * argDouble)1327 bool JSRuntimeOptions::ParseDoubleParam(const std::string &option, double *argDouble)
1328 {
1329     *argDouble = std::stod(optarg, nullptr);
1330     if (errno == ERANGE) {
1331         LOG_ECMA(ERROR) << "getopt: \"" << option << "\" argument has invalid parameter value \"" << optarg <<"\"\n";
1332         return false;
1333     }
1334     return true;
1335 }
1336 
ParseIntParam(const std::string & option,int * argInt)1337 bool JSRuntimeOptions::ParseIntParam(const std::string &option, int *argInt)
1338 {
1339     if (StartsWith(optarg, "0x")) {
1340         const int HEX = 16;
1341         *argInt = std::stoi(optarg, nullptr, HEX);
1342     } else {
1343         *argInt = std::stoi(optarg);
1344     }
1345 
1346     if (errno == ERANGE) {
1347         LOG_ECMA(ERROR) << "getopt: \"" << option << "\" argument has invalid parameter value \"" << optarg <<"\"\n";
1348         return false;
1349     }
1350     return true;
1351 }
1352 
ParseUint32Param(const std::string & option,uint32_t * argUInt32)1353 bool JSRuntimeOptions::ParseUint32Param(const std::string &option, uint32_t *argUInt32)
1354 {
1355     if (StartsWith(optarg, "0x")) {
1356         const int HEX = 16;
1357         *argUInt32 = std::strtoull(optarg, nullptr, HEX);
1358     } else {
1359         const int DEC = 10;
1360         *argUInt32 = std::strtoull(optarg, nullptr, DEC);
1361     }
1362 
1363     if (errno == ERANGE) {
1364         LOG_ECMA(ERROR) << "getopt: \"" << option << "\" argument has invalid parameter value \"" << optarg <<"\"\n";
1365         return false;
1366     }
1367     return true;
1368 }
1369 
ParseUint64Param(const std::string & option,uint64_t * argUInt64)1370 bool JSRuntimeOptions::ParseUint64Param(const std::string &option, uint64_t *argUInt64)
1371 {
1372     if (StartsWith(optarg, "0x")) {
1373         const int HEX = 16;
1374         *argUInt64 = std::strtoull(optarg, nullptr, HEX);
1375     } else {
1376         const int DEC = 10;
1377         *argUInt64 = std::strtoull(optarg, nullptr, DEC);
1378     }
1379 
1380     if (errno == ERANGE) {
1381         LOG_ECMA(ERROR) << "getopt: \"" << option << "\" argument has invalid parameter value \"" << optarg <<"\"\n";
1382         return false;
1383     }
1384     return true;
1385 }
1386 
ParseListArgParam(const std::string & option,arg_list_t * argListStr,std::string delimiter)1387 void JSRuntimeOptions::ParseListArgParam(const std::string &option, arg_list_t *argListStr, std::string delimiter)
1388 {
1389     argListStr->clear();
1390     std::size_t strIndex = 0;
1391     std::size_t pos = option.find_first_of(delimiter, strIndex);
1392     while ((pos < option.size()) && (pos > strIndex)) {
1393         argListStr->push_back(option.substr(strIndex, pos - strIndex));
1394         strIndex = pos;
1395         strIndex = option.find_first_not_of(delimiter, strIndex);
1396         pos = option.find_first_of(delimiter, strIndex);
1397     }
1398     if (pos > strIndex) {
1399         argListStr->push_back(option.substr(strIndex, pos - strIndex));
1400     }
1401     return;
1402 }
1403 
SetOptionsForTargetCompilation()1404 void JSRuntimeOptions::SetOptionsForTargetCompilation()
1405 {
1406     if (IsTargetCompilerMode()) {
1407         SetTargetTriple("aarch64-unknown-linux-gnu");
1408         SetMaxAotMethodSize(MAX_APP_COMPILE_METHOD_SIZE);
1409         SetEnableOptTrackField(false);
1410         SetEnableOptInlining(false);
1411         SetEnableArrayBoundsCheckElimination(false);
1412         if (IsPartialCompilerMode()) {
1413             SetEnableOptPGOType(true);
1414             if (IsPGOProfilerPathEmpty()) {
1415                 LOG_ECMA(DEBUG) << "no pgo profile file in partial mode!";
1416             }
1417         } else {
1418             SetEnableOptPGOType(false);
1419             SetPGOProfilerPath("");
1420         }
1421     }
1422     if (IsCompilerPipelineHostAOT()) {
1423         SetTargetTriple("aarch64-unknown-linux-gnu");
1424         SetMaxAotMethodSize(MAX_APP_COMPILE_METHOD_SIZE);
1425         SetEnableOptTrackField(false);
1426         SetEnableOptInlining(false);
1427         SetEnableArrayBoundsCheckElimination(false);
1428         SetEnableOptPGOType(true);
1429         SetFastAOTCompileMode(true);
1430         SetOptLevel(DEFAULT_OPT_LEVEL);
1431         SetCompilerEnableLiteCG(true);
1432         SetEnableLoweringBuiltin(false);
1433     }
1434 }
1435 }
1436