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