2 +----------------------------------------------------------------------+
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/runtime-compiler.h"
18 #include "hphp/runtime/vm/native.h"
19 #include "hphp/runtime/vm/repo.h"
20 #include "hphp/runtime/base/static-string-table.h"
21 #include "hphp/runtime/base/unit-cache.h"
22 #include "hphp/zend/zend-string.h"
23 #include "hphp/util/assertions.h"
24 #include "hphp/util/sha1.h"
25 #include <folly/Range.h>
29 TRACE_SET_MOD(runtime
);
31 CompileStringFn g_hphp_compiler_parse
;
33 void hphp_compiler_init() {
34 g_hphp_compiler_parse(nullptr, 0, SHA1(), nullptr, Native::s_noNativeFuncs
,
35 nullptr, false, RepoOptions::defaults());
38 Unit
* compile_file(const char* s
, size_t sz
, const SHA1
& sha1
,
39 const char* fname
, const Native::FuncTable
& nativeFuncs
,
40 const RepoOptions
& options
, Unit
** releaseUnit
) {
41 return g_hphp_compiler_parse(s
, sz
, sha1
, fname
, nativeFuncs
, releaseUnit
,
45 Unit
* compile_string(const char* s
,
48 const Native::FuncTable
& nativeFuncs
,
49 const RepoOptions
& options
,
50 bool forDebuggerEval
) {
51 auto const name
= fname
? fname
: "";
52 auto const sha1
= SHA1
{
53 mangleUnitSha1(string_sha1(folly::StringPiece
{s
, sz
}), name
, options
)};
54 if (auto u
= Repo::get().loadUnit(name
, sha1
, nativeFuncs
).release()) {
57 // NB: fname needs to be long-lived if generating a bytecode repo because it
58 // can be cached via a Location ultimately contained by ErrorInfo for printing
60 return g_hphp_compiler_parse(s
, sz
, sha1
, fname
, nativeFuncs
, nullptr,
61 forDebuggerEval
, options
);
64 Unit
* compile_systemlib_string(const char* s
, size_t sz
, const char* fname
,
65 const Native::FuncTable
& nativeFuncs
) {
66 assertx(fname
[0] == '/' && fname
[1] == ':');
67 if (RuntimeOption::RepoAuthoritative
) {
68 if (auto u
= lookupSyslibUnit(makeStaticString(fname
), nativeFuncs
)) {
72 return compile_string(s
, sz
, fname
, nativeFuncs
, RepoOptions::defaults());
75 Unit
* compile_debugger_string(
76 const char* s
, size_t sz
, const RepoOptions
& options
78 return compile_string(
82 Native::s_noNativeFuncs
,