mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-03 22:02:51 +01:00
In preparation for lowering information from multiple `SemIR::File`s into a single `llvm::Module`. The primary purpose of this is to support lowering a local specific for an imported generic function, where the instructions for the generic function are in a different file than the instructions for the specific. See #5475 for a draft PR implementing that functionality on top of this. The per-`llvm::Module` state now lives in `Lower::Context`, and `Lower::FileContext` tracks only the per-`SemIR::File` information. `Lower::Context` should not mention any `SemIR` IDs that are file-specific. For now, the C++ lowering and the specific coalescing logic are kept per-file for simplicity.
31 lines
1.1 KiB
C++
31 lines
1.1 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 "toolchain/lower/lower.h"
|
|
|
|
#include <memory>
|
|
#include <optional>
|
|
|
|
#include "toolchain/lower/context.h"
|
|
#include "toolchain/lower/file_context.h"
|
|
|
|
namespace Carbon::Lower {
|
|
|
|
auto LowerToLLVM(llvm::LLVMContext& llvm_context,
|
|
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs,
|
|
std::optional<llvm::ArrayRef<Parse::GetTreeAndSubtreesFn>>
|
|
tree_and_subtrees_getters_for_debug_info,
|
|
llvm::StringRef module_name, const SemIR::File& sem_ir,
|
|
const SemIR::InstNamer* inst_namer,
|
|
llvm::raw_ostream* vlog_stream)
|
|
-> std::unique_ptr<llvm::Module> {
|
|
Context context(llvm_context, std::move(fs),
|
|
tree_and_subtrees_getters_for_debug_info, module_name,
|
|
vlog_stream);
|
|
context.GetFileContext(&sem_ir, inst_namer).LowerDefinitions();
|
|
return std::move(context).Finalize();
|
|
}
|
|
|
|
} // namespace Carbon::Lower
|