Use custom AssemblyAnnotationWriter to improve vasm/llvm printing
[hiphop-php.git] / hphp / runtime / vm / as-shared.cpp
blob57b6c6d683e6089d5fa5c7df1e005e241472342e
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-2014 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/runtime/vm/as-shared.h"
18 #include <folly/gen/Base.h>
19 #include <folly/gen/String.h>
21 #include <vector>
23 namespace HPHP {
25 //////////////////////////////////////////////////////////////////////
27 namespace {
29 using ContextMask = uint32_t;
31 constexpr auto C = static_cast<ContextMask>(AttrContext::Class);
32 constexpr auto F = static_cast<ContextMask>(AttrContext::Func);
33 constexpr auto P = static_cast<ContextMask>(AttrContext::Prop);
34 constexpr auto T = static_cast<ContextMask>(AttrContext::TraitImport);
36 constexpr bool supported(ContextMask mask, AttrContext a) {
37 return mask & static_cast<ContextMask>(a);
40 #define HHAS_ATTRS \
41 X(AttrPublic, F|P|T, "public"); \
42 X(AttrProtected, F|P|T, "protected"); \
43 X(AttrPrivate, F|P|T, "private"); \
44 X(AttrStatic, F|P, "static"); \
45 X(AttrInterface, C, "interface"); \
46 X(AttrNoExpandTrait, C, "no_expand_trait"); \
47 X(AttrAbstract, C|F|T, "abstract"); \
48 X(AttrNoOverride, C|F|T, "no_override"); \
49 X(AttrFinal, C|F|T, "final"); \
50 X(AttrTrait, C|F, "trait"); \
51 X(AttrUnique, C|F, "unique"); \
52 X(AttrBuiltin, C|F, "builtin"); \
53 X(AttrNoOverrideMagicGet, C, "nov_get"); \
54 X(AttrNoOverrideMagicSet, C, "nov_set"); \
55 X(AttrNoOverrideMagicIsset, C, "nov_isset"); \
56 X(AttrNoOverrideMagicUnset, C, "nov_unset");
60 //////////////////////////////////////////////////////////////////////
62 std::string attrs_to_string(AttrContext ctx, Attr attrs) {
63 std::vector<std::string> vec;
65 #define X(attr, mask, str) \
66 if (supported(mask, ctx) && (attrs & attr)) vec.push_back(str);
67 HHAS_ATTRS
68 #undef X
70 using namespace folly::gen;
71 return from(vec) | unsplit<std::string>(" ");
74 folly::Optional<Attr> string_to_attr(AttrContext ctx,
75 const std::string& name) {
76 #define X(attr, mask, str) \
77 if (supported(mask, ctx) && name == str) return attr;
78 HHAS_ATTRS
79 #undef X
81 return folly::none;
84 //////////////////////////////////////////////////////////////////////