From af6e875d4255dafac2a7ad3c505fa810d4f7b381 Mon Sep 17 00:00:00 2001 From: Katy Voor Date: Thu, 10 Mar 2022 15:58:01 -0800 Subject: [PATCH] CMake to avoid checking in opcodes.rs (#9030) Summary: Separate opcodes macro into its own header so it can be as lightweight as possible when we include it in `gen-rust.cpp`. This makes compiling it in CMake much easier as we don't have to deal with many dependencies. Pull Request resolved: https://github.com/facebook/hhvm/pull/9030 Pull Request resolved: https://github.com/facebook/hhvm/pull/9029 Reviewed By: fredemmott Differential Revision: D34762816 fbshipit-source-id: 0aa4be5657a0d245fe23e3d95f9161489e25a20a --- hphp/hack/CMakeLists.txt | 17 +- hphp/hack/dev_env_common.sh.in | 1 + hphp/runtime/vm/hhbc.h | 268 +--------------------------- hphp/runtime/vm/opcodes.h | 292 +++++++++++++++++++++++++++++++ hphp/tools/hhbc-gen/gen-rust.cpp | 3 +- hphp/tools/hhbc-gen/hhbc.rs | 9 +- 6 files changed, 316 insertions(+), 274 deletions(-) create mode 100644 hphp/runtime/vm/opcodes.h diff --git a/hphp/hack/CMakeLists.txt b/hphp/hack/CMakeLists.txt index c818d8b9fcc355..d51244a3097454 100644 --- a/hphp/hack/CMakeLists.txt +++ b/hphp/hack/CMakeLists.txt @@ -119,6 +119,15 @@ invoke_dune(hack_dune all) set(CARGO_BUILD "${CMAKE_SOURCE_DIR}/hphp/hack/scripts/build_rust_to_ocaml.sh") +set(OPCODES "${CMAKE_BINARY_DIR}/hphp/tools/opcodes.rs") + +add_executable(gen-rust1 "${CMAKE_SOURCE_DIR}/hphp/tools/hhbc-gen/gen-rust.cpp") +add_custom_command( + OUTPUT "${OPCODES}" + COMMAND gen-rust1 > "${OPCODES}" + COMMENT "Generating opcodes.rs" +) + if(DEFINED ENV{HACKDEBUG}) set(PROFILE "debug") else() @@ -196,7 +205,7 @@ add_custom_command( ${CARGO_BUILD} ffi_cbindgen ffi_cbindgen --exe --header "${HHBC_AST_HEADER}" --srcs "${HHBC_AST_SRC_ARG}" --namespaces "HPHP,hackc,hhbc" --includes "${FFI_HEADER},${NAMING_SPECIAL_NAMES_HEADER},${TYPE_CONSTRAINT_HEADER},${ATTR_HEADER},${FCALL_HEADER},${HHBC_HEADER}" - DEPENDS rustc cargo + DEPENDS rustc cargo "${OPCODES}" COMMENT "Generating hhbc-ast.h" ) @@ -230,7 +239,7 @@ function(build_cxx_bridge NAME FFI_BRIDGE_DIR) ${CMAKE_COMMAND} -E copy "${GENERATED}.rs.cc" "${RUST_PART_CXX}" && ${CMAKE_COMMAND} -E copy "${GENERATED}.rs.h" "${RUST_PART_HEADER}" WORKING_DIRECTORY ${FFI_BRIDGE_SRC} - DEPENDS rustc cargo + DEPENDS rustc cargo "${OPCODES}" ) add_custom_target( "${NAME}_cxx" @@ -264,8 +273,8 @@ endif() # you're working with Hack, but means that e.g. hhvm can't find # `hh_single_compile` in the source tree. Keep it around, but require it to be # explicitly used -add_custom_target(hack ALL DEPENDS hack_dune) -add_custom_target(hack_test DEPENDS hack_dune_test) +add_custom_target(hack ALL DEPENDS hack_dune "${OPCODES}") +add_custom_target(hack_test DEPENDS hack_dune_test "${OPCODES}") configure_file(dev_env.sh.in dev_env.sh ESCAPE_QUOTES @ONLY) configure_file(dev_env_common.sh.in dev_env_common.sh ESCAPE_QUOTES @ONLY) diff --git a/hphp/hack/dev_env_common.sh.in b/hphp/hack/dev_env_common.sh.in index 5d2ad265d4edda..722edb6f00b8ec 100644 --- a/hphp/hack/dev_env_common.sh.in +++ b/hphp/hack/dev_env_common.sh.in @@ -15,6 +15,7 @@ export HACK_NO_CARGO_VENDOR=true export OPAMROOT="@OPAMROOT@" export PYTHONPATH="@HPHP_HOME@" # needed for verify.py for `hack_dune_test` export CARGO_HOME="@CARGO_HOME@" +export CMAKE_BINARY_DIR="@CMAKE_BINARY_DIR@" export RUSTC="@RUSTC_BIN_DIR@/rustc" export DUNE_BUILD_DIR="@DUNE_BUILD_DIR@" export HACK_SOURCE_ROOT="@CMAKE_CURRENT_SOURCE_DIR@" diff --git a/hphp/runtime/vm/hhbc.h b/hphp/runtime/vm/hhbc.h index 75b0158585fcf3..0443563f6a5223 100644 --- a/hphp/runtime/vm/hhbc.h +++ b/hphp/runtime/vm/hhbc.h @@ -25,6 +25,7 @@ #include "hphp/runtime/vm/fcall-args-flags.h" #include "hphp/runtime/vm/hhbc-shared.h" #include "hphp/runtime/vm/member-key.h" +#include "hphp/runtime/vm/opcodes.h" #include "hphp/util/compact-vector.h" #include "hphp/util/either.h" #include "hphp/util/functional.h" @@ -316,273 +317,6 @@ inline bool isIncDecO(IncDecOp op) { constexpr uint32_t kMaxConcatN = 4; -// name immediates inputs outputs flags -#define OPCODES \ - O(Nop, NA, NOV, NOV, NF) \ - O(EntryNop, NA, NOV, NOV, NF) \ - O(BreakTraceHint, NA, NOV, NOV, NF) \ - O(PopC, NA, ONE(CV), NOV, NF) \ - O(PopU, NA, ONE(UV), NOV, NF) \ - O(PopU2, NA, TWO(CV,UV), ONE(CV), NF) \ - O(PopL, ONE(LA), ONE(CV), NOV, NF) \ - O(Dup, NA, ONE(CV), TWO(CV,CV), NF) \ - O(CGetCUNop, NA, ONE(CUV), ONE(CV), NF) \ - O(UGetCUNop, NA, ONE(CUV), ONE(UV), NF) \ - O(Null, NA, NOV, ONE(CV), NF) \ - O(NullUninit, NA, NOV, ONE(UV), NF) \ - O(True, NA, NOV, ONE(CV), NF) \ - O(False, NA, NOV, ONE(CV), NF) \ - O(FuncCred, NA, NOV, ONE(CV), NF) \ - O(Int, ONE(I64A), NOV, ONE(CV), NF) \ - O(Double, ONE(DA), NOV, ONE(CV), NF) \ - O(String, ONE(SA), NOV, ONE(CV), NF) \ - O(Dict, ONE(AA), NOV, ONE(CV), NF) \ - O(Keyset, ONE(AA), NOV, ONE(CV), NF) \ - O(Vec, ONE(AA), NOV, ONE(CV), NF) \ - O(NewDictArray, ONE(IVA), NOV, ONE(CV), NF) \ - O(NewStructDict, ONE(VSA), SMANY, ONE(CV), NF) \ - O(NewVec, ONE(IVA), CMANY, ONE(CV), NF) \ - O(NewKeysetArray, ONE(IVA), CMANY, ONE(CV), NF) \ - O(AddElemC, NA, THREE(CV,CV,CV), ONE(CV), NF) \ - O(AddNewElemC, NA, TWO(CV,CV), ONE(CV), NF) \ - O(NewCol, ONE(OA(CollectionType)), \ - NOV, ONE(CV), NF) \ - O(NewPair, NA, TWO(CV,CV), ONE(CV), NF) \ - O(ColFromArray, ONE(OA(CollectionType)), \ - ONE(CV), ONE(CV), NF) \ - O(CnsE, ONE(SA), NOV, ONE(CV), NF) \ - O(ClsCns, ONE(SA), ONE(CV), ONE(CV), NF) \ - O(ClsCnsD, TWO(SA,SA), NOV, ONE(CV), NF) \ - O(ClsCnsL, ONE(LA), ONE(CV), ONE(CV), NF) \ - O(ClassName, NA, ONE(CV), ONE(CV), NF) \ - O(LazyClassFromClass, NA, ONE(CV), ONE(CV), NF) \ - O(File, NA, NOV, ONE(CV), NF) \ - O(Dir, NA, NOV, ONE(CV), NF) \ - O(Method, NA, NOV, ONE(CV), NF) \ - O(Concat, NA, TWO(CV,CV), ONE(CV), NF) \ - O(ConcatN, ONE(IVA), CMANY, ONE(CV), NF) \ - O(Add, NA, TWO(CV,CV), ONE(CV), NF) \ - O(Sub, NA, TWO(CV,CV), ONE(CV), NF) \ - O(Mul, NA, TWO(CV,CV), ONE(CV), NF) \ - O(AddO, NA, TWO(CV,CV), ONE(CV), NF) \ - O(SubO, NA, TWO(CV,CV), ONE(CV), NF) \ - O(MulO, NA, TWO(CV,CV), ONE(CV), NF) \ - O(Div, NA, TWO(CV,CV), ONE(CV), NF) \ - O(Mod, NA, TWO(CV,CV), ONE(CV), NF) \ - O(Pow, NA, TWO(CV,CV), ONE(CV), NF) \ - O(Not, NA, ONE(CV), ONE(CV), NF) \ - O(Same, NA, TWO(CV,CV), ONE(CV), NF) \ - O(NSame, NA, TWO(CV,CV), ONE(CV), NF) \ - O(Eq, NA, TWO(CV,CV), ONE(CV), NF) \ - O(Neq, NA, TWO(CV,CV), ONE(CV), NF) \ - O(Lt, NA, TWO(CV,CV), ONE(CV), NF) \ - O(Lte, NA, TWO(CV,CV), ONE(CV), NF) \ - O(Gt, NA, TWO(CV,CV), ONE(CV), NF) \ - O(Gte, NA, TWO(CV,CV), ONE(CV), NF) \ - O(Cmp, NA, TWO(CV,CV), ONE(CV), NF) \ - O(BitAnd, NA, TWO(CV,CV), ONE(CV), NF) \ - O(BitOr, NA, TWO(CV,CV), ONE(CV), NF) \ - O(BitXor, NA, TWO(CV,CV), ONE(CV), NF) \ - O(BitNot, NA, ONE(CV), ONE(CV), NF) \ - O(Shl, NA, TWO(CV,CV), ONE(CV), NF) \ - O(Shr, NA, TWO(CV,CV), ONE(CV), NF) \ - O(CastBool, NA, ONE(CV), ONE(CV), NF) \ - O(CastInt, NA, ONE(CV), ONE(CV), NF) \ - O(CastDouble, NA, ONE(CV), ONE(CV), NF) \ - O(CastString, NA, ONE(CV), ONE(CV), NF) \ - O(CastDict, NA, ONE(CV), ONE(CV), NF) \ - O(CastKeyset, NA, ONE(CV), ONE(CV), NF) \ - O(CastVec, NA, ONE(CV), ONE(CV), NF) \ - O(DblAsBits, NA, ONE(CV), ONE(CV), NF) \ - O(InstanceOf, NA, TWO(CV,CV), ONE(CV), NF) \ - O(InstanceOfD, ONE(SA), ONE(CV), ONE(CV), NF) \ - O(IsLateBoundCls, NA, ONE(CV), ONE(CV), NF) \ - O(IsTypeStructC, ONE(OA(TypeStructResolveOp)), \ - TWO(CV,CV), ONE(CV), NF) \ - O(ThrowAsTypeStructException, \ - NA, TWO(CV,CV), NOV, TF) \ - O(CombineAndResolveTypeStruct, \ - ONE(IVA), CMANY, ONE(CV), NF) \ - O(Select, NA, THREE(CV,CV,CV), ONE(CV), NF) \ - O(Print, NA, ONE(CV), ONE(CV), NF) \ - O(Clone, NA, ONE(CV), ONE(CV), NF) \ - O(Exit, NA, ONE(CV), ONE(CV), TF) \ - O(Fatal, ONE(OA(FatalOp)), ONE(CV), NOV, TF) \ - O(Jmp, ONE(BA), NOV, NOV, CF_TF) \ - O(JmpNS, ONE(BA), NOV, NOV, CF_TF) \ - O(JmpZ, ONE(BA), ONE(CV), NOV, CF) \ - O(JmpNZ, ONE(BA), ONE(CV), NOV, CF) \ - O(Switch, THREE(OA(SwitchKind),I64A,BLA), \ - ONE(CV), NOV, CF_TF) \ - O(SSwitch, ONE(SLA), ONE(CV), NOV, CF_TF) \ - O(RetC, NA, ONE(CV), NOV, CF_TF) \ - O(RetM, ONE(IVA), CMANY, NOV, CF_TF) \ - O(RetCSuspended, NA, ONE(CV), NOV, CF_TF) \ - O(Throw, NA, ONE(CV), NOV, CF_TF) \ - O(CGetL, ONE(NLA), NOV, ONE(CV), NF) \ - O(CGetQuietL, ONE(LA), NOV, ONE(CV), NF) \ - O(CUGetL, ONE(LA), NOV, ONE(CUV), NF) \ - O(CGetL2, ONE(NLA), ONE(CV), TWO(CV,CV), NF) \ - O(PushL, ONE(LA), NOV, ONE(CV), NF) \ - O(CGetG, NA, ONE(CV), ONE(CV), NF) \ - O(CGetS, ONE(OA(ReadonlyOp)), \ - TWO(CV,CV), ONE(CV), NF) \ - O(ClassGetC, NA, ONE(CV), ONE(CV), NF) \ - O(ClassGetTS, NA, ONE(CV), TWO(CV,CV), NF) \ - O(GetMemoKeyL, ONE(NLA), NOV, ONE(CV), NF) \ - O(AKExists, NA, TWO(CV,CV), ONE(CV), NF) \ - O(IssetL, ONE(LA), NOV, ONE(CV), NF) \ - O(IssetG, NA, ONE(CV), ONE(CV), NF) \ - O(IssetS, NA, TWO(CV,CV), ONE(CV), NF) \ - O(IsUnsetL, ONE(LA), NOV, ONE(CV), NF) \ - O(IsTypeC, ONE(OA(IsTypeOp)),ONE(CV), ONE(CV), NF) \ - O(IsTypeL, TWO(NLA, \ - OA(IsTypeOp)), NOV, ONE(CV), NF) \ - O(AssertRATL, TWO(ILA,RATA), NOV, NOV, NF) \ - O(AssertRATStk, TWO(IVA,RATA), NOV, NOV, NF) \ - O(SetL, ONE(LA), ONE(CV), ONE(CV), NF) \ - O(SetG, NA, TWO(CV,CV), ONE(CV), NF) \ - O(SetS, ONE(OA(ReadonlyOp)), \ - THREE(CV,CV,CV), ONE(CV), NF) \ - O(SetOpL, TWO(LA, \ - OA(SetOpOp)), ONE(CV), ONE(CV), NF) \ - O(SetOpG, ONE(OA(SetOpOp)), TWO(CV,CV), ONE(CV), NF) \ - O(SetOpS, ONE(OA(SetOpOp)), THREE(CV,CV,CV), ONE(CV), NF) \ - O(IncDecL, TWO(NLA, OA(IncDecOp)), \ - NOV, ONE(CV), NF) \ - O(IncDecG, ONE(OA(IncDecOp)),ONE(CV), ONE(CV), NF) \ - O(IncDecS, ONE(OA(IncDecOp)),TWO(CV,CV), ONE(CV), NF) \ - O(UnsetL, ONE(LA), NOV, NOV, NF) \ - O(UnsetG, NA, ONE(CV), NOV, NF) \ - \ - O(ResolveFunc, ONE(SA), NOV, ONE(CV), NF) \ - O(ResolveMethCaller,ONE(SA), NOV, ONE(CV), NF) \ - O(ResolveRFunc, ONE(SA), ONE(CV), ONE(CV), NF) \ - O(ResolveClsMethod,ONE(SA), ONE(CV), ONE(CV), NF) \ - O(ResolveClsMethodD, \ - TWO(SA,SA), NOV, ONE(CV), NF) \ - O(ResolveClsMethodS, \ - TWO(OA(SpecialClsRef),SA), \ - NOV, ONE(CV), NF) \ - O(ResolveRClsMethod, \ - ONE(SA), TWO(CV,CV), ONE(CV), NF) \ - O(ResolveRClsMethodD, \ - TWO(SA,SA), ONE(CV), ONE(CV), NF) \ - O(ResolveRClsMethodS, \ - TWO(OA(SpecialClsRef),SA), \ - ONE(CV), ONE(CV), NF) \ - O(ResolveClass, ONE(SA), NOV, ONE(CV), NF) \ - O(LazyClass, ONE(SA), NOV, ONE(CV), NF) \ - O(NewObj, NA, ONE(CV), ONE(CV), NF) \ - O(NewObjR, NA, TWO(CV,CV), ONE(CV), NF) \ - O(NewObjD, ONE(SA), NOV, ONE(CV), NF) \ - O(NewObjRD, ONE(SA), ONE(CV), ONE(CV), NF) \ - O(NewObjS, ONE(OA(SpecialClsRef)), \ - NOV, ONE(CV), NF) \ - O(LockObj, NA, ONE(CV), ONE(CV), NF) \ - O(FCallClsMethod, THREE(FCA,SA,OA(IsLogAsDynamicCallOp)), \ - FCALL(2, 0), FCALL, CF) \ - O(FCallClsMethodD, FOUR(FCA,SA,SA,SA), \ - FCALL(0, 0), FCALL, CF) \ - O(FCallClsMethodS, THREE(FCA,SA,OA(SpecialClsRef)), \ - FCALL(1, 0), FCALL, CF) \ - O(FCallClsMethodSD,FOUR(FCA,SA,OA(SpecialClsRef),SA), \ - FCALL(0, 0), FCALL, CF) \ - O(FCallCtor, TWO(FCA,SA), FCALL(0, 1), FCALL, CF) \ - O(FCallFunc, ONE(FCA), FCALL(1, 0), FCALL, CF) \ - O(FCallFuncD, TWO(FCA,SA), FCALL(0, 0), FCALL, CF) \ - O(FCallObjMethod, THREE(FCA,SA,OA(ObjMethodOp)), \ - FCALL(1, 1), FCALL, CF) \ - O(FCallObjMethodD, FOUR(FCA,SA,OA(ObjMethodOp),SA), \ - FCALL(0, 1), FCALL, CF) \ - O(IterInit, TWO(ITA,BA), ONE(CV), NOV, CF) \ - O(LIterInit, THREE(ITA,LA,BA), NOV, NOV, CF) \ - O(IterNext, TWO(ITA,BA), NOV, NOV, CF) \ - O(LIterNext, THREE(ITA,LA,BA), NOV, NOV, CF) \ - O(IterFree, ONE(IA), NOV, NOV, NF) \ - O(LIterFree, TWO(IA,LA), NOV, NOV, NF) \ - O(Incl, NA, ONE(CV), ONE(CV), NF) \ - O(InclOnce, NA, ONE(CV), ONE(CV), NF) \ - O(Req, NA, ONE(CV), ONE(CV), NF) \ - O(ReqOnce, NA, ONE(CV), ONE(CV), NF) \ - O(ReqDoc, NA, ONE(CV), ONE(CV), NF) \ - O(Eval, NA, ONE(CV), ONE(CV), NF) \ - O(This, NA, NOV, ONE(CV), NF) \ - O(BareThis, ONE(OA(BareThisOp)), \ - NOV, ONE(CV), NF) \ - O(CheckThis, NA, NOV, NOV, NF) \ - O(ChainFaults, NA, TWO(CV,CV), ONE(CV), NF) \ - O(OODeclExists, ONE(OA(OODeclExistsOp)), \ - TWO(CV,CV), ONE(CV), NF) \ - O(VerifyOutType, ONE(IVA), ONE(CV), ONE(CV), NF) \ - O(VerifyParamType, ONE(ILA), NOV, NOV, NF) \ - O(VerifyParamTypeTS, ONE(ILA), ONE(CV), NOV, NF) \ - O(VerifyRetTypeC, NA, ONE(CV), ONE(CV), NF) \ - O(VerifyRetTypeTS, NA, TWO(CV,CV), ONE(CV), NF) \ - O(VerifyRetNonNullC, NA, ONE(CV), ONE(CV), NF) \ - O(SelfCls, NA, NOV, ONE(CV), NF) \ - O(ParentCls, NA, NOV, ONE(CV), NF) \ - O(LateBoundCls, NA, NOV, ONE(CV), NF) \ - O(RecordReifiedGeneric, NA, ONE(CV), ONE(CV), NF) \ - O(CheckReifiedGenericMismatch, NA, ONE(CV), NOV, NF) \ - O(NativeImpl, NA, NOV, NOV, CF_TF) \ - O(CreateCl, TWO(IVA,IVA), CUMANY, ONE(CV), NF) \ - O(CreateCont, NA, NOV, ONE(CV), CF) \ - O(ContEnter, NA, ONE(CV), ONE(CV), CF) \ - O(ContRaise, NA, ONE(CV), ONE(CV), CF) \ - O(Yield, NA, ONE(CV), ONE(CV), CF) \ - O(YieldK, NA, TWO(CV,CV), ONE(CV), CF) \ - O(ContCheck, ONE(OA(ContCheckOp)), NOV, NOV, NF) \ - O(ContValid, NA, NOV, ONE(CV), NF) \ - O(ContKey, NA, NOV, ONE(CV), NF) \ - O(ContCurrent, NA, NOV, ONE(CV), NF) \ - O(ContGetReturn, NA, NOV, ONE(CV), NF) \ - O(WHResult, NA, ONE(CV), ONE(CV), NF) \ - O(SetImplicitContextByValue, \ - NA, ONE(CV), ONE(CV), NF) \ - O(Await, NA, ONE(CV), ONE(CV), CF) \ - O(AwaitAll, ONE(LAR), NOV, ONE(CV), CF) \ - O(Idx, NA, THREE(CV,CV,CV), ONE(CV), NF) \ - O(ArrayIdx, NA, THREE(CV,CV,CV), ONE(CV), NF) \ - O(ArrayMarkLegacy, NA, TWO(CV,CV), ONE(CV), NF) \ - O(ArrayUnmarkLegacy, NA, TWO(CV,CV), ONE(CV), NF) \ - O(CheckProp, ONE(SA), NOV, ONE(CV), NF) \ - O(InitProp, TWO(SA, OA(InitPropOp)), \ - ONE(CV), NOV, NF) \ - O(Silence, TWO(LA,OA(SilenceOp)), \ - NOV, NOV, NF) \ - O(ThrowNonExhaustiveSwitch, NA, NOV, NOV, NF) \ - O(RaiseClassStringConversionWarning, \ - NA, NOV, NOV, NF) \ - O(BaseGC, TWO(IVA, OA(MOpMode)), \ - NOV, NOV, NF) \ - O(BaseGL, TWO(LA, OA(MOpMode)), \ - NOV, NOV, NF) \ - O(BaseSC, FOUR(IVA, IVA, OA(MOpMode), OA(ReadonlyOp)), \ - NOV, NOV, NF) \ - O(BaseL, THREE(NLA, OA(MOpMode), OA(ReadonlyOp)), \ - NOV, NOV, NF) \ - O(BaseC, TWO(IVA, OA(MOpMode)), \ - NOV, NOV, NF) \ - O(BaseH, NA, NOV, NOV, NF) \ - O(Dim, TWO(OA(MOpMode), KA), \ - NOV, NOV, NF) \ - O(QueryM, THREE(IVA, OA(QueryMOp), KA), \ - MFINAL, ONE(CV), NF) \ - O(SetM, TWO(IVA, KA), C_MFINAL(1), ONE(CV), NF) \ - O(SetRangeM, THREE(IVA, IVA, OA(SetRangeOp)), \ - C_MFINAL(3), NOV, NF) \ - O(IncDecM, THREE(IVA, OA(IncDecOp), KA), \ - MFINAL, ONE(CV), NF) \ - O(SetOpM, THREE(IVA, OA(SetOpOp), KA), \ - C_MFINAL(1), ONE(CV), NF) \ - O(UnsetM, TWO(IVA, KA), MFINAL, NOV, NF) \ - O(MemoGet, TWO(BA, LAR), NOV, ONE(CV), CF) \ - O(MemoGetEager, THREE(BA, BA, LAR), \ - NOV, ONE(CV), CF) \ - O(MemoSet, ONE(LAR), ONE(CV), ONE(CV), NF) \ - O(MemoSetEager, ONE(LAR), ONE(CV), ONE(CV), NF) - #define O(...) + 1 constexpr size_t Op_count = OPCODES; #undef O diff --git a/hphp/runtime/vm/opcodes.h b/hphp/runtime/vm/opcodes.h new file mode 100644 index 00000000000000..ca98dcbdd8265a --- /dev/null +++ b/hphp/runtime/vm/opcodes.h @@ -0,0 +1,292 @@ +/* + +----------------------------------------------------------------------+ + | HipHop for PHP | + +----------------------------------------------------------------------+ + | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ +*/ + +#pragma once + +/* The OPCODES macro is used in many places across HHVM and HackC. Keeping it + * in this file allows us to keep includes lightweight. + */ + +namespace HPHP { + +// name immediates inputs outputs flags +#define OPCODES \ + O(Nop, NA, NOV, NOV, NF) \ + O(EntryNop, NA, NOV, NOV, NF) \ + O(BreakTraceHint, NA, NOV, NOV, NF) \ + O(PopC, NA, ONE(CV), NOV, NF) \ + O(PopU, NA, ONE(UV), NOV, NF) \ + O(PopU2, NA, TWO(CV,UV), ONE(CV), NF) \ + O(PopL, ONE(LA), ONE(CV), NOV, NF) \ + O(Dup, NA, ONE(CV), TWO(CV,CV), NF) \ + O(CGetCUNop, NA, ONE(CUV), ONE(CV), NF) \ + O(UGetCUNop, NA, ONE(CUV), ONE(UV), NF) \ + O(Null, NA, NOV, ONE(CV), NF) \ + O(NullUninit, NA, NOV, ONE(UV), NF) \ + O(True, NA, NOV, ONE(CV), NF) \ + O(False, NA, NOV, ONE(CV), NF) \ + O(FuncCred, NA, NOV, ONE(CV), NF) \ + O(Int, ONE(I64A), NOV, ONE(CV), NF) \ + O(Double, ONE(DA), NOV, ONE(CV), NF) \ + O(String, ONE(SA), NOV, ONE(CV), NF) \ + O(Dict, ONE(AA), NOV, ONE(CV), NF) \ + O(Keyset, ONE(AA), NOV, ONE(CV), NF) \ + O(Vec, ONE(AA), NOV, ONE(CV), NF) \ + O(NewDictArray, ONE(IVA), NOV, ONE(CV), NF) \ + O(NewStructDict, ONE(VSA), SMANY, ONE(CV), NF) \ + O(NewVec, ONE(IVA), CMANY, ONE(CV), NF) \ + O(NewKeysetArray, ONE(IVA), CMANY, ONE(CV), NF) \ + O(AddElemC, NA, THREE(CV,CV,CV), ONE(CV), NF) \ + O(AddNewElemC, NA, TWO(CV,CV), ONE(CV), NF) \ + O(NewCol, ONE(OA(CollectionType)), \ + NOV, ONE(CV), NF) \ + O(NewPair, NA, TWO(CV,CV), ONE(CV), NF) \ + O(ColFromArray, ONE(OA(CollectionType)), \ + ONE(CV), ONE(CV), NF) \ + O(CnsE, ONE(SA), NOV, ONE(CV), NF) \ + O(ClsCns, ONE(SA), ONE(CV), ONE(CV), NF) \ + O(ClsCnsD, TWO(SA,SA), NOV, ONE(CV), NF) \ + O(ClsCnsL, ONE(LA), ONE(CV), ONE(CV), NF) \ + O(ClassName, NA, ONE(CV), ONE(CV), NF) \ + O(LazyClassFromClass, NA, ONE(CV), ONE(CV), NF) \ + O(File, NA, NOV, ONE(CV), NF) \ + O(Dir, NA, NOV, ONE(CV), NF) \ + O(Method, NA, NOV, ONE(CV), NF) \ + O(Concat, NA, TWO(CV,CV), ONE(CV), NF) \ + O(ConcatN, ONE(IVA), CMANY, ONE(CV), NF) \ + O(Add, NA, TWO(CV,CV), ONE(CV), NF) \ + O(Sub, NA, TWO(CV,CV), ONE(CV), NF) \ + O(Mul, NA, TWO(CV,CV), ONE(CV), NF) \ + O(AddO, NA, TWO(CV,CV), ONE(CV), NF) \ + O(SubO, NA, TWO(CV,CV), ONE(CV), NF) \ + O(MulO, NA, TWO(CV,CV), ONE(CV), NF) \ + O(Div, NA, TWO(CV,CV), ONE(CV), NF) \ + O(Mod, NA, TWO(CV,CV), ONE(CV), NF) \ + O(Pow, NA, TWO(CV,CV), ONE(CV), NF) \ + O(Not, NA, ONE(CV), ONE(CV), NF) \ + O(Same, NA, TWO(CV,CV), ONE(CV), NF) \ + O(NSame, NA, TWO(CV,CV), ONE(CV), NF) \ + O(Eq, NA, TWO(CV,CV), ONE(CV), NF) \ + O(Neq, NA, TWO(CV,CV), ONE(CV), NF) \ + O(Lt, NA, TWO(CV,CV), ONE(CV), NF) \ + O(Lte, NA, TWO(CV,CV), ONE(CV), NF) \ + O(Gt, NA, TWO(CV,CV), ONE(CV), NF) \ + O(Gte, NA, TWO(CV,CV), ONE(CV), NF) \ + O(Cmp, NA, TWO(CV,CV), ONE(CV), NF) \ + O(BitAnd, NA, TWO(CV,CV), ONE(CV), NF) \ + O(BitOr, NA, TWO(CV,CV), ONE(CV), NF) \ + O(BitXor, NA, TWO(CV,CV), ONE(CV), NF) \ + O(BitNot, NA, ONE(CV), ONE(CV), NF) \ + O(Shl, NA, TWO(CV,CV), ONE(CV), NF) \ + O(Shr, NA, TWO(CV,CV), ONE(CV), NF) \ + O(CastBool, NA, ONE(CV), ONE(CV), NF) \ + O(CastInt, NA, ONE(CV), ONE(CV), NF) \ + O(CastDouble, NA, ONE(CV), ONE(CV), NF) \ + O(CastString, NA, ONE(CV), ONE(CV), NF) \ + O(CastDict, NA, ONE(CV), ONE(CV), NF) \ + O(CastKeyset, NA, ONE(CV), ONE(CV), NF) \ + O(CastVec, NA, ONE(CV), ONE(CV), NF) \ + O(DblAsBits, NA, ONE(CV), ONE(CV), NF) \ + O(InstanceOf, NA, TWO(CV,CV), ONE(CV), NF) \ + O(InstanceOfD, ONE(SA), ONE(CV), ONE(CV), NF) \ + O(IsLateBoundCls, NA, ONE(CV), ONE(CV), NF) \ + O(IsTypeStructC, ONE(OA(TypeStructResolveOp)), \ + TWO(CV,CV), ONE(CV), NF) \ + O(ThrowAsTypeStructException, \ + NA, TWO(CV,CV), NOV, TF) \ + O(CombineAndResolveTypeStruct, \ + ONE(IVA), CMANY, ONE(CV), NF) \ + O(Select, NA, THREE(CV,CV,CV), ONE(CV), NF) \ + O(Print, NA, ONE(CV), ONE(CV), NF) \ + O(Clone, NA, ONE(CV), ONE(CV), NF) \ + O(Exit, NA, ONE(CV), ONE(CV), TF) \ + O(Fatal, ONE(OA(FatalOp)), ONE(CV), NOV, TF) \ + O(Jmp, ONE(BA), NOV, NOV, CF_TF) \ + O(JmpNS, ONE(BA), NOV, NOV, CF_TF) \ + O(JmpZ, ONE(BA), ONE(CV), NOV, CF) \ + O(JmpNZ, ONE(BA), ONE(CV), NOV, CF) \ + O(Switch, THREE(OA(SwitchKind),I64A,BLA), \ + ONE(CV), NOV, CF_TF) \ + O(SSwitch, ONE(SLA), ONE(CV), NOV, CF_TF) \ + O(RetC, NA, ONE(CV), NOV, CF_TF) \ + O(RetM, ONE(IVA), CMANY, NOV, CF_TF) \ + O(RetCSuspended, NA, ONE(CV), NOV, CF_TF) \ + O(Throw, NA, ONE(CV), NOV, CF_TF) \ + O(CGetL, ONE(NLA), NOV, ONE(CV), NF) \ + O(CGetQuietL, ONE(LA), NOV, ONE(CV), NF) \ + O(CUGetL, ONE(LA), NOV, ONE(CUV), NF) \ + O(CGetL2, ONE(NLA), ONE(CV), TWO(CV,CV), NF) \ + O(PushL, ONE(LA), NOV, ONE(CV), NF) \ + O(CGetG, NA, ONE(CV), ONE(CV), NF) \ + O(CGetS, ONE(OA(ReadonlyOp)), \ + TWO(CV,CV), ONE(CV), NF) \ + O(ClassGetC, NA, ONE(CV), ONE(CV), NF) \ + O(ClassGetTS, NA, ONE(CV), TWO(CV,CV), NF) \ + O(GetMemoKeyL, ONE(NLA), NOV, ONE(CV), NF) \ + O(AKExists, NA, TWO(CV,CV), ONE(CV), NF) \ + O(IssetL, ONE(LA), NOV, ONE(CV), NF) \ + O(IssetG, NA, ONE(CV), ONE(CV), NF) \ + O(IssetS, NA, TWO(CV,CV), ONE(CV), NF) \ + O(IsUnsetL, ONE(LA), NOV, ONE(CV), NF) \ + O(IsTypeC, ONE(OA(IsTypeOp)),ONE(CV), ONE(CV), NF) \ + O(IsTypeL, TWO(NLA, \ + OA(IsTypeOp)), NOV, ONE(CV), NF) \ + O(AssertRATL, TWO(ILA,RATA), NOV, NOV, NF) \ + O(AssertRATStk, TWO(IVA,RATA), NOV, NOV, NF) \ + O(SetL, ONE(LA), ONE(CV), ONE(CV), NF) \ + O(SetG, NA, TWO(CV,CV), ONE(CV), NF) \ + O(SetS, ONE(OA(ReadonlyOp)), \ + THREE(CV,CV,CV), ONE(CV), NF) \ + O(SetOpL, TWO(LA, \ + OA(SetOpOp)), ONE(CV), ONE(CV), NF) \ + O(SetOpG, ONE(OA(SetOpOp)), TWO(CV,CV), ONE(CV), NF) \ + O(SetOpS, ONE(OA(SetOpOp)), THREE(CV,CV,CV), ONE(CV), NF) \ + O(IncDecL, TWO(NLA, OA(IncDecOp)), \ + NOV, ONE(CV), NF) \ + O(IncDecG, ONE(OA(IncDecOp)),ONE(CV), ONE(CV), NF) \ + O(IncDecS, ONE(OA(IncDecOp)),TWO(CV,CV), ONE(CV), NF) \ + O(UnsetL, ONE(LA), NOV, NOV, NF) \ + O(UnsetG, NA, ONE(CV), NOV, NF) \ + \ + O(ResolveFunc, ONE(SA), NOV, ONE(CV), NF) \ + O(ResolveMethCaller,ONE(SA), NOV, ONE(CV), NF) \ + O(ResolveRFunc, ONE(SA), ONE(CV), ONE(CV), NF) \ + O(ResolveClsMethod,ONE(SA), ONE(CV), ONE(CV), NF) \ + O(ResolveClsMethodD, \ + TWO(SA,SA), NOV, ONE(CV), NF) \ + O(ResolveClsMethodS, \ + TWO(OA(SpecialClsRef),SA), \ + NOV, ONE(CV), NF) \ + O(ResolveRClsMethod, \ + ONE(SA), TWO(CV,CV), ONE(CV), NF) \ + O(ResolveRClsMethodD, \ + TWO(SA,SA), ONE(CV), ONE(CV), NF) \ + O(ResolveRClsMethodS, \ + TWO(OA(SpecialClsRef),SA), \ + ONE(CV), ONE(CV), NF) \ + O(ResolveClass, ONE(SA), NOV, ONE(CV), NF) \ + O(LazyClass, ONE(SA), NOV, ONE(CV), NF) \ + O(NewObj, NA, ONE(CV), ONE(CV), NF) \ + O(NewObjR, NA, TWO(CV,CV), ONE(CV), NF) \ + O(NewObjD, ONE(SA), NOV, ONE(CV), NF) \ + O(NewObjRD, ONE(SA), ONE(CV), ONE(CV), NF) \ + O(NewObjS, ONE(OA(SpecialClsRef)), \ + NOV, ONE(CV), NF) \ + O(LockObj, NA, ONE(CV), ONE(CV), NF) \ + O(FCallClsMethod, THREE(FCA,SA,OA(IsLogAsDynamicCallOp)), \ + FCALL(2, 0), FCALL, CF) \ + O(FCallClsMethodD, FOUR(FCA,SA,SA,SA), \ + FCALL(0, 0), FCALL, CF) \ + O(FCallClsMethodS, THREE(FCA,SA,OA(SpecialClsRef)), \ + FCALL(1, 0), FCALL, CF) \ + O(FCallClsMethodSD,FOUR(FCA,SA,OA(SpecialClsRef),SA), \ + FCALL(0, 0), FCALL, CF) \ + O(FCallCtor, TWO(FCA,SA), FCALL(0, 1), FCALL, CF) \ + O(FCallFunc, ONE(FCA), FCALL(1, 0), FCALL, CF) \ + O(FCallFuncD, TWO(FCA,SA), FCALL(0, 0), FCALL, CF) \ + O(FCallObjMethod, THREE(FCA,SA,OA(ObjMethodOp)), \ + FCALL(1, 1), FCALL, CF) \ + O(FCallObjMethodD, FOUR(FCA,SA,OA(ObjMethodOp),SA), \ + FCALL(0, 1), FCALL, CF) \ + O(IterInit, TWO(ITA,BA), ONE(CV), NOV, CF) \ + O(LIterInit, THREE(ITA,LA,BA), NOV, NOV, CF) \ + O(IterNext, TWO(ITA,BA), NOV, NOV, CF) \ + O(LIterNext, THREE(ITA,LA,BA), NOV, NOV, CF) \ + O(IterFree, ONE(IA), NOV, NOV, NF) \ + O(LIterFree, TWO(IA,LA), NOV, NOV, NF) \ + O(Incl, NA, ONE(CV), ONE(CV), NF) \ + O(InclOnce, NA, ONE(CV), ONE(CV), NF) \ + O(Req, NA, ONE(CV), ONE(CV), NF) \ + O(ReqOnce, NA, ONE(CV), ONE(CV), NF) \ + O(ReqDoc, NA, ONE(CV), ONE(CV), NF) \ + O(Eval, NA, ONE(CV), ONE(CV), NF) \ + O(This, NA, NOV, ONE(CV), NF) \ + O(BareThis, ONE(OA(BareThisOp)), \ + NOV, ONE(CV), NF) \ + O(CheckThis, NA, NOV, NOV, NF) \ + O(ChainFaults, NA, TWO(CV,CV), ONE(CV), NF) \ + O(OODeclExists, ONE(OA(OODeclExistsOp)), \ + TWO(CV,CV), ONE(CV), NF) \ + O(VerifyOutType, ONE(IVA), ONE(CV), ONE(CV), NF) \ + O(VerifyParamType, ONE(ILA), NOV, NOV, NF) \ + O(VerifyParamTypeTS, ONE(ILA), ONE(CV), NOV, NF) \ + O(VerifyRetTypeC, NA, ONE(CV), ONE(CV), NF) \ + O(VerifyRetTypeTS, NA, TWO(CV,CV), ONE(CV), NF) \ + O(VerifyRetNonNullC, NA, ONE(CV), ONE(CV), NF) \ + O(SelfCls, NA, NOV, ONE(CV), NF) \ + O(ParentCls, NA, NOV, ONE(CV), NF) \ + O(LateBoundCls, NA, NOV, ONE(CV), NF) \ + O(RecordReifiedGeneric, NA, ONE(CV), ONE(CV), NF) \ + O(CheckReifiedGenericMismatch, NA, ONE(CV), NOV, NF) \ + O(NativeImpl, NA, NOV, NOV, CF_TF) \ + O(CreateCl, TWO(IVA,IVA), CUMANY, ONE(CV), NF) \ + O(CreateCont, NA, NOV, ONE(CV), CF) \ + O(ContEnter, NA, ONE(CV), ONE(CV), CF) \ + O(ContRaise, NA, ONE(CV), ONE(CV), CF) \ + O(Yield, NA, ONE(CV), ONE(CV), CF) \ + O(YieldK, NA, TWO(CV,CV), ONE(CV), CF) \ + O(ContCheck, ONE(OA(ContCheckOp)), NOV, NOV, NF) \ + O(ContValid, NA, NOV, ONE(CV), NF) \ + O(ContKey, NA, NOV, ONE(CV), NF) \ + O(ContCurrent, NA, NOV, ONE(CV), NF) \ + O(ContGetReturn, NA, NOV, ONE(CV), NF) \ + O(WHResult, NA, ONE(CV), ONE(CV), NF) \ + O(SetImplicitContextByValue, \ + NA, ONE(CV), ONE(CV), NF) \ + O(Await, NA, ONE(CV), ONE(CV), CF) \ + O(AwaitAll, ONE(LAR), NOV, ONE(CV), CF) \ + O(Idx, NA, THREE(CV,CV,CV), ONE(CV), NF) \ + O(ArrayIdx, NA, THREE(CV,CV,CV), ONE(CV), NF) \ + O(ArrayMarkLegacy, NA, TWO(CV,CV), ONE(CV), NF) \ + O(ArrayUnmarkLegacy, NA, TWO(CV,CV), ONE(CV), NF) \ + O(CheckProp, ONE(SA), NOV, ONE(CV), NF) \ + O(InitProp, TWO(SA, OA(InitPropOp)), \ + ONE(CV), NOV, NF) \ + O(Silence, TWO(LA,OA(SilenceOp)), \ + NOV, NOV, NF) \ + O(ThrowNonExhaustiveSwitch, NA, NOV, NOV, NF) \ + O(RaiseClassStringConversionWarning, \ + NA, NOV, NOV, NF) \ + O(BaseGC, TWO(IVA, OA(MOpMode)), \ + NOV, NOV, NF) \ + O(BaseGL, TWO(LA, OA(MOpMode)), \ + NOV, NOV, NF) \ + O(BaseSC, FOUR(IVA, IVA, OA(MOpMode), OA(ReadonlyOp)), \ + NOV, NOV, NF) \ + O(BaseL, THREE(NLA, OA(MOpMode), OA(ReadonlyOp)), \ + NOV, NOV, NF) \ + O(BaseC, TWO(IVA, OA(MOpMode)), \ + NOV, NOV, NF) \ + O(BaseH, NA, NOV, NOV, NF) \ + O(Dim, TWO(OA(MOpMode), KA), \ + NOV, NOV, NF) \ + O(QueryM, THREE(IVA, OA(QueryMOp), KA), \ + MFINAL, ONE(CV), NF) \ + O(SetM, TWO(IVA, KA), C_MFINAL(1), ONE(CV), NF) \ + O(SetRangeM, THREE(IVA, IVA, OA(SetRangeOp)), \ + C_MFINAL(3), NOV, NF) \ + O(IncDecM, THREE(IVA, OA(IncDecOp), KA), \ + MFINAL, ONE(CV), NF) \ + O(SetOpM, THREE(IVA, OA(SetOpOp), KA), \ + C_MFINAL(1), ONE(CV), NF) \ + O(UnsetM, TWO(IVA, KA), MFINAL, NOV, NF) \ + O(MemoGet, TWO(BA, LAR), NOV, ONE(CV), CF) \ + O(MemoGetEager, THREE(BA, BA, LAR), \ + NOV, ONE(CV), CF) \ + O(MemoSet, ONE(LAR), ONE(CV), ONE(CV), NF) \ + O(MemoSetEager, ONE(LAR), ONE(CV), ONE(CV), NF) + +} diff --git a/hphp/tools/hhbc-gen/gen-rust.cpp b/hphp/tools/hhbc-gen/gen-rust.cpp index f6545a21084ef4..1342a469f42e2a 100644 --- a/hphp/tools/hhbc-gen/gen-rust.cpp +++ b/hphp/tools/hhbc-gen/gen-rust.cpp @@ -15,7 +15,8 @@ */ #include -#include "hphp/runtime/vm/hhbc.h" +#include +#include "hphp/runtime/vm/opcodes.h" using namespace HPHP; diff --git a/hphp/tools/hhbc-gen/hhbc.rs b/hphp/tools/hhbc-gen/hhbc.rs index cd174c7c3d8606..d5bfff405580df 100644 --- a/hphp/tools/hhbc-gen/hhbc.rs +++ b/hphp/tools/hhbc-gen/hhbc.rs @@ -6,12 +6,17 @@ // NOTE: Most of the types in this file come from runtime/vm/hhbc.h and need to // be kept in sync. -mod opcodes; - use bitflags::bitflags; use once_cell::sync::OnceCell; use std::collections::{HashMap, HashSet}; +#[cfg(fbcode_build)] +mod opcodes; +#[cfg(not(fbcode_build))] +mod opcodes { + include!(concat!(env!("CMAKE_BINARY_DIR"), "/hphp/tools/opcodes.rs")); +} + #[derive(Clone, Debug, Eq, PartialEq)] pub enum FlavorDesc { CUV,