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)12std::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)21int 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 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 #ifdef V8_COMPRESS_POINTERS 37 std::cerr << "Pointer compression is incompatible with -m32.\n"; 38 base::OS::Abort(); 39 #else 40 options.force_32bit_output = true; 41 #endif 42 } else if (argument == "-annotate-ir") { 43 options.annotate_ir = true; 44 } else if (argument == "-strip-v8-root") { 45 options.strip_v8_root = true; 46 } else { 47 // Strip the v8-root in case it is a prefix of the file path itself. 48 // This is used when building in Google3. 49 if (options.strip_v8_root && 50 argument.substr(0, options.v8_root.size()) == options.v8_root) { 51 argument = argument.substr(options.v8_root.size() + 1); 52 } 53 // Otherwise it's a .tq file. Remember it for compilation. 54 files.emplace_back(std::move(argument)); 55 if (!StringEndsWith(files.back(), ".tq")) { 56 std::cerr << "Unexpected command-line argument \"" << files.back() 57 << "\", expected a .tq file.\n"; 58 base::OS::Abort(); 59 } 60 } 61 } 62 63 TorqueCompilerResult result = CompileTorque(files, options); 64 65 // PositionAsString requires the SourceFileMap to be set to 66 // resolve the file name. Needed to report errors and lint warnings. 67 SourceFileMap::Scope source_file_map_scope(*result.source_file_map); 68 69 for (const TorqueMessage& message : result.messages) { 70 if (message.position) { 71 std::cerr << PositionAsString(*message.position) << ": "; 72 } 73 74 std::cerr << ErrorPrefixFor(message.kind) << ": " << message.message 75 << "\n"; 76 } 77 78 if (!result.messages.empty()) v8::base::OS::Abort(); 79 80 return 0; 81 } 82 83 } // namespace torque 84 } // namespace internal 85 } // namespace v8 86 main(int argc,const char ** argv)87int main(int argc, const char** argv) { 88 return v8::internal::torque::WrappedMain(argc, argv); 89 } 90