• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "src/torque/source-positions.h"
6 #include "src/torque/torque-compiler.h"
7 
8 namespace v8 {
9 namespace internal {
10 namespace torque {
11 
ErrorPrefixFor(TorqueMessage::Kind kind)12 std::string ErrorPrefixFor(TorqueMessage::Kind kind) {
13   switch (kind) {
14     case TorqueMessage::Kind::kError:
15       return "Torque Error";
16     case TorqueMessage::Kind::kLint:
17       return "Lint error";
18   }
19 }
20 
WrappedMain(int argc,const char ** argv)21 int WrappedMain(int argc, const char** argv) {
22   TorqueCompilerOptions options;
23   options.collect_language_server_data = false;
24   options.force_assert_statements = false;
25 
26   std::vector<std::string> files;
27 
28   for (int i = 1; i < argc; ++i) {
29     // Check for options
30     const std::string argument(argv[i]);
31     if (argument == "-o") {
32       options.output_directory = argv[++i];
33     } else if (argument == "-v8-root") {
34       options.v8_root = std::string(argv[++i]);
35     } else if (argument == "-m32") {
36       options.force_32bit_output = true;
37     } else {
38       // Otherwise it's a .tq file. Remember it for compilation.
39       files.emplace_back(std::move(argument));
40       if (!StringEndsWith(files.back(), ".tq")) {
41         std::cerr << "Unexpected command-line argument \"" << files.back()
42                   << "\", expected a .tq file.\n";
43         base::OS::Abort();
44       }
45     }
46   }
47 
48   TorqueCompilerResult result = CompileTorque(files, options);
49 
50   // PositionAsString requires the SourceFileMap to be set to
51   // resolve the file name. Needed to report errors and lint warnings.
52   SourceFileMap::Scope source_file_map_scope(*result.source_file_map);
53 
54   for (const TorqueMessage& message : result.messages) {
55     if (message.position) {
56       std::cerr << *message.position << ": ";
57     }
58 
59     std::cerr << ErrorPrefixFor(message.kind) << ": " << message.message
60               << "\n";
61   }
62 
63   if (!result.messages.empty()) v8::base::OS::Abort();
64 
65   return 0;
66 }
67 
68 }  // namespace torque
69 }  // namespace internal
70 }  // namespace v8
71 
main(int argc,const char ** argv)72 int main(int argc, const char** argv) {
73   return v8::internal::torque::WrappedMain(argc, argv);
74 }
75