1/*
2 * Copyright (c) 2024 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#ifndef OHOS_ARKCOMPILER_AOTCOMPILER_CONSTANTS_H
17#define OHOS_ARKCOMPILER_AOTCOMPILER_CONSTANTS_H
18
19#include <string>
20#include <unordered_map>
21#include <unordered_set>
22
23#include "aot_compiler_error_utils.h"
24
25namespace OHOS::ArkCompiler {
26namespace Cmds {
27constexpr const char* ARK_AOT_COMPILER = "/system/bin/ark_aot_compiler";
28} // namespace Cmds
29
30namespace ArgsIdx {
31const std::string BUNDLE_UID = "BundleUid";
32const std::string BUNDLE_GID = "BundleGid";
33const std::string AN_FILE_NAME = "anFileName";
34const std::string APP_SIGNATURE = "appIdentifier";
35const std::string ABC_PATH = "ABC-Path";
36} // namespace ArgsIdx
37
38namespace Symbols {
39constexpr const char* PREFIX = "--";
40constexpr const char* EQ = "=";
41} // namespace Symbols
42
43std::unordered_set<std::string> AotArgsSet {
44    "aot-file",
45    "ark-properties",
46    "ark-bundleName",
47    "asm-interpreter",
48    "asm-opcode-disable-range",
49    "builtins-lazy",
50    "compiler-log",
51    "compiler-log-methods",
52    "compiler-log-snapshot",
53    "compiler-log-time",
54    "compiler-type-threshold",
55    "enable-ark-tools",
56    "compiler-trace-bc",
57    "compiler-trace-deopt",
58    "compiler-trace-inline",
59    "compiler-trace-value-numbering",
60    "compiler-trace-instruction-combine",
61    "compiler-max-inline-bytecodes",
62    "compiler-deopt-threshold",
63    "compiler-device-state",
64    "compiler-thermal-level",
65    "compiler-stress-deopt",
66    "compiler-opt-code-profiler",
67    "compiler-opt-bc-range",
68    "compiler-opt-bc-range-help",
69    "enable-force-gc",
70    "enable-ic",
71    "enable-runtime-stat",
72    "compiler-opt-constant-folding",
73    "compiler-opt-array-bounds-check-elimination",
74    "compiler-opt-type-lowering",
75    "compiler-opt-early-elimination",
76    "compiler-opt-later-elimination",
77    "compiler-opt-instr-combine",
78    "compiler-opt-string",
79    "compiler-opt-value-numbering",
80    "compiler-opt-new-value-numbering",
81    "compiler-opt-inlining",
82    "compiler-opt-pgotype",
83    "compiler-opt-track-field",
84    "entry-point",
85    "force-full-gc",
86    "force-shared-gc-frequency",
87    "gc-thread-num",
88    "heap-size-limit",
89    "icu-data-path",
90    "enable-worker",
91    "log-components",
92    "log-debug",
93    "log-error",
94    "log-fatal",
95    "log-info",
96    "log-level",
97    "log-warning",
98    "gc-long-paused-time",
99    "compiler-opt-max-method",
100    "compiler-module-methods",
101    "max-unmovable-space",
102    "merge-abc",
103    "enable-context",
104    "compiler-opt-level",
105    "reloc-mode",
106    "serializer-buffer-size-limit",
107    "startup-time",
108    "stub-file",
109    "compiler-target-triple",
110    "enable-print-execute-time",
111    "enable-pgo-profiler",
112    "enable-elements-kind",
113    "compiler-pgo-profiler-path",
114    "compiler-pgo-hotness-threshold",
115    "compiler-pgo-save-min-interval",
116    "compiler-verify-vtable",
117    "compiler-select-methods",
118    "compiler-skip-methods",
119    "target-compiler-mode",
120    "hap-path",
121    "hap-abc-offset",
122    "hap-abc-size",
123    "compiler-no-check",
124    "compiler-pipeline-host-aot",
125    "compiler-fast-compile",
126    "compiler-opt-loop-peeling",
127    "compiler-opt-array-onheap-check",
128    "compiler-pkg-info",
129    "compiler-external-pkg-info",
130    "compiler-enable-external-pkg",
131    "compiler-framework-abc-path",
132    "compiler-enable-lexenv-specialization",
133    "compiler-enable-native-inline",
134    "compiler-enable-lowering-builtin",
135    "compiler-enable-litecg",
136    "compiler-enable-jit",
137    "compiler-enable-osr",
138    "compiler-trace-jit",
139    "compiler-jit-hotness-threshold",
140    "compiler-osr-hotness-threshold",
141    "compiler-force-jit-compile-main",
142    "compiler-enable-jit-pgo",
143    "compiler-enable-aot-pgo",
144    "compiler-enable-framework-aot",
145    "compiler-enable-profile-dump",
146    "compiler-typed-op-profiler",
147    "compiler-opt-branch-profiling",
148    "test-assert",
149    "compiler-methods-range",
150    "compiler-codegen-options",
151    "compiler-opt-escape-analysis",
152    "compiler-trace-escape-analysis",
153    "compiler-opt-induction-variable",
154    "compiler-trace-induction-variable",
155    "compiler-memory-analysis",
156    "compiler-check-pgo-version",
157    "compiler-enable-baselinejit",
158    "compiler-baselinejit-hotness-threshold",
159    "compiler-force-baselinejit-compile-main",
160    "compiler-baseline-pgo",
161};
162
163/**
164 * @param RetStatusOfCompiler return code of ark_aot_compiler
165 * @attention it must sync with ErrCode of "ets_runtime/ecmascript/aot_compiler.cpp"
166 */
167enum class RetStatusOfCompiler {
168    ERR_OK = (0),   // IMPORTANT: Only if aot compiler SUCCESS and save an/ai SUCCESS, return ERR_OK.
169    ERR_FAIL = (-1),
170    ERR_HELP = (1),
171    ERR_NO_AP = (2),
172    ERR_MERGE_AP = (3),
173    ERR_CHECK_VERSION = (4),
174    ERR_AN_EMPTY = (5),
175    ERR_AN_FAIL = (6),
176    ERR_AI_FAIL = (7),
177};
178
179struct InfoOfCompiler {
180    int32_t retCode { -1 };
181    std::string mesg;
182};
183
184const std::unordered_map<int, InfoOfCompiler> RetInfoOfCompiler {
185    {static_cast<int>(RetStatusOfCompiler::ERR_OK), {ERR_OK, "AOT compiler success"}},
186    {static_cast<int>(RetStatusOfCompiler::ERR_NO_AP), {ERR_OK_NO_AOT_FILE, "AOT compiler not run: no ap file"}},
187    {static_cast<int>(RetStatusOfCompiler::ERR_CHECK_VERSION),
188        {ERR_OK_NO_AOT_FILE, "AOT compiler not run: check version"}},
189    {static_cast<int>(RetStatusOfCompiler::ERR_MERGE_AP),
190        {ERR_AOT_COMPILER_CALL_FAILED, "AOT compiler fail: merge ap error"}},
191    {static_cast<int>(RetStatusOfCompiler::ERR_AN_EMPTY),
192        {ERR_AOT_COMPILER_CALL_FAILED, "AOT compiler fail: empty an file"}},
193    {static_cast<int>(RetStatusOfCompiler::ERR_AN_FAIL),
194        {ERR_AOT_COMPILER_CALL_FAILED, "AOT compiler fail: save an error"}},
195    {static_cast<int>(RetStatusOfCompiler::ERR_AI_FAIL),
196        {ERR_AOT_COMPILER_CALL_FAILED, "AOT compiler fail: save ai error"}},
197};
198
199const InfoOfCompiler OtherInfoOfCompiler = {ERR_AOT_COMPILER_CALL_FAILED, "AOT compiler fail: other error"};
200} // namespace OHOS::ArkCompiler
201#endif  // OHOS_ARKCOMPILER_AOTCOMPILER_CONSTANTS_H