Files
carbon-lang/toolchain/lower/lower.cpp
T
Richard Smith 519e633147 Improve backtrace for lowering crashes. (#5651)
Factor out the logic for mapping from a `LocId` into a diagnostic
location from check into sem_ir so it can be reused by lowering. Include
the function and instruction being lowered in the pretty stack trace.
Example stack trace:

```carbon
2.      filename: examples/sieve.carbon
3.      core/prelude/types/int.carbon:213:3: lowering function Core.Op(Core.IntLiteral as Core.ImplicitAs(i32))
            fn Op[addr self: Self*](other: Self) = "int.sadd_assign";
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4.      core/prelude/operators/arithmetic.carbon:22:27: lowering call
            fn Op[addr self: Self*](other: Other);
                                    ^~~~~~~~~~~~
```
2025-06-16 23:21:22 +00:00

29 lines
1.0 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, bool want_debug_info,
llvm::ArrayRef<Parse::GetTreeAndSubtreesFn> tree_and_subtrees_getters,
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), want_debug_info,
tree_and_subtrees_getters, module_name, vlog_stream);
context.GetFileContext(&sem_ir, inst_namer).LowerDefinitions();
return std::move(context).Finalize();
}
} // namespace Carbon::Lower