mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 06:41:06 +01:00
The install directory contains the BUILD logic for creating an installable tree of data files and executables for the toolchain, and a library to facilitate toolchain code accessing the paths to their data within this installation. Then adds an installation of LLD in a synthetic LLVM installation, and teaches the Clang runner to configure this and use it for linking instead of the system linker. Currently, the install paths only really manage access to the LLVM binaries installed and used by the Clang runner for linking, but eventually other data files like the prelude and runtime libraries will be fleshed out as well. There are TODOs for moving more things over here such as the prelude. One interesting aspect of this is where to put helpers like parts of LLVM in our install. This PR suggests nesting those files under `lib/carbon`. While using a `lib` subdirectory isn't a perfect fit for the FHS (Filesystem Hierarchy Standard), having a single location where private data is collected is significantly superior to spreading them across the system. This also matches similar patterns used by Clang itself and several other language toolchains and standard libraries. The install directory also provides a natural place for us to build out packaging rules to create installable packages in various formats, but that remains future work. --------- Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
105 lines
4.3 KiB
C++
105 lines
4.3 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 <gmock/gmock.h>
|
|
#include <gtest/gtest.h>
|
|
|
|
#include "common/ostream.h"
|
|
#include "llvm/Support/MemoryBuffer.h"
|
|
#include "llvm/Support/VirtualFileSystem.h"
|
|
#include "testing/base/gtest_main.h"
|
|
#include "testing/base/test_raw_ostream.h"
|
|
#include "toolchain/driver/driver.h"
|
|
#include "toolchain/testing/yaml_test_helpers.h"
|
|
|
|
namespace Carbon::SemIR {
|
|
namespace {
|
|
|
|
using ::Carbon::Testing::TestRawOstream;
|
|
using ::testing::_;
|
|
using ::testing::AllOf;
|
|
using ::testing::Contains;
|
|
using ::testing::Each;
|
|
using ::testing::ElementsAre;
|
|
using ::testing::Ge;
|
|
using ::testing::IsEmpty;
|
|
using ::testing::MatchesRegex;
|
|
using ::testing::Pair;
|
|
using ::testing::SizeIs;
|
|
|
|
namespace Yaml = ::Carbon::Testing::Yaml;
|
|
|
|
TEST(SemIRTest, YAML) {
|
|
llvm::vfs::InMemoryFileSystem fs;
|
|
CARBON_CHECK(fs.addFile(
|
|
"test.carbon", /*ModificationTime=*/0,
|
|
llvm::MemoryBuffer::getMemBuffer("fn F() { var x: () = (); return; }")));
|
|
const auto install_paths =
|
|
InstallPaths::MakeForBazelRunfiles(Testing::GetTestExePath());
|
|
TestRawOstream print_stream;
|
|
Driver d(fs, &install_paths, "", print_stream, llvm::errs());
|
|
auto run_result =
|
|
d.RunCommand({"compile", "--no-prelude-import", "--phase=check",
|
|
"--dump-raw-sem-ir", "test.carbon"});
|
|
EXPECT_TRUE(run_result.success);
|
|
|
|
// Matches the ID of an instruction. Instruction counts may change as various
|
|
// support changes, so this code is only doing loose structural checks.
|
|
auto type_block_id = Yaml::Scalar(MatchesRegex(R"(typeBlock\d+)"));
|
|
auto inst_id = Yaml::Scalar(MatchesRegex(R"(inst\+\d+)"));
|
|
auto constant_id =
|
|
Yaml::Scalar(MatchesRegex(R"((template|symbolic) inst(\w+|\+\d+))"));
|
|
auto inst_builtin = Yaml::Scalar(MatchesRegex(R"(inst\w+)"));
|
|
auto type_id = Yaml::Scalar(MatchesRegex(R"(type\d+)"));
|
|
auto type_builtin = Pair(
|
|
type_id, Yaml::Mapping(ElementsAre(Pair("constant", constant_id),
|
|
Pair("value_rep", Yaml::Mapping(_)))));
|
|
|
|
auto file = Yaml::Mapping(ElementsAre(
|
|
Pair("import_irs_size", "1"),
|
|
Pair("name_scopes", Yaml::Mapping(SizeIs(1))),
|
|
Pair("bind_names", Yaml::Mapping(SizeIs(1))),
|
|
Pair("functions", Yaml::Mapping(SizeIs(1))),
|
|
Pair("classes", Yaml::Mapping(SizeIs(0))),
|
|
Pair("types", Yaml::Mapping(Each(type_builtin))),
|
|
Pair("type_blocks", Yaml::Mapping(SizeIs(Ge(1)))),
|
|
Pair("insts",
|
|
Yaml::Mapping(AllOf(
|
|
Each(Key(inst_id)),
|
|
// kind is required, other parts are optional.
|
|
Each(Pair(_, Yaml::Mapping(Contains(Pair("kind", _))))),
|
|
// A 0-arg instruction.
|
|
Contains(
|
|
Pair(_, Yaml::Mapping(ElementsAre(Pair("kind", "Return"))))),
|
|
// A 1-arg instruction.
|
|
Contains(Pair(_, Yaml::Mapping(ElementsAre(
|
|
Pair("kind", "TupleType"),
|
|
Pair("arg0", type_block_id),
|
|
Pair("type", "typeTypeType"))))),
|
|
// A 2-arg instruction.
|
|
Contains(Pair(
|
|
_, Yaml::Mapping(ElementsAre(Pair("kind", "Assign"),
|
|
Pair("arg0", inst_id),
|
|
Pair("arg1", inst_id)))))))),
|
|
Pair("constant_values",
|
|
Yaml::Mapping(AllOf(Each(Pair(inst_id, constant_id))))),
|
|
// This production has only two instruction blocks.
|
|
Pair("inst_blocks",
|
|
Yaml::Mapping(ElementsAre(
|
|
Pair("empty", Yaml::Mapping(IsEmpty())),
|
|
Pair("exports", Yaml::Mapping(Each(Pair(_, inst_id)))),
|
|
Pair("global_init", Yaml::Mapping(IsEmpty())),
|
|
Pair("block3", Yaml::Mapping(Each(Pair(_, inst_id)))),
|
|
Pair("block4", Yaml::Mapping(Each(Pair(_, inst_id)))),
|
|
Pair("block5", Yaml::Mapping(Each(Pair(_, inst_id)))))))));
|
|
|
|
auto root = Yaml::Sequence(ElementsAre(Yaml::Mapping(
|
|
ElementsAre(Pair("filename", "test.carbon"), Pair("sem_ir", file)))));
|
|
|
|
EXPECT_THAT(Yaml::Value::FromText(print_stream.TakeStr()), IsYaml(root));
|
|
}
|
|
|
|
} // namespace
|
|
} // namespace Carbon::SemIR
|