[torque] no longer generate assemblers per namespace
Instead of generating one CodeStubAssembler-like class per namespace, Torque-generated macros are now free-standing functions not included from CSA code, and explicitly exported macros become part of the new TorqueGeneratedExportedMacrosAssembler, which CodeStubAssembler inherits from, thus making them available to all CSA code. Structs are now defined in a new header csa-types-tq.h as free-standing types with the prefix "TorqueStruct". This is a preparation for generating per Torque-file instead of per namespace. Change-Id: I60fadc493a63f85d1d340768ec6f11ae47be0cb8 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1628787 Commit-Queue: Tobias Tebbi <tebbi@chromium.org> Reviewed-by: Sigurd Schneider <sigurds@chromium.org> Cr-Commit-Position: refs/heads/master@{#61865}
This commit is contained in:
parent
70bd7cf0ef
commit
19d8bfa5a8
9
BUILD.gn
9
BUILD.gn
@ -1063,6 +1063,9 @@ action("run_torque") {
|
|||||||
"$target_gen_dir/torque-generated/class-definitions-tq.cc",
|
"$target_gen_dir/torque-generated/class-definitions-tq.cc",
|
||||||
"$target_gen_dir/torque-generated/class-definitions-tq-inl.h",
|
"$target_gen_dir/torque-generated/class-definitions-tq-inl.h",
|
||||||
"$target_gen_dir/torque-generated/class-definitions-tq.h",
|
"$target_gen_dir/torque-generated/class-definitions-tq.h",
|
||||||
|
"$target_gen_dir/torque-generated/exported-macros-assembler-tq.cc",
|
||||||
|
"$target_gen_dir/torque-generated/exported-macros-assembler-tq.h",
|
||||||
|
"$target_gen_dir/torque-generated/csa-types-tq.h",
|
||||||
]
|
]
|
||||||
foreach(namespace, torque_namespaces) {
|
foreach(namespace, torque_namespaces) {
|
||||||
outputs += [
|
outputs += [
|
||||||
@ -1104,7 +1107,11 @@ v8_source_set("torque_generated_initializers") {
|
|||||||
":v8_maybe_icu",
|
":v8_maybe_icu",
|
||||||
]
|
]
|
||||||
|
|
||||||
sources = []
|
sources = [
|
||||||
|
"$target_gen_dir/torque-generated/csa-types-tq.h",
|
||||||
|
"$target_gen_dir/torque-generated/exported-macros-assembler-tq.cc",
|
||||||
|
"$target_gen_dir/torque-generated/exported-macros-assembler-tq.h",
|
||||||
|
]
|
||||||
foreach(namespace, torque_namespaces) {
|
foreach(namespace, torque_namespaces) {
|
||||||
sources += [
|
sources += [
|
||||||
"$target_gen_dir/torque-generated/builtins-$namespace-gen-tq.cc",
|
"$target_gen_dir/torque-generated/builtins-$namespace-gen-tq.cc",
|
||||||
|
@ -112,9 +112,8 @@ Node* ArgumentsBuiltinsAssembler::EmitFastNewRestParameter(Node* context,
|
|||||||
ParameterMode mode = OptimalParameterMode();
|
ParameterMode mode = OptimalParameterMode();
|
||||||
Node* zero = IntPtrOrSmiConstant(0, mode);
|
Node* zero = IntPtrOrSmiConstant(0, mode);
|
||||||
|
|
||||||
TorqueGeneratedArgumentsBuiltinsAssembler::ArgumentsInfo info =
|
TorqueStructArgumentsInfo info = GetArgumentsFrameAndCount(
|
||||||
GetArgumentsFrameAndCount(CAST(context),
|
CAST(context), UncheckedCast<JSFunction>(function));
|
||||||
UncheckedCast<JSFunction>(function));
|
|
||||||
|
|
||||||
VARIABLE(result, MachineRepresentation::kTagged);
|
VARIABLE(result, MachineRepresentation::kTagged);
|
||||||
Label no_rest_parameters(this), runtime(this, Label::kDeferred),
|
Label no_rest_parameters(this), runtime(this, Label::kDeferred),
|
||||||
@ -167,9 +166,8 @@ Node* ArgumentsBuiltinsAssembler::EmitFastNewStrictArguments(Node* context,
|
|||||||
ParameterMode mode = OptimalParameterMode();
|
ParameterMode mode = OptimalParameterMode();
|
||||||
Node* zero = IntPtrOrSmiConstant(0, mode);
|
Node* zero = IntPtrOrSmiConstant(0, mode);
|
||||||
|
|
||||||
TorqueGeneratedArgumentsBuiltinsAssembler::ArgumentsInfo info =
|
TorqueStructArgumentsInfo info = GetArgumentsFrameAndCount(
|
||||||
GetArgumentsFrameAndCount(CAST(context),
|
CAST(context), UncheckedCast<JSFunction>(function));
|
||||||
UncheckedCast<JSFunction>(function));
|
|
||||||
|
|
||||||
GotoIfFixedArraySizeDoesntFitInNewSpace(
|
GotoIfFixedArraySizeDoesntFitInNewSpace(
|
||||||
info.argument_count, &runtime,
|
info.argument_count, &runtime,
|
||||||
@ -216,9 +214,8 @@ Node* ArgumentsBuiltinsAssembler::EmitFastNewSloppyArguments(Node* context,
|
|||||||
Label done(this, &result), empty(this), no_parameters(this),
|
Label done(this, &result), empty(this), no_parameters(this),
|
||||||
runtime(this, Label::kDeferred);
|
runtime(this, Label::kDeferred);
|
||||||
|
|
||||||
TorqueGeneratedArgumentsBuiltinsAssembler::ArgumentsInfo info =
|
TorqueStructArgumentsInfo info = GetArgumentsFrameAndCount(
|
||||||
GetArgumentsFrameAndCount(CAST(context),
|
CAST(context), UncheckedCast<JSFunction>(function));
|
||||||
UncheckedCast<JSFunction>(function));
|
|
||||||
|
|
||||||
GotoIf(WordEqual(info.argument_count, zero), &empty);
|
GotoIf(WordEqual(info.argument_count, zero), &empty);
|
||||||
|
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
#define V8_BUILTINS_BUILTINS_ARGUMENTS_GEN_H_
|
#define V8_BUILTINS_BUILTINS_ARGUMENTS_GEN_H_
|
||||||
|
|
||||||
#include "src/codegen/code-stub-assembler.h"
|
#include "src/codegen/code-stub-assembler.h"
|
||||||
#include "torque-generated/builtins-arguments-gen-tq.h"
|
|
||||||
|
|
||||||
namespace v8 {
|
namespace v8 {
|
||||||
namespace internal {
|
namespace internal {
|
||||||
@ -15,13 +14,10 @@ using Node = compiler::Node;
|
|||||||
using CodeAssemblerState = compiler::CodeAssemblerState;
|
using CodeAssemblerState = compiler::CodeAssemblerState;
|
||||||
using CodeAssemblerLabel = compiler::CodeAssemblerLabel;
|
using CodeAssemblerLabel = compiler::CodeAssemblerLabel;
|
||||||
|
|
||||||
class ArgumentsBuiltinsAssembler
|
class ArgumentsBuiltinsAssembler : public CodeStubAssembler {
|
||||||
: public CodeStubAssembler,
|
|
||||||
public TorqueGeneratedArgumentsBuiltinsAssembler {
|
|
||||||
public:
|
public:
|
||||||
explicit ArgumentsBuiltinsAssembler(CodeAssemblerState* state)
|
explicit ArgumentsBuiltinsAssembler(CodeAssemblerState* state)
|
||||||
: CodeStubAssembler(state),
|
: CodeStubAssembler(state) {}
|
||||||
TorqueGeneratedArgumentsBuiltinsAssembler(state) {}
|
|
||||||
|
|
||||||
Node* EmitFastNewStrictArguments(Node* context, Node* function);
|
Node* EmitFastNewStrictArguments(Node* context, Node* function);
|
||||||
Node* EmitFastNewSloppyArguments(Node* context, Node* function);
|
Node* EmitFastNewSloppyArguments(Node* context, Node* function);
|
||||||
|
@ -15,13 +15,12 @@
|
|||||||
#include "src/objects/allocation-site-inl.h"
|
#include "src/objects/allocation-site-inl.h"
|
||||||
#include "src/objects/arguments-inl.h"
|
#include "src/objects/arguments-inl.h"
|
||||||
#include "src/objects/property-cell.h"
|
#include "src/objects/property-cell.h"
|
||||||
#include "torque-generated/builtins-typed-array-createtypedarray-gen-tq.h"
|
|
||||||
|
|
||||||
namespace v8 {
|
namespace v8 {
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
using Node = compiler::Node;
|
using Node = compiler::Node;
|
||||||
using IteratorRecord = TorqueGeneratedIteratorBuiltinsAssembler::IteratorRecord;
|
using IteratorRecord = TorqueStructIteratorRecord;
|
||||||
|
|
||||||
ArrayBuiltinsAssembler::ArrayBuiltinsAssembler(
|
ArrayBuiltinsAssembler::ArrayBuiltinsAssembler(
|
||||||
compiler::CodeAssemblerState* state)
|
compiler::CodeAssemblerState* state)
|
||||||
@ -37,9 +36,7 @@ ArrayBuiltinsAssembler::ArrayBuiltinsAssembler(
|
|||||||
TNode<Smi> length = CAST(len_);
|
TNode<Smi> length = CAST(len_);
|
||||||
const char* method_name = "%TypedArray%.prototype.map";
|
const char* method_name = "%TypedArray%.prototype.map";
|
||||||
|
|
||||||
TorqueGeneratedTypedArrayCreatetypedarrayBuiltinsAssembler typedarray_asm(
|
TNode<JSTypedArray> a = TypedArraySpeciesCreateByLength(
|
||||||
state());
|
|
||||||
TNode<JSTypedArray> a = typedarray_asm.TypedArraySpeciesCreateByLength(
|
|
||||||
context(), method_name, original_array, length);
|
context(), method_name, original_array, length);
|
||||||
// In the Spec and our current implementation, the length check is already
|
// In the Spec and our current implementation, the length check is already
|
||||||
// performed in TypedArraySpeciesCreate.
|
// performed in TypedArraySpeciesCreate.
|
||||||
|
@ -13,8 +13,6 @@
|
|||||||
#include "src/objects/hash-table-inl.h"
|
#include "src/objects/hash-table-inl.h"
|
||||||
#include "src/objects/js-collection.h"
|
#include "src/objects/js-collection.h"
|
||||||
#include "src/objects/ordered-hash-table.h"
|
#include "src/objects/ordered-hash-table.h"
|
||||||
#include "torque-generated/builtins-base-gen-tq.h"
|
|
||||||
#include "torque-generated/builtins-collections-gen-tq.h"
|
|
||||||
|
|
||||||
namespace v8 {
|
namespace v8 {
|
||||||
namespace internal {
|
namespace internal {
|
||||||
@ -25,13 +23,10 @@ using TNode = compiler::TNode<T>;
|
|||||||
template <class T>
|
template <class T>
|
||||||
using TVariable = compiler::TypedCodeAssemblerVariable<T>;
|
using TVariable = compiler::TypedCodeAssemblerVariable<T>;
|
||||||
|
|
||||||
class BaseCollectionsAssembler
|
class BaseCollectionsAssembler : public CodeStubAssembler {
|
||||||
: public CodeStubAssembler,
|
|
||||||
public TorqueGeneratedCollectionsBuiltinsAssembler {
|
|
||||||
public:
|
public:
|
||||||
explicit BaseCollectionsAssembler(compiler::CodeAssemblerState* state)
|
explicit BaseCollectionsAssembler(compiler::CodeAssemblerState* state)
|
||||||
: CodeStubAssembler(state),
|
: CodeStubAssembler(state) {}
|
||||||
TorqueGeneratedCollectionsBuiltinsAssembler(state) {}
|
|
||||||
|
|
||||||
virtual ~BaseCollectionsAssembler() = default;
|
virtual ~BaseCollectionsAssembler() = default;
|
||||||
|
|
||||||
@ -160,7 +155,7 @@ void BaseCollectionsAssembler::AddConstructorEntry(
|
|||||||
var_exception);
|
var_exception);
|
||||||
CSA_ASSERT(this, Word32BinaryNot(IsTheHole(key_value)));
|
CSA_ASSERT(this, Word32BinaryNot(IsTheHole(key_value)));
|
||||||
if (variant == kMap || variant == kWeakMap) {
|
if (variant == kMap || variant == kWeakMap) {
|
||||||
TorqueGeneratedBaseBuiltinsAssembler::KeyValuePair pair =
|
TorqueStructKeyValuePair pair =
|
||||||
if_may_have_side_effects != nullptr
|
if_may_have_side_effects != nullptr
|
||||||
? LoadKeyValuePairNoSideEffects(context, key_value,
|
? LoadKeyValuePairNoSideEffects(context, key_value,
|
||||||
if_may_have_side_effects)
|
if_may_have_side_effects)
|
||||||
@ -320,7 +315,7 @@ void BaseCollectionsAssembler::AddConstructorEntriesFromIterable(
|
|||||||
|
|
||||||
TNode<Object> add_func = GetAddFunction(variant, context, collection);
|
TNode<Object> add_func = GetAddFunction(variant, context, collection);
|
||||||
IteratorBuiltinsAssembler iterator_assembler(this->state());
|
IteratorBuiltinsAssembler iterator_assembler(this->state());
|
||||||
IteratorBuiltinsAssembler::IteratorRecord iterator =
|
TorqueStructIteratorRecord iterator =
|
||||||
iterator_assembler.GetIterator(context, iterable);
|
iterator_assembler.GetIterator(context, iterable);
|
||||||
|
|
||||||
CSA_ASSERT(this, Word32BinaryNot(IsUndefined(iterator.object)));
|
CSA_ASSERT(this, Word32BinaryNot(IsUndefined(iterator.object)));
|
||||||
|
@ -11,13 +11,11 @@
|
|||||||
#include "src/builtins/builtins.h"
|
#include "src/builtins/builtins.h"
|
||||||
#include "src/codegen/code-stub-assembler.h"
|
#include "src/codegen/code-stub-assembler.h"
|
||||||
#include "src/heap/factory-inl.h"
|
#include "src/heap/factory-inl.h"
|
||||||
#include "torque-generated/builtins-base-gen-tq.h"
|
|
||||||
|
|
||||||
namespace v8 {
|
namespace v8 {
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
using IteratorRecord = TorqueGeneratedIteratorBuiltinsAssembler::IteratorRecord;
|
using IteratorRecord = TorqueStructIteratorRecord;
|
||||||
|
|
||||||
using compiler::Node;
|
using compiler::Node;
|
||||||
|
|
||||||
TNode<Object> IteratorBuiltinsAssembler::GetIteratorMethod(Node* context,
|
TNode<Object> IteratorBuiltinsAssembler::GetIteratorMethod(Node* context,
|
||||||
|
@ -6,21 +6,18 @@
|
|||||||
#define V8_BUILTINS_BUILTINS_ITERATOR_GEN_H_
|
#define V8_BUILTINS_BUILTINS_ITERATOR_GEN_H_
|
||||||
|
|
||||||
#include "src/codegen/code-stub-assembler.h"
|
#include "src/codegen/code-stub-assembler.h"
|
||||||
#include "torque-generated/builtins-base-gen-tq.h"
|
|
||||||
#include "torque-generated/builtins-iterator-gen-tq.h"
|
|
||||||
|
|
||||||
namespace v8 {
|
namespace v8 {
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
using compiler::Node;
|
using compiler::Node;
|
||||||
|
|
||||||
class IteratorBuiltinsAssembler
|
class IteratorBuiltinsAssembler : public CodeStubAssembler {
|
||||||
: public CodeStubAssembler,
|
|
||||||
public TorqueGeneratedIteratorBuiltinsAssembler {
|
|
||||||
public:
|
public:
|
||||||
explicit IteratorBuiltinsAssembler(compiler::CodeAssemblerState* state)
|
explicit IteratorBuiltinsAssembler(compiler::CodeAssemblerState* state)
|
||||||
: CodeStubAssembler(state),
|
: CodeStubAssembler(state) {}
|
||||||
TorqueGeneratedIteratorBuiltinsAssembler(state) {}
|
|
||||||
|
using IteratorRecord = TorqueStructIteratorRecord;
|
||||||
|
|
||||||
// Returns object[Symbol.iterator].
|
// Returns object[Symbol.iterator].
|
||||||
TNode<Object> GetIteratorMethod(Node* context, Node* object);
|
TNode<Object> GetIteratorMethod(Node* context, Node* object);
|
||||||
|
@ -21,7 +21,7 @@ namespace internal {
|
|||||||
using Node = compiler::Node;
|
using Node = compiler::Node;
|
||||||
template <class T>
|
template <class T>
|
||||||
using TNode = CodeStubAssembler::TNode<T>;
|
using TNode = CodeStubAssembler::TNode<T>;
|
||||||
using IteratorRecord = IteratorBuiltinsAssembler::IteratorRecord;
|
using IteratorRecord = TorqueStructIteratorRecord;
|
||||||
|
|
||||||
Node* PromiseBuiltinsAssembler::AllocateJSPromise(Node* context) {
|
Node* PromiseBuiltinsAssembler::AllocateJSPromise(Node* context) {
|
||||||
Node* const native_context = LoadNativeContext(context);
|
Node* const native_context = LoadNativeContext(context);
|
||||||
|
@ -7,8 +7,6 @@
|
|||||||
|
|
||||||
#include "src/codegen/code-stub-assembler.h"
|
#include "src/codegen/code-stub-assembler.h"
|
||||||
#include "src/objects/promise.h"
|
#include "src/objects/promise.h"
|
||||||
#include "torque-generated/builtins-base-gen-tq.h"
|
|
||||||
#include "torque-generated/builtins-iterator-gen-tq.h"
|
|
||||||
|
|
||||||
namespace v8 {
|
namespace v8 {
|
||||||
namespace internal {
|
namespace internal {
|
||||||
@ -140,7 +138,7 @@ class V8_EXPORT_PRIVATE PromiseBuiltinsAssembler : public CodeStubAssembler {
|
|||||||
|
|
||||||
Node* PerformPromiseAll(
|
Node* PerformPromiseAll(
|
||||||
Node* context, Node* constructor, Node* capability,
|
Node* context, Node* constructor, Node* capability,
|
||||||
const TorqueGeneratedIteratorBuiltinsAssembler::IteratorRecord& record,
|
const TorqueStructIteratorRecord& record,
|
||||||
const PromiseAllResolvingElementFunction& create_resolve_element_function,
|
const PromiseAllResolvingElementFunction& create_resolve_element_function,
|
||||||
const PromiseAllResolvingElementFunction& create_reject_element_function,
|
const PromiseAllResolvingElementFunction& create_reject_element_function,
|
||||||
Label* if_exception, Variable* var_exception);
|
Label* if_exception, Variable* var_exception);
|
||||||
|
@ -7,7 +7,6 @@
|
|||||||
|
|
||||||
#include "src/codegen/code-stub-assembler.h"
|
#include "src/codegen/code-stub-assembler.h"
|
||||||
#include "src/objects/js-proxy.h"
|
#include "src/objects/js-proxy.h"
|
||||||
#include "torque-generated/builtins-proxy-gen-tq.h"
|
|
||||||
|
|
||||||
namespace v8 {
|
namespace v8 {
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
@ -10,7 +10,6 @@
|
|||||||
#include "src/builtins/growable-fixed-array-gen.h"
|
#include "src/builtins/growable-fixed-array-gen.h"
|
||||||
#include "src/handles/handles-inl.h"
|
#include "src/handles/handles-inl.h"
|
||||||
#include "src/heap/factory-inl.h"
|
#include "src/heap/factory-inl.h"
|
||||||
#include "torque-generated/builtins-typed-array-createtypedarray-gen-tq.h"
|
|
||||||
|
|
||||||
namespace v8 {
|
namespace v8 {
|
||||||
namespace internal {
|
namespace internal {
|
||||||
@ -226,7 +225,7 @@ TNode<IntPtrT> TypedArrayBuiltinsAssembler::GetTypedArrayElementSize(
|
|||||||
return element_size.value();
|
return element_size.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
TorqueGeneratedTypedArrayBuiltinsAssembler::TypedArrayElementsInfo
|
TorqueStructTypedArrayElementsInfo
|
||||||
TypedArrayBuiltinsAssembler::GetTypedArrayElementsInfo(
|
TypedArrayBuiltinsAssembler::GetTypedArrayElementsInfo(
|
||||||
TNode<JSTypedArray> typed_array) {
|
TNode<JSTypedArray> typed_array) {
|
||||||
TNode<Int32T> elements_kind = LoadElementsKind(typed_array);
|
TNode<Int32T> elements_kind = LoadElementsKind(typed_array);
|
||||||
@ -241,8 +240,8 @@ TypedArrayBuiltinsAssembler::GetTypedArrayElementsInfo(
|
|||||||
var_size_log2 = UintPtrConstant(ElementsKindToShiftSize(kind));
|
var_size_log2 = UintPtrConstant(ElementsKindToShiftSize(kind));
|
||||||
});
|
});
|
||||||
|
|
||||||
return TorqueGeneratedTypedArrayBuiltinsAssembler::TypedArrayElementsInfo{
|
return TorqueStructTypedArrayElementsInfo{var_size_log2.value(),
|
||||||
var_size_log2.value(), elements_kind};
|
elements_kind};
|
||||||
}
|
}
|
||||||
|
|
||||||
TNode<JSFunction> TypedArrayBuiltinsAssembler::GetDefaultConstructor(
|
TNode<JSFunction> TypedArrayBuiltinsAssembler::GetDefaultConstructor(
|
||||||
|
@ -6,15 +6,13 @@
|
|||||||
#define V8_BUILTINS_BUILTINS_TYPED_ARRAY_GEN_H_
|
#define V8_BUILTINS_BUILTINS_TYPED_ARRAY_GEN_H_
|
||||||
|
|
||||||
#include "src/codegen/code-stub-assembler.h"
|
#include "src/codegen/code-stub-assembler.h"
|
||||||
#include "torque-generated/builtins-typed-array-gen-tq.h"
|
|
||||||
|
|
||||||
namespace v8 {
|
namespace v8 {
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
class TypedArrayBuiltinsAssembler : public CodeStubAssembler {
|
class TypedArrayBuiltinsAssembler : public CodeStubAssembler {
|
||||||
public:
|
public:
|
||||||
using ElementsInfo =
|
using ElementsInfo = TorqueStructTypedArrayElementsInfo;
|
||||||
TorqueGeneratedTypedArrayBuiltinsAssembler::TypedArrayElementsInfo;
|
|
||||||
explicit TypedArrayBuiltinsAssembler(compiler::CodeAssemblerState* state)
|
explicit TypedArrayBuiltinsAssembler(compiler::CodeAssemblerState* state)
|
||||||
: CodeStubAssembler(state) {}
|
: CodeStubAssembler(state) {}
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ using SloppyTNode = compiler::SloppyTNode<T>;
|
|||||||
|
|
||||||
CodeStubAssembler::CodeStubAssembler(compiler::CodeAssemblerState* state)
|
CodeStubAssembler::CodeStubAssembler(compiler::CodeAssemblerState* state)
|
||||||
: compiler::CodeAssembler(state),
|
: compiler::CodeAssembler(state),
|
||||||
TorqueGeneratedBaseBuiltinsAssembler(state) {
|
TorqueGeneratedExportedMacrosAssembler(state) {
|
||||||
if (DEBUG_BOOL && FLAG_csa_trap_on_node != nullptr) {
|
if (DEBUG_BOOL && FLAG_csa_trap_on_node != nullptr) {
|
||||||
HandleBreakOnNode();
|
HandleBreakOnNode();
|
||||||
}
|
}
|
||||||
@ -13724,15 +13724,13 @@ Node* CodeStubAssembler::CheckEnumCache(Node* receiver, Label* if_empty,
|
|||||||
return receiver_map;
|
return receiver_map;
|
||||||
}
|
}
|
||||||
|
|
||||||
TNode<Object> CodeStubAssembler::GetArgumentValue(
|
TNode<Object> CodeStubAssembler::GetArgumentValue(TorqueStructArguments args,
|
||||||
TorqueGeneratedBaseBuiltinsAssembler::Arguments args,
|
|
||||||
TNode<IntPtrT> index) {
|
TNode<IntPtrT> index) {
|
||||||
return CodeStubArguments(this, args).GetOptionalArgumentValue(index);
|
return CodeStubArguments(this, args).GetOptionalArgumentValue(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
TorqueGeneratedBaseBuiltinsAssembler::Arguments
|
TorqueStructArguments CodeStubAssembler::GetFrameArguments(
|
||||||
CodeStubAssembler::GetFrameArguments(TNode<RawPtrT> frame,
|
TNode<RawPtrT> frame, TNode<IntPtrT> argc) {
|
||||||
TNode<IntPtrT> argc) {
|
|
||||||
return CodeStubArguments(this, argc, frame, INTPTR_PARAMETERS)
|
return CodeStubArguments(this, argc, frame, INTPTR_PARAMETERS)
|
||||||
.GetTorqueArguments();
|
.GetTorqueArguments();
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
#include "src/objects/smi.h"
|
#include "src/objects/smi.h"
|
||||||
#include "src/roots/roots.h"
|
#include "src/roots/roots.h"
|
||||||
|
|
||||||
#include "torque-generated/builtins-base-gen-tq.h"
|
#include "torque-generated/exported-macros-assembler-tq.h"
|
||||||
|
|
||||||
namespace v8 {
|
namespace v8 {
|
||||||
namespace internal {
|
namespace internal {
|
||||||
@ -205,7 +205,7 @@ enum class PrimitiveType { kBoolean, kNumber, kString, kSymbol };
|
|||||||
// from a compiler directory OWNER).
|
// from a compiler directory OWNER).
|
||||||
class V8_EXPORT_PRIVATE CodeStubAssembler
|
class V8_EXPORT_PRIVATE CodeStubAssembler
|
||||||
: public compiler::CodeAssembler,
|
: public compiler::CodeAssembler,
|
||||||
public TorqueGeneratedBaseBuiltinsAssembler {
|
public TorqueGeneratedExportedMacrosAssembler {
|
||||||
public:
|
public:
|
||||||
using Node = compiler::Node;
|
using Node = compiler::Node;
|
||||||
template <class T>
|
template <class T>
|
||||||
@ -3311,12 +3311,11 @@ class V8_EXPORT_PRIVATE CodeStubAssembler
|
|||||||
Label* if_fast, Label* if_slow);
|
Label* if_fast, Label* if_slow);
|
||||||
Node* CheckEnumCache(Node* receiver, Label* if_empty, Label* if_runtime);
|
Node* CheckEnumCache(Node* receiver, Label* if_empty, Label* if_runtime);
|
||||||
|
|
||||||
TNode<Object> GetArgumentValue(
|
TNode<Object> GetArgumentValue(TorqueStructArguments args,
|
||||||
TorqueGeneratedBaseBuiltinsAssembler::Arguments args,
|
|
||||||
TNode<IntPtrT> index);
|
TNode<IntPtrT> index);
|
||||||
|
|
||||||
TorqueGeneratedBaseBuiltinsAssembler::Arguments GetFrameArguments(
|
TorqueStructArguments GetFrameArguments(TNode<RawPtrT> frame,
|
||||||
TNode<RawPtrT> frame, TNode<IntPtrT> argc);
|
TNode<IntPtrT> argc);
|
||||||
|
|
||||||
// Support for printf-style debugging
|
// Support for printf-style debugging
|
||||||
void Print(const char* s);
|
void Print(const char* s);
|
||||||
@ -3620,9 +3619,8 @@ class V8_EXPORT_PRIVATE CodeStubArguments {
|
|||||||
|
|
||||||
// Used by Torque to construct arguments based on a Torque-defined
|
// Used by Torque to construct arguments based on a Torque-defined
|
||||||
// struct of values.
|
// struct of values.
|
||||||
CodeStubArguments(
|
CodeStubArguments(CodeStubAssembler* assembler,
|
||||||
CodeStubAssembler* assembler,
|
TorqueStructArguments torque_arguments)
|
||||||
TorqueGeneratedBaseBuiltinsAssembler::Arguments torque_arguments)
|
|
||||||
: assembler_(assembler),
|
: assembler_(assembler),
|
||||||
argc_mode_(CodeStubAssembler::INTPTR_PARAMETERS),
|
argc_mode_(CodeStubAssembler::INTPTR_PARAMETERS),
|
||||||
receiver_mode_(ReceiverMode::kHasReceiver),
|
receiver_mode_(ReceiverMode::kHasReceiver),
|
||||||
@ -3659,10 +3657,9 @@ class V8_EXPORT_PRIVATE CodeStubArguments {
|
|||||||
return argc_;
|
return argc_;
|
||||||
}
|
}
|
||||||
|
|
||||||
TorqueGeneratedBaseBuiltinsAssembler::Arguments GetTorqueArguments() const {
|
TorqueStructArguments GetTorqueArguments() const {
|
||||||
DCHECK_EQ(argc_mode_, CodeStubAssembler::INTPTR_PARAMETERS);
|
DCHECK_EQ(argc_mode_, CodeStubAssembler::INTPTR_PARAMETERS);
|
||||||
return TorqueGeneratedBaseBuiltinsAssembler::Arguments{
|
return TorqueStructArguments{assembler_->UncheckedCast<RawPtrT>(fp_), base_,
|
||||||
assembler_->UncheckedCast<RawPtrT>(fp_), base_,
|
|
||||||
assembler_->UncheckedCast<IntPtrT>(argc_)};
|
assembler_->UncheckedCast<IntPtrT>(argc_)};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -474,12 +474,12 @@ struct types_have_common_values<MaybeObject, T> {
|
|||||||
template <class T>
|
template <class T>
|
||||||
class TNode {
|
class TNode {
|
||||||
public:
|
public:
|
||||||
static_assert(is_valid_type_tag<T>::value, "invalid type tag");
|
|
||||||
|
|
||||||
template <class U,
|
template <class U,
|
||||||
typename std::enable_if<is_subtype<U, T>::value, int>::type = 0>
|
typename std::enable_if<is_subtype<U, T>::value, int>::type = 0>
|
||||||
TNode(const TNode<U>& other) : node_(other) {}
|
TNode(const TNode<U>& other) : node_(other) {
|
||||||
TNode() : node_(nullptr) {}
|
LazyTemplateChecks();
|
||||||
|
}
|
||||||
|
TNode() : TNode(nullptr) {}
|
||||||
|
|
||||||
TNode operator=(TNode other) {
|
TNode operator=(TNode other) {
|
||||||
DCHECK_NOT_NULL(other.node_);
|
DCHECK_NOT_NULL(other.node_);
|
||||||
@ -492,9 +492,14 @@ class TNode {
|
|||||||
static TNode UncheckedCast(compiler::Node* node) { return TNode(node); }
|
static TNode UncheckedCast(compiler::Node* node) { return TNode(node); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit TNode(compiler::Node* node) : node_(node) {}
|
explicit TNode(compiler::Node* node) : node_(node) { LazyTemplateChecks(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// These checks shouldn't be checked before TNode is actually used.
|
||||||
|
void LazyTemplateChecks() {
|
||||||
|
static_assert(is_valid_type_tag<T>::value, "invalid type tag");
|
||||||
|
}
|
||||||
|
|
||||||
compiler::Node* node_;
|
compiler::Node* node_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -131,8 +131,7 @@ void CSAGenerator::EmitInstruction(
|
|||||||
} else if (results.size() == 1) {
|
} else if (results.size() == 1) {
|
||||||
out_ << results[0] << " = ";
|
out_ << results[0] << " = ";
|
||||||
}
|
}
|
||||||
out_ << instruction.constant->ExternalAssemblerName() << "(state_)."
|
out_ << instruction.constant->external_name() << "(state_)";
|
||||||
<< instruction.constant->name()->value << "()";
|
|
||||||
if (type->IsStructType()) {
|
if (type->IsStructType()) {
|
||||||
out_ << ".Flatten();\n";
|
out_ << ".Flatten();\n";
|
||||||
} else {
|
} else {
|
||||||
@ -321,8 +320,12 @@ void CSAGenerator::EmitInstruction(const CallCsaMacroInstruction& instruction,
|
|||||||
DCHECK_EQ(0, results.size());
|
DCHECK_EQ(0, results.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
out_ << instruction.macro->external_assembler_name() << "(state_)."
|
if (ExternMacro* extern_macro = ExternMacro::DynamicCast(instruction.macro)) {
|
||||||
<< instruction.macro->ExternalName() << "(";
|
out_ << extern_macro->external_assembler_name() << "(state_).";
|
||||||
|
} else {
|
||||||
|
args.insert(args.begin(), "state_");
|
||||||
|
}
|
||||||
|
out_ << instruction.macro->ExternalName() << "(";
|
||||||
PrintCommaSeparatedList(out_, args);
|
PrintCommaSeparatedList(out_, args);
|
||||||
if (needs_flattening) {
|
if (needs_flattening) {
|
||||||
out_ << ").Flatten();\n";
|
out_ << ").Flatten();\n";
|
||||||
@ -386,8 +389,12 @@ void CSAGenerator::EmitInstruction(
|
|||||||
PrintCommaSeparatedList(out_, results);
|
PrintCommaSeparatedList(out_, results);
|
||||||
out_ << ") = ";
|
out_ << ") = ";
|
||||||
}
|
}
|
||||||
out_ << instruction.macro->external_assembler_name() << "(state_)."
|
if (ExternMacro* extern_macro = ExternMacro::DynamicCast(instruction.macro)) {
|
||||||
<< instruction.macro->ExternalName() << "(";
|
out_ << extern_macro->external_assembler_name() << "(state_).";
|
||||||
|
} else {
|
||||||
|
args.insert(args.begin(), "state_");
|
||||||
|
}
|
||||||
|
out_ << instruction.macro->ExternalName() << "(";
|
||||||
PrintCommaSeparatedList(out_, args);
|
PrintCommaSeparatedList(out_, args);
|
||||||
bool first = args.empty();
|
bool first = args.empty();
|
||||||
for (size_t i = 0; i < label_names.size(); ++i) {
|
for (size_t i = 0; i < label_names.size(); ++i) {
|
||||||
|
@ -43,7 +43,8 @@ class Declarable {
|
|||||||
virtual ~Declarable() = default;
|
virtual ~Declarable() = default;
|
||||||
enum Kind {
|
enum Kind {
|
||||||
kNamespace,
|
kNamespace,
|
||||||
kMacro,
|
kTorqueMacro,
|
||||||
|
kExternMacro,
|
||||||
kMethod,
|
kMethod,
|
||||||
kBuiltin,
|
kBuiltin,
|
||||||
kRuntimeFunction,
|
kRuntimeFunction,
|
||||||
@ -55,8 +56,10 @@ class Declarable {
|
|||||||
};
|
};
|
||||||
Kind kind() const { return kind_; }
|
Kind kind() const { return kind_; }
|
||||||
bool IsNamespace() const { return kind() == kNamespace; }
|
bool IsNamespace() const { return kind() == kNamespace; }
|
||||||
bool IsMacro() const { return kind() == kMacro || kind() == kMethod; }
|
bool IsMacro() const { return IsTorqueMacro() || IsExternMacro(); }
|
||||||
|
bool IsTorqueMacro() const { return kind() == kTorqueMacro || IsMethod(); }
|
||||||
bool IsMethod() const { return kind() == kMethod; }
|
bool IsMethod() const { return kind() == kMethod; }
|
||||||
|
bool IsExternMacro() const { return kind() == kExternMacro; }
|
||||||
bool IsIntrinsic() const { return kind() == kIntrinsic; }
|
bool IsIntrinsic() const { return kind() == kIntrinsic; }
|
||||||
bool IsBuiltin() const { return kind() == kBuiltin; }
|
bool IsBuiltin() const { return kind() == kBuiltin; }
|
||||||
bool IsRuntimeFunction() const { return kind() == kRuntimeFunction; }
|
bool IsRuntimeFunction() const { return kind() == kRuntimeFunction; }
|
||||||
@ -178,9 +181,6 @@ class Namespace : public Scope {
|
|||||||
explicit Namespace(const std::string& name)
|
explicit Namespace(const std::string& name)
|
||||||
: Scope(Declarable::kNamespace), name_(name) {}
|
: Scope(Declarable::kNamespace), name_(name) {}
|
||||||
const std::string& name() const { return name_; }
|
const std::string& name() const { return name_; }
|
||||||
std::string ExternalName() const {
|
|
||||||
return "TorqueGenerated" + CamelifyString(name()) + "BuiltinsAssembler";
|
|
||||||
}
|
|
||||||
bool IsDefaultNamespace() const;
|
bool IsDefaultNamespace() const;
|
||||||
bool IsTestNamespace() const;
|
bool IsTestNamespace() const;
|
||||||
std::ostream& source_stream() { return source_stream_; }
|
std::ostream& source_stream() { return source_stream_; }
|
||||||
@ -231,18 +231,19 @@ class NamespaceConstant : public Value {
|
|||||||
public:
|
public:
|
||||||
DECLARE_DECLARABLE_BOILERPLATE(NamespaceConstant, constant)
|
DECLARE_DECLARABLE_BOILERPLATE(NamespaceConstant, constant)
|
||||||
|
|
||||||
Expression* body() { return body_; }
|
const std::string& external_name() const { return external_name_; }
|
||||||
std::string ExternalAssemblerName() const {
|
Expression* body() const { return body_; }
|
||||||
return Namespace::cast(ParentScope())->ExternalName();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class Declarations;
|
friend class Declarations;
|
||||||
explicit NamespaceConstant(Identifier* constant_name, const Type* type,
|
explicit NamespaceConstant(Identifier* constant_name,
|
||||||
|
std::string external_name, const Type* type,
|
||||||
Expression* body)
|
Expression* body)
|
||||||
: Value(Declarable::kNamespaceConstant, type, constant_name),
|
: Value(Declarable::kNamespaceConstant, type, constant_name),
|
||||||
|
external_name_(std::move(external_name)),
|
||||||
body_(body) {}
|
body_(body) {}
|
||||||
|
|
||||||
|
std::string external_name_;
|
||||||
Expression* body_;
|
Expression* body_;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -317,42 +318,67 @@ class Macro : public Callable {
|
|||||||
return Callable::ShouldBeInlined();
|
return Callable::ShouldBeInlined();
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string& external_assembler_name() const {
|
|
||||||
return external_assembler_name_;
|
|
||||||
}
|
|
||||||
bool IsAccessibleFromCSA() const { return accessible_from_csa_; }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Macro(Declarable::Kind kind, std::string external_name,
|
Macro(Declarable::Kind kind, std::string external_name,
|
||||||
std::string readable_name, std::string external_assembler_name,
|
std::string readable_name, const Signature& signature,
|
||||||
const Signature& signature, bool transitioning,
|
bool transitioning, base::Optional<Statement*> body)
|
||||||
base::Optional<Statement*> body, bool is_user_defined,
|
|
||||||
bool accessible_from_csa)
|
|
||||||
: Callable(kind, std::move(external_name), std::move(readable_name),
|
: Callable(kind, std::move(external_name), std::move(readable_name),
|
||||||
signature, transitioning, body),
|
signature, transitioning, body) {
|
||||||
external_assembler_name_(std::move(external_assembler_name)),
|
|
||||||
accessible_from_csa_(accessible_from_csa) {
|
|
||||||
SetIsUserDefined(is_user_defined);
|
|
||||||
if (signature.parameter_types.var_args) {
|
if (signature.parameter_types.var_args) {
|
||||||
ReportError("Varargs are not supported for macros.");
|
ReportError("Varargs are not supported for macros.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class ExternMacro : public Macro {
|
||||||
|
public:
|
||||||
|
DECLARE_DECLARABLE_BOILERPLATE(ExternMacro, ExternMacro)
|
||||||
|
|
||||||
|
const std::string& external_assembler_name() const {
|
||||||
|
return external_assembler_name_;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class Declarations;
|
friend class Declarations;
|
||||||
Macro(std::string external_name, std::string readable_name,
|
ExternMacro(const std::string& name, std::string external_assembler_name,
|
||||||
std::string external_assembler_name, const Signature& signature,
|
Signature signature, bool transitioning)
|
||||||
bool transitioning, base::Optional<Statement*> body,
|
: Macro(Declarable::kExternMacro, name, name, std::move(signature),
|
||||||
bool is_user_defined, bool accessible_from_csa)
|
transitioning, base::nullopt),
|
||||||
: Macro(Declarable::kMacro, std::move(external_name),
|
external_assembler_name_(std::move(external_assembler_name)) {}
|
||||||
std::move(readable_name), external_assembler_name, signature,
|
|
||||||
transitioning, body, is_user_defined, accessible_from_csa) {}
|
|
||||||
|
|
||||||
std::string external_assembler_name_;
|
std::string external_assembler_name_;
|
||||||
bool accessible_from_csa_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class Method : public Macro {
|
class TorqueMacro : public Macro {
|
||||||
|
public:
|
||||||
|
DECLARE_DECLARABLE_BOILERPLATE(TorqueMacro, TorqueMacro)
|
||||||
|
bool IsExportedToCSA() const { return exported_to_csa_; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
TorqueMacro(Declarable::Kind kind, std::string external_name,
|
||||||
|
std::string readable_name, const Signature& signature,
|
||||||
|
bool transitioning, base::Optional<Statement*> body,
|
||||||
|
bool is_user_defined, bool exported_to_csa)
|
||||||
|
: Macro(kind, std::move(external_name), std::move(readable_name),
|
||||||
|
signature, transitioning, body),
|
||||||
|
exported_to_csa_(exported_to_csa) {
|
||||||
|
SetIsUserDefined(is_user_defined);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
friend class Declarations;
|
||||||
|
TorqueMacro(std::string external_name, std::string readable_name,
|
||||||
|
const Signature& signature, bool transitioning,
|
||||||
|
base::Optional<Statement*> body, bool is_user_defined,
|
||||||
|
bool exported_to_csa)
|
||||||
|
: TorqueMacro(Declarable::kTorqueMacro, std::move(external_name),
|
||||||
|
std::move(readable_name), signature, transitioning, body,
|
||||||
|
is_user_defined, exported_to_csa) {}
|
||||||
|
|
||||||
|
bool exported_to_csa_ = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Method : public TorqueMacro {
|
||||||
public:
|
public:
|
||||||
DECLARE_DECLARABLE_BOILERPLATE(Method, Method)
|
DECLARE_DECLARABLE_BOILERPLATE(Method, Method)
|
||||||
bool ShouldBeInlined() const override {
|
bool ShouldBeInlined() const override {
|
||||||
@ -366,11 +392,11 @@ class Method : public Macro {
|
|||||||
private:
|
private:
|
||||||
friend class Declarations;
|
friend class Declarations;
|
||||||
Method(AggregateType* aggregate_type, std::string external_name,
|
Method(AggregateType* aggregate_type, std::string external_name,
|
||||||
std::string readable_name, std::string external_assembler_name,
|
std::string readable_name, const Signature& signature,
|
||||||
const Signature& signature, bool transitioning, Statement* body)
|
bool transitioning, Statement* body)
|
||||||
: Macro(Declarable::kMethod, std::move(external_name),
|
: TorqueMacro(Declarable::kMethod, std::move(external_name),
|
||||||
std::move(readable_name), std::move(external_assembler_name),
|
std::move(readable_name), signature, transitioning, body,
|
||||||
signature, transitioning, body, true, false),
|
true, false),
|
||||||
aggregate_type_(aggregate_type) {}
|
aggregate_type_(aggregate_type) {}
|
||||||
AggregateType* aggregate_type_;
|
AggregateType* aggregate_type_;
|
||||||
};
|
};
|
||||||
|
@ -371,9 +371,9 @@ Callable* DeclarationVisitor::Specialize(
|
|||||||
readable_name << ">";
|
readable_name << ">";
|
||||||
Callable* callable;
|
Callable* callable;
|
||||||
if (MacroDeclaration::DynamicCast(declaration) != nullptr) {
|
if (MacroDeclaration::DynamicCast(declaration) != nullptr) {
|
||||||
callable = Declarations::CreateMacro(
|
callable = Declarations::CreateTorqueMacro(
|
||||||
generated_name, readable_name.str(), false, base::nullopt,
|
generated_name, readable_name.str(), false, type_signature,
|
||||||
type_signature, declaration->transitioning, *body, true);
|
declaration->transitioning, *body, true);
|
||||||
} else if (IntrinsicDeclaration::DynamicCast(declaration) != nullptr) {
|
} else if (IntrinsicDeclaration::DynamicCast(declaration) != nullptr) {
|
||||||
callable = Declarations::CreateIntrinsic(declaration->name, type_signature);
|
callable = Declarations::CreateIntrinsic(declaration->name, type_signature);
|
||||||
} else {
|
} else {
|
||||||
|
@ -152,23 +152,24 @@ const TypeAlias* Declarations::PredeclareTypeAlias(const Identifier* name,
|
|||||||
return Declare(name->value, std::move(alias_ptr));
|
return Declare(name->value, std::move(alias_ptr));
|
||||||
}
|
}
|
||||||
|
|
||||||
Macro* Declarations::CreateMacro(
|
TorqueMacro* Declarations::CreateTorqueMacro(
|
||||||
std::string external_name, std::string readable_name,
|
std::string external_name, std::string readable_name, bool exported_to_csa,
|
||||||
bool accessible_from_csa,
|
Signature signature, bool transitioning, base::Optional<Statement*> body,
|
||||||
base::Optional<std::string> external_assembler_name, Signature signature,
|
bool is_user_defined) {
|
||||||
bool transitioning, base::Optional<Statement*> body, bool is_user_defined) {
|
|
||||||
if (!accessible_from_csa) {
|
|
||||||
// TODO(tebbi): Switch to more predictable names to improve incremental
|
// TODO(tebbi): Switch to more predictable names to improve incremental
|
||||||
// compilation.
|
// compilation.
|
||||||
external_name += "_" + std::to_string(GlobalContext::FreshId());
|
external_name += "_" + std::to_string(GlobalContext::FreshId());
|
||||||
|
return RegisterDeclarable(std::unique_ptr<TorqueMacro>(new TorqueMacro(
|
||||||
|
std::move(external_name), std::move(readable_name), std::move(signature),
|
||||||
|
transitioning, body, is_user_defined, exported_to_csa)));
|
||||||
}
|
}
|
||||||
if (!external_assembler_name) {
|
|
||||||
external_assembler_name = CurrentNamespace()->ExternalName();
|
ExternMacro* Declarations::CreateExternMacro(
|
||||||
}
|
std::string name, std::string external_assembler_name, Signature signature,
|
||||||
return RegisterDeclarable(std::unique_ptr<Macro>(
|
bool transitioning) {
|
||||||
new Macro(std::move(external_name), std::move(readable_name),
|
return RegisterDeclarable(std::unique_ptr<ExternMacro>(
|
||||||
std::move(*external_assembler_name), std::move(signature),
|
new ExternMacro(std::move(name), std::move(external_assembler_name),
|
||||||
transitioning, body, is_user_defined, accessible_from_csa)));
|
std::move(signature), transitioning)));
|
||||||
}
|
}
|
||||||
|
|
||||||
Macro* Declarations::DeclareMacro(
|
Macro* Declarations::DeclareMacro(
|
||||||
@ -181,9 +182,14 @@ Macro* Declarations::DeclareMacro(
|
|||||||
ReportError("cannot redeclare macro ", name,
|
ReportError("cannot redeclare macro ", name,
|
||||||
" with identical explicit parameters");
|
" with identical explicit parameters");
|
||||||
}
|
}
|
||||||
Macro* macro = CreateMacro(name, name, accessible_from_csa,
|
Macro* macro;
|
||||||
std::move(external_assembler_name), signature,
|
if (external_assembler_name) {
|
||||||
|
macro = CreateExternMacro(name, std::move(*external_assembler_name),
|
||||||
|
signature, transitioning);
|
||||||
|
} else {
|
||||||
|
macro = CreateTorqueMacro(name, name, accessible_from_csa, signature,
|
||||||
transitioning, body, is_user_defined);
|
transitioning, body, is_user_defined);
|
||||||
|
}
|
||||||
Declare(name, macro);
|
Declare(name, macro);
|
||||||
if (op) {
|
if (op) {
|
||||||
if (TryLookupMacro(*op, signature.GetExplicitTypes())) {
|
if (TryLookupMacro(*op, signature.GetExplicitTypes())) {
|
||||||
@ -201,8 +207,7 @@ Method* Declarations::CreateMethod(AggregateType* container_type,
|
|||||||
std::string generated_name{container_type->GetGeneratedMethodName(name)};
|
std::string generated_name{container_type->GetGeneratedMethodName(name)};
|
||||||
Method* result = RegisterDeclarable(std::unique_ptr<Method>(
|
Method* result = RegisterDeclarable(std::unique_ptr<Method>(
|
||||||
new Method(container_type, container_type->GetGeneratedMethodName(name),
|
new Method(container_type, container_type->GetGeneratedMethodName(name),
|
||||||
name, CurrentNamespace()->ExternalName(), std::move(signature),
|
name, std::move(signature), transitioning, body)));
|
||||||
transitioning, body)));
|
|
||||||
container_type->RegisterMethod(result);
|
container_type->RegisterMethod(result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -260,7 +265,10 @@ NamespaceConstant* Declarations::DeclareNamespaceConstant(Identifier* name,
|
|||||||
const Type* type,
|
const Type* type,
|
||||||
Expression* body) {
|
Expression* body) {
|
||||||
CheckAlreadyDeclared<Value>(name->value, "constant");
|
CheckAlreadyDeclared<Value>(name->value, "constant");
|
||||||
NamespaceConstant* result = new NamespaceConstant(name, type, body);
|
std::string external_name =
|
||||||
|
name->value + "_" + std::to_string(GlobalContext::FreshId());
|
||||||
|
NamespaceConstant* result =
|
||||||
|
new NamespaceConstant(name, std::move(external_name), type, body);
|
||||||
Declare(name->value, std::unique_ptr<Declarable>(result));
|
Declare(name->value, std::unique_ptr<Declarable>(result));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -77,12 +77,16 @@ class Declarations {
|
|||||||
static const TypeAlias* PredeclareTypeAlias(const Identifier* name,
|
static const TypeAlias* PredeclareTypeAlias(const Identifier* name,
|
||||||
TypeDeclaration* type,
|
TypeDeclaration* type,
|
||||||
bool redeclaration);
|
bool redeclaration);
|
||||||
static Macro* CreateMacro(std::string external_name,
|
static TorqueMacro* CreateTorqueMacro(std::string external_name,
|
||||||
std::string readable_name, bool accessible_from_csa,
|
std::string readable_name,
|
||||||
base::Optional<std::string> external_assembler_name,
|
bool exported_to_csa,
|
||||||
Signature signature, bool transitioning,
|
Signature signature, bool transitioning,
|
||||||
base::Optional<Statement*> body,
|
base::Optional<Statement*> body,
|
||||||
bool is_user_defined);
|
bool is_user_defined);
|
||||||
|
static ExternMacro* CreateExternMacro(std::string name,
|
||||||
|
std::string external_assembler_name,
|
||||||
|
Signature signature,
|
||||||
|
bool transitioning);
|
||||||
static Macro* DeclareMacro(
|
static Macro* DeclareMacro(
|
||||||
const std::string& name, bool accessible_from_csa,
|
const std::string& name, bool accessible_from_csa,
|
||||||
base::Optional<std::string> external_assembler_name,
|
base::Optional<std::string> external_assembler_name,
|
||||||
|
@ -74,25 +74,15 @@ void ImplementationVisitor::BeginNamespaceFile(Namespace* nspace) {
|
|||||||
header << "#ifndef " << headerDefine << "\n";
|
header << "#ifndef " << headerDefine << "\n";
|
||||||
header << "#define " << headerDefine << "\n\n";
|
header << "#define " << headerDefine << "\n\n";
|
||||||
header << "#include \"src/compiler/code-assembler.h\"\n";
|
header << "#include \"src/compiler/code-assembler.h\"\n";
|
||||||
if (nspace != GlobalContext::GetDefaultNamespace()) {
|
|
||||||
header << "#include \"src/codegen/code-stub-assembler.h\"\n";
|
header << "#include \"src/codegen/code-stub-assembler.h\"\n";
|
||||||
}
|
|
||||||
header << "#include \"src/utils/utils.h\"\n";
|
header << "#include \"src/utils/utils.h\"\n";
|
||||||
header << "#include \"torque-generated/field-offsets-tq.h\"\n";
|
header << "#include \"torque-generated/field-offsets-tq.h\"\n";
|
||||||
|
header << "#include \"torque-generated/csa-types-tq.h\"\n";
|
||||||
header << "\n";
|
header << "\n";
|
||||||
|
|
||||||
header << "namespace v8 {\n"
|
header << "namespace v8 {\n"
|
||||||
<< "namespace internal {\n"
|
<< "namespace internal {\n"
|
||||||
<< "\n";
|
<< "\n";
|
||||||
|
|
||||||
header << "class ";
|
|
||||||
// TODO(sigurds): Decide which assemblers we should export for testing.
|
|
||||||
header << "V8_EXPORT_PRIVATE ";
|
|
||||||
header << nspace->ExternalName() << " {\n";
|
|
||||||
header << " public:\n";
|
|
||||||
header << " explicit " << nspace->ExternalName()
|
|
||||||
<< "(compiler::CodeAssemblerState* state) : state_(state), ca_(state) "
|
|
||||||
"{ USE(state_, ca_); }\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImplementationVisitor::EndNamespaceFile(Namespace* nspace) {
|
void ImplementationVisitor::EndNamespaceFile(Namespace* nspace) {
|
||||||
@ -109,10 +99,6 @@ void ImplementationVisitor::EndNamespaceFile(Namespace* nspace) {
|
|||||||
<< "} // namespace v8\n"
|
<< "} // namespace v8\n"
|
||||||
<< "\n";
|
<< "\n";
|
||||||
|
|
||||||
header << " private:\n"
|
|
||||||
<< " compiler::CodeAssemblerState* const state_;\n"
|
|
||||||
<< " compiler::CodeAssembler ca_;\n"
|
|
||||||
<< "};\n\n";
|
|
||||||
header << "} // namespace internal\n"
|
header << "} // namespace internal\n"
|
||||||
<< "} // namespace v8\n"
|
<< "} // namespace v8\n"
|
||||||
<< "\n";
|
<< "\n";
|
||||||
@ -121,18 +107,18 @@ void ImplementationVisitor::EndNamespaceFile(Namespace* nspace) {
|
|||||||
|
|
||||||
void ImplementationVisitor::Visit(NamespaceConstant* decl) {
|
void ImplementationVisitor::Visit(NamespaceConstant* decl) {
|
||||||
Signature signature{{}, base::nullopt, {{}, false}, 0, decl->type(), {}};
|
Signature signature{{}, base::nullopt, {{}, false}, 0, decl->type(), {}};
|
||||||
const std::string& name = decl->name()->value;
|
|
||||||
|
|
||||||
BindingsManagersScope bindings_managers_scope;
|
BindingsManagersScope bindings_managers_scope;
|
||||||
|
|
||||||
header_out() << " ";
|
header_out() << " ";
|
||||||
GenerateFunctionDeclaration(header_out(), "", name, signature, {});
|
GenerateFunctionDeclaration(header_out(), "", decl->external_name(),
|
||||||
|
signature, {});
|
||||||
header_out() << ";\n";
|
header_out() << ";\n";
|
||||||
|
|
||||||
GenerateFunctionDeclaration(source_out(),
|
GenerateFunctionDeclaration(source_out(), "", decl->external_name(),
|
||||||
CurrentNamespace()->ExternalName() + "::", name,
|
|
||||||
signature, {});
|
signature, {});
|
||||||
source_out() << " {\n";
|
source_out() << " {\n";
|
||||||
|
source_out() << " compiler::CodeAssembler ca_(state_);\n";
|
||||||
|
|
||||||
DCHECK(!signature.return_type->IsVoidOrNever());
|
DCHECK(!signature.return_type->IsVoidOrNever());
|
||||||
|
|
||||||
@ -161,41 +147,6 @@ void ImplementationVisitor::Visit(TypeAlias* alias) {
|
|||||||
"extern classes are currently only supported in the default "
|
"extern classes are currently only supported in the default "
|
||||||
"namespace");
|
"namespace");
|
||||||
}
|
}
|
||||||
} else if (const StructType* struct_type =
|
|
||||||
StructType::DynamicCast(alias->type())) {
|
|
||||||
const std::string& name = struct_type->name();
|
|
||||||
header_out() << " struct " << name << " {\n";
|
|
||||||
for (auto& field : struct_type->fields()) {
|
|
||||||
header_out() << " "
|
|
||||||
<< field.name_and_type.type->GetGeneratedTypeName();
|
|
||||||
header_out() << " " << field.name_and_type.name << ";\n";
|
|
||||||
}
|
|
||||||
header_out() << "\n std::tuple<";
|
|
||||||
bool first = true;
|
|
||||||
for (const Type* type : LowerType(struct_type)) {
|
|
||||||
if (!first) {
|
|
||||||
header_out() << ", ";
|
|
||||||
}
|
|
||||||
first = false;
|
|
||||||
header_out() << type->GetGeneratedTypeName();
|
|
||||||
}
|
|
||||||
header_out() << "> Flatten() const {\n"
|
|
||||||
<< " return std::tuple_cat(";
|
|
||||||
first = true;
|
|
||||||
for (auto& field : struct_type->fields()) {
|
|
||||||
if (!first) {
|
|
||||||
header_out() << ", ";
|
|
||||||
}
|
|
||||||
first = false;
|
|
||||||
if (field.name_and_type.type->IsStructType()) {
|
|
||||||
header_out() << field.name_and_type.name << ".Flatten()";
|
|
||||||
} else {
|
|
||||||
header_out() << "std::make_tuple(" << field.name_and_type.name << ")";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
header_out() << ");\n";
|
|
||||||
header_out() << " }\n";
|
|
||||||
header_out() << " };\n";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -314,13 +265,12 @@ void ImplementationVisitor::VisitMacroCommon(Macro* macro) {
|
|||||||
bool has_return_value =
|
bool has_return_value =
|
||||||
can_return && return_type != TypeOracle::GetVoidType();
|
can_return && return_type != TypeOracle::GetVoidType();
|
||||||
|
|
||||||
header_out() << " ";
|
|
||||||
GenerateMacroFunctionDeclaration(header_out(), "", macro);
|
GenerateMacroFunctionDeclaration(header_out(), "", macro);
|
||||||
header_out() << ";\n";
|
header_out() << ";\n";
|
||||||
|
|
||||||
GenerateMacroFunctionDeclaration(
|
GenerateMacroFunctionDeclaration(source_out(), "", macro);
|
||||||
source_out(), CurrentNamespace()->ExternalName() + "::", macro);
|
|
||||||
source_out() << " {\n";
|
source_out() << " {\n";
|
||||||
|
source_out() << " compiler::CodeAssembler ca_(state_);\n";
|
||||||
|
|
||||||
Stack<std::string> lowered_parameters;
|
Stack<std::string> lowered_parameters;
|
||||||
Stack<const Type*> lowered_parameter_types;
|
Stack<const Type*> lowered_parameter_types;
|
||||||
@ -416,8 +366,7 @@ void ImplementationVisitor::VisitMacroCommon(Macro* macro) {
|
|||||||
source_out() << "}\n\n";
|
source_out() << "}\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImplementationVisitor::Visit(Macro* macro) {
|
void ImplementationVisitor::Visit(TorqueMacro* macro) {
|
||||||
if (macro->IsExternal()) return;
|
|
||||||
VisitMacroCommon(macro);
|
VisitMacroCommon(macro);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -481,7 +430,7 @@ void ImplementationVisitor::Visit(Builtin* builtin) {
|
|||||||
<< " TNode<IntPtrT> arguments_length(ChangeInt32ToIntPtr(argc));\n";
|
<< " TNode<IntPtrT> arguments_length(ChangeInt32ToIntPtr(argc));\n";
|
||||||
source_out() << " TNode<RawPtrT> arguments_frame = "
|
source_out() << " TNode<RawPtrT> arguments_frame = "
|
||||||
"UncheckedCast<RawPtrT>(LoadFramePointer());\n";
|
"UncheckedCast<RawPtrT>(LoadFramePointer());\n";
|
||||||
source_out() << " TorqueGeneratedBaseBuiltinsAssembler::Arguments "
|
source_out() << " TorqueStructArguments "
|
||||||
"torque_arguments(GetFrameArguments(arguments_frame, "
|
"torque_arguments(GetFrameArguments(arguments_frame, "
|
||||||
"arguments_length));\n";
|
"arguments_length));\n";
|
||||||
source_out() << " CodeStubArguments arguments(this, torque_arguments);\n";
|
source_out() << " CodeStubArguments arguments(this, torque_arguments);\n";
|
||||||
@ -1536,9 +1485,11 @@ void ImplementationVisitor::GenerateMacroFunctionDeclaration(
|
|||||||
macro->signature(), macro->parameter_names());
|
macro->signature(), macro->parameter_names());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImplementationVisitor::GenerateFunctionDeclaration(
|
std::vector<std::string> ImplementationVisitor::GenerateFunctionDeclaration(
|
||||||
std::ostream& o, const std::string& macro_prefix, const std::string& name,
|
std::ostream& o, const std::string& macro_prefix, const std::string& name,
|
||||||
const Signature& signature, const NameVector& parameter_names) {
|
const Signature& signature, const NameVector& parameter_names,
|
||||||
|
bool pass_code_assembler_state) {
|
||||||
|
std::vector<std::string> generated_parameter_names;
|
||||||
if (signature.return_type->IsVoidOrNever()) {
|
if (signature.return_type->IsVoidOrNever()) {
|
||||||
o << "void";
|
o << "void";
|
||||||
} else {
|
} else {
|
||||||
@ -1546,27 +1497,32 @@ void ImplementationVisitor::GenerateFunctionDeclaration(
|
|||||||
}
|
}
|
||||||
o << " " << macro_prefix << name << "(";
|
o << " " << macro_prefix << name << "(";
|
||||||
|
|
||||||
DCHECK_EQ(signature.types().size(), parameter_names.size());
|
|
||||||
auto type_iterator = signature.types().begin();
|
|
||||||
bool first = true;
|
bool first = true;
|
||||||
for (const Identifier* name : parameter_names) {
|
if (pass_code_assembler_state) {
|
||||||
if (!first) {
|
first = false;
|
||||||
o << ", ";
|
o << "compiler::CodeAssemblerState* state_";
|
||||||
}
|
}
|
||||||
const Type* parameter_type = *type_iterator;
|
|
||||||
|
DCHECK_GE(signature.types().size(), parameter_names.size());
|
||||||
|
for (size_t i = 0; i < signature.types().size(); ++i) {
|
||||||
|
if (!first) o << ", ";
|
||||||
|
first = false;
|
||||||
|
const Type* parameter_type = signature.types()[i];
|
||||||
const std::string& generated_type_name =
|
const std::string& generated_type_name =
|
||||||
parameter_type->GetGeneratedTypeName();
|
parameter_type->GetGeneratedTypeName();
|
||||||
o << generated_type_name << " " << ExternalParameterName(name->value);
|
|
||||||
type_iterator++;
|
generated_parameter_names.push_back(ExternalParameterName(
|
||||||
first = false;
|
i < parameter_names.size() ? parameter_names[i]->value
|
||||||
|
: std::to_string(i)));
|
||||||
|
o << generated_type_name << " " << generated_parameter_names.back();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const LabelDeclaration& label_info : signature.labels) {
|
for (const LabelDeclaration& label_info : signature.labels) {
|
||||||
if (!first) {
|
if (!first) o << ", ";
|
||||||
o << ", ";
|
first = false;
|
||||||
}
|
generated_parameter_names.push_back(
|
||||||
o << "compiler::CodeAssemblerLabel* "
|
ExternalLabelName(label_info.name->value));
|
||||||
<< ExternalLabelName(label_info.name->value);
|
o << "compiler::CodeAssemblerLabel* " << generated_parameter_names.back();
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
for (const Type* type : label_info.types) {
|
for (const Type* type : label_info.types) {
|
||||||
std::string generated_type_name;
|
std::string generated_type_name;
|
||||||
@ -1578,13 +1534,15 @@ void ImplementationVisitor::GenerateFunctionDeclaration(
|
|||||||
generated_type_name += ">*";
|
generated_type_name += ">*";
|
||||||
}
|
}
|
||||||
o << ", ";
|
o << ", ";
|
||||||
o << generated_type_name << " "
|
generated_parameter_names.push_back(
|
||||||
<< ExternalLabelParameterName(label_info.name->value, i);
|
ExternalLabelParameterName(label_info.name->value, i));
|
||||||
|
o << generated_type_name << " " << generated_parameter_names.back();
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
o << ")";
|
o << ")";
|
||||||
|
return generated_parameter_names;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
@ -1955,9 +1913,7 @@ LocationReference ImplementationVisitor::GetLocationReference(
|
|||||||
if (auto* constant = NamespaceConstant::DynamicCast(value)) {
|
if (auto* constant = NamespaceConstant::DynamicCast(value)) {
|
||||||
if (constant->type()->IsConstexpr()) {
|
if (constant->type()->IsConstexpr()) {
|
||||||
return LocationReference::Temporary(
|
return LocationReference::Temporary(
|
||||||
VisitResult(constant->type(), constant->ExternalAssemblerName() +
|
VisitResult(constant->type(), constant->external_name() + "(state_)"),
|
||||||
"(state_)." +
|
|
||||||
constant->name()->value + "()"),
|
|
||||||
"namespace constant " + expr->name->value);
|
"namespace constant " + expr->name->value);
|
||||||
}
|
}
|
||||||
assembler().Emit(NamespaceConstantInstruction{constant});
|
assembler().Emit(NamespaceConstantInstruction{constant});
|
||||||
@ -2214,9 +2170,15 @@ VisitResult ImplementationVisitor::GenerateCall(
|
|||||||
if (return_type->IsConstexpr()) {
|
if (return_type->IsConstexpr()) {
|
||||||
DCHECK_EQ(0, arguments.labels.size());
|
DCHECK_EQ(0, arguments.labels.size());
|
||||||
std::stringstream result;
|
std::stringstream result;
|
||||||
result << "(" << macro->external_assembler_name() << "(state_)."
|
result << "(";
|
||||||
<< macro->ExternalName() << "(";
|
|
||||||
bool first = true;
|
bool first = true;
|
||||||
|
if (auto* extern_macro = ExternMacro::DynamicCast(macro)) {
|
||||||
|
result << extern_macro->external_assembler_name() << "(state_)."
|
||||||
|
<< extern_macro->ExternalName() << "(";
|
||||||
|
} else {
|
||||||
|
result << macro->ExternalName() << "(state_";
|
||||||
|
first = false;
|
||||||
|
}
|
||||||
for (VisitResult arg : arguments.parameters) {
|
for (VisitResult arg : arguments.parameters) {
|
||||||
DCHECK(!arg.IsOnStack());
|
DCHECK(!arg.IsOnStack());
|
||||||
if (!first) {
|
if (!first) {
|
||||||
@ -2629,8 +2591,10 @@ void ImplementationVisitor::Visit(Declarable* declarable) {
|
|||||||
CurrentScope::Scope current_scope(declarable->ParentScope());
|
CurrentScope::Scope current_scope(declarable->ParentScope());
|
||||||
CurrentSourcePosition::Scope current_source_position(declarable->Position());
|
CurrentSourcePosition::Scope current_source_position(declarable->Position());
|
||||||
switch (declarable->kind()) {
|
switch (declarable->kind()) {
|
||||||
case Declarable::kMacro:
|
case Declarable::kExternMacro:
|
||||||
return Visit(Macro::cast(declarable));
|
return Visit(ExternMacro::cast(declarable));
|
||||||
|
case Declarable::kTorqueMacro:
|
||||||
|
return Visit(TorqueMacro::cast(declarable));
|
||||||
case Declarable::kMethod:
|
case Declarable::kMethod:
|
||||||
return Visit(Method::cast(declarable));
|
return Visit(Method::cast(declarable));
|
||||||
case Declarable::kBuiltin:
|
case Declarable::kBuiltin:
|
||||||
@ -3504,6 +3468,117 @@ void ImplementationVisitor::GenerateClassVerifiers(
|
|||||||
WriteFile(output_directory + "/" + file_name + ".cc", cc_contents.str());
|
WriteFile(output_directory + "/" + file_name + ".cc", cc_contents.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ImplementationVisitor::GenerateExportedMacrosAssembler(
|
||||||
|
const std::string& output_directory) {
|
||||||
|
std::string file_name = "exported-macros-assembler-tq";
|
||||||
|
std::stringstream h_contents;
|
||||||
|
std::stringstream cc_contents;
|
||||||
|
{
|
||||||
|
IncludeGuardScope include_guard(h_contents, file_name + ".h");
|
||||||
|
|
||||||
|
h_contents << "#include \"src/compiler/code-assembler.h\"\n";
|
||||||
|
h_contents << "#include \"src/execution/frames.h\"\n";
|
||||||
|
h_contents << "#include \"torque-generated/csa-types-tq.h\"\n";
|
||||||
|
cc_contents << "#include \"torque-generated/" << file_name << ".h\"\n";
|
||||||
|
for (Namespace* n : GlobalContext::Get().GetNamespaces()) {
|
||||||
|
cc_contents << "#include \"torque-generated/builtins-" +
|
||||||
|
DashifyString(n->name()) + "-gen-tq.h\"\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
NamespaceScope h_namespaces(h_contents, {"v8", "internal"});
|
||||||
|
NamespaceScope cc_namespaces(cc_contents, {"v8", "internal"});
|
||||||
|
|
||||||
|
h_contents << "class V8_EXPORT_PRIVATE "
|
||||||
|
"TorqueGeneratedExportedMacrosAssembler {\n"
|
||||||
|
<< " public:\n"
|
||||||
|
<< " explicit TorqueGeneratedExportedMacrosAssembler"
|
||||||
|
"(compiler::CodeAssemblerState* state) : state_(state) {\n"
|
||||||
|
<< " USE(state_);\n"
|
||||||
|
<< " }\n";
|
||||||
|
|
||||||
|
for (auto& declarable : GlobalContext::AllDeclarables()) {
|
||||||
|
TorqueMacro* macro = TorqueMacro::DynamicCast(declarable.get());
|
||||||
|
if (!(macro && macro->IsExportedToCSA())) continue;
|
||||||
|
|
||||||
|
h_contents << " ";
|
||||||
|
GenerateFunctionDeclaration(h_contents, "", macro->ReadableName(),
|
||||||
|
macro->signature(), macro->parameter_names(),
|
||||||
|
false);
|
||||||
|
h_contents << ";\n";
|
||||||
|
|
||||||
|
std::vector<std::string> parameter_names = GenerateFunctionDeclaration(
|
||||||
|
cc_contents,
|
||||||
|
"TorqueGeneratedExportedMacrosAssembler::", macro->ReadableName(),
|
||||||
|
macro->signature(), macro->parameter_names(), false);
|
||||||
|
cc_contents << "{\n";
|
||||||
|
cc_contents << "return " << macro->ExternalName() << "(state_";
|
||||||
|
for (auto& name : parameter_names) {
|
||||||
|
cc_contents << ", " << name;
|
||||||
|
}
|
||||||
|
cc_contents << ");\n";
|
||||||
|
cc_contents << "}\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
h_contents << " private:\n"
|
||||||
|
<< " compiler::CodeAssemblerState* state_;\n"
|
||||||
|
<< "};\n";
|
||||||
|
}
|
||||||
|
WriteFile(output_directory + "/" + file_name + ".h", h_contents.str());
|
||||||
|
WriteFile(output_directory + "/" + file_name + ".cc", cc_contents.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImplementationVisitor::GenerateCSATypes(
|
||||||
|
const std::string& output_directory) {
|
||||||
|
std::string file_name = "csa-types-tq";
|
||||||
|
std::stringstream h_contents;
|
||||||
|
{
|
||||||
|
IncludeGuardScope include_guard(h_contents, file_name + ".h");
|
||||||
|
h_contents << "#include \"src/compiler/code-assembler.h\"\n\n";
|
||||||
|
|
||||||
|
NamespaceScope h_namespaces(h_contents, {"v8", "internal"});
|
||||||
|
|
||||||
|
for (auto& declarable : GlobalContext::AllDeclarables()) {
|
||||||
|
TypeAlias* alias = TypeAlias::DynamicCast(declarable.get());
|
||||||
|
if (!alias || alias->IsRedeclaration()) continue;
|
||||||
|
const StructType* struct_type = StructType::DynamicCast(alias->type());
|
||||||
|
if (!struct_type) continue;
|
||||||
|
const std::string& name = struct_type->name();
|
||||||
|
h_contents << "struct TorqueStruct" << name << " {\n";
|
||||||
|
for (auto& field : struct_type->fields()) {
|
||||||
|
h_contents << " " << field.name_and_type.type->GetGeneratedTypeName();
|
||||||
|
h_contents << " " << field.name_and_type.name << ";\n";
|
||||||
|
}
|
||||||
|
h_contents << "\n std::tuple<";
|
||||||
|
bool first = true;
|
||||||
|
for (const Type* type : LowerType(struct_type)) {
|
||||||
|
if (!first) {
|
||||||
|
h_contents << ", ";
|
||||||
|
}
|
||||||
|
first = false;
|
||||||
|
h_contents << type->GetGeneratedTypeName();
|
||||||
|
}
|
||||||
|
h_contents << "> Flatten() const {\n"
|
||||||
|
<< " return std::tuple_cat(";
|
||||||
|
first = true;
|
||||||
|
for (auto& field : struct_type->fields()) {
|
||||||
|
if (!first) {
|
||||||
|
h_contents << ", ";
|
||||||
|
}
|
||||||
|
first = false;
|
||||||
|
if (field.name_and_type.type->IsStructType()) {
|
||||||
|
h_contents << field.name_and_type.name << ".Flatten()";
|
||||||
|
} else {
|
||||||
|
h_contents << "std::make_tuple(" << field.name_and_type.name << ")";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
h_contents << ");\n";
|
||||||
|
h_contents << " }\n";
|
||||||
|
h_contents << "};\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
WriteFile(output_directory + "/" + file_name + ".h", h_contents.str());
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace torque
|
} // namespace torque
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
} // namespace v8
|
} // namespace v8
|
||||||
|
@ -280,6 +280,8 @@ class ImplementationVisitor {
|
|||||||
void GeneratePrintDefinitions(const std::string& output_directory);
|
void GeneratePrintDefinitions(const std::string& output_directory);
|
||||||
void GenerateClassDefinitions(const std::string& output_directory);
|
void GenerateClassDefinitions(const std::string& output_directory);
|
||||||
void GenerateClassVerifiers(const std::string& output_directory);
|
void GenerateClassVerifiers(const std::string& output_directory);
|
||||||
|
void GenerateExportedMacrosAssembler(const std::string& output_directory);
|
||||||
|
void GenerateCSATypes(const std::string& output_directory);
|
||||||
|
|
||||||
VisitResult Visit(Expression* expr);
|
VisitResult Visit(Expression* expr);
|
||||||
const Type* Visit(Statement* stmt);
|
const Type* Visit(Statement* stmt);
|
||||||
@ -327,7 +329,8 @@ class ImplementationVisitor {
|
|||||||
const std::vector<VisitResult>& arguments,
|
const std::vector<VisitResult>& arguments,
|
||||||
const std::vector<Block*> label_blocks);
|
const std::vector<Block*> label_blocks);
|
||||||
void VisitMacroCommon(Macro* macro);
|
void VisitMacroCommon(Macro* macro);
|
||||||
void Visit(Macro* macro);
|
void Visit(ExternMacro* macro) {}
|
||||||
|
void Visit(TorqueMacro* macro);
|
||||||
void Visit(Method* macro);
|
void Visit(Method* macro);
|
||||||
void Visit(Builtin* builtin);
|
void Visit(Builtin* builtin);
|
||||||
void Visit(NamespaceConstant* decl);
|
void Visit(NamespaceConstant* decl);
|
||||||
@ -538,11 +541,10 @@ class ImplementationVisitor {
|
|||||||
void GenerateMacroFunctionDeclaration(std::ostream& o,
|
void GenerateMacroFunctionDeclaration(std::ostream& o,
|
||||||
const std::string& macro_prefix,
|
const std::string& macro_prefix,
|
||||||
Macro* macro);
|
Macro* macro);
|
||||||
void GenerateFunctionDeclaration(std::ostream& o,
|
std::vector<std::string> GenerateFunctionDeclaration(
|
||||||
const std::string& macro_prefix,
|
std::ostream& o, const std::string& macro_prefix, const std::string& name,
|
||||||
const std::string& name,
|
const Signature& signature, const NameVector& parameter_names,
|
||||||
const Signature& signature,
|
bool pass_code_assembler_state = true);
|
||||||
const NameVector& parameter_names);
|
|
||||||
|
|
||||||
VisitResult GenerateImplicitConvert(const Type* destination_type,
|
VisitResult GenerateImplicitConvert(const Type* destination_type,
|
||||||
VisitResult source);
|
VisitResult source);
|
||||||
|
@ -83,6 +83,8 @@ void CompileCurrentAst(TorqueCompilerOptions options) {
|
|||||||
implementation_visitor.GeneratePrintDefinitions(output_directory);
|
implementation_visitor.GeneratePrintDefinitions(output_directory);
|
||||||
implementation_visitor.GenerateClassDefinitions(output_directory);
|
implementation_visitor.GenerateClassDefinitions(output_directory);
|
||||||
implementation_visitor.GenerateClassVerifiers(output_directory);
|
implementation_visitor.GenerateClassVerifiers(output_directory);
|
||||||
|
implementation_visitor.GenerateExportedMacrosAssembler(output_directory);
|
||||||
|
implementation_visitor.GenerateCSATypes(output_directory);
|
||||||
|
|
||||||
for (Namespace* n : GlobalContext::Get().GetNamespaces()) {
|
for (Namespace* n : GlobalContext::Get().GetNamespaces()) {
|
||||||
implementation_visitor.EndNamespaceFile(n);
|
implementation_visitor.EndNamespaceFile(n);
|
||||||
|
@ -10,6 +10,7 @@ namespace torque {
|
|||||||
|
|
||||||
DEFINE_CONTEXTUAL_VARIABLE(TypeOracle)
|
DEFINE_CONTEXTUAL_VARIABLE(TypeOracle)
|
||||||
|
|
||||||
|
// static
|
||||||
void TypeOracle::FinalizeClassTypes() {
|
void TypeOracle::FinalizeClassTypes() {
|
||||||
for (const std::unique_ptr<AggregateType>& p : Get().struct_types_) {
|
for (const std::unique_ptr<AggregateType>& p : Get().struct_types_) {
|
||||||
p->Finalize();
|
p->Finalize();
|
||||||
|
@ -95,7 +95,7 @@ std::string Type::GetGeneratedTypeName() const {
|
|||||||
|
|
||||||
std::string Type::GetGeneratedTNodeTypeName() const {
|
std::string Type::GetGeneratedTNodeTypeName() const {
|
||||||
std::string result = GetGeneratedTNodeTypeNameImpl();
|
std::string result = GetGeneratedTNodeTypeNameImpl();
|
||||||
if (result.empty()) {
|
if (result.empty() || IsConstexpr()) {
|
||||||
ReportError("Generated TNode type is required for type '", ToString(),
|
ReportError("Generated TNode type is required for type '", ToString(),
|
||||||
"'. Use 'generates' clause in definition.");
|
"'. Use 'generates' clause in definition.");
|
||||||
}
|
}
|
||||||
@ -272,7 +272,7 @@ const Field& AggregateType::LookupField(const std::string& name) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string StructType::GetGeneratedTypeNameImpl() const {
|
std::string StructType::GetGeneratedTypeNameImpl() const {
|
||||||
return nspace()->ExternalName() + "::" + name();
|
return "TorqueStruct" + name();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Method*> AggregateType::Methods(const std::string& name) const {
|
std::vector<Method*> AggregateType::Methods(const std::string& name) const {
|
||||||
@ -310,11 +310,7 @@ bool ClassType::HasIndexedField() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string ClassType::GetGeneratedTNodeTypeNameImpl() const {
|
std::string ClassType::GetGeneratedTNodeTypeNameImpl() const {
|
||||||
if (!IsExtern()) return generates_;
|
return generates_;
|
||||||
std::string prefix = nspace()->IsDefaultNamespace()
|
|
||||||
? std::string{}
|
|
||||||
: (nspace()->ExternalName() + "::");
|
|
||||||
return prefix + generates_;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ClassType::GetGeneratedTypeNameImpl() const {
|
std::string ClassType::GetGeneratedTypeNameImpl() const {
|
||||||
|
@ -30,11 +30,10 @@ namespace {
|
|||||||
using Label = CodeAssemblerLabel;
|
using Label = CodeAssemblerLabel;
|
||||||
using Variable = CodeAssemblerVariable;
|
using Variable = CodeAssemblerVariable;
|
||||||
|
|
||||||
class TestTorqueAssembler : public CodeStubAssembler,
|
class TestTorqueAssembler : public CodeStubAssembler {
|
||||||
public TorqueGeneratedTestBuiltinsAssembler {
|
|
||||||
public:
|
public:
|
||||||
explicit TestTorqueAssembler(CodeAssemblerState* state)
|
explicit TestTorqueAssembler(CodeAssemblerState* state)
|
||||||
: CodeStubAssembler(state), TorqueGeneratedTestBuiltinsAssembler(state) {}
|
: CodeStubAssembler(state) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
@ -339,7 +339,6 @@ namespace test {
|
|||||||
return TestStructC{x: TestStruct2(), y: TestStruct2()};
|
return TestStructC{x: TestStruct2(), y: TestStruct2()};
|
||||||
}
|
}
|
||||||
|
|
||||||
@export
|
|
||||||
macro TestStructInLabel(implicit context: Context)(): never labels
|
macro TestStructInLabel(implicit context: Context)(): never labels
|
||||||
Foo(TestStructA) {
|
Foo(TestStructA) {
|
||||||
goto Foo(TestStruct2());
|
goto Foo(TestStruct2());
|
||||||
|
Loading…
Reference in New Issue
Block a user