blob: 346592ea43382876e455ae3db49fcc1e149731b3 [file] [log] [blame]
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001// 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
Ben Murdochda12d292016-06-02 14:46:10 +01005#ifndef V8_FAST_ACCESSOR_ASSEMBLER_H_
6#define V8_FAST_ACCESSOR_ASSEMBLER_H_
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00007
8#include <stdint.h>
9#include <vector>
10
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000011#include "include/v8-experimental.h"
12#include "src/base/macros.h"
13#include "src/base/smart-pointers.h"
14#include "src/handles.h"
15
Ben Murdochda12d292016-06-02 14:46:10 +010016// For CodeStubAssembler::Label. (We cannot forward-declare inner classes.)
Ben Murdochc5610432016-08-08 18:44:38 +010017#include "src/code-stub-assembler.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000018
19namespace v8 {
20namespace internal {
21
22class Code;
23class Isolate;
24class Zone;
25
26namespace compiler {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000027class Node;
Ben Murdochda12d292016-06-02 14:46:10 +010028}
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000029
30// This interface "exports" an aggregated subset of RawMachineAssembler, for
31// use by the API to implement Fast Dom Accessors.
32//
33// This interface is made for this single purpose only and does not attempt
34// to implement a general purpose solution. If you need one, please look at
35// RawMachineAssembler instead.
36//
37// The life cycle of a FastAccessorAssembler has two phases:
38// - After creating the instance, you can call an arbitrary sequence of
39// builder functions to build the desired function.
40// - When done, you can Build() the accessor and query for the build results.
41//
42// You cannot call any result getters before Build() was called & successful;
43// and you cannot call any builder functions after Build() was called.
44class FastAccessorAssembler {
45 public:
46 typedef v8::experimental::FastAccessorBuilder::ValueId ValueId;
47 typedef v8::experimental::FastAccessorBuilder::LabelId LabelId;
Ben Murdoch097c5b22016-05-18 11:27:45 +010048 typedef v8::FunctionCallback FunctionCallback;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000049
50 explicit FastAccessorAssembler(Isolate* isolate);
51 ~FastAccessorAssembler();
52
53 // Builder / assembler functions:
54 ValueId IntegerConstant(int int_constant);
55 ValueId GetReceiver();
56 ValueId LoadInternalField(ValueId value_id, int field_no);
57 ValueId LoadValue(ValueId value_id, int offset);
58 ValueId LoadObject(ValueId value_id, int offset);
59
60 // Builder / assembler functions for control flow.
61 void ReturnValue(ValueId value_id);
62 void CheckFlagSetOrReturnNull(ValueId value_id, int mask);
63 void CheckNotZeroOrReturnNull(ValueId value_id);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000064 LabelId MakeLabel();
65 void SetLabel(LabelId label_id);
66 void CheckNotZeroOrJump(ValueId value_id, LabelId label_id);
67
Ben Murdoch097c5b22016-05-18 11:27:45 +010068 // C++ callback.
69 ValueId Call(FunctionCallback callback, ValueId arg);
70
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000071 // Assemble the code.
72 MaybeHandle<Code> Build();
73
74 private:
Ben Murdochda12d292016-06-02 14:46:10 +010075 ValueId FromRaw(compiler::Node* node);
Ben Murdochc5610432016-08-08 18:44:38 +010076 LabelId FromRaw(CodeStubAssembler::Label* label);
Ben Murdochda12d292016-06-02 14:46:10 +010077 compiler::Node* FromId(ValueId value) const;
Ben Murdochc5610432016-08-08 18:44:38 +010078 CodeStubAssembler::Label* FromId(LabelId value) const;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000079
Ben Murdochda12d292016-06-02 14:46:10 +010080 void Clear();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000081 Zone* zone() { return &zone_; }
Ben Murdochda12d292016-06-02 14:46:10 +010082 Isolate* isolate() const { return isolate_; }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000083
84 Zone zone_;
Ben Murdochda12d292016-06-02 14:46:10 +010085 Isolate* isolate_;
Ben Murdochc5610432016-08-08 18:44:38 +010086 base::SmartPointer<CodeStubAssembler> assembler_;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000087
88 // To prevent exposing the RMA internals to the outside world, we'll map
89 // Node + Label pointers integers wrapped in ValueId and LabelId instances.
90 // These vectors maintain this mapping.
Ben Murdochda12d292016-06-02 14:46:10 +010091 std::vector<compiler::Node*> nodes_;
Ben Murdochc5610432016-08-08 18:44:38 +010092 std::vector<CodeStubAssembler::Label*> labels_;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000093
94 // Remember the current state for easy error checking. (We prefer to be
95 // strict as this class will be exposed at the API.)
96 enum { kBuilding, kBuilt, kError } state_;
97
98 DISALLOW_COPY_AND_ASSIGN(FastAccessorAssembler);
99};
100
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000101} // namespace internal
102} // namespace v8
103
Ben Murdochda12d292016-06-02 14:46:10 +0100104#endif // V8_FAST_ACCESSOR_ASSEMBLER_H_