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 #ifndef ECMASCRIPT_COMPILER_ECMA_OPCODE_DES_H 16 #define ECMASCRIPT_COMPILER_ECMA_OPCODE_DES_H 17 18 #include <map> 19 #include <string> 20 21 namespace panda::ecmascript::kungfu { 22 23 #define ECMA_OPCODE_LIST(V) \ 24 V(LDNAN) \ 25 V(LDINFINITY) \ 26 V(LDNEWTARGET) \ 27 V(LDUNDEFINED) \ 28 V(LDNULL) \ 29 V(LDSYMBOL) \ 30 V(LDGLOBAL) \ 31 V(LDTRUE) \ 32 V(LDFALSE) \ 33 V(LDHOLE) \ 34 V(LDTHIS) \ 35 V(POPLEXENV) \ 36 V(GETUNMAPPEDARGS) \ 37 V(ASYNCFUNCTIONENTER) \ 38 V(CREATEASYNCGENERATOROBJ_V8) \ 39 V(LDFUNCTION) \ 40 V(DEBUGGER) \ 41 V(GETPROPITERATOR) \ 42 V(GETITERATOR_IMM8) \ 43 V(GETITERATOR_IMM16) \ 44 V(CLOSEITERATOR_IMM8_V8) \ 45 V(CLOSEITERATOR_IMM16_V8) \ 46 V(ASYNCGENERATORRESOLVE_V8_V8_V8) \ 47 V(CREATEEMPTYOBJECT) \ 48 V(CREATEEMPTYARRAY_IMM8) \ 49 V(CREATEEMPTYARRAY_IMM16) \ 50 V(CREATEGENERATOROBJ_V8) \ 51 V(CREATEITERRESULTOBJ_V8_V8) \ 52 V(CREATEOBJECTWITHEXCLUDEDKEYS_IMM8_V8_V8) \ 53 V(CALLTHIS0_IMM8_V8) \ 54 V(CREATEARRAYWITHBUFFER_IMM8_ID16) \ 55 V(CREATEARRAYWITHBUFFER_IMM16_ID16) \ 56 V(CALLTHIS1_IMM8_V8_V8) \ 57 V(CALLTHIS2_IMM8_V8_V8_V8) \ 58 V(CREATEOBJECTWITHBUFFER_IMM8_ID16) \ 59 V(CREATEOBJECTWITHBUFFER_IMM16_ID16) \ 60 V(CREATEREGEXPWITHLITERAL_IMM8_ID16_IMM8) \ 61 V(CREATEREGEXPWITHLITERAL_IMM16_ID16_IMM8) \ 62 V(NEWOBJAPPLY_IMM8_V8) \ 63 V(NEWOBJAPPLY_IMM16_V8) \ 64 V(NEWOBJRANGE_IMM8_IMM8_V8) \ 65 V(NEWOBJRANGE_IMM16_IMM8_V8) \ 66 V(NEWLEXENV_IMM8) \ 67 V(NEWLEXENVWITHNAME_IMM8_ID16) \ 68 V(ADD2_IMM8_V8) \ 69 V(SUB2_IMM8_V8) \ 70 V(MUL2_IMM8_V8) \ 71 V(DIV2_IMM8_V8) \ 72 V(MOD2_IMM8_V8) \ 73 V(EQ_IMM8_V8) \ 74 V(NOTEQ_IMM8_V8) \ 75 V(LESS_IMM8_V8) \ 76 V(LESSEQ_IMM8_V8) \ 77 V(GREATER_IMM8_V8) \ 78 V(GREATEREQ_IMM8_V8) \ 79 V(SHL2_IMM8_V8) \ 80 V(SHR2_IMM8_V8) \ 81 V(ASHR2_IMM8_V8) \ 82 V(AND2_IMM8_V8) \ 83 V(OR2_IMM8_V8) \ 84 V(XOR2_IMM8_V8) \ 85 V(EXP_IMM8_V8) \ 86 V(TYPEOF_IMM8) \ 87 V(TYPEOF_IMM16) \ 88 V(TONUMBER_IMM8) \ 89 V(TONUMERIC_IMM8) \ 90 V(NEG_IMM8) \ 91 V(NOT_IMM8) \ 92 V(INC_IMM8) \ 93 V(DEC_IMM8) \ 94 V(ISIN_IMM8_V8) \ 95 V(INSTANCEOF_IMM8_V8) \ 96 V(STRICTNOTEQ_IMM8_V8) \ 97 V(STRICTEQ_IMM8_V8) \ 98 V(ISTRUE) \ 99 V(ISFALSE) \ 100 V(CALLTHIS3_IMM8_V8_V8_V8_V8) \ 101 V(CALLTHISRANGE_IMM8_IMM8_V8) \ 102 V(SUPERCALLTHISRANGE_IMM8_IMM8_V8) \ 103 V(SUPERCALLARROWRANGE_IMM8_IMM8_V8) \ 104 V(DEFINEFUNC_IMM8_ID16_IMM8) \ 105 V(DEFINEFUNC_IMM16_ID16_IMM8) \ 106 V(DEFINEMETHOD_IMM8_ID16_IMM8) \ 107 V(DEFINEMETHOD_IMM16_ID16_IMM8) \ 108 V(CALLARG0_IMM8) \ 109 V(SUPERCALLSPREAD_IMM8_V8) \ 110 V(APPLY_IMM8_V8_V8) \ 111 V(CALLARGS2_IMM8_V8_V8) \ 112 V(CALLARGS3_IMM8_V8_V8_V8) \ 113 V(CALLRANGE_IMM8_IMM8_V8) \ 114 V(LDEXTERNALMODULEVAR_IMM8) \ 115 V(LDTHISBYNAME_IMM8_ID16) \ 116 V(DEFINEGETTERSETTERBYVALUE_V8_V8_V8_V8) \ 117 V(LDTHISBYNAME_IMM16_ID16) \ 118 V(STTHISBYNAME_IMM8_ID16) \ 119 V(STTHISBYNAME_IMM16_ID16) \ 120 V(LDTHISBYVALUE_IMM8) \ 121 V(LDTHISBYVALUE_IMM16) \ 122 V(STTHISBYVALUE_IMM8_V8) \ 123 V(STTHISBYVALUE_IMM16_V8) \ 124 V(DYNAMICIMPORT) \ 125 V(DEFINECLASSWITHBUFFER_IMM8_ID16_ID16_IMM16_V8) \ 126 V(DEFINECLASSWITHBUFFER_IMM16_ID16_ID16_IMM16_V8) \ 127 V(RESUMEGENERATOR) \ 128 V(GETRESUMEMODE) \ 129 V(GETTEMPLATEOBJECT_IMM8) \ 130 V(GETTEMPLATEOBJECT_IMM16) \ 131 V(GETNEXTPROPNAME_V8) \ 132 V(JEQZ_IMM8) \ 133 V(JEQZ_IMM16) \ 134 V(SETOBJECTWITHPROTO_IMM8_V8) \ 135 V(DELOBJPROP_V8) \ 136 V(SUSPENDGENERATOR_V8) \ 137 V(ASYNCFUNCTIONAWAITUNCAUGHT_V8) \ 138 V(COPYDATAPROPERTIES_V8) \ 139 V(STARRAYSPREAD_V8_V8) \ 140 V(SETOBJECTWITHPROTO_IMM16_V8) \ 141 V(LDOBJBYVALUE_IMM8_V8) \ 142 V(LDOBJBYVALUE_IMM16_V8) \ 143 V(STOBJBYVALUE_IMM8_V8_V8) \ 144 V(STOBJBYVALUE_IMM16_V8_V8) \ 145 V(STOWNBYVALUE_IMM8_V8_V8) \ 146 V(STOWNBYVALUE_IMM16_V8_V8) \ 147 V(LDSUPERBYVALUE_IMM8_V8) \ 148 V(LDSUPERBYVALUE_IMM16_V8) \ 149 V(STSUPERBYVALUE_IMM8_V8_V8) \ 150 V(STSUPERBYVALUE_IMM16_V8_V8) \ 151 V(LDOBJBYINDEX_IMM8_IMM16) \ 152 V(LDOBJBYINDEX_IMM16_IMM16) \ 153 V(STOBJBYINDEX_IMM8_V8_IMM16) \ 154 V(STOBJBYINDEX_IMM16_V8_IMM16) \ 155 V(STOWNBYINDEX_IMM8_V8_IMM16) \ 156 V(STOWNBYINDEX_IMM16_V8_IMM16) \ 157 V(ASYNCFUNCTIONRESOLVE_V8) \ 158 V(ASYNCFUNCTIONREJECT_V8) \ 159 V(COPYRESTARGS_IMM8) \ 160 V(LDLEXVAR_IMM4_IMM4) \ 161 V(STLEXVAR_IMM4_IMM4) \ 162 V(GETMODULENAMESPACE_IMM8) \ 163 V(STMODULEVAR_IMM8) \ 164 V(TRYLDGLOBALBYNAME_IMM8_ID16) \ 165 V(TRYLDGLOBALBYNAME_IMM16_ID16) \ 166 V(TRYSTGLOBALBYNAME_IMM8_ID16) \ 167 V(TRYSTGLOBALBYNAME_IMM16_ID16) \ 168 V(LDGLOBALVAR_IMM16_ID16) \ 169 V(STGLOBALVAR_IMM16_ID16) \ 170 V(LDOBJBYNAME_IMM8_ID16) \ 171 V(LDOBJBYNAME_IMM16_ID16) \ 172 V(STOBJBYNAME_IMM8_ID16_V8) \ 173 V(STOBJBYNAME_IMM16_ID16_V8) \ 174 V(STOWNBYNAME_IMM8_ID16_V8) \ 175 V(STOWNBYNAME_IMM16_ID16_V8) \ 176 V(LDSUPERBYNAME_IMM8_ID16) \ 177 V(LDSUPERBYNAME_IMM16_ID16) \ 178 V(STSUPERBYNAME_IMM8_ID16_V8) \ 179 V(STSUPERBYNAME_IMM16_ID16_V8) \ 180 V(LDLOCALMODULEVAR_IMM8) \ 181 V(STCONSTTOGLOBALRECORD_IMM16_ID16) \ 182 V(STTOGLOBALRECORD_IMM16_ID16) \ 183 V(JEQZ_IMM32) \ 184 V(JNEZ_IMM8) \ 185 V(JNEZ_IMM16) \ 186 V(JNEZ_IMM32) \ 187 V(STOWNBYVALUEWITHNAMESET_IMM8_V8_V8) \ 188 V(STOWNBYVALUEWITHNAMESET_IMM16_V8_V8) \ 189 V(STOWNBYNAMEWITHNAMESET_IMM8_ID16_V8) \ 190 V(STOWNBYNAMEWITHNAMESET_IMM16_ID16_V8) \ 191 V(LDBIGINT_ID16) \ 192 V(LDA_STR_ID16) \ 193 V(JMP_IMM8) \ 194 V(JMP_IMM16) \ 195 V(JMP_IMM32) \ 196 V(JSTRICTEQZ_IMM8) \ 197 V(JSTRICTEQZ_IMM16) \ 198 V(JNSTRICTEQZ_IMM8) \ 199 V(JNSTRICTEQZ_IMM16) \ 200 V(JEQNULL_IMM8) \ 201 V(JEQNULL_IMM16) \ 202 V(LDA_V8) \ 203 V(STA_V8) \ 204 V(LDAI_IMM32) \ 205 V(FLDAI_IMM64) \ 206 V(RETURN) \ 207 V(RETURNUNDEFINED) \ 208 V(LDLEXVAR_IMM8_IMM8) \ 209 V(JNENULL_IMM8) \ 210 V(STLEXVAR_IMM8_IMM8) \ 211 V(JNENULL_IMM16) \ 212 V(CALLARG1_IMM8_V8) \ 213 V(JSTRICTEQNULL_IMM8) \ 214 V(JSTRICTEQNULL_IMM16) \ 215 V(JNSTRICTEQNULL_IMM8) \ 216 V(JNSTRICTEQNULL_IMM16) \ 217 V(JEQUNDEFINED_IMM8) \ 218 V(JEQUNDEFINED_IMM16) \ 219 V(JNEUNDEFINED_IMM8) \ 220 V(JNEUNDEFINED_IMM16) \ 221 V(JSTRICTEQUNDEFINED_IMM8) \ 222 V(JSTRICTEQUNDEFINED_IMM16) \ 223 V(JNSTRICTEQUNDEFINED_IMM8) \ 224 V(JNSTRICTEQUNDEFINED_IMM16) \ 225 V(JEQ_V8_IMM8) \ 226 V(JEQ_V8_IMM16) \ 227 V(JNE_V8_IMM8) \ 228 V(JNE_V8_IMM16) \ 229 V(JSTRICTEQ_V8_IMM8) \ 230 V(JSTRICTEQ_V8_IMM16) \ 231 V(JNSTRICTEQ_V8_IMM8) \ 232 V(JNSTRICTEQ_V8_IMM16) \ 233 V(MOV_V4_V4) \ 234 V(MOV_V8_V8) \ 235 V(MOV_V16_V16) \ 236 V(ASYNCGENERATORREJECT_V8) \ 237 V(NOP) \ 238 V(SETGENERATORSTATE_IMM8) \ 239 V(GETASYNCITERATOR_IMM8) \ 240 V(LDPRIVATEPROPERTY_IMM8_IMM16_IMM16) \ 241 V(STPRIVATEPROPERTY_IMM8_IMM16_IMM16_V8) \ 242 V(TESTIN_IMM8_IMM16_IMM16) \ 243 V(DEPRECATED_LDLEXENV_PREF_NONE) \ 244 V(WIDE_CREATEOBJECTWITHEXCLUDEDKEYS_PREF_IMM16_V8_V8) \ 245 V(THROW_PREF_NONE) \ 246 V(DEPRECATED_POPLEXENV_PREF_NONE) \ 247 V(WIDE_NEWOBJRANGE_PREF_IMM16_V8) \ 248 V(THROW_NOTEXISTS_PREF_NONE) \ 249 V(DEPRECATED_GETITERATORNEXT_PREF_V8_V8) \ 250 V(WIDE_NEWLEXENV_PREF_IMM16) \ 251 V(THROW_PATTERNNONCOERCIBLE_PREF_NONE) \ 252 V(DEPRECATED_CREATEARRAYWITHBUFFER_PREF_IMM16) \ 253 V(WIDE_NEWLEXENVWITHNAME_PREF_IMM16_ID16) \ 254 V(THROW_DELETESUPERPROPERTY_PREF_NONE) \ 255 V(DEPRECATED_CREATEOBJECTWITHBUFFER_PREF_IMM16) \ 256 V(WIDE_CALLRANGE_PREF_IMM16_V8) \ 257 V(THROW_CONSTASSIGNMENT_PREF_V8) \ 258 V(DEPRECATED_TONUMBER_PREF_V8) \ 259 V(WIDE_CALLTHISRANGE_PREF_IMM16_V8) \ 260 V(THROW_IFNOTOBJECT_PREF_V8) \ 261 V(DEPRECATED_TONUMERIC_PREF_V8) \ 262 V(WIDE_SUPERCALLTHISRANGE_PREF_IMM16_V8) \ 263 V(THROW_UNDEFINEDIFHOLE_PREF_V8_V8) \ 264 V(THROW_UNDEFINEDIFHOLEWITHNAME_PREF_ID16) \ 265 V(DEPRECATED_NEG_PREF_V8) \ 266 V(WIDE_SUPERCALLARROWRANGE_PREF_IMM16_V8) \ 267 V(THROW_IFSUPERNOTCORRECTCALL_PREF_IMM8) \ 268 V(DEPRECATED_NOT_PREF_V8) \ 269 V(WIDE_LDOBJBYINDEX_PREF_IMM32) \ 270 V(THROW_IFSUPERNOTCORRECTCALL_PREF_IMM16) \ 271 V(DEPRECATED_INC_PREF_V8) \ 272 V(WIDE_STOBJBYINDEX_PREF_V8_IMM32) \ 273 V(DEPRECATED_DEC_PREF_V8) \ 274 V(WIDE_STOWNBYINDEX_PREF_V8_IMM32) \ 275 V(DEPRECATED_CALLARG0_PREF_V8) \ 276 V(WIDE_COPYRESTARGS_PREF_IMM16) \ 277 V(DEPRECATED_CALLARG1_PREF_V8_V8) \ 278 V(WIDE_LDLEXVAR_PREF_IMM16_IMM16) \ 279 V(DEPRECATED_CALLARGS2_PREF_V8_V8_V8) \ 280 V(WIDE_STLEXVAR_PREF_IMM16_IMM16) \ 281 V(DEPRECATED_CALLARGS3_PREF_V8_V8_V8_V8) \ 282 V(WIDE_GETMODULENAMESPACE_PREF_IMM16) \ 283 V(DEPRECATED_CALLRANGE_PREF_IMM16_V8) \ 284 V(WIDE_STMODULEVAR_PREF_IMM16) \ 285 V(DEPRECATED_CALLSPREAD_PREF_V8_V8_V8) \ 286 V(WIDE_LDLOCALMODULEVAR_PREF_IMM16) \ 287 V(DEPRECATED_CALLTHISRANGE_PREF_IMM16_V8) \ 288 V(WIDE_LDEXTERNALMODULEVAR_PREF_IMM16) \ 289 V(DEPRECATED_DEFINECLASSWITHBUFFER_PREF_ID16_IMM16_IMM16_V8_V8) \ 290 V(WIDE_LDPATCHVAR_PREF_IMM16) \ 291 V(DEPRECATED_RESUMEGENERATOR_PREF_V8) \ 292 V(WIDE_STPATCHVAR_PREF_IMM16) \ 293 V(DEPRECATED_GETRESUMEMODE_PREF_V8) \ 294 V(DEPRECATED_GETTEMPLATEOBJECT_PREF_V8) \ 295 V(DEPRECATED_DELOBJPROP_PREF_V8_V8) \ 296 V(DEPRECATED_SUSPENDGENERATOR_PREF_V8_V8) \ 297 V(DEPRECATED_ASYNCFUNCTIONAWAITUNCAUGHT_PREF_V8_V8) \ 298 V(DEPRECATED_COPYDATAPROPERTIES_PREF_V8_V8) \ 299 V(DEPRECATED_SETOBJECTWITHPROTO_PREF_V8_V8) \ 300 V(DEPRECATED_LDOBJBYVALUE_PREF_V8_V8) \ 301 V(DEPRECATED_LDSUPERBYVALUE_PREF_V8_V8) \ 302 V(DEPRECATED_LDOBJBYINDEX_PREF_V8_IMM32) \ 303 V(DEPRECATED_ASYNCFUNCTIONRESOLVE_PREF_V8_V8_V8) \ 304 V(DEPRECATED_ASYNCFUNCTIONREJECT_PREF_V8_V8_V8) \ 305 V(DEPRECATED_STLEXVAR_PREF_IMM4_IMM4_V8) \ 306 V(DEPRECATED_STLEXVAR_PREF_IMM8_IMM8_V8) \ 307 V(DEPRECATED_STLEXVAR_PREF_IMM16_IMM16_V8) \ 308 V(DEPRECATED_GETMODULENAMESPACE_PREF_ID32) \ 309 V(DEPRECATED_STMODULEVAR_PREF_ID32) \ 310 V(DEPRECATED_LDOBJBYNAME_PREF_ID32_V8) \ 311 V(DEPRECATED_LDSUPERBYNAME_PREF_ID32_V8) \ 312 V(DEPRECATED_LDMODULEVAR_PREF_ID32_IMM8) \ 313 V(DEPRECATED_STCONSTTOGLOBALRECORD_PREF_ID32) \ 314 V(DEPRECATED_STLETTOGLOBALRECORD_PREF_ID32) \ 315 V(DEPRECATED_STCLASSTOGLOBALRECORD_PREF_ID32) \ 316 V(DEPRECATED_LDHOMEOBJECT_PREF_NONE) \ 317 V(DEPRECATED_CREATEOBJECTHAVINGMETHOD_PREF_IMM16) \ 318 V(DEPRECATED_DYNAMICIMPORT_PREF_V8) \ 319 V(CALLRUNTIME_NOTIFYCONCURRENTRESULT_PREF_NONE) \ 320 V(DEFINEFIELDBYNAME_IMM8_ID16_V8) \ 321 V(CALLRUNTIME_DEFINEFIELDBYVALUE_PREF_IMM8_V8_V8) \ 322 V(CALLRUNTIME_DEFINEFIELDBYINDEX_PREF_IMM8_IMM32_V8) \ 323 V(CALLRUNTIME_TOPROPERTYKEY_PREF_NONE) \ 324 V(CALLRUNTIME_CREATEPRIVATEPROPERTY_PREF_IMM16_ID16) \ 325 V(CALLRUNTIME_DEFINEPRIVATEPROPERTY_PREF_IMM8_IMM16_IMM16_V8) \ 326 V(CALLRUNTIME_CALLINIT_PREF_IMM8_V8) \ 327 V(CALLRUNTIME_DEFINESENDABLECLASS_PREF_IMM16_ID16_ID16_IMM16_V8) \ 328 V(CALLRUNTIME_LDSENDABLECLASS_PREF_IMM16) \ 329 GetEcmaOpcodeStr(EcmaOpcode opcode)330inline std::string GetEcmaOpcodeStr(EcmaOpcode opcode) 331 { 332 const std::map<EcmaOpcode, const char *> strMap = { 333 #define BYTECODE_NAME_MAP(name) { EcmaOpcode::name, #name }, 334 ECMA_OPCODE_LIST(BYTECODE_NAME_MAP) 335 #undef BYTECODE_NAME_MAP 336 }; 337 if (strMap.count(opcode) > 0) { 338 return strMap.at(opcode); 339 } 340 return "bytecode-" + std::to_string(static_cast<uint16_t>(opcode)); 341 } 342 343 } // namespace panda::ecmascript::kungfu 344 #endif // ECMASCRIPT_COMPILER_ECMA_OPCODE_DES_H_ 345