V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
unoptimized-compilation-info.h
1 // Copyright 2018 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_UNOPTIMIZED_COMPILATION_INFO_H_
6 #define V8_UNOPTIMIZED_COMPILATION_INFO_H_
7 
8 #include <memory>
9 
10 #include "src/feedback-vector.h"
11 #include "src/globals.h"
12 #include "src/handles.h"
13 #include "src/objects.h"
14 #include "src/source-position-table.h"
15 #include "src/utils.h"
16 
17 namespace v8 {
18 namespace internal {
19 
20 class AsmWasmData;
21 class CoverageInfo;
22 class DeclarationScope;
23 class FunctionLiteral;
24 class Isolate;
25 class ParseInfo;
26 class SourceRangeMap;
27 class Zone;
28 
29 // UnoptimizedCompilationInfo encapsulates the information needed to compile
30 // unoptimized code for a given function, and the results of the compilation.
31 class V8_EXPORT_PRIVATE UnoptimizedCompilationInfo final {
32  public:
33  UnoptimizedCompilationInfo(Zone* zone, ParseInfo* parse_info,
34  FunctionLiteral* literal);
35 
36  Zone* zone() { return zone_; }
37 
38  // Compilation flag accessors.
39 
40  void MarkAsEval() { SetFlag(kIsEval); }
41  bool is_eval() const { return GetFlag(kIsEval); }
42 
43  void MarkAsNative() { SetFlag(kIsNative); }
44  bool is_native() const { return GetFlag(kIsNative); }
45 
46  void MarkAsCollectTypeProfile() { SetFlag(kCollectTypeProfile); }
47  bool collect_type_profile() const { return GetFlag(kCollectTypeProfile); }
48 
49  // Accessors for the input data of the function being compiled.
50 
51  FunctionLiteral* literal() const { return literal_; }
52  void set_literal(FunctionLiteral* literal) {
53  DCHECK_NOT_NULL(literal);
54  literal_ = literal;
55  }
56 
57  DeclarationScope* scope() const;
58 
59  int num_parameters() const;
60  int num_parameters_including_this() const;
61 
62  // Accessors for optional compilation features.
63 
64  SourcePositionTableBuilder::RecordingMode SourcePositionRecordingMode() const;
65 
66  bool has_source_range_map() const { return source_range_map_ != nullptr; }
67  SourceRangeMap* source_range_map() const { return source_range_map_; }
68  void set_source_range_map(SourceRangeMap* source_range_map) {
69  source_range_map_ = source_range_map;
70  }
71 
72  bool has_coverage_info() const { return !coverage_info_.is_null(); }
73  Handle<CoverageInfo> coverage_info() const { return coverage_info_; }
74  void set_coverage_info(Handle<CoverageInfo> coverage_info) {
75  coverage_info_ = coverage_info;
76  }
77 
78  // Accessors for the output of compilation.
79 
80  bool has_bytecode_array() const { return !bytecode_array_.is_null(); }
81  Handle<BytecodeArray> bytecode_array() const { return bytecode_array_; }
82  void SetBytecodeArray(Handle<BytecodeArray> bytecode_array) {
83  bytecode_array_ = bytecode_array;
84  }
85 
86  bool has_asm_wasm_data() const { return !asm_wasm_data_.is_null(); }
87  Handle<AsmWasmData> asm_wasm_data() const { return asm_wasm_data_; }
88  void SetAsmWasmData(Handle<AsmWasmData> asm_wasm_data) {
89  asm_wasm_data_ = asm_wasm_data;
90  }
91 
92  FeedbackVectorSpec* feedback_vector_spec() { return &feedback_vector_spec_; }
93 
94  private:
95  // Various configuration flags for a compilation, as well as some properties
96  // of the compiled code produced by a compilation.
97  enum Flag {
98  kIsEval = 1 << 0,
99  kIsNative = 1 << 1,
100  kCollectTypeProfile = 1 << 2,
101  kUntrustedCodeMitigations = 1 << 3,
102  };
103 
104  void SetFlag(Flag flag) { flags_ |= flag; }
105  bool GetFlag(Flag flag) const { return (flags_ & flag) != 0; }
106 
107  // Compilation flags.
108  unsigned flags_;
109 
110  // The zone from which the compilation pipeline working on this
111  // OptimizedCompilationInfo allocates.
112  Zone* zone_;
113 
114  // The root AST node of the function literal being compiled.
115  FunctionLiteral* literal_;
116 
117  // Used when block coverage is enabled.
118  SourceRangeMap* source_range_map_;
119 
120  // Encapsulates coverage information gathered by the bytecode generator.
121  // Needs to be stored on the shared function info once compilation completes.
122  Handle<CoverageInfo> coverage_info_;
123 
124  // Holds the bytecode array generated by the interpreter.
125  Handle<BytecodeArray> bytecode_array_;
126 
127  // Holds the asm_wasm data struct generated by the asmjs compiler.
128  Handle<AsmWasmData> asm_wasm_data_;
129 
130  // Holds the feedback vector spec generated during compilation
131  FeedbackVectorSpec feedback_vector_spec_;
132 };
133 
134 } // namespace internal
135 } // namespace v8
136 
137 #endif // V8_UNOPTIMIZED_COMPILATION_INFO_H_
Definition: libplatform.h:13