// Copyright 2012 the V8 project authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef V8_COMPILER_H_ #define V8_COMPILER_H_ #include "src/allocation.h" #include "src/ast.h" #include "src/bailout-reason.h" #include "src/zone.h" namespace v8 { namespace internal { class AstValueFactory; class HydrogenCodeStub; class ParseInfo; class ScriptData; struct OffsetRange { OffsetRange(int from, int to) : from(from), to(to) {} int from; int to; }; // This class encapsulates encoding and decoding of sources positions from // which hydrogen values originated. // When FLAG_track_hydrogen_positions is set this object encodes the // identifier of the inlining and absolute offset from the start of the // inlined function. // When the flag is not set we simply track absolute offset from the // script start. class SourcePosition { public: static SourcePosition Unknown() { return SourcePosition::FromRaw(kNoPosition); } bool IsUnknown() const { return value_ == kNoPosition; } uint32_t position() const { return PositionField::decode(value_); } void set_position(uint32_t position) { if (FLAG_hydrogen_track_positions) { value_ = static_cast(PositionField::update(value_, position)); } else { value_ = position; } } uint32_t inlining_id() const { return InliningIdField::decode(value_); } void set_inlining_id(uint32_t inlining_id) { if (FLAG_hydrogen_track_positions) { value_ = static_cast(InliningIdField::update(value_, inlining_id)); } } uint32_t raw() const { return value_; } private: static const uint32_t kNoPosition = static_cast(RelocInfo::kNoPosition); typedef BitField InliningIdField; // Offset from the start of the inlined function. typedef BitField PositionField; friend class HPositionInfo; friend class Deoptimizer; static SourcePosition FromRaw(uint32_t raw_position) { SourcePosition position; position.value_ = raw_position; return position; } // If FLAG_hydrogen_track_positions is set contains bitfields InliningIdField // and PositionField. // Otherwise contains absolute offset from the script start. uint32_t value_; }; std::ostream& operator<<(std::ostream& os, const SourcePosition& p); struct InlinedFunctionInfo { InlinedFunctionInfo(int parent_id, SourcePosition inline_position, int script_id, int start_position) : parent_id(parent_id), inline_position(inline_position), script_id(script_id), start_position(start_position) {} int parent_id; SourcePosition inline_position; int script_id; int start_position; std::vector deopt_pc_offsets; static const int kNoParentId = -1; }; // CompilationInfo encapsulates some information known at compile time. It // is constructed based on the resources available at compile-time. class CompilationInfo { public: // Various configuration flags for a compilation, as well as some properties // of the compiled code produced by a compilation. enum Flag { kDeferredCalling = 1 << 0, kNonDeferredCalling = 1 << 1, kSavesCallerDoubles = 1 << 2, kRequiresFrame = 1 << 3, kMustNotHaveEagerFrame = 1 << 4, kDeoptimizationSupport = 1 << 5, kDebug = 1 << 6, kCompilingForDebugging = 1 << 7, kSerializing = 1 << 8, kContextSpecializing = 1 << 9, kInliningEnabled = 1 << 10, kTypingEnabled = 1 << 11, kDisableFutureOptimization = 1 << 12, kSplittingEnabled = 1 << 13, kBuiltinInliningEnabled = 1 << 14 }; explicit CompilationInfo(ParseInfo* parse_info); CompilationInfo(CodeStub* stub, Isolate* isolate, Zone* zone); virtual ~CompilationInfo(); ParseInfo* parse_info() const { return parse_info_; } // ----------------------------------------------------------- // TODO(titzer): inline and delete accessors of ParseInfo // ----------------------------------------------------------- Handle