diff --git a/src/builtins/array.tq b/src/builtins/array.tq index 09b11b86e4..8e3b3ea704 100644 --- a/src/builtins/array.tq +++ b/src/builtins/array.tq @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include 'src/builtins/builtins-array-gen.h' + namespace array { // Naming convention from elements.cc. We have a similar intent but implement // fastpaths using generics instead of using a class hierarchy for elements diff --git a/src/builtins/base.tq b/src/builtins/base.tq index eb51368329..6f3786d80c 100644 --- a/src/builtins/base.tq +++ b/src/builtins/base.tq @@ -2,6 +2,15 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include 'src/builtins/builtins-utils-gen.h' +#include 'src/builtins/builtins.h' +#include 'src/code-factory.h' +#include 'src/elements-kind.h' +#include 'src/heap/factory-inl.h' +#include 'src/objects.h' +#include 'src/objects/arguments.h' +#include 'src/objects/bigint.h' + type Arguments constexpr 'CodeStubArguments*'; type void; type never; diff --git a/src/builtins/builtins-collections-gen.cc b/src/builtins/builtins-collections-gen.cc index 9f379eec1d..8057606866 100644 --- a/src/builtins/builtins-collections-gen.cc +++ b/src/builtins/builtins-collections-gen.cc @@ -17,6 +17,9 @@ namespace v8 { namespace internal { +using compiler::Node; +template +using TNode = compiler::TNode; template using TVariable = compiler::TypedCodeAssemblerVariable; diff --git a/src/builtins/builtins-collections-gen.h b/src/builtins/builtins-collections-gen.h index 2249d3e101..a78ad5a4a7 100644 --- a/src/builtins/builtins-collections-gen.h +++ b/src/builtins/builtins-collections-gen.h @@ -10,18 +10,14 @@ namespace v8 { namespace internal { -using compiler::Node; -template -using TNode = compiler::TNode; - void BranchIfIterableWithOriginalKeyOrValueMapIterator( - compiler::CodeAssemblerState* state, TNode iterable, - TNode context, compiler::CodeAssemblerLabel* if_true, + compiler::CodeAssemblerState* state, compiler::TNode iterable, + compiler::TNode context, compiler::CodeAssemblerLabel* if_true, compiler::CodeAssemblerLabel* if_false); void BranchIfIterableWithOriginalValueSetIterator( - compiler::CodeAssemblerState* state, TNode iterable, - TNode context, compiler::CodeAssemblerLabel* if_true, + compiler::CodeAssemblerState* state, compiler::TNode iterable, + compiler::TNode context, compiler::CodeAssemblerLabel* if_true, compiler::CodeAssemblerLabel* if_false); } // namespace internal diff --git a/src/builtins/builtins-test-gen.h b/src/builtins/builtins-test-gen.h deleted file mode 100644 index d5fa33acc4..0000000000 --- a/src/builtins/builtins-test-gen.h +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright 2018 the V8 project authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef V8_BUILTINS_BUILTINS_TEST_GEN_H_ -#define V8_BUILTINS_BUILTINS_TEST_GEN_H_ - -#include "src/code-stub-assembler.h" - -namespace v8 { -namespace internal { - -class TestBuiltinsAssembler : public CodeStubAssembler { - public: - explicit TestBuiltinsAssembler(compiler::CodeAssemblerState* state) - : CodeStubAssembler(state) {} -}; - -} // namespace internal -} // namespace v8 - -#endif // V8_BUILTINS_BUILTINS_TEST_GEN_H_ diff --git a/src/builtins/collections.tq b/src/builtins/collections.tq index 31dcb6fb4a..e4bc3b758b 100644 --- a/src/builtins/collections.tq +++ b/src/builtins/collections.tq @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include 'src/builtins/builtins-collections-gen.h' + namespace collections { macro LoadKeyValuePairNoSideEffects(implicit context: Context)(o: Object): KeyValuePair diff --git a/src/builtins/data-view.tq b/src/builtins/data-view.tq index 9bc0500159..3ad9d7a69c 100644 --- a/src/builtins/data-view.tq +++ b/src/builtins/data-view.tq @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include 'src/builtins/builtins-data-view-gen.h' + namespace data_view { extern operator '.buffer' macro LoadJSArrayBufferViewBuffer(JSArrayBufferView): JSArrayBuffer; diff --git a/src/builtins/iterator.tq b/src/builtins/iterator.tq index 06231cfccd..5c9439dfc7 100644 --- a/src/builtins/iterator.tq +++ b/src/builtins/iterator.tq @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include 'src/builtins/builtins-iterator-gen.h' + namespace iterator { // Returned from IteratorBuiltinsAssembler::GetIterator(). struct IteratorRecord { diff --git a/src/builtins/typed-array.tq b/src/builtins/typed-array.tq index 85a4711500..6bd28cf7e7 100644 --- a/src/builtins/typed-array.tq +++ b/src/builtins/typed-array.tq @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include 'src/builtins/builtins-typed-array-gen.h' + namespace typed_array { extern runtime TypedArraySortFast(Context, Object): JSTypedArray; extern macro TypedArrayBuiltinsAssembler::ValidateTypedArray( diff --git a/src/torque/ast.h b/src/torque/ast.h index 93a6cfa29b..5a6075cf78 100644 --- a/src/torque/ast.h +++ b/src/torque/ast.h @@ -65,7 +65,8 @@ namespace torque { V(ExternConstDeclaration) \ V(StructDeclaration) \ V(NamespaceDeclaration) \ - V(ConstDeclaration) + V(ConstDeclaration) \ + V(CppIncludeDeclaration) #define AST_CALLABLE_NODE_KIND_LIST(V) \ V(TorqueMacroDeclaration) \ @@ -825,6 +826,13 @@ struct StructDeclaration : Declaration { std::vector fields; }; +struct CppIncludeDeclaration : Declaration { + DEFINE_AST_NODE_LEAF_BOILERPLATE(CppIncludeDeclaration) + CppIncludeDeclaration(SourcePosition pos, std::string include_path) + : Declaration(kKind, pos), include_path(std::move(include_path)) {} + std::string include_path; +}; + #define ENUM_ITEM(name) \ case AstNode::Kind::k##name: \ return std::is_base_of::value; \ diff --git a/src/torque/csa-generator.cc b/src/torque/csa-generator.cc index 9434480923..6ac83946f4 100644 --- a/src/torque/csa-generator.cc +++ b/src/torque/csa-generator.cc @@ -680,8 +680,8 @@ void CSAGenerator::EmitCSAValue(VisitResult result, out << "}"; } else { DCHECK_EQ(1, result.stack_range().Size()); - out << "TNode<" << result.type()->GetGeneratedTNodeTypeName() << ">{" - << values.Peek(result.stack_range().begin()) << "}"; + out << "compiler::TNode<" << result.type()->GetGeneratedTNodeTypeName() + << ">{" << values.Peek(result.stack_range().begin()) << "}"; } } diff --git a/src/torque/declarable.h b/src/torque/declarable.h index 8783c46a42..17420e0b09 100644 --- a/src/torque/declarable.h +++ b/src/torque/declarable.h @@ -20,6 +20,7 @@ namespace internal { namespace torque { class Scope; +class Namespace; DECLARE_CONTEXTUAL_VARIABLE(CurrentScope, Scope*); diff --git a/src/torque/declaration-visitor.cc b/src/torque/declaration-visitor.cc index 5e7bcf4581..38bf40b380 100644 --- a/src/torque/declaration-visitor.cc +++ b/src/torque/declaration-visitor.cc @@ -237,6 +237,10 @@ void DeclarationVisitor::Visit(StructDeclaration* decl) { Declarations::DeclareStruct(decl->name, fields); } +void DeclarationVisitor::Visit(CppIncludeDeclaration* decl) { + GlobalContext::AddCppInclude(decl->include_path); +} + void DeclarationVisitor::Visit(TypeDeclaration* decl) { std::string generates = decl->generates ? *decl->generates : std::string(""); if (decl->generates) { diff --git a/src/torque/declaration-visitor.h b/src/torque/declaration-visitor.h index 9961581e53..6f0fe33c4f 100644 --- a/src/torque/declaration-visitor.h +++ b/src/torque/declaration-visitor.h @@ -81,6 +81,7 @@ class DeclarationVisitor : public FileVisitor { void Visit(SpecializationDeclaration* decl); void Visit(ExternConstDeclaration* decl); void Visit(StructDeclaration* decl); + void Visit(CppIncludeDeclaration* decl); Signature MakeSpecializedSignature(const SpecializationKey& key); Callable* SpecializeImplicit(const SpecializationKey& key); diff --git a/src/torque/global-context.h b/src/torque/global-context.h index 31837215be..b4c723e3fc 100644 --- a/src/torque/global-context.h +++ b/src/torque/global-context.h @@ -44,6 +44,13 @@ class GlobalContext : public ContextualClass { return result; } + static void AddCppInclude(std::string include_path) { + Get().cpp_includes_.push_back(std::move(include_path)); + } + static const std::vector& CppIncludes() { + return Get().cpp_includes_; + } + static void SetVerbose() { Get().verbose_ = true; } static bool verbose() { return Get().verbose_; } static Ast* ast() { return &Get().ast_; } @@ -53,6 +60,7 @@ class GlobalContext : public ContextualClass { Namespace* default_namespace_; Ast ast_; std::vector> declarables_; + std::vector cpp_includes_; }; template diff --git a/src/torque/implementation-visitor.cc b/src/torque/implementation-visitor.cc index 74c96557d3..9ff5b584d4 100644 --- a/src/torque/implementation-visitor.cc +++ b/src/torque/implementation-visitor.cc @@ -49,22 +49,13 @@ void ImplementationVisitor::BeginNamespaceFile(Namespace* nspace) { std::ostream& source = nspace->source_stream(); std::ostream& header = nspace->header_stream(); - source << "#include \"src/objects/arguments.h\"\n"; - source << "#include \"src/builtins/builtins-utils-gen.h\"\n"; - source << "#include \"src/builtins/builtins.h\"\n"; - source << "#include \"src/code-factory.h\"\n"; - source << "#include \"src/elements-kind.h\"\n"; - source << "#include \"src/heap/factory-inl.h\"\n"; - source << "#include \"src/objects.h\"\n"; - source << "#include \"src/objects/bigint.h\"\n"; + for (const std::string& include_path : GlobalContext::CppIncludes()) { + source << "#include " << StringLiteralQuote(include_path) << "\n"; + } for (Namespace* n : GlobalContext::Get().GetNamespaces()) { source << "#include \"torque-generated/builtins-" + DashifyString(n->name()) + "-from-dsl-gen.h\"\n"; - if (n != GlobalContext::GetDefaultNamespace()) { - source << "#include \"src/builtins/builtins-" + DashifyString(n->name()) + - "-gen.h\"\n"; - } } source << "\n"; diff --git a/src/torque/torque-parser.cc b/src/torque/torque-parser.cc index 34a7e10105..dfb0ca9a6c 100644 --- a/src/torque/torque-parser.cc +++ b/src/torque/torque-parser.cc @@ -553,6 +553,14 @@ base::Optional MakeStructDeclaration( return ParseResult{result}; } +base::Optional MakeCppIncludeDeclaration( + ParseResultIterator* child_results) { + auto include_path = child_results->NextAs(); + Declaration* result = + MakeNode(std::move(include_path)); + return ParseResult{result}; +} + base::Optional MakeExternalBuiltin( ParseResultIterator* child_results) { auto transitioning = child_results->NextAs(); @@ -1524,7 +1532,8 @@ struct TorqueGrammar : Grammar { Rule({Token("struct"), &identifier, Token("{"), List(Sequence({&nameAndType, Token(";")})), Token("}")}, - MakeStructDeclaration)}; + MakeStructDeclaration), + Rule({Token("#include"), &externalString}, MakeCppIncludeDeclaration)}; // Result: Declaration* Symbol namespaceDeclaration = {