Line data Source code
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 1 : int WrappedMain(int argc, const char** argv) {
22 : std::string output_directory;
23 : bool verbose = false;
24 2 : SourceFileMap::Scope source_file_map_scope;
25 : CurrentSourceFile::Scope unknown_sourcefile_scope(
26 2 : SourceFileMap::AddSource("<unknown>"));
27 2 : CurrentAst::Scope ast_scope;
28 1 : LintErrorStatus::Scope lint_error_status_scope;
29 :
30 25 : for (int i = 1; i < argc; ++i) {
31 : // Check for options
32 24 : if (!strcmp("-o", argv[i])) {
33 1 : output_directory = argv[++i];
34 1 : continue;
35 : }
36 23 : 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 23 : std::string path = argv[i];
45 46 : SourceId source_id = SourceFileMap::AddSource(path);
46 23 : CurrentSourceFile::Scope source_id_scope(source_id);
47 46 : std::ifstream file_stream(path);
48 : std::string file_content = {std::istreambuf_iterator<char>(file_stream),
49 23 : std::istreambuf_iterator<char>()};
50 23 : ParseTorque(file_content);
51 : }
52 :
53 2 : GlobalContext::Scope global_context(std::move(CurrentAst::Get()));
54 1 : if (verbose) GlobalContext::SetVerbose();
55 2 : TypeOracle::Scope type_oracle;
56 :
57 1 : if (output_directory.length() != 0) {
58 1 : DeclarationVisitor().Visit(GlobalContext::Get().ast());
59 :
60 1 : ImplementationVisitor visitor;
61 12 : for (Namespace* n : GlobalContext::Get().GetNamespaces()) {
62 10 : visitor.BeginNamespaceFile(n);
63 : }
64 :
65 1 : visitor.VisitAllDeclarables();
66 :
67 1 : std::string output_header_path = output_directory;
68 : output_header_path += "/builtin-definitions-from-dsl.h";
69 1 : visitor.GenerateBuiltinDefinitions(output_header_path);
70 :
71 1 : output_header_path = output_directory + "/class-definitions-from-dsl.h";
72 1 : visitor.GenerateClassDefinitions(output_header_path);
73 :
74 12 : for (Namespace* n : GlobalContext::Get().GetNamespaces()) {
75 10 : visitor.EndNamespaceFile(n);
76 10 : visitor.GenerateImplementation(output_directory, n);
77 : }
78 : }
79 :
80 1 : if (LintErrorStatus::HasLintErrors()) std::abort();
81 :
82 1 : return 0;
83 : }
84 :
85 : } // namespace torque
86 : } // namespace internal
87 : } // namespace v8
88 :
89 1 : int main(int argc, const char** argv) {
90 1 : return v8::internal::torque::WrappedMain(argc, argv);
91 3 : }
|