mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-26 04:01:15 +00:00
- Do not include entities imported from files that we are not dumping. - Do not include constants and import_refs that are not referenced by something that we are including in the formatted output. --------- Co-authored-by: Jon Ross-Perkins <jperkins@google.com> Co-authored-by: Carbon Infra Bot <carbon-external-infra@google.com>
43 lines
1.3 KiB
C++
43 lines
1.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
|
|
|
|
#ifndef CARBON_TOOLCHAIN_SEM_IR_FORMATTER_H_
|
|
#define CARBON_TOOLCHAIN_SEM_IR_FORMATTER_H_
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
#include "toolchain/lex/tokenized_buffer.h"
|
|
#include "toolchain/parse/tree.h"
|
|
#include "toolchain/sem_ir/file.h"
|
|
#include "toolchain/sem_ir/inst_namer.h"
|
|
|
|
namespace Carbon::SemIR {
|
|
|
|
// Formatter for printing textual Semantics IR.
|
|
class Formatter {
|
|
public:
|
|
// A callback that indicates whether a specific entity, identified by its
|
|
// declaration, should be included in the output.
|
|
using ShouldFormatEntityFn =
|
|
llvm::function_ref<auto(InstId decl_inst_id)->bool>;
|
|
|
|
explicit Formatter(
|
|
const Lex::TokenizedBuffer& tokenized_buffer,
|
|
const Parse::Tree& parse_tree, const File& sem_ir,
|
|
ShouldFormatEntityFn should_format_entity = [](InstId) { return true; });
|
|
~Formatter();
|
|
|
|
// Prints the full IR.
|
|
auto Print(llvm::raw_ostream& out) -> void;
|
|
|
|
private:
|
|
const File& sem_ir_;
|
|
ShouldFormatEntityFn should_format_entity_;
|
|
// Caches naming between Print calls.
|
|
InstNamer inst_namer_;
|
|
};
|
|
|
|
} // namespace Carbon::SemIR
|
|
|
|
#endif // CARBON_TOOLCHAIN_SEM_IR_FORMATTER_H_
|