Преглед на файлове

Switch Driver back to parameters for construction (#4849)

This is for more complex construction, see #4846
Jon Ross-Perkins преди 1 година
родител
ревизия
0d0e202ce8

+ 2 - 5
testing/base/source_gen_test.cpp

@@ -147,11 +147,8 @@ auto TestCompile(llvm::StringRef source) -> bool {
       new llvm::vfs::InMemoryFileSystem;
   InstallPaths installation(
       InstallPaths::MakeForBazelRunfiles(Testing::GetExePath()));
-  Driver driver({.fs = fs,
-                 .installation = &installation,
-                 .input_stream = nullptr,
-                 .output_stream = &llvm::outs(),
-                 .error_stream = &llvm::errs()});
+  Driver driver(fs, &installation, /*input_stream=*/nullptr, &llvm::outs(),
+                &llvm::errs());
 
   AddPreludeFilesToVfs(installation, fs);
 

+ 2 - 6
toolchain/check/check_fuzzer.cpp

@@ -39,12 +39,8 @@ extern "C" int LLVMFuzzerTestOneInput(const unsigned char* data, size_t size) {
                                        /*RequiresNullTerminator=*/false)));
 
   llvm::raw_null_ostream null_ostream;
-  Driver driver({.fs = fs,
-                 .installation = install_paths,
-                 .input_stream = nullptr,
-                 .output_stream = &null_ostream,
-                 .error_stream = &null_ostream,
-                 .fuzzing = true});
+  Driver driver(fs, install_paths, /*input_stream=*/nullptr, &null_ostream,
+                &null_ostream, /*fuzzing=*/true);
 
   // TODO: Get checking to a point where it can handle invalid parse trees
   // without crashing.

+ 2 - 5
toolchain/driver/compile_benchmark.cpp

@@ -23,11 +23,8 @@ class CompileBenchmark {
  public:
   CompileBenchmark()
       : installation_(InstallPaths::MakeForBazelRunfiles(GetExePath())),
-        driver_({.fs = fs_,
-                 .installation = &installation_,
-                 .input_stream = nullptr,
-                 .output_stream = &llvm::outs(),
-                 .error_stream = &llvm::errs()}) {
+        driver_(fs_, &installation_, /*input_stream=*/nullptr, &llvm::outs(),
+                &llvm::errs()) {
     AddPreludeFilesToVfs(installation_, fs_);
   }
 

+ 8 - 2
toolchain/driver/driver.h

@@ -20,8 +20,14 @@ namespace Carbon {
 // with the language.
 class Driver {
  public:
-  // Constructs a driver with the provided environment.
-  explicit Driver(DriverEnv env) : driver_env_(std::move(env)) {}
+  // Constructs a driver with the provided environment. `input_stream` is
+  // optional; other parameters are required.
+  explicit Driver(llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs,
+                  const InstallPaths* installation, FILE* input_stream,
+                  llvm::raw_pwrite_stream* output_stream,
+                  llvm::raw_pwrite_stream* error_stream, bool fuzzing = false)
+      : driver_env_(std::move(fs), installation, input_stream, output_stream,
+                    error_stream, fuzzing) {}
 
   // Parses the given arguments into both a subcommand to select the operation
   // to perform and any arguments to that subcommand.

+ 13 - 1
toolchain/driver/driver_env.h

@@ -13,7 +13,19 @@
 
 namespace Carbon {
 
+// Driver environment information, encapsulated for easy passing to subcommands.
 struct DriverEnv {
+  explicit DriverEnv(llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs,
+                     const InstallPaths* installation, FILE* input_stream,
+                     llvm::raw_pwrite_stream* output_stream,
+                     llvm::raw_pwrite_stream* error_stream, bool fuzzing)
+      : fs(std::move(fs)),
+        installation(installation),
+        input_stream(input_stream),
+        output_stream(output_stream),
+        error_stream(error_stream),
+        fuzzing(fuzzing) {}
+
   // The filesystem for source code.
   llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs;
 
@@ -33,7 +45,7 @@ struct DriverEnv {
   // Tracks when the driver is being fuzzed. This allows specific commands to
   // error rather than perform operations that aren't well behaved during
   // fuzzing.
-  bool fuzzing = false;
+  bool fuzzing;
 };
 
 }  // namespace Carbon

+ 2 - 6
toolchain/driver/driver_fuzzer.cpp

@@ -82,12 +82,8 @@ extern "C" auto LLVMFuzzerTestOneInput(const unsigned char* data, size_t size)
       new llvm::vfs::InMemoryFileSystem;
   RawStringOstream error_stream;
   llvm::raw_null_ostream null_ostream;
-  Driver driver({.fs = fs,
-                 .installation = install_paths,
-                 .input_stream = nullptr,
-                 .output_stream = &null_ostream,
-                 .error_stream = &error_stream,
-                 .fuzzing = true});
+  Driver driver(fs, install_paths, /*input_stream=*/nullptr, &null_ostream,
+                &error_stream, /*fuzzing=*/true);
   if (!driver.RunCommand(args).success) {
     auto str = error_stream.TakeStr();
     if (llvm::StringRef(str).find("error:") == llvm::StringRef::npos) {

+ 2 - 5
toolchain/driver/driver_test.cpp

@@ -43,11 +43,8 @@ class DriverTest : public testing::Test {
   DriverTest()
       : installation_(
             InstallPaths::MakeForBazelRunfiles(Testing::GetExePath())),
-        driver_({.fs = fs_,
-                 .installation = &installation_,
-                 .input_stream = nullptr,
-                 .output_stream = &test_output_stream_,
-                 .error_stream = &test_error_stream_}) {
+        driver_(fs_, &installation_, /*input_stream=*/nullptr,
+                &test_output_stream_, &test_error_stream_) {
     char* tmpdir_env = getenv("TEST_TMPDIR");
     CARBON_CHECK(tmpdir_env != nullptr);
     test_tmpdir_ = tmpdir_env;

+ 1 - 5
toolchain/install/busybox_main.cpp

@@ -45,11 +45,7 @@ static auto Main(int argc, char** argv) -> ErrorOr<int> {
   }
   args.append(argv + 1, argv + argc);
 
-  Driver driver({.fs = fs,
-                 .installation = &install_paths,
-                 .input_stream = stdin,
-                 .output_stream = &llvm::outs(),
-                 .error_stream = &llvm::errs()});
+  Driver driver(fs, &install_paths, stdin, &llvm::outs(), &llvm::errs());
   bool success = driver.RunCommand(args).success;
   return success ? EXIT_SUCCESS : EXIT_FAILURE;
 }

+ 2 - 5
toolchain/sem_ir/yaml_test.cpp

@@ -38,11 +38,8 @@ TEST(SemIRTest, YAML) {
   const auto install_paths =
       InstallPaths::MakeForBazelRunfiles(Testing::GetExePath());
   RawStringOstream print_stream;
-  Driver driver({.fs = fs,
-                 .installation = &install_paths,
-                 .input_stream = nullptr,
-                 .output_stream = &print_stream,
-                 .error_stream = &llvm::errs()});
+  Driver driver(fs, &install_paths, /*input_stream=*/nullptr, &print_stream,
+                &llvm::errs());
   auto run_result =
       driver.RunCommand({"compile", "--no-prelude-import", "--phase=check",
                          "--dump-raw-sem-ir", "test.carbon"});

+ 2 - 5
toolchain/testing/file_test.cpp

@@ -115,11 +115,8 @@ auto ToolchainFileTest::Run(
     }
   }
 
-  Driver driver({.fs = fs,
-                 .installation = &installation_,
-                 .input_stream = input_stream,
-                 .output_stream = &output_stream,
-                 .error_stream = &error_stream});
+  Driver driver(fs, &installation_, input_stream, &output_stream,
+                &error_stream);
   auto driver_result = driver.RunCommand(test_args);
   // If any diagnostics have been produced, add a trailing newline to make the
   // last diagnostic match intermediate diagnostics (that have a newline