Skip to content

Commit 0d0e202

Browse files
authored
Switch Driver back to parameters for construction (#4849)
This is for more complex construction, see #4846
1 parent 8727445 commit 0d0e202

File tree

10 files changed

+36
-45
lines changed

10 files changed

+36
-45
lines changed

testing/base/source_gen_test.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,8 @@ auto TestCompile(llvm::StringRef source) -> bool {
147147
new llvm::vfs::InMemoryFileSystem;
148148
InstallPaths installation(
149149
InstallPaths::MakeForBazelRunfiles(Testing::GetExePath()));
150-
Driver driver({.fs = fs,
151-
.installation = &installation,
152-
.input_stream = nullptr,
153-
.output_stream = &llvm::outs(),
154-
.error_stream = &llvm::errs()});
150+
Driver driver(fs, &installation, /*input_stream=*/nullptr, &llvm::outs(),
151+
&llvm::errs());
155152

156153
AddPreludeFilesToVfs(installation, fs);
157154

toolchain/check/check_fuzzer.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,8 @@ extern "C" int LLVMFuzzerTestOneInput(const unsigned char* data, size_t size) {
3939
/*RequiresNullTerminator=*/false)));
4040

4141
llvm::raw_null_ostream null_ostream;
42-
Driver driver({.fs = fs,
43-
.installation = install_paths,
44-
.input_stream = nullptr,
45-
.output_stream = &null_ostream,
46-
.error_stream = &null_ostream,
47-
.fuzzing = true});
42+
Driver driver(fs, install_paths, /*input_stream=*/nullptr, &null_ostream,
43+
&null_ostream, /*fuzzing=*/true);
4844

4945
// TODO: Get checking to a point where it can handle invalid parse trees
5046
// without crashing.

toolchain/driver/compile_benchmark.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,8 @@ class CompileBenchmark {
2323
public:
2424
CompileBenchmark()
2525
: installation_(InstallPaths::MakeForBazelRunfiles(GetExePath())),
26-
driver_({.fs = fs_,
27-
.installation = &installation_,
28-
.input_stream = nullptr,
29-
.output_stream = &llvm::outs(),
30-
.error_stream = &llvm::errs()}) {
26+
driver_(fs_, &installation_, /*input_stream=*/nullptr, &llvm::outs(),
27+
&llvm::errs()) {
3128
AddPreludeFilesToVfs(installation_, fs_);
3229
}
3330

toolchain/driver/driver.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,14 @@ namespace Carbon {
2020
// with the language.
2121
class Driver {
2222
public:
23-
// Constructs a driver with the provided environment.
24-
explicit Driver(DriverEnv env) : driver_env_(std::move(env)) {}
23+
// Constructs a driver with the provided environment. `input_stream` is
24+
// optional; other parameters are required.
25+
explicit Driver(llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs,
26+
const InstallPaths* installation, FILE* input_stream,
27+
llvm::raw_pwrite_stream* output_stream,
28+
llvm::raw_pwrite_stream* error_stream, bool fuzzing = false)
29+
: driver_env_(std::move(fs), installation, input_stream, output_stream,
30+
error_stream, fuzzing) {}
2531

2632
// Parses the given arguments into both a subcommand to select the operation
2733
// to perform and any arguments to that subcommand.

toolchain/driver/driver_env.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,19 @@
1313

1414
namespace Carbon {
1515

16+
// Driver environment information, encapsulated for easy passing to subcommands.
1617
struct DriverEnv {
18+
explicit DriverEnv(llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs,
19+
const InstallPaths* installation, FILE* input_stream,
20+
llvm::raw_pwrite_stream* output_stream,
21+
llvm::raw_pwrite_stream* error_stream, bool fuzzing)
22+
: fs(std::move(fs)),
23+
installation(installation),
24+
input_stream(input_stream),
25+
output_stream(output_stream),
26+
error_stream(error_stream),
27+
fuzzing(fuzzing) {}
28+
1729
// The filesystem for source code.
1830
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs;
1931

@@ -33,7 +45,7 @@ struct DriverEnv {
3345
// Tracks when the driver is being fuzzed. This allows specific commands to
3446
// error rather than perform operations that aren't well behaved during
3547
// fuzzing.
36-
bool fuzzing = false;
48+
bool fuzzing;
3749
};
3850

3951
} // namespace Carbon

toolchain/driver/driver_fuzzer.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,8 @@ extern "C" auto LLVMFuzzerTestOneInput(const unsigned char* data, size_t size)
8282
new llvm::vfs::InMemoryFileSystem;
8383
RawStringOstream error_stream;
8484
llvm::raw_null_ostream null_ostream;
85-
Driver driver({.fs = fs,
86-
.installation = install_paths,
87-
.input_stream = nullptr,
88-
.output_stream = &null_ostream,
89-
.error_stream = &error_stream,
90-
.fuzzing = true});
85+
Driver driver(fs, install_paths, /*input_stream=*/nullptr, &null_ostream,
86+
&error_stream, /*fuzzing=*/true);
9187
if (!driver.RunCommand(args).success) {
9288
auto str = error_stream.TakeStr();
9389
if (llvm::StringRef(str).find("error:") == llvm::StringRef::npos) {

toolchain/driver/driver_test.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,8 @@ class DriverTest : public testing::Test {
4343
DriverTest()
4444
: installation_(
4545
InstallPaths::MakeForBazelRunfiles(Testing::GetExePath())),
46-
driver_({.fs = fs_,
47-
.installation = &installation_,
48-
.input_stream = nullptr,
49-
.output_stream = &test_output_stream_,
50-
.error_stream = &test_error_stream_}) {
46+
driver_(fs_, &installation_, /*input_stream=*/nullptr,
47+
&test_output_stream_, &test_error_stream_) {
5148
char* tmpdir_env = getenv("TEST_TMPDIR");
5249
CARBON_CHECK(tmpdir_env != nullptr);
5350
test_tmpdir_ = tmpdir_env;

toolchain/install/busybox_main.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,7 @@ static auto Main(int argc, char** argv) -> ErrorOr<int> {
4545
}
4646
args.append(argv + 1, argv + argc);
4747

48-
Driver driver({.fs = fs,
49-
.installation = &install_paths,
50-
.input_stream = stdin,
51-
.output_stream = &llvm::outs(),
52-
.error_stream = &llvm::errs()});
48+
Driver driver(fs, &install_paths, stdin, &llvm::outs(), &llvm::errs());
5349
bool success = driver.RunCommand(args).success;
5450
return success ? EXIT_SUCCESS : EXIT_FAILURE;
5551
}

toolchain/sem_ir/yaml_test.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,8 @@ TEST(SemIRTest, YAML) {
3838
const auto install_paths =
3939
InstallPaths::MakeForBazelRunfiles(Testing::GetExePath());
4040
RawStringOstream print_stream;
41-
Driver driver({.fs = fs,
42-
.installation = &install_paths,
43-
.input_stream = nullptr,
44-
.output_stream = &print_stream,
45-
.error_stream = &llvm::errs()});
41+
Driver driver(fs, &install_paths, /*input_stream=*/nullptr, &print_stream,
42+
&llvm::errs());
4643
auto run_result =
4744
driver.RunCommand({"compile", "--no-prelude-import", "--phase=check",
4845
"--dump-raw-sem-ir", "test.carbon"});

toolchain/testing/file_test.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,8 @@ auto ToolchainFileTest::Run(
115115
}
116116
}
117117

118-
Driver driver({.fs = fs,
119-
.installation = &installation_,
120-
.input_stream = input_stream,
121-
.output_stream = &output_stream,
122-
.error_stream = &error_stream});
118+
Driver driver(fs, &installation_, input_stream, &output_stream,
119+
&error_stream);
123120
auto driver_result = driver.RunCommand(test_args);
124121
// If any diagnostics have been produced, add a trailing newline to make the
125122
// last diagnostic match intermediate diagnostics (that have a newline

0 commit comments

Comments
 (0)