V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
torque.cc
1 // Copyright 2017 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include <fstream>
6 #include <iostream>
7 
8 #include "src/torque/declarable.h"
9 #include "src/torque/declaration-visitor.h"
10 #include "src/torque/global-context.h"
11 #include "src/torque/implementation-visitor.h"
12 #include "src/torque/torque-parser.h"
13 #include "src/torque/type-oracle.h"
14 #include "src/torque/types.h"
15 #include "src/torque/utils.h"
16 
17 namespace v8 {
18 namespace internal {
19 namespace torque {
20 
21 int WrappedMain(int argc, const char** argv) {
22  std::string output_directory;
23  bool verbose = false;
24  SourceFileMap::Scope source_file_map_scope;
25  CurrentSourceFile::Scope unknown_sourcefile_scope(
26  SourceFileMap::AddSource("<unknown>"));
27  CurrentAst::Scope ast_scope;
28  LintErrorStatus::Scope lint_error_status_scope;
29 
30  for (int i = 1; i < argc; ++i) {
31  // Check for options
32  if (!strcmp("-o", argv[i])) {
33  output_directory = argv[++i];
34  continue;
35  }
36  if (!strcmp("-v", argv[i])) {
37  verbose = true;
38  continue;
39  }
40 
41  // Otherwise it's a .tq
42  // file, parse it and
43  // remember the syntax tree
44  std::string path = argv[i];
45  SourceId source_id = SourceFileMap::AddSource(path);
46  CurrentSourceFile::Scope source_id_scope(source_id);
47  std::ifstream file_stream(path);
48  std::string file_content = {std::istreambuf_iterator<char>(file_stream),
49  std::istreambuf_iterator<char>()};
50  ParseTorque(file_content);
51  }
52 
53  GlobalContext::Scope global_context(std::move(CurrentAst::Get()));
54  if (verbose) GlobalContext::SetVerbose();
55  TypeOracle::Scope type_oracle;
56 
57  if (output_directory.length() != 0) {
58  DeclarationVisitor().Visit(GlobalContext::Get().ast());
59 
60  ImplementationVisitor visitor;
61  for (Namespace* n : GlobalContext::Get().GetNamespaces()) {
62  visitor.BeginNamespaceFile(n);
63  }
64 
65  visitor.VisitAllDeclarables();
66 
67  std::string output_header_path = output_directory;
68  output_header_path += "/builtin-definitions-from-dsl.h";
69  visitor.GenerateBuiltinDefinitions(output_header_path);
70 
71  for (Namespace* n : GlobalContext::Get().GetNamespaces()) {
72  visitor.EndNamespaceFile(n);
73  visitor.GenerateImplementation(output_directory, n);
74  }
75  }
76 
77  if (LintErrorStatus::HasLintErrors()) std::abort();
78 
79  return 0;
80 }
81 
82 } // namespace torque
83 } // namespace internal
84 } // namespace v8
85 
86 int main(int argc, const char** argv) {
87  return v8::internal::torque::WrappedMain(argc, argv);
88 }
Definition: libplatform.h:13