Commit 23b48920 authored by Tobias Tebbi's avatar Tobias Tebbi Committed by Commit Bot

[torque] qualified access to CSA assemblers

No longer use inheritance to associate Torque-generated assemblers
with corresponding CSA subclasses. Instead, all references to CSA
and CSA-derived assemblers are now explicitly qualified, by generating
a short-lived assembler instance in-place. As a consequence, Torque
files have to mention the assembler external macros live in.
The CodeStubAssembler is the default for this and can be omitted.
As a drive-by cleanup, also distinguish between names that are emitted
in C++ and names that are intended to be read in error messages. This
is relevant for generic instantiations, where the generated names are
rather unreadably mangled.

As a follow-up, it will be easy to allow for qualified access to
different modules, thus implementing full namespace semantics for
modules.

Bug: v8:7793
Change-Id: Ie6f1b6b549b510fb49be2442393d898d5f130950
Reviewed-on: https://chromium-review.googlesource.com/c/1309636
Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
Reviewed-by: 's avatarDaniel Clifford <danno@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57235}
parent 7621325d
...@@ -7,10 +7,11 @@ module array { ...@@ -7,10 +7,11 @@ module array {
// Fast C call to write a fixed array (see Buffer.fixedArray) to a single // Fast C call to write a fixed array (see Buffer.fixedArray) to a single
// string. // string.
extern macro CallJSArrayArrayJoinConcatToSequentialString( extern macro
ArrayBuiltinsAssembler::CallJSArrayArrayJoinConcatToSequentialString(
FixedArray, intptr, String, String): String; FixedArray, intptr, String, String): String;
extern macro CallArrayJoin( extern macro ArrayBuiltinsAssembler::CallArrayJoin(
Context, constexpr bool, JSReceiver, String, Number, Object, Object): Context, constexpr bool, JSReceiver, String, Number, Object, Object):
String String
labels IfException(Object); labels IfException(Object);
......
...@@ -901,10 +901,11 @@ extern macro IsArraySpeciesProtectorCellInvalid(): bool; ...@@ -901,10 +901,11 @@ extern macro IsArraySpeciesProtectorCellInvalid(): bool;
extern macro IsTypedArraySpeciesProtectorCellInvalid(): bool; extern macro IsTypedArraySpeciesProtectorCellInvalid(): bool;
extern macro IsPromiseSpeciesProtectorCellInvalid(): bool; extern macro IsPromiseSpeciesProtectorCellInvalid(): bool;
extern operator '.buffer' macro LoadTypedArrayBuffer(JSTypedArray): extern operator '.buffer' macro
JSArrayBuffer; TypedArrayBuiltinsAssembler::LoadTypedArrayBuffer(JSTypedArray): JSArrayBuffer;
extern operator '.data_ptr' macro LoadDataPtr(JSTypedArray): RawPtr; extern operator '.data_ptr' macro TypedArrayBuiltinsAssembler::LoadDataPtr(
JSTypedArray): RawPtr;
extern operator '.elements_kind' macro LoadMapElementsKind(Map): ElementsKind; extern operator '.elements_kind' macro LoadMapElementsKind(Map): ElementsKind;
extern operator '.elements_kind' macro LoadElementsKind(JSTypedArray): extern operator '.elements_kind' macro LoadElementsKind(JSTypedArray):
......
...@@ -21,7 +21,7 @@ using Node = compiler::Node; ...@@ -21,7 +21,7 @@ using Node = compiler::Node;
ArrayBuiltinsAssembler::ArrayBuiltinsAssembler( ArrayBuiltinsAssembler::ArrayBuiltinsAssembler(
compiler::CodeAssemblerState* state) compiler::CodeAssemblerState* state)
: BaseBuiltinsFromDSLAssembler(state), : CodeStubAssembler(state),
k_(this, MachineRepresentation::kTagged), k_(this, MachineRepresentation::kTagged),
a_(this, MachineRepresentation::kTagged), a_(this, MachineRepresentation::kTagged),
to_(this, MachineRepresentation::kTagged, SmiConstant(0)), to_(this, MachineRepresentation::kTagged, SmiConstant(0)),
......
...@@ -5,12 +5,12 @@ ...@@ -5,12 +5,12 @@
#ifndef V8_BUILTINS_BUILTINS_ARRAY_GEN_H_ #ifndef V8_BUILTINS_BUILTINS_ARRAY_GEN_H_
#define V8_BUILTINS_BUILTINS_ARRAY_GEN_H_ #define V8_BUILTINS_BUILTINS_ARRAY_GEN_H_
#include "torque-generated/builtins-base-from-dsl-gen.h" #include "src/code-stub-assembler.h"
namespace v8 { namespace v8 {
namespace internal { namespace internal {
class ArrayBuiltinsAssembler : public BaseBuiltinsFromDSLAssembler { class ArrayBuiltinsAssembler : public CodeStubAssembler {
public: public:
explicit ArrayBuiltinsAssembler(compiler::CodeAssemblerState* state); explicit ArrayBuiltinsAssembler(compiler::CodeAssemblerState* state);
......
...@@ -5,17 +5,17 @@ ...@@ -5,17 +5,17 @@
#ifndef V8_BUILTINS_BUILTINS_DATA_VIEW_GEN_H_ #ifndef V8_BUILTINS_BUILTINS_DATA_VIEW_GEN_H_
#define V8_BUILTINS_BUILTINS_DATA_VIEW_GEN_H_ #define V8_BUILTINS_BUILTINS_DATA_VIEW_GEN_H_
#include "src/code-stub-assembler.h"
#include "src/elements-kind.h" #include "src/elements-kind.h"
#include "src/objects/bigint.h" #include "src/objects/bigint.h"
#include "torque-generated/builtins-base-from-dsl-gen.h"
namespace v8 { namespace v8 {
namespace internal { namespace internal {
class DataViewBuiltinsAssembler : public BaseBuiltinsFromDSLAssembler { class DataViewBuiltinsAssembler : public CodeStubAssembler {
public: public:
explicit DataViewBuiltinsAssembler(compiler::CodeAssemblerState* state) explicit DataViewBuiltinsAssembler(compiler::CodeAssemblerState* state)
: BaseBuiltinsFromDSLAssembler(state) {} : CodeStubAssembler(state) {}
TNode<Int32T> LoadUint8(TNode<RawPtrT> data_pointer, TNode<UintPtrT> offset) { TNode<Int32T> LoadUint8(TNode<RawPtrT> data_pointer, TNode<UintPtrT> offset) {
return UncheckedCast<Int32T>( return UncheckedCast<Int32T>(
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef V8_BUILTINS_BUILTINS_ITERATOR_GEN_H_ #ifndef V8_BUILTINS_BUILTINS_ITERATOR_GEN_H_
#define V8_BUILTINS_BUILTINS_ITERATOR_GEN_H_ #define V8_BUILTINS_BUILTINS_ITERATOR_GEN_H_
#include "src/code-stub-assembler.h"
#include "torque-generated/builtins-base-from-dsl-gen.h" #include "torque-generated/builtins-base-from-dsl-gen.h"
namespace v8 { namespace v8 {
...@@ -12,36 +13,38 @@ namespace internal { ...@@ -12,36 +13,38 @@ namespace internal {
using compiler::Node; using compiler::Node;
class IteratorBuiltinsAssembler : public BaseBuiltinsFromDSLAssembler { class IteratorBuiltinsAssembler : public CodeStubAssembler {
public: public:
explicit IteratorBuiltinsAssembler(compiler::CodeAssemblerState* state) explicit IteratorBuiltinsAssembler(compiler::CodeAssemblerState* state)
: BaseBuiltinsFromDSLAssembler(state) {} : CodeStubAssembler(state) {}
// Returns object[Symbol.iterator]. // Returns object[Symbol.iterator].
TNode<Object> GetIteratorMethod(Node* context, Node* object); TNode<Object> GetIteratorMethod(Node* context, Node* object);
// https://tc39.github.io/ecma262/#sec-getiterator --- never used for // https://tc39.github.io/ecma262/#sec-getiterator --- never used for
// @@asyncIterator. // @@asyncIterator.
IteratorRecord GetIterator(Node* context, Node* object, BaseBuiltinsFromDSLAssembler::IteratorRecord GetIterator(
Label* if_exception = nullptr, Node* context, Node* object, Label* if_exception = nullptr,
Variable* exception = nullptr); Variable* exception = nullptr);
IteratorRecord GetIterator(Node* context, Node* object, Node* method, BaseBuiltinsFromDSLAssembler::IteratorRecord GetIterator(
Label* if_exception = nullptr, Node* context, Node* object, Node* method, Label* if_exception = nullptr,
Variable* exception = nullptr); Variable* exception = nullptr);
// https://tc39.github.io/ecma262/#sec-iteratorstep // https://tc39.github.io/ecma262/#sec-iteratorstep
// Returns `false` if the iterator is done, otherwise returns an // Returns `false` if the iterator is done, otherwise returns an
// iterator result. // iterator result.
// `fast_iterator_result_map` refers to the map for the JSIteratorResult // `fast_iterator_result_map` refers to the map for the JSIteratorResult
// object, loaded from the native context. // object, loaded from the native context.
TNode<Object> IteratorStep(Node* context, const IteratorRecord& iterator, TNode<Object> IteratorStep(
Label* if_done, Node* context,
Node* fast_iterator_result_map = nullptr, const BaseBuiltinsFromDSLAssembler::IteratorRecord& iterator,
Label* if_exception = nullptr, Label* if_done, Node* fast_iterator_result_map = nullptr,
Variable* exception = nullptr); Label* if_exception = nullptr, Variable* exception = nullptr);
TNode<Object> IteratorStep(Node* context, const IteratorRecord& iterator, TNode<Object> IteratorStep(
Node* fast_iterator_result_map, Label* if_done) { Node* context,
const BaseBuiltinsFromDSLAssembler::IteratorRecord& iterator,
Node* fast_iterator_result_map, Label* if_done) {
return IteratorStep(context, iterator, if_done, fast_iterator_result_map); return IteratorStep(context, iterator, if_done, fast_iterator_result_map);
} }
...@@ -55,11 +58,14 @@ class IteratorBuiltinsAssembler : public BaseBuiltinsFromDSLAssembler { ...@@ -55,11 +58,14 @@ class IteratorBuiltinsAssembler : public BaseBuiltinsFromDSLAssembler {
Variable* exception = nullptr); Variable* exception = nullptr);
// https://tc39.github.io/ecma262/#sec-iteratorclose // https://tc39.github.io/ecma262/#sec-iteratorclose
void IteratorCloseOnException(Node* context, const IteratorRecord& iterator, void IteratorCloseOnException(
Label* if_exception = nullptr, Node* context,
Variable* exception = nullptr); const BaseBuiltinsFromDSLAssembler::IteratorRecord& iterator,
void IteratorCloseOnException(Node* context, const IteratorRecord& iterator, Label* if_exception = nullptr, Variable* exception = nullptr);
Variable* exception); void IteratorCloseOnException(
Node* context,
const BaseBuiltinsFromDSLAssembler::IteratorRecord& iterator,
Variable* exception);
// #sec-iterabletolist // #sec-iterabletolist
// Build a JSArray by iterating over {iterable} using {iterator_fn}, // Build a JSArray by iterating over {iterable} using {iterator_fn},
......
...@@ -17,6 +17,7 @@ namespace v8 { ...@@ -17,6 +17,7 @@ namespace v8 {
namespace internal { namespace internal {
using compiler::Node; using compiler::Node;
using IteratorRecord = BaseBuiltinsFromDSLAssembler::IteratorRecord;
Node* PromiseBuiltinsAssembler::AllocateJSPromise(Node* context) { Node* PromiseBuiltinsAssembler::AllocateJSPromise(Node* context) {
Node* const native_context = LoadNativeContext(context); Node* const native_context = LoadNativeContext(context);
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef V8_BUILTINS_BUILTINS_PROMISE_GEN_H_ #ifndef V8_BUILTINS_BUILTINS_PROMISE_GEN_H_
#define V8_BUILTINS_BUILTINS_PROMISE_GEN_H_ #define V8_BUILTINS_BUILTINS_PROMISE_GEN_H_
#include "src/code-stub-assembler.h"
#include "src/contexts.h" #include "src/contexts.h"
#include "src/objects/promise.h" #include "src/objects/promise.h"
#include "torque-generated/builtins-base-from-dsl-gen.h" #include "torque-generated/builtins-base-from-dsl-gen.h"
...@@ -14,7 +15,7 @@ namespace internal { ...@@ -14,7 +15,7 @@ namespace internal {
typedef compiler::CodeAssemblerState CodeAssemblerState; typedef compiler::CodeAssemblerState CodeAssemblerState;
class PromiseBuiltinsAssembler : public BaseBuiltinsFromDSLAssembler { class PromiseBuiltinsAssembler : public CodeStubAssembler {
public: public:
enum PromiseResolvingFunctionContextSlot { enum PromiseResolvingFunctionContextSlot {
// The promise which resolve/reject callbacks fulfill. // The promise which resolve/reject callbacks fulfill.
...@@ -70,7 +71,7 @@ class PromiseBuiltinsAssembler : public BaseBuiltinsFromDSLAssembler { ...@@ -70,7 +71,7 @@ class PromiseBuiltinsAssembler : public BaseBuiltinsFromDSLAssembler {
}; };
explicit PromiseBuiltinsAssembler(compiler::CodeAssemblerState* state) explicit PromiseBuiltinsAssembler(compiler::CodeAssemblerState* state)
: BaseBuiltinsFromDSLAssembler(state) {} : CodeStubAssembler(state) {}
// These allocate and initialize a promise with pending state and // These allocate and initialize a promise with pending state and
// undefined fields. // undefined fields.
// //
...@@ -180,9 +181,10 @@ class PromiseBuiltinsAssembler : public BaseBuiltinsFromDSLAssembler { ...@@ -180,9 +181,10 @@ class PromiseBuiltinsAssembler : public BaseBuiltinsFromDSLAssembler {
Node* CreateThrowerFunction(Node* reason, Node* native_context); Node* CreateThrowerFunction(Node* reason, Node* native_context);
Node* PerformPromiseAll(Node* context, Node* constructor, Node* capability, Node* PerformPromiseAll(
const IteratorRecord& record, Label* if_exception, Node* context, Node* constructor, Node* capability,
Variable* var_exception); const BaseBuiltinsFromDSLAssembler::IteratorRecord& record,
Label* if_exception, Variable* var_exception);
void SetForwardingHandlerIfTrue(Node* context, Node* condition, void SetForwardingHandlerIfTrue(Node* context, Node* condition,
const NodeGenerator& object); const NodeGenerator& object);
......
...@@ -5,15 +5,15 @@ ...@@ -5,15 +5,15 @@
#ifndef V8_BUILTINS_BUILTINS_TEST_GEN_H_ #ifndef V8_BUILTINS_BUILTINS_TEST_GEN_H_
#define V8_BUILTINS_BUILTINS_TEST_GEN_H_ #define V8_BUILTINS_BUILTINS_TEST_GEN_H_
#include "torque-generated/builtins-base-from-dsl-gen.h" #include "src/code-stub-assembler.h"
namespace v8 { namespace v8 {
namespace internal { namespace internal {
class TestBuiltinsAssembler : public BaseBuiltinsFromDSLAssembler { class TestBuiltinsAssembler : public CodeStubAssembler {
public: public:
explicit TestBuiltinsAssembler(compiler::CodeAssemblerState* state) explicit TestBuiltinsAssembler(compiler::CodeAssemblerState* state)
: BaseBuiltinsFromDSLAssembler(state) {} : CodeStubAssembler(state) {}
}; };
} // namespace internal } // namespace internal
......
...@@ -5,22 +5,21 @@ ...@@ -5,22 +5,21 @@
#ifndef V8_BUILTINS_BUILTINS_TYPED_ARRAY_GEN_H_ #ifndef V8_BUILTINS_BUILTINS_TYPED_ARRAY_GEN_H_
#define V8_BUILTINS_BUILTINS_TYPED_ARRAY_GEN_H_ #define V8_BUILTINS_BUILTINS_TYPED_ARRAY_GEN_H_
#include "torque-generated/builtins-base-from-dsl-gen.h" #include "src/code-stub-assembler.h"
namespace v8 { namespace v8 {
namespace internal { namespace internal {
class TypedArrayBuiltinsAssembler : public BaseBuiltinsFromDSLAssembler { class TypedArrayBuiltinsAssembler : public CodeStubAssembler {
public: public:
explicit TypedArrayBuiltinsAssembler(compiler::CodeAssemblerState* state) explicit TypedArrayBuiltinsAssembler(compiler::CodeAssemblerState* state)
: BaseBuiltinsFromDSLAssembler(state) {} : CodeStubAssembler(state) {}
TNode<JSTypedArray> SpeciesCreateByLength(TNode<Context> context, TNode<JSTypedArray> SpeciesCreateByLength(TNode<Context> context,
TNode<JSTypedArray> exemplar, TNode<JSTypedArray> exemplar,
TNode<Smi> len, TNode<Smi> len,
const char* method_name); const char* method_name);
protected:
void GenerateTypedArrayPrototypeIterationMethod(TNode<Context> context, void GenerateTypedArrayPrototypeIterationMethod(TNode<Context> context,
TNode<Object> receiver, TNode<Object> receiver,
const char* method_name, const char* method_name,
......
...@@ -119,8 +119,8 @@ module data_view { ...@@ -119,8 +119,8 @@ module data_view {
extern macro Float64InsertLowWord32(float64, uint32): float64; extern macro Float64InsertLowWord32(float64, uint32): float64;
extern macro Float64InsertHighWord32(float64, uint32): float64; extern macro Float64InsertHighWord32(float64, uint32): float64;
extern macro LoadUint8(RawPtr, uintptr): uint32; extern macro DataViewBuiltinsAssembler::LoadUint8(RawPtr, uintptr): uint32;
extern macro LoadInt8(RawPtr, uintptr): int32; extern macro DataViewBuiltinsAssembler::LoadInt8(RawPtr, uintptr): int32;
macro LoadDataView8( macro LoadDataView8(
buffer: JSArrayBuffer, offset: uintptr, signed: constexpr bool): Smi { buffer: JSArrayBuffer, offset: uintptr, signed: constexpr bool): Smi {
...@@ -221,7 +221,7 @@ module data_view { ...@@ -221,7 +221,7 @@ module data_view {
extern macro AllocateBigInt(intptr): BigInt; extern macro AllocateBigInt(intptr): BigInt;
extern macro StoreBigIntBitfield(BigInt, intptr): void; extern macro StoreBigIntBitfield(BigInt, intptr): void;
extern macro StoreBigIntDigit(BigInt, constexpr int31, uintptr): void; extern macro StoreBigIntDigit(BigInt, constexpr int31, uintptr): void;
extern macro DataViewEncodeBigIntBits( extern macro DataViewBuiltinsAssembler::DataViewEncodeBigIntBits(
constexpr bool, constexpr int31): intptr; constexpr bool, constexpr int31): intptr;
const kPositiveBigInt: constexpr bool = false; const kPositiveBigInt: constexpr bool = false;
...@@ -385,7 +385,8 @@ module data_view { ...@@ -385,7 +385,8 @@ module data_view {
extern macro ToSmiIndex(Object, Context): Smi extern macro ToSmiIndex(Object, Context): Smi
labels RangeError; labels RangeError;
extern macro DataViewElementSize(constexpr ElementsKind): constexpr int31; extern macro DataViewBuiltinsAssembler::DataViewElementSize(
constexpr ElementsKind): constexpr int31;
macro DataViewGet( macro DataViewGet(
context: Context, receiver: Object, offset: Object, context: Context, receiver: Object, offset: Object,
...@@ -536,7 +537,8 @@ module data_view { ...@@ -536,7 +537,8 @@ module data_view {
extern macro TruncateFloat64ToFloat32(float64): float32; extern macro TruncateFloat64ToFloat32(float64): float32;
extern macro TruncateFloat64ToWord32(float64): uint32; extern macro TruncateFloat64ToWord32(float64): uint32;
extern macro StoreWord8(RawPtr, uintptr, uint32): void; extern macro DataViewBuiltinsAssembler::StoreWord8(
RawPtr, uintptr, uint32): void;
macro StoreDataView8(buffer: JSArrayBuffer, offset: uintptr, value: uint32) { macro StoreDataView8(buffer: JSArrayBuffer, offset: uintptr, value: uint32) {
StoreWord8(buffer.backing_store, offset, value & 0xFF); StoreWord8(buffer.backing_store, offset, value & 0xFF);
...@@ -618,8 +620,10 @@ module data_view { ...@@ -618,8 +620,10 @@ module data_view {
} }
} }
extern macro DataViewDecodeBigIntLength(BigInt): uintptr; extern macro DataViewBuiltinsAssembler::DataViewDecodeBigIntLength(BigInt):
extern macro DataViewDecodeBigIntSign(BigInt): uintptr; uintptr;
extern macro DataViewBuiltinsAssembler::DataViewDecodeBigIntSign(BigInt):
uintptr;
extern macro LoadBigIntDigit(BigInt, constexpr int31): uintptr; extern macro LoadBigIntDigit(BigInt, constexpr int31): uintptr;
// We might get here a BigInt that is bigger than 64 bits, but we're only // We might get here a BigInt that is bigger than 64 bits, but we're only
......
...@@ -3,23 +3,28 @@ ...@@ -3,23 +3,28 @@
// found in the LICENSE file. // found in the LICENSE file.
module iterator { module iterator {
extern macro GetIteratorMethod(implicit context: Context)(Object): Object; extern macro IteratorBuiltinsAssembler::GetIteratorMethod(
extern macro GetIterator(implicit context: Context)(Object): IteratorRecord; implicit context: Context)(Object): Object;
extern macro IteratorBuiltinsAssembler::GetIterator(
implicit context: Context)(Object): IteratorRecord;
extern macro IteratorStep(implicit context: Context)(IteratorRecord): Object extern macro IteratorBuiltinsAssembler::IteratorStep(
implicit context: Context)(IteratorRecord): Object
labels Done; labels Done;
extern macro IteratorStep(implicit context: Context)(IteratorRecord, Map): extern macro IteratorBuiltinsAssembler::IteratorStep(
Object implicit context: Context)(IteratorRecord, Map): Object
labels Done; labels Done;
extern macro IteratorValue(implicit context: Context)(Object): Object; extern macro IteratorBuiltinsAssembler::IteratorValue(
extern macro IteratorValue(implicit context: Context)(Object, Map): Object; implicit context: Context)(Object): Object;
extern macro IteratorBuiltinsAssembler::IteratorValue(
implicit context: Context)(Object, Map): Object;
extern macro IteratorCloseOnException(implicit context: Context)( extern macro IteratorBuiltinsAssembler::IteratorCloseOnException(
IteratorRecord); implicit context: Context)(IteratorRecord);
extern macro IterableToList(implicit context: Context)( extern macro IteratorBuiltinsAssembler::IterableToList(
Object, Object): JSArray; implicit context: Context)(Object, Object): JSArray;
extern builtin IterableToListMayPreserveHoles(implicit context: Context)( extern builtin IterableToListMayPreserveHoles(implicit context: Context)(
Object, Object); Object, Object);
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
module typed_array { module typed_array {
extern runtime TypedArraySortFast(Context, Object): JSTypedArray; extern runtime TypedArraySortFast(Context, Object): JSTypedArray;
extern macro ValidateTypedArray( extern macro TypedArrayBuiltinsAssembler::ValidateTypedArray(
Context, Object, constexpr string): JSTypedArray; Context, Object, constexpr string): JSTypedArray;
extern macro LoadFixedTypedArrayElementAsTagged( extern macro LoadFixedTypedArrayElementAsTagged(
......
...@@ -3110,7 +3110,6 @@ class V8_EXPORT_PRIVATE CodeStubAssembler : public compiler::CodeAssembler { ...@@ -3110,7 +3110,6 @@ class V8_EXPORT_PRIVATE CodeStubAssembler : public compiler::CodeAssembler {
void SetPropertyLength(TNode<Context> context, TNode<Object> array, void SetPropertyLength(TNode<Context> context, TNode<Object> array,
TNode<Number> length); TNode<Number> length);
protected:
// Implements DescriptorArray::Search(). // Implements DescriptorArray::Search().
void DescriptorLookup(SloppyTNode<Name> unique_name, void DescriptorLookup(SloppyTNode<Name> unique_name,
SloppyTNode<DescriptorArray> descriptors, SloppyTNode<DescriptorArray> descriptors,
......
...@@ -644,13 +644,16 @@ struct MacroDeclaration : CallableNode { ...@@ -644,13 +644,16 @@ struct MacroDeclaration : CallableNode {
struct ExternalMacroDeclaration : MacroDeclaration { struct ExternalMacroDeclaration : MacroDeclaration {
DEFINE_AST_NODE_LEAF_BOILERPLATE(ExternalMacroDeclaration) DEFINE_AST_NODE_LEAF_BOILERPLATE(ExternalMacroDeclaration)
ExternalMacroDeclaration(SourcePosition pos, bool transitioning, ExternalMacroDeclaration(SourcePosition pos, bool transitioning,
std::string external_assembler_name,
std::string name, base::Optional<std::string> op, std::string name, base::Optional<std::string> op,
ParameterList parameters, ParameterList parameters,
TypeExpression* return_type, TypeExpression* return_type,
const LabelAndTypesVector& labels) const LabelAndTypesVector& labels)
: MacroDeclaration(kKind, pos, transitioning, std::move(name), : MacroDeclaration(kKind, pos, transitioning, std::move(name),
std::move(op), std::move(parameters), return_type, std::move(op), std::move(parameters), return_type,
labels) {} labels),
external_assembler_name(std::move(external_assembler_name)) {}
std::string external_assembler_name;
}; };
struct TorqueMacroDeclaration : MacroDeclaration { struct TorqueMacroDeclaration : MacroDeclaration {
......
...@@ -118,7 +118,8 @@ void CSAGenerator::EmitInstruction(const ModuleConstantInstruction& instruction, ...@@ -118,7 +118,8 @@ void CSAGenerator::EmitInstruction(const ModuleConstantInstruction& instruction,
} else if (results.size() == 1) { } else if (results.size() == 1) {
out_ << results[0] << " = "; out_ << results[0] << " = ";
} }
out_ << instruction.constant->constant_name() << "()"; out_ << instruction.constant->ExternalAssemblerName() << "(state())."
<< instruction.constant->constant_name() << "()";
if (type->IsStructType()) { if (type->IsStructType()) {
out_ << ".Flatten();\n"; out_ << ".Flatten();\n";
} else { } else {
...@@ -173,7 +174,8 @@ void CSAGenerator::EmitInstruction(const CallCsaMacroInstruction& instruction, ...@@ -173,7 +174,8 @@ void CSAGenerator::EmitInstruction(const CallCsaMacroInstruction& instruction,
<< return_type->GetGeneratedTNodeTypeName() << ">("; << return_type->GetGeneratedTNodeTypeName() << ">(";
} }
} }
out_ << instruction.macro->name() << "("; out_ << instruction.macro->external_assembler_name() << "(state())."
<< instruction.macro->ExternalName() << "(";
PrintCommaSeparatedList(out_, args); PrintCommaSeparatedList(out_, args);
if (return_type->IsStructType()) { if (return_type->IsStructType()) {
out_ << ").Flatten();\n"; out_ << ").Flatten();\n";
...@@ -251,7 +253,8 @@ void CSAGenerator::EmitInstruction( ...@@ -251,7 +253,8 @@ void CSAGenerator::EmitInstruction(
PrintCommaSeparatedList(out_, results); PrintCommaSeparatedList(out_, results);
out_ << ") = "; out_ << ") = ";
} }
out_ << instruction.macro->name() << "("; out_ << instruction.macro->external_assembler_name() << "(state())."
<< 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) {
...@@ -303,8 +306,8 @@ void CSAGenerator::EmitInstruction(const CallBuiltinInstruction& instruction, ...@@ -303,8 +306,8 @@ void CSAGenerator::EmitInstruction(const CallBuiltinInstruction& instruction,
std::vector<const Type*> result_types = std::vector<const Type*> result_types =
LowerType(instruction.builtin->signature().return_type); LowerType(instruction.builtin->signature().return_type);
if (instruction.is_tailcall) { if (instruction.is_tailcall) {
out_ << " TailCallBuiltin(Builtins::k" << instruction.builtin->name() out_ << " TailCallBuiltin(Builtins::k"
<< ", "; << instruction.builtin->ExternalName() << ", ";
PrintCommaSeparatedList(out_, arguments); PrintCommaSeparatedList(out_, arguments);
out_ << ");\n"; out_ << ");\n";
} else { } else {
...@@ -321,7 +324,8 @@ void CSAGenerator::EmitInstruction(const CallBuiltinInstruction& instruction, ...@@ -321,7 +324,8 @@ void CSAGenerator::EmitInstruction(const CallBuiltinInstruction& instruction,
stack->Push(result_name); stack->Push(result_name);
out_ << " " << result_name << " = "; out_ << " " << result_name << " = ";
if (generated_type != "Object") out_ << "CAST("; if (generated_type != "Object") out_ << "CAST(";
out_ << "CallBuiltin(Builtins::k" << instruction.builtin->name() << ", "; out_ << "CallBuiltin(Builtins::k" << instruction.builtin->ExternalName()
<< ", ";
PrintCommaSeparatedList(out_, arguments); PrintCommaSeparatedList(out_, arguments);
if (generated_type != "Object") out_ << ")"; if (generated_type != "Object") out_ << ")";
out_ << ");\n"; out_ << ");\n";
...@@ -330,8 +334,8 @@ void CSAGenerator::EmitInstruction(const CallBuiltinInstruction& instruction, ...@@ -330,8 +334,8 @@ void CSAGenerator::EmitInstruction(const CallBuiltinInstruction& instruction,
DCHECK_EQ(0, result_types.size()); DCHECK_EQ(0, result_types.size());
// TODO(tebbi): Actually, builtins have to return a value, so we should // TODO(tebbi): Actually, builtins have to return a value, so we should
// not have to handle this case. // not have to handle this case.
out_ << " CallBuiltin(Builtins::k" << instruction.builtin->name() out_ << " CallBuiltin(Builtins::k"
<< ", "; << instruction.builtin->ExternalName() << ", ";
PrintCommaSeparatedList(out_, arguments); PrintCommaSeparatedList(out_, arguments);
out_ << ");\n"; out_ << ");\n";
} }
...@@ -426,7 +430,7 @@ void CSAGenerator::EmitInstruction(const CallRuntimeInstruction& instruction, ...@@ -426,7 +430,7 @@ void CSAGenerator::EmitInstruction(const CallRuntimeInstruction& instruction,
} }
if (instruction.is_tailcall) { if (instruction.is_tailcall) {
out_ << " TailCallRuntime(Runtime::k" out_ << " TailCallRuntime(Runtime::k"
<< instruction.runtime_function->name() << ", "; << instruction.runtime_function->ExternalName() << ", ";
PrintCommaSeparatedList(out_, arguments); PrintCommaSeparatedList(out_, arguments);
out_ << ");\n"; out_ << ");\n";
} else { } else {
...@@ -441,14 +445,14 @@ void CSAGenerator::EmitInstruction(const CallRuntimeInstruction& instruction, ...@@ -441,14 +445,14 @@ void CSAGenerator::EmitInstruction(const CallRuntimeInstruction& instruction,
if (result_types.size() == 1) { if (result_types.size() == 1) {
stack->Push(result_name); stack->Push(result_name);
out_ << " " << result_name << " = CAST(CallRuntime(Runtime::k" out_ << " " << result_name << " = CAST(CallRuntime(Runtime::k"
<< instruction.runtime_function->name() << ", "; << instruction.runtime_function->ExternalName() << ", ";
PrintCommaSeparatedList(out_, arguments); PrintCommaSeparatedList(out_, arguments);
out_ << "));\n"; out_ << "));\n";
out_ << " USE(" << result_name << ");\n"; out_ << " USE(" << result_name << ");\n";
} else { } else {
DCHECK_EQ(0, result_types.size()); DCHECK_EQ(0, result_types.size());
out_ << " CallRuntime(Runtime::k" out_ << " CallRuntime(Runtime::k"
<< instruction.runtime_function->name() << ", "; << instruction.runtime_function->ExternalName() << ", ";
PrintCommaSeparatedList(out_, arguments); PrintCommaSeparatedList(out_, arguments);
out_ << ");\n"; out_ << ");\n";
if (return_type == TypeOracle::GetNeverType()) { if (return_type == TypeOracle::GetNeverType()) {
...@@ -561,7 +565,7 @@ void CSAGenerator::EmitCSAValue(VisitResult result, ...@@ -561,7 +565,7 @@ void CSAGenerator::EmitCSAValue(VisitResult result,
if (!result.IsOnStack()) { if (!result.IsOnStack()) {
out << result.constexpr_value(); out << result.constexpr_value();
} else if (auto* struct_type = StructType::DynamicCast(result.type())) { } else if (auto* struct_type = StructType::DynamicCast(result.type())) {
out << struct_type->name() << "{"; out << struct_type->GetGeneratedTypeName() << "{";
bool first = true; bool first = true;
for (auto& field : struct_type->fields()) { for (auto& field : struct_type->fields()) {
if (!first) { if (!first) {
......
...@@ -14,7 +14,7 @@ namespace torque { ...@@ -14,7 +14,7 @@ namespace torque {
DEFINE_CONTEXTUAL_VARIABLE(CurrentScope); DEFINE_CONTEXTUAL_VARIABLE(CurrentScope);
std::ostream& operator<<(std::ostream& os, const Callable& m) { std::ostream& operator<<(std::ostream& os, const Callable& m) {
os << "callable " << m.name() << "("; os << "callable " << m.ReadableName() << "(";
if (m.signature().implicit_count != 0) { if (m.signature().implicit_count != 0) {
os << "implicit "; os << "implicit ";
TypeVector implicit_parameter_types( TypeVector implicit_parameter_types(
...@@ -35,14 +35,14 @@ std::ostream& operator<<(std::ostream& os, const Callable& m) { ...@@ -35,14 +35,14 @@ std::ostream& operator<<(std::ostream& os, const Callable& m) {
} }
std::ostream& operator<<(std::ostream& os, const Builtin& b) { std::ostream& operator<<(std::ostream& os, const Builtin& b) {
os << "builtin " << *b.signature().return_type << " " << b.name() os << "builtin " << *b.signature().return_type << " " << b.ReadableName()
<< b.signature().parameter_types; << b.signature().parameter_types;
return os; return os;
} }
std::ostream& operator<<(std::ostream& os, const RuntimeFunction& b) { std::ostream& operator<<(std::ostream& os, const RuntimeFunction& b) {
os << "runtime function " << *b.signature().return_type << " " << b.name() os << "runtime function " << *b.signature().return_type << " "
<< b.signature().parameter_types; << b.ReadableName() << b.signature().parameter_types;
return os; return os;
} }
......
...@@ -117,6 +117,9 @@ class Module : public Scope { ...@@ -117,6 +117,9 @@ class Module : public Scope {
explicit Module(const std::string& name) explicit Module(const std::string& name)
: Scope(Declarable::kModule), name_(name) {} : Scope(Declarable::kModule), name_(name) {}
const std::string& name() const { return name_; } const std::string& name() const { return name_; }
std::string ExternalName() const {
return CamelifyString(name()) + "BuiltinsFromDSLAssembler";
}
std::ostream& source_stream() { return source_stream_; } std::ostream& source_stream() { return source_stream_; }
std::ostream& header_stream() { return header_stream_; } std::ostream& header_stream() { return header_stream_; }
std::string source() { return source_stream_.str(); } std::string source() { return source_stream_.str(); }
...@@ -167,6 +170,9 @@ class ModuleConstant : public Value { ...@@ -167,6 +170,9 @@ class ModuleConstant : public Value {
const std::string& constant_name() const { return constant_name_; } const std::string& constant_name() const { return constant_name_; }
Expression* body() { return body_; } Expression* body() { return body_; }
std::string ExternalAssemblerName() const {
return Module::cast(ParentScope())->ExternalName();
}
private: private:
friend class Declarations; friend class Declarations;
...@@ -195,7 +201,8 @@ class ExternConstant : public Value { ...@@ -195,7 +201,8 @@ class ExternConstant : public Value {
class Callable : public Scope { class Callable : public Scope {
public: public:
DECLARE_DECLARABLE_BOILERPLATE(Callable, callable); DECLARE_DECLARABLE_BOILERPLATE(Callable, callable);
const std::string& name() const { return name_; } const std::string& ExternalName() const { return external_name_; }
const std::string& ReadableName() const { return readable_name_; }
const Signature& signature() const { return signature_; } const Signature& signature() const { return signature_; }
const NameVector& parameter_names() const { const NameVector& parameter_names() const {
return signature_.parameter_names; return signature_.parameter_names;
...@@ -210,12 +217,14 @@ class Callable : public Scope { ...@@ -210,12 +217,14 @@ class Callable : public Scope {
bool IsExternal() const { return !body_.has_value(); } bool IsExternal() const { return !body_.has_value(); }
protected: protected:
Callable(Declarable::Kind kind, const std::string& name, Callable(Declarable::Kind kind, std::string external_name,
const Signature& signature, bool transitioning, std::string readable_name, Signature signature, bool transitioning,
base::Optional<Statement*> body) base::Optional<Statement*> body)
: Scope(kind), : Scope(kind),
name_(name), external_name_(std::move(external_name)),
signature_(signature),
readable_name_(std::move(readable_name)),
signature_(std::move(signature)),
transitioning_(transitioning), transitioning_(transitioning),
returns_(0), returns_(0),
body_(body) { body_(body) {
...@@ -223,7 +232,8 @@ class Callable : public Scope { ...@@ -223,7 +232,8 @@ class Callable : public Scope {
} }
private: private:
std::string name_; std::string external_name_;
std::string readable_name_;
Signature signature_; Signature signature_;
bool transitioning_; bool transitioning_;
size_t returns_; size_t returns_;
...@@ -234,15 +244,24 @@ class Macro : public Callable { ...@@ -234,15 +244,24 @@ class Macro : public Callable {
public: public:
DECLARE_DECLARABLE_BOILERPLATE(Macro, macro); DECLARE_DECLARABLE_BOILERPLATE(Macro, macro);
const std::string& external_assembler_name() const {
return external_assembler_name_;
}
private: private:
friend class Declarations; friend class Declarations;
Macro(const std::string& name, const Signature& signature, bool transitioning, Macro(std::string external_name, std::string readable_name,
base::Optional<Statement*> body) std::string external_assembler_name, const Signature& signature,
: Callable(Declarable::kMacro, name, signature, transitioning, body) { bool transitioning, base::Optional<Statement*> body)
: Callable(Declarable::kMacro, std::move(external_name),
std::move(readable_name), signature, transitioning, body),
external_assembler_name_(std::move(external_assembler_name)) {
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.");
} }
} }
std::string external_assembler_name_;
}; };
class Builtin : public Callable { class Builtin : public Callable {
...@@ -256,10 +275,11 @@ class Builtin : public Callable { ...@@ -256,10 +275,11 @@ class Builtin : public Callable {
private: private:
friend class Declarations; friend class Declarations;
Builtin(const std::string& name, Builtin::Kind kind, Builtin(std::string external_name, std::string readable_name,
const Signature& signature, bool transitioning, Builtin::Kind kind, const Signature& signature, bool transitioning,
base::Optional<Statement*> body) base::Optional<Statement*> body)
: Callable(Declarable::kBuiltin, name, signature, transitioning, body), : Callable(Declarable::kBuiltin, std::move(external_name),
std::move(readable_name), signature, transitioning, body),
kind_(kind) {} kind_(kind) {}
Kind kind_; Kind kind_;
...@@ -273,8 +293,8 @@ class RuntimeFunction : public Callable { ...@@ -273,8 +293,8 @@ class RuntimeFunction : public Callable {
friend class Declarations; friend class Declarations;
RuntimeFunction(const std::string& name, const Signature& signature, RuntimeFunction(const std::string& name, const Signature& signature,
bool transitioning) bool transitioning)
: Callable(Declarable::kRuntimeFunction, name, signature, transitioning, : Callable(Declarable::kRuntimeFunction, name, name, signature,
base::nullopt) {} transitioning, base::nullopt) {}
}; };
class Generic : public Declarable { class Generic : public Declarable {
......
...@@ -35,8 +35,9 @@ void DeclarationVisitor::Visit(CallableNode* decl, const Signature& signature, ...@@ -35,8 +35,9 @@ void DeclarationVisitor::Visit(CallableNode* decl, const Signature& signature,
} }
Builtin* DeclarationVisitor::CreateBuiltin(BuiltinDeclaration* decl, Builtin* DeclarationVisitor::CreateBuiltin(BuiltinDeclaration* decl,
const std::string& external_name, std::string external_name,
const Signature& signature, std::string readable_name,
Signature signature,
base::Optional<Statement*> body) { base::Optional<Statement*> body) {
const bool javascript = decl->javascript_linkage; const bool javascript = decl->javascript_linkage;
const bool varargs = decl->signature->parameters.has_varargs; const bool varargs = decl->signature->parameters.has_varargs;
...@@ -80,8 +81,9 @@ Builtin* DeclarationVisitor::CreateBuiltin(BuiltinDeclaration* decl, ...@@ -80,8 +81,9 @@ Builtin* DeclarationVisitor::CreateBuiltin(BuiltinDeclaration* decl,
ReportError(stream.str()); ReportError(stream.str());
} }
return Declarations::CreateBuiltin(external_name, kind, signature, return Declarations::CreateBuiltin(
decl->transitioning, body); std::move(external_name), std::move(readable_name), kind,
std::move(signature), decl->transitioning, body);
} }
void DeclarationVisitor::Visit(ExternalRuntimeDeclaration* decl, void DeclarationVisitor::Visit(ExternalRuntimeDeclaration* decl,
...@@ -122,22 +124,22 @@ void DeclarationVisitor::Visit(ExternalMacroDeclaration* decl, ...@@ -122,22 +124,22 @@ void DeclarationVisitor::Visit(ExternalMacroDeclaration* decl,
<< " with signature "; << " with signature ";
} }
Declarations::DeclareMacro(decl->name, signature, decl->transitioning, body, Declarations::DeclareMacro(decl->name, decl->external_assembler_name,
decl->op); signature, decl->transitioning, body, decl->op);
} }
void DeclarationVisitor::Visit(TorqueBuiltinDeclaration* decl, void DeclarationVisitor::Visit(TorqueBuiltinDeclaration* decl,
const Signature& signature, const Signature& signature,
base::Optional<Statement*> body) { base::Optional<Statement*> body) {
Declarations::Declare(decl->name, Declarations::Declare(
CreateBuiltin(decl, decl->name, signature, body)); decl->name, CreateBuiltin(decl, decl->name, decl->name, signature, body));
} }
void DeclarationVisitor::Visit(TorqueMacroDeclaration* decl, void DeclarationVisitor::Visit(TorqueMacroDeclaration* decl,
const Signature& signature, const Signature& signature,
base::Optional<Statement*> body) { base::Optional<Statement*> body) {
Declarations::DeclareMacro(decl->name, signature, decl->transitioning, body, Declarations::DeclareMacro(decl->name, base::nullopt, signature,
decl->op); decl->transitioning, body, decl->op);
} }
void DeclarationVisitor::Visit(ConstDeclaration* decl) { void DeclarationVisitor::Visit(ConstDeclaration* decl) {
...@@ -320,13 +322,24 @@ Callable* DeclarationVisitor::Specialize( ...@@ -320,13 +322,24 @@ Callable* DeclarationVisitor::Specialize(
std::string generated_name = Declarations::GetGeneratedCallableName( std::string generated_name = Declarations::GetGeneratedCallableName(
declaration->name, key.specialized_types); declaration->name, key.specialized_types);
std::stringstream readable_name;
readable_name << declaration->name << "<";
bool first = true;
for (const Type* t : key.specialized_types) {
if (!first) readable_name << ", ";
readable_name << *t;
first = false;
}
readable_name << ">";
Callable* callable; Callable* callable;
if (MacroDeclaration::DynamicCast(declaration) != nullptr) { if (MacroDeclaration::DynamicCast(declaration) != nullptr) {
callable = Declarations::CreateMacro(generated_name, type_signature, callable = Declarations::CreateMacro(generated_name, readable_name.str(),
base::nullopt, type_signature,
declaration->transitioning, body); declaration->transitioning, body);
} else { } else {
BuiltinDeclaration* builtin = BuiltinDeclaration::cast(declaration); BuiltinDeclaration* builtin = BuiltinDeclaration::cast(declaration);
callable = CreateBuiltin(builtin, generated_name, type_signature, body); callable = CreateBuiltin(builtin, generated_name, readable_name.str(),
type_signature, body);
} }
key.generic->AddSpecialization(key.specialized_types, callable); key.generic->AddSpecialization(key.specialized_types, callable);
return callable; return callable;
......
...@@ -51,14 +51,14 @@ class DeclarationVisitor : public FileVisitor { ...@@ -51,14 +51,14 @@ class DeclarationVisitor : public FileVisitor {
Declarations::DeclareType(decl->name, type, true); Declarations::DeclareType(decl->name, type, true);
} }
Builtin* CreateBuiltin(BuiltinDeclaration* decl, Builtin* CreateBuiltin(BuiltinDeclaration* decl, std::string external_name,
const std::string& external_name, std::string readable_name, Signature signature,
const Signature& signature,
base::Optional<Statement*> body); base::Optional<Statement*> body);
void Visit(ExternalBuiltinDeclaration* decl, const Signature& signature, void Visit(ExternalBuiltinDeclaration* decl, const Signature& signature,
base::Optional<Statement*> body) { base::Optional<Statement*> body) {
Declarations::Declare( Declarations::Declare(
decl->name, CreateBuiltin(decl, decl->name, signature, base::nullopt)); decl->name,
CreateBuiltin(decl, decl->name, decl->name, signature, base::nullopt));
} }
void Visit(ExternalRuntimeDeclaration* decl, const Signature& sig, void Visit(ExternalRuntimeDeclaration* decl, const Signature& sig,
......
...@@ -169,23 +169,30 @@ void Declarations::DeclareStruct(const std::string& name, ...@@ -169,23 +169,30 @@ void Declarations::DeclareStruct(const std::string& name,
DeclareType(name, new_type, false); DeclareType(name, new_type, false);
} }
Macro* Declarations::CreateMacro(const std::string& name, Macro* Declarations::CreateMacro(
const Signature& signature, bool transitioning, std::string external_name, std::string readable_name,
base::Optional<Statement*> body) { base::Optional<std::string> external_assembler_name, Signature signature,
return RegisterDeclarable( bool transitioning, base::Optional<Statement*> body) {
std::unique_ptr<Macro>(new Macro(name, signature, transitioning, body))); if (!external_assembler_name) {
external_assembler_name = CurrentModule()->ExternalName();
}
return RegisterDeclarable(std::unique_ptr<Macro>(
new Macro(std::move(external_name), std::move(readable_name),
std::move(*external_assembler_name), std::move(signature),
transitioning, body)));
} }
Macro* Declarations::DeclareMacro(const std::string& name, Macro* Declarations::DeclareMacro(
const Signature& signature, const std::string& name,
bool transitioning, base::Optional<std::string> external_assembler_name,
base::Optional<Statement*> body, const Signature& signature, bool transitioning,
base::Optional<std::string> op) { base::Optional<Statement*> body, base::Optional<std::string> op) {
if (TryLookupMacro(name, signature.GetExplicitTypes())) { if (TryLookupMacro(name, signature.GetExplicitTypes())) {
ReportError("cannot redeclare macro ", name, ReportError("cannot redeclare macro ", name,
" with identical explicit parameters"); " with identical explicit parameters");
} }
Macro* macro = CreateMacro(name, signature, transitioning, body); Macro* macro = CreateMacro(name, name, std::move(external_assembler_name),
signature, transitioning, body);
Declare(name, macro); Declare(name, macro);
if (op) { if (op) {
if (TryLookupMacro(*op, signature.GetExplicitTypes())) { if (TryLookupMacro(*op, signature.GetExplicitTypes())) {
...@@ -197,13 +204,14 @@ Macro* Declarations::DeclareMacro(const std::string& name, ...@@ -197,13 +204,14 @@ Macro* Declarations::DeclareMacro(const std::string& name,
return macro; return macro;
} }
Builtin* Declarations::CreateBuiltin(const std::string& name, Builtin* Declarations::CreateBuiltin(std::string external_name,
Builtin::Kind kind, std::string readable_name,
const Signature& signature, Builtin::Kind kind, Signature signature,
bool transitioning, bool transitioning,
base::Optional<Statement*> body) { base::Optional<Statement*> body) {
return RegisterDeclarable(std::unique_ptr<Builtin>( return RegisterDeclarable(std::unique_ptr<Builtin>(
new Builtin(name, kind, signature, transitioning, body))); new Builtin(std::move(external_name), std::move(readable_name), kind,
std::move(signature), transitioning, body)));
} }
Builtin* Declarations::DeclareBuiltin(const std::string& name, Builtin* Declarations::DeclareBuiltin(const std::string& name,
...@@ -212,8 +220,8 @@ Builtin* Declarations::DeclareBuiltin(const std::string& name, ...@@ -212,8 +220,8 @@ Builtin* Declarations::DeclareBuiltin(const std::string& name,
bool transitioning, bool transitioning,
base::Optional<Statement*> body) { base::Optional<Statement*> body) {
CheckAlreadyDeclared<Builtin>(name, "builtin"); CheckAlreadyDeclared<Builtin>(name, "builtin");
return Declare(name, return Declare(
CreateBuiltin(name, kind, signature, transitioning, body)); name, CreateBuiltin(name, name, kind, signature, transitioning, body));
} }
RuntimeFunction* Declarations::DeclareRuntimeFunction( RuntimeFunction* Declarations::DeclareRuntimeFunction(
......
...@@ -85,16 +85,20 @@ class Declarations { ...@@ -85,16 +85,20 @@ class Declarations {
static void DeclareStruct(const std::string& name, static void DeclareStruct(const std::string& name,
const std::vector<NameAndType>& fields); const std::vector<NameAndType>& fields);
static Macro* CreateMacro(const std::string& name, const Signature& signature, static Macro* CreateMacro(std::string external_name,
bool transitioning, std::string readable_name,
base::Optional<std::string> external_assembler_name,
Signature signature, bool transitioning,
base::Optional<Statement*> body); base::Optional<Statement*> body);
static Macro* DeclareMacro(const std::string& name, static Macro* DeclareMacro(
const Signature& signature, bool transitioning, const std::string& name,
base::Optional<Statement*> body, base::Optional<std::string> external_assembler_name,
base::Optional<std::string> op = {}); const Signature& signature, bool transitioning,
base::Optional<Statement*> body, base::Optional<std::string> op = {});
static Builtin* CreateBuiltin(const std::string& name, Builtin::Kind kind,
const Signature& signature, bool transitioning, static Builtin* CreateBuiltin(std::string external_name,
std::string readable_name, Builtin::Kind kind,
Signature signature, bool transitioning,
base::Optional<Statement*> body); base::Optional<Statement*> body);
static Builtin* DeclareBuiltin(const std::string& name, Builtin::Kind kind, static Builtin* DeclareBuiltin(const std::string& name, Builtin::Kind kind,
const Signature& signature, bool transitioning, const Signature& signature, bool transitioning,
......
...@@ -49,13 +49,6 @@ void ImplementationVisitor::BeginModuleFile(Module* module) { ...@@ -49,13 +49,6 @@ void ImplementationVisitor::BeginModuleFile(Module* module) {
std::ostream& source = module->source_stream(); std::ostream& source = module->source_stream();
std::ostream& header = module->header_stream(); std::ostream& header = module->header_stream();
if (module == GlobalContext::GetDefaultModule()) {
source << "#include \"src/torque-assembler.h\"";
} else {
source << "#include \"src/builtins/builtins-" +
DashifyString(module->name()) + "-gen.h\"";
}
source << "\n";
source << "#include \"src/objects/arguments.h\"\n"; source << "#include \"src/objects/arguments.h\"\n";
source << "#include \"src/builtins/builtins-utils-gen.h\"\n"; source << "#include \"src/builtins/builtins-utils-gen.h\"\n";
source << "#include \"src/builtins/builtins.h\"\n"; source << "#include \"src/builtins/builtins.h\"\n";
...@@ -65,8 +58,15 @@ void ImplementationVisitor::BeginModuleFile(Module* module) { ...@@ -65,8 +58,15 @@ void ImplementationVisitor::BeginModuleFile(Module* module) {
source << "#include \"src/objects.h\"\n"; source << "#include \"src/objects.h\"\n";
source << "#include \"src/objects/bigint.h\"\n"; source << "#include \"src/objects/bigint.h\"\n";
source << "#include \"builtins-" + DashifyString(module->name()) + for (Module* m : GlobalContext::Get().GetModules()) {
"-from-dsl-gen.h\"\n\n"; source << "#include \"torque-generated/builtins-" +
DashifyString(m->name()) + "-from-dsl-gen.h\"\n";
if (m != GlobalContext::GetDefaultModule()) {
source << "#include \"src/builtins/builtins-" + DashifyString(m->name()) +
"-gen.h\"\n";
}
}
source << "\n";
source source
<< "namespace v8 {\n" << "namespace v8 {\n"
...@@ -84,24 +84,19 @@ void ImplementationVisitor::BeginModuleFile(Module* module) { ...@@ -84,24 +84,19 @@ void ImplementationVisitor::BeginModuleFile(Module* module) {
std::string("V8_TORQUE_") + upper_name + "_FROM_DSL_BASE_H__"; std::string("V8_TORQUE_") + upper_name + "_FROM_DSL_BASE_H__";
header << "#ifndef " << headerDefine << "\n"; header << "#ifndef " << headerDefine << "\n";
header << "#define " << headerDefine << "\n\n"; header << "#define " << headerDefine << "\n\n";
if (module == GlobalContext::GetDefaultModule()) {
header << "#include \"src/torque-assembler.h\""; header << "#include \"src/torque-assembler.h\"";
} else {
header << "#include \"src/builtins/builtins-" +
DashifyString(module->name()) + "-gen.h\"\n";
}
header << "\n\n "; header << "\n\n ";
header << "namespace v8 {\n" header << "namespace v8 {\n"
<< "namespace internal {\n" << "namespace internal {\n"
<< "\n"; << "\n";
header << "class " << GetDSLAssemblerName(module) << ": public " header << "class " << module->ExternalName()
<< GetBaseAssemblerName(module) << " {\n"; << ": public TorqueAssembler {\n";
header << " public:\n"; header << " public:\n";
header << " explicit " << GetDSLAssemblerName(module) header
<< "(compiler::CodeAssemblerState* state) : " << " explicit " << module->ExternalName()
<< GetBaseAssemblerName(module) << "(state) {}\n"; << "(compiler::CodeAssemblerState* state) : TorqueAssembler(state) {}\n";
header << "\n"; header << "\n";
header << " using Node = compiler::Node;\n"; header << " using Node = compiler::Node;\n";
...@@ -143,7 +138,7 @@ void ImplementationVisitor::Visit(ModuleConstant* decl) { ...@@ -143,7 +138,7 @@ void ImplementationVisitor::Visit(ModuleConstant* decl) {
header_out() << ";\n"; header_out() << ";\n";
GenerateFunctionDeclaration(source_out(), GenerateFunctionDeclaration(source_out(),
GetDSLAssemblerName(CurrentModule()) + "::", name, CurrentModule()->ExternalName() + "::", name,
signature, {}); signature, {});
source_out() << " {\n"; source_out() << " {\n";
...@@ -220,7 +215,7 @@ void ImplementationVisitor::Visit(Macro* macro) { ...@@ -220,7 +215,7 @@ void ImplementationVisitor::Visit(Macro* macro) {
header_out() << ";\n"; header_out() << ";\n";
GenerateMacroFunctionDeclaration( GenerateMacroFunctionDeclaration(
source_out(), GetDSLAssemblerName(CurrentModule()) + "::", macro); source_out(), CurrentModule()->ExternalName() + "::", macro);
source_out() << " {\n"; source_out() << " {\n";
Stack<std::string> lowered_parameters; Stack<std::string> lowered_parameters;
...@@ -270,20 +265,20 @@ void ImplementationVisitor::Visit(Macro* macro) { ...@@ -270,20 +265,20 @@ void ImplementationVisitor::Visit(Macro* macro) {
if (result->IsNever()) { if (result->IsNever()) {
if (!macro->signature().return_type->IsNever() && !macro->HasReturns()) { if (!macro->signature().return_type->IsNever() && !macro->HasReturns()) {
std::stringstream s; std::stringstream s;
s << "macro " << macro->name() s << "macro " << macro->ReadableName()
<< " that never returns must have return type never"; << " that never returns must have return type never";
ReportError(s.str()); ReportError(s.str());
} }
} else { } else {
if (macro->signature().return_type->IsNever()) { if (macro->signature().return_type->IsNever()) {
std::stringstream s; std::stringstream s;
s << "macro " << macro->name() s << "macro " << macro->ReadableName()
<< " has implicit return at end of its declartion but return type " << " has implicit return at end of its declartion but return type "
"never"; "never";
ReportError(s.str()); ReportError(s.str());
} else if (!macro->signature().return_type->IsVoid()) { } else if (!macro->signature().return_type->IsVoid()) {
std::stringstream s; std::stringstream s;
s << "macro " << macro->name() s << "macro " << macro->ReadableName()
<< " expects to return a value but doesn't on all paths"; << " expects to return a value but doesn't on all paths";
ReportError(s.str()); ReportError(s.str());
} }
...@@ -341,10 +336,10 @@ std::string AddParameter(size_t i, Builtin* builtin, ...@@ -341,10 +336,10 @@ std::string AddParameter(size_t i, Builtin* builtin,
void ImplementationVisitor::Visit(Builtin* builtin) { void ImplementationVisitor::Visit(Builtin* builtin) {
if (builtin->IsExternal()) return; if (builtin->IsExternal()) return;
CurrentScope::Scope current_scope(builtin); CurrentScope::Scope current_scope(builtin);
const std::string& name = builtin->name(); const std::string& name = builtin->ExternalName();
const Signature& signature = builtin->signature(); const Signature& signature = builtin->signature();
source_out() << "TF_BUILTIN(" << name << ", " source_out() << "TF_BUILTIN(" << name << ", "
<< GetDSLAssemblerName(CurrentModule()) << ") {\n"; << CurrentModule()->ExternalName() << ") {\n";
CurrentCallable::Scope current_callable(builtin); CurrentCallable::Scope current_callable(builtin);
Stack<const Type*> parameter_types; Stack<const Type*> parameter_types;
...@@ -672,7 +667,7 @@ VisitResult ImplementationVisitor::GetBuiltinCode(Builtin* builtin) { ...@@ -672,7 +667,7 @@ VisitResult ImplementationVisitor::GetBuiltinCode(Builtin* builtin) {
const Type* type = TypeOracle::GetFunctionPointerType( const Type* type = TypeOracle::GetFunctionPointerType(
builtin->signature().parameter_types.types, builtin->signature().parameter_types.types,
builtin->signature().return_type); builtin->signature().return_type);
assembler().Emit(PushCodePointerInstruction{builtin->name(), type}); assembler().Emit(PushCodePointerInstruction{builtin->ExternalName(), type});
return VisitResult(type, assembler().TopRange(1)); return VisitResult(type, assembler().TopRange(1));
} }
...@@ -1184,25 +1179,9 @@ void ImplementationVisitor::GenerateImplementation(const std::string& dir, ...@@ -1184,25 +1179,9 @@ void ImplementationVisitor::GenerateImplementation(const std::string& dir,
ReplaceFileContentsIfDifferent(header_file_name, new_header); ReplaceFileContentsIfDifferent(header_file_name, new_header);
} }
std::string ImplementationVisitor::GetBaseAssemblerName(Module* module) {
if (module == GlobalContext::GetDefaultModule()) {
return "TorqueAssembler";
} else {
std::string assembler_name(CamelifyString(module->name()) +
"BuiltinsAssembler");
return assembler_name;
}
}
std::string ImplementationVisitor::GetDSLAssemblerName(Module* module) {
std::string assembler_name(CamelifyString(module->name()) +
"BuiltinsFromDSLAssembler");
return assembler_name;
}
void ImplementationVisitor::GenerateMacroFunctionDeclaration( void ImplementationVisitor::GenerateMacroFunctionDeclaration(
std::ostream& o, const std::string& macro_prefix, Macro* macro) { std::ostream& o, const std::string& macro_prefix, Macro* macro) {
GenerateFunctionDeclaration(o, macro_prefix, macro->name(), GenerateFunctionDeclaration(o, macro_prefix, macro->ExternalName(),
macro->signature(), macro->parameter_names()); macro->signature(), macro->parameter_names());
} }
...@@ -1218,7 +1197,7 @@ void ImplementationVisitor::GenerateFunctionDeclaration( ...@@ -1218,7 +1197,7 @@ void ImplementationVisitor::GenerateFunctionDeclaration(
std::string return_type_name(signature.return_type->GetGeneratedTypeName()); std::string return_type_name(signature.return_type->GetGeneratedTypeName());
if (const StructType* struct_type = if (const StructType* struct_type =
StructType::DynamicCast(signature.return_type)) { StructType::DynamicCast(signature.return_type)) {
o << GetDSLAssemblerName(struct_type->module()) << "::"; o << struct_type->module()->ExternalName() << "::";
} else if (macro_prefix != "" && (return_type_name.length() > 5) && } else if (macro_prefix != "" && (return_type_name.length() > 5) &&
(return_type_name.substr(0, 5) == "TNode")) { (return_type_name.substr(0, 5) == "TNode")) {
o << "compiler::"; o << "compiler::";
...@@ -1706,8 +1685,9 @@ VisitResult ImplementationVisitor::GenerateCall( ...@@ -1706,8 +1685,9 @@ VisitResult ImplementationVisitor::GenerateCall(
size_t label_count = callable->signature().labels.size(); size_t label_count = callable->signature().labels.size();
if (label_count != arguments.labels.size()) { if (label_count != arguments.labels.size()) {
std::stringstream s; std::stringstream s;
s << "unexpected number of otherwise labels for " << callable->name() s << "unexpected number of otherwise labels for "
<< " (expected " << std::to_string(label_count) << " found " << callable->ReadableName() << " (expected "
<< std::to_string(label_count) << " found "
<< std::to_string(arguments.labels.size()) << ")"; << std::to_string(arguments.labels.size()) << ")";
ReportError(s.str()); ReportError(s.str());
} }
...@@ -1743,7 +1723,8 @@ VisitResult ImplementationVisitor::GenerateCall( ...@@ -1743,7 +1723,8 @@ 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->name() << "("; result << "(" << macro->external_assembler_name() << "(state())."
<< macro->ExternalName() << "(";
bool first = true; bool first = true;
for (VisitResult arg : arguments.parameters) { for (VisitResult arg : arguments.parameters) {
DCHECK(!arg.IsOnStack()); DCHECK(!arg.IsOnStack());
...@@ -2054,9 +2035,9 @@ void ImplementationVisitor::GenerateBuiltinDefinitions(std::string& file_name) { ...@@ -2054,9 +2035,9 @@ void ImplementationVisitor::GenerateBuiltinDefinitions(std::string& file_name) {
int firstParameterIndex = 1; int firstParameterIndex = 1;
bool declareParameters = true; bool declareParameters = true;
if (builtin->IsStub()) { if (builtin->IsStub()) {
new_contents_stream << "TFS(" << builtin->name(); new_contents_stream << "TFS(" << builtin->ExternalName();
} else { } else {
new_contents_stream << "TFJ(" << builtin->name(); new_contents_stream << "TFJ(" << builtin->ExternalName();
if (builtin->IsVarArgsJavaScript()) { if (builtin->IsVarArgsJavaScript()) {
new_contents_stream new_contents_stream
<< ", SharedFunctionInfo::kDontAdaptArgumentsSentinel"; << ", SharedFunctionInfo::kDontAdaptArgumentsSentinel";
...@@ -2097,7 +2078,7 @@ void ImplementationVisitor::GenerateBuiltinDefinitions(std::string& file_name) { ...@@ -2097,7 +2078,7 @@ void ImplementationVisitor::GenerateBuiltinDefinitions(std::string& file_name) {
ReportError("unable to find any builtin with type \"", *type, "\""); ReportError("unable to find any builtin with type \"", *type, "\"");
} }
new_contents_stream << " V(" << type->function_pointer_type_id() << "," new_contents_stream << " V(" << type->function_pointer_type_id() << ","
<< example_builtin->name() << ")\\\n"; << example_builtin->ExternalName() << ")\\\n";
} }
new_contents_stream << "\n"; new_contents_stream << "\n";
......
...@@ -284,10 +284,6 @@ class ImplementationVisitor : public FileVisitor { ...@@ -284,10 +284,6 @@ class ImplementationVisitor : public FileVisitor {
}; };
private: private:
std::string GetBaseAssemblerName(Module* module);
std::string GetDSLAssemblerName(Module* module);
base::Optional<Block*> GetCatchBlock(); base::Optional<Block*> GetCatchBlock();
void GenerateCatchBlock(base::Optional<Block*> catch_block); void GenerateCatchBlock(base::Optional<Block*> catch_block);
......
...@@ -353,6 +353,8 @@ base::Optional<ParseResult> MakeExternalMacro( ...@@ -353,6 +353,8 @@ base::Optional<ParseResult> MakeExternalMacro(
ParseResultIterator* child_results) { ParseResultIterator* child_results) {
auto transitioning = child_results->NextAs<bool>(); auto transitioning = child_results->NextAs<bool>();
auto operator_name = child_results->NextAs<base::Optional<std::string>>(); auto operator_name = child_results->NextAs<base::Optional<std::string>>();
auto external_assembler_name =
child_results->NextAs<base::Optional<std::string>>();
auto name = child_results->NextAs<std::string>(); auto name = child_results->NextAs<std::string>();
auto generic_parameters = child_results->NextAs<GenericParameters>(); auto generic_parameters = child_results->NextAs<GenericParameters>();
LintGenericParameters(generic_parameters); LintGenericParameters(generic_parameters);
...@@ -361,7 +363,9 @@ base::Optional<ParseResult> MakeExternalMacro( ...@@ -361,7 +363,9 @@ base::Optional<ParseResult> MakeExternalMacro(
auto return_type = child_results->NextAs<TypeExpression*>(); auto return_type = child_results->NextAs<TypeExpression*>();
auto labels = child_results->NextAs<LabelAndTypesVector>(); auto labels = child_results->NextAs<LabelAndTypesVector>();
MacroDeclaration* macro = MakeNode<ExternalMacroDeclaration>( MacroDeclaration* macro = MakeNode<ExternalMacroDeclaration>(
transitioning, name, operator_name, args, return_type, labels); transitioning,
external_assembler_name ? *external_assembler_name : "CodeStubAssembler",
name, operator_name, args, return_type, labels);
Declaration* result; Declaration* result;
if (generic_parameters.empty()) { if (generic_parameters.empty()) {
result = MakeNode<StandardDeclaration>(macro, base::nullopt); result = MakeNode<StandardDeclaration>(macro, base::nullopt);
...@@ -1408,8 +1412,9 @@ struct TorqueGrammar : Grammar { ...@@ -1408,8 +1412,9 @@ struct TorqueGrammar : Grammar {
Rule({Token("extern"), CheckIf(Token("transitioning")), Rule({Token("extern"), CheckIf(Token("transitioning")),
Optional<std::string>( Optional<std::string>(
Sequence({Token("operator"), &externalString})), Sequence({Token("operator"), &externalString})),
Token("macro"), &identifier, Token("macro"),
TryOrDefault<GenericParameters>(&genericParameters), Optional<std::string>(Sequence({&identifier, Token("::")})),
&identifier, TryOrDefault<GenericParameters>(&genericParameters),
&typeListMaybeVarArgs, &optionalReturnType, optionalLabelList, &typeListMaybeVarArgs, &optionalReturnType, optionalLabelList,
Token(";")}, Token(";")},
MakeExternalMacro), MakeExternalMacro),
......
...@@ -193,6 +193,10 @@ std::string StructType::ToExplicitString() const { ...@@ -193,6 +193,10 @@ std::string StructType::ToExplicitString() const {
return result.str(); return result.str();
} }
std::string StructType::GetGeneratedTypeName() const {
return module_->ExternalName() + "::" + GetStructName();
}
void PrintSignature(std::ostream& os, const Signature& sig, bool with_names) { void PrintSignature(std::ostream& os, const Signature& sig, bool with_names) {
os << "("; os << "(";
for (size_t i = 0; i < sig.parameter_types.types.size(); ++i) { for (size_t i = 0; i < sig.parameter_types.types.size(); ++i) {
......
...@@ -358,7 +358,7 @@ class StructType final : public Type { ...@@ -358,7 +358,7 @@ class StructType final : public Type {
DECLARE_TYPE_BOILERPLATE(StructType); DECLARE_TYPE_BOILERPLATE(StructType);
std::string ToExplicitString() const override; std::string ToExplicitString() const override;
std::string MangledName() const override { return name_; } std::string MangledName() const override { return name_; }
std::string GetGeneratedTypeName() const override { return GetStructName(); } std::string GetGeneratedTypeName() const override;
std::string GetGeneratedTNodeTypeName() const override { UNREACHABLE(); } std::string GetGeneratedTNodeTypeName() const override { UNREACHABLE(); }
const Type* NonConstexprVersion() const override { return this; } const Type* NonConstexprVersion() const override { return this; }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment