mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 21:50:14 +01:00
This removes the `data_dir` from the driver favoring the installation abstraction for the both locating the prelude and linking utilities. With this, an installed toolchain should also be able to compile and link Carbon successfully, and the build of the examples should exercise this path almost exactly. (The only difference is using the driver `cc_binary` directly rather than relying on the symlink from inside the install tree.)
44 lines
1.6 KiB
C++
44 lines
1.6 KiB
C++
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
// Exceptions. See /LICENSE for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
|
#include "llvm/Support/MemoryBuffer.h"
|
|
#include "llvm/Support/VirtualFileSystem.h"
|
|
#include "toolchain/driver/driver.h"
|
|
|
|
namespace Carbon::Testing {
|
|
|
|
// NOLINTNEXTLINE: Match the documented fuzzer entry point declaration style.
|
|
extern "C" int LLVMFuzzerTestOneInput(const unsigned char* data,
|
|
std::size_t size) {
|
|
// Ignore large inputs.
|
|
// TODO: See tokenized_buffer_fuzzer.cpp.
|
|
if (size > 100000) {
|
|
return 0;
|
|
}
|
|
|
|
static constexpr llvm::StringLiteral TestFileName = "test.carbon";
|
|
llvm::vfs::InMemoryFileSystem fs;
|
|
llvm::StringRef data_ref(reinterpret_cast<const char*>(data), size);
|
|
CARBON_CHECK(fs.addFile(
|
|
TestFileName, /*ModificationTime=*/0,
|
|
llvm::MemoryBuffer::getMemBuffer(data_ref, /*BufferName=*/TestFileName,
|
|
/*RequiresNullTerminator=*/false)));
|
|
|
|
// TODO: We should try to thread the executable path into here.
|
|
const auto install_paths = InstallPaths::Make("");
|
|
llvm::raw_null_ostream null_ostream;
|
|
Driver driver(fs, &install_paths, null_ostream, null_ostream);
|
|
|
|
// TODO: Get checking to a point where it can handle invalid parse trees
|
|
// without crashing.
|
|
if (!driver.RunCommand({"compile", "--phase=parse", TestFileName}).success) {
|
|
return 0;
|
|
}
|
|
driver.RunCommand({"compile", "--phase=check", TestFileName});
|
|
return 0;
|
|
}
|
|
|
|
} // namespace Carbon::Testing
|