Deshim VirtualExecutor in folly
[hiphop-php.git] / hphp / hhbbc / unit-util.cpp
blobfddc4190ca98d77578e015d1a14d2e259eebab76
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 +----------------------------------------------------------------------+
16 #include "hphp/hhbbc/unit-util.h"
18 #include "hphp/hhbbc/representation.h"
19 #include "hphp/runtime/base/file-util.h"
20 #include "hphp/runtime/base/static-string-table.h"
21 #include "hphp/runtime/vm/native.h"
23 namespace HPHP::HHBBC {
25 //////////////////////////////////////////////////////////////////////
27 namespace {
28 const StaticString s_nativeUnitName("/!native");
31 //////////////////////////////////////////////////////////////////////
33 bool is_systemlib_part(SString filename) {
34 return FileUtil::isSystemName(filename->slice());
37 bool is_systemlib_part(const php::Unit& unit) {
38 return is_systemlib_part(unit.filename);
41 //////////////////////////////////////////////////////////////////////
43 bool is_native_unit(SString unit) {
44 return unit == s_nativeUnitName.get();
47 bool is_native_unit(const php::Unit& unit) {
48 return is_native_unit(unit.filename);
51 std::unique_ptr<php::Unit> make_native_unit() {
52 auto unit = std::make_unique<php::Unit>();
53 unit->filename = s_nativeUnitName.get();
55 for (auto const& [name, val] : Native::getConstants()) {
56 assertx(type(val) != KindOfUninit);
57 auto cns = std::make_unique<php::Constant>();
58 cns->name = name;
59 cns->val = val;
60 cns->attrs = AttrPersistent;
61 unit->constants.emplace_back(std::move(cns));
64 // Keep a consistent ordering of the constants.
65 std::sort(
66 begin(unit->constants),
67 end(unit->constants),
68 [] (const std::unique_ptr<php::Constant>& a,
69 const std::unique_ptr<php::Constant>& b) {
70 return string_data_lt{}(a->name, b->name);
74 return unit;
77 //////////////////////////////////////////////////////////////////////