summaryrefslogtreecommitdiff
path: root/deps/v8/src/torque/torque.cc
blob: 4dc6ac80abfc5b8b7b4cd7d79dcebf410c111107 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright 2017 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.

#include "src/torque/source-positions.h"
#include "src/torque/torque-compiler.h"

namespace v8 {
namespace internal {
namespace torque {

int WrappedMain(int argc, const char** argv) {
  std::string output_directory;
  bool verbose = false;
  std::vector<std::string> files;

  for (int i = 1; i < argc; ++i) {
    // Check for options
    if (!strcmp("-o", argv[i])) {
      output_directory = argv[++i];
      continue;
    }
    if (!strcmp("-v", argv[i])) {
      verbose = true;
      continue;
    }

    // Otherwise it's a .tq file. Remember it for compilation.
    files.emplace_back(argv[i]);
  }

  TorqueCompilerOptions options;
  options.output_directory = output_directory;
  options.verbose = verbose;
  options.collect_language_server_data = false;
  options.abort_on_lint_errors = true;

  TorqueCompilerResult result = CompileTorque(files, options);
  if (result.error) {
    // PositionAsString requires the SourceFileMap to be set to
    // resolve the file name.
    SourceFileMap::Scope source_file_map_scope(result.source_file_map);

    TorqueError& error = *result.error;
    if (error.position) std::cerr << PositionAsString(*error.position) << ": ";
    std::cerr << "Torque error: " << error.message << "\n";
    v8::base::OS::Abort();
  }

  return 0;
}

}  // namespace torque
}  // namespace internal
}  // namespace v8

int main(int argc, const char** argv) {
  return v8::internal::torque::WrappedMain(argc, argv);
}