convertClassKey expects key to have KnownDataType
[hiphop-php.git] / hphp / runtime / vm / jit / irgen-internal.cpp
blobb7276e439fd3cf6fd2dfec18a1329bae27560a59
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #include "hphp/runtime/vm/jit/irgen-internal.h"
19 namespace HPHP { namespace jit { namespace irgen {
21 //////////////////////////////////////////////////////////////////////
23 const StaticString
24 s_FATAL_NULL_THIS(Strings::FATAL_NULL_THIS),
25 s_clsToStringWarning(Strings::CLASS_TO_STRING);
27 SSATmp* checkAndLoadThis(IRGS& env) {
28 if (!hasThis(env)) {
29 auto const err = cns(env, s_FATAL_NULL_THIS.get());
30 gen(env, RaiseError, err);
31 return cns(env, TBottom);
33 return ldThis(env);
36 SSATmp* convertClsMethToVec(IRGS& env, SSATmp* clsMeth) {
37 assertx(clsMeth->isA(TClsMeth));
38 auto const cls = gen(env, LdClsName, gen(env, LdClsFromClsMeth, clsMeth));
39 auto const func = gen(env, LdFuncName, gen(env, LdFuncFromClsMeth, clsMeth));
40 auto vec = gen(env, AllocVArray, PackedArrayData { 2 });
41 gen(env, InitVecElem, IndexData { 0 }, vec, cls);
42 gen(env, InitVecElem, IndexData { 1 }, vec, func);
43 return vec;
46 SSATmp* convertClassKey(IRGS& env, SSATmp* key) {
47 assertx (key->type().isKnownDataType());
48 if (key->isA(TCls)) {
49 if (RuntimeOption::EvalRaiseClassConversionWarning) {
50 gen(env, RaiseWarning, cns(env, s_clsToStringWarning.get()));
52 return gen(env, LdClsName, key);
54 if (key->isA(TLazyCls)) {
55 if (RuntimeOption::EvalRaiseClassConversionWarning) {
56 gen(env, RaiseWarning, cns(env, s_clsToStringWarning.get()));
58 return gen(env, LdLazyClsName, key);
60 assertx(!key->type().maybe(TCls | TLazyCls));
61 return key;
64 void defineStack(IRGS& env, FPInvOffset bcSPOff) {
65 // Define SP.
66 if (resumeMode(env) != ResumeMode::None) {
67 // rvmsp() points to the top of the stack in resumables
68 auto const irSPOff = bcSPOff;
69 gen(env, DefRegSP, DefStackData { irSPOff, bcSPOff });
70 } else {
71 // stack starts at the FP in regular functions
72 auto const irSPOff = FPInvOffset { 0 };
73 gen(env, DefFrameRelSP, DefStackData { irSPOff, bcSPOff }, fp(env));
76 // Now that the stack is initialized, update the BC marker and perform
77 // initial sync of the exception stack boundary.
78 updateMarker(env);
79 env.irb->exceptionStackBoundary();
81 if (RuntimeOption::EvalHHIRGenerateAsserts) {
82 // Assert that we're in the correct function.
83 gen(env, DbgAssertFunc, fp(env));
87 }}}