Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 1 | // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef V8_COMPILER_FAST_ACCESSOR_ASSEMBLER_H_ |
| 6 | #define V8_COMPILER_FAST_ACCESSOR_ASSEMBLER_H_ |
| 7 | |
| 8 | #include <stdint.h> |
| 9 | #include <vector> |
| 10 | |
| 11 | // Clients of this interface shouldn't depend on lots of compiler internals. |
| 12 | // Do not include anything from src/compiler here! |
| 13 | #include "include/v8-experimental.h" |
| 14 | #include "src/base/macros.h" |
| 15 | #include "src/base/smart-pointers.h" |
| 16 | #include "src/handles.h" |
| 17 | |
| 18 | |
| 19 | namespace v8 { |
| 20 | namespace internal { |
| 21 | |
| 22 | class Code; |
| 23 | class Isolate; |
| 24 | class Zone; |
| 25 | |
| 26 | namespace compiler { |
| 27 | |
| 28 | class Node; |
| 29 | class RawMachineAssembler; |
| 30 | class RawMachineLabel; |
| 31 | |
| 32 | |
| 33 | // This interface "exports" an aggregated subset of RawMachineAssembler, for |
| 34 | // use by the API to implement Fast Dom Accessors. |
| 35 | // |
| 36 | // This interface is made for this single purpose only and does not attempt |
| 37 | // to implement a general purpose solution. If you need one, please look at |
| 38 | // RawMachineAssembler instead. |
| 39 | // |
| 40 | // The life cycle of a FastAccessorAssembler has two phases: |
| 41 | // - After creating the instance, you can call an arbitrary sequence of |
| 42 | // builder functions to build the desired function. |
| 43 | // - When done, you can Build() the accessor and query for the build results. |
| 44 | // |
| 45 | // You cannot call any result getters before Build() was called & successful; |
| 46 | // and you cannot call any builder functions after Build() was called. |
| 47 | class FastAccessorAssembler { |
| 48 | public: |
| 49 | typedef v8::experimental::FastAccessorBuilder::ValueId ValueId; |
| 50 | typedef v8::experimental::FastAccessorBuilder::LabelId LabelId; |
| 51 | |
| 52 | explicit FastAccessorAssembler(Isolate* isolate); |
| 53 | ~FastAccessorAssembler(); |
| 54 | |
| 55 | // Builder / assembler functions: |
| 56 | ValueId IntegerConstant(int int_constant); |
| 57 | ValueId GetReceiver(); |
| 58 | ValueId LoadInternalField(ValueId value_id, int field_no); |
| 59 | ValueId LoadValue(ValueId value_id, int offset); |
| 60 | ValueId LoadObject(ValueId value_id, int offset); |
| 61 | |
| 62 | // Builder / assembler functions for control flow. |
| 63 | void ReturnValue(ValueId value_id); |
| 64 | void CheckFlagSetOrReturnNull(ValueId value_id, int mask); |
| 65 | void CheckNotZeroOrReturnNull(ValueId value_id); |
| 66 | |
| 67 | // TODO(vogelheim): Implement a C++ callback. |
| 68 | // void CheckNotNullOrCallback(ValueId value_id, ..c++-callback type..., |
| 69 | // ValueId arg1, ValueId arg2, ...); |
| 70 | |
| 71 | LabelId MakeLabel(); |
| 72 | void SetLabel(LabelId label_id); |
| 73 | void CheckNotZeroOrJump(ValueId value_id, LabelId label_id); |
| 74 | |
| 75 | // Assemble the code. |
| 76 | MaybeHandle<Code> Build(); |
| 77 | |
| 78 | private: |
| 79 | ValueId FromRaw(Node* node); |
| 80 | LabelId FromRaw(RawMachineLabel* label); |
| 81 | Node* FromId(ValueId value) const; |
| 82 | RawMachineLabel* FromId(LabelId value) const; |
| 83 | |
| 84 | Zone* zone() { return &zone_; } |
| 85 | |
| 86 | Zone zone_; |
| 87 | base::SmartPointer<RawMachineAssembler> assembler_; |
| 88 | |
| 89 | // To prevent exposing the RMA internals to the outside world, we'll map |
| 90 | // Node + Label pointers integers wrapped in ValueId and LabelId instances. |
| 91 | // These vectors maintain this mapping. |
| 92 | std::vector<Node*> nodes_; |
| 93 | std::vector<RawMachineLabel*> labels_; |
| 94 | |
| 95 | // Remember the current state for easy error checking. (We prefer to be |
| 96 | // strict as this class will be exposed at the API.) |
| 97 | enum { kBuilding, kBuilt, kError } state_; |
| 98 | |
| 99 | DISALLOW_COPY_AND_ASSIGN(FastAccessorAssembler); |
| 100 | }; |
| 101 | |
| 102 | } // namespace compiler |
| 103 | } // namespace internal |
| 104 | } // namespace v8 |
| 105 | |
| 106 | #endif // V8_COMPILER_FAST_ACCESSOR_ASSEMBLER_H_ |