// Copyright 2019 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. #include <optional> #include "src/torque/implementation-visitor.h" namespace v8::internal::torque { namespace { // Contains all necessary state for a single class type during the process of // assigning instance types, and provides a convenient way to access the list of // types that inherit from this one. struct InstanceTypeTree { … }; // Assembles all class types into a tree, but doesn't yet attempt to assign // instance types for them. std::unique_ptr<InstanceTypeTree> BuildInstanceTypeTree() { … } // Propagates constraints about instance types from children to their parents. void PropagateInstanceTypeConstraints(InstanceTypeTree* root) { … } // Assigns values for the type itself, not including any children. Returns the // next available value. int SelectOwnValues(InstanceTypeTree* root, int start_value) { … } // Sorting function for types that don't have specific values they must include. // Prioritizes bigger type ranges (those with more subtypes) first, and // then sorts alphabetically within each size category. struct CompareUnconstrainedTypes { … }; // Assigns concrete values for every instance type range, and sorts the children // at each layer of the tree into increasing order. Appends the newly-assigned // tree to the destination vector. Returns the first unassigned value after // those that have been used. int SolveInstanceTypeConstraints( std::unique_ptr<InstanceTypeTree> root, int start_value, std::vector<std::unique_ptr<InstanceTypeTree>>* destination) { … } std::unique_ptr<InstanceTypeTree> SolveInstanceTypeConstraints( std::unique_ptr<InstanceTypeTree> root) { … } std::unique_ptr<InstanceTypeTree> AssignInstanceTypes() { … } // Prints items in macro lists for the given type and its descendants. // - definitions: This list is pairs of instance type name and assigned value, // such as V(ODDBALL_TYPE, 67). It includes FIRST_* and LAST_* items for each // type that has more than one associated InstanceType. Items within those // ranges are indented for readability. // - values: This list is just instance type names, like V(ODDBALL_TYPE). It // does not include any FIRST_* and LAST_* range markers. // - fully_defined_single_instance_types: This list is pairs of class name and // instance type, for classes which have defined layouts and a single // corresponding instance type. // - fully_defined_multiple_instance_types: This list is pairs of class name and // instance type, for classes which have defined layouts and subclasses. // - only_declared_single_instance_types: This list is pairs of class name and // instance type, for classes which have a single corresponding instance type // and do not have layout definitions in Torque. // - only_declared_multiple_instance_types: This list is pairs of class name and // instance type, for classes which have subclasses but also have a single // corresponding instance type, and do not have layout definitions in Torque. // - fully_defined_range_instance_types: This list is triples of class name, // first instance type, and last instance type, for classes which have defined // layouts and multiple corresponding instance types. // - only_declared_range_instance_types: This list is triples of class name, // first instance type, and last instance type, for classes which have // multiple corresponding instance types and do not have layout definitions in // Torque. void PrintInstanceTypes(InstanceTypeTree* root, std::ostream& definitions, std::ostream& values, std::ostream& fully_defined_single_instance_types, std::ostream& fully_defined_multiple_instance_types, std::ostream& only_declared_single_instance_types, std::ostream& only_declared_multiple_instance_types, std::ostream& fully_defined_range_instance_types, std::ostream& only_declared_range_instance_types, const std::string& indent) { … } } // namespace void ImplementationVisitor::GenerateInstanceTypes( const std::string& output_directory) { … } } // namespace v8::internal::torque