mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 12:41:03 +01:00
This unifies `dump-tokens` and `dump-parse-tree` so that we don't keep writing basically the same code repeatedly. I'll need to modify the output of SemanticsIR::Print more, and may soon unify printing multiple IRs this way (particularly including the builtins SemanticsIR) but this is intended to offer a starting point. I may eventually try to unify lit.cfg.py files, but I was thinking about whether that works in various contexts we may run in and eventually decided copying the driver/testdata/lit.cfg.py file would be the easiest solution.
49 lines
1.3 KiB
C++
49 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_SEMANTICS_SEMANTICS_IR_H_
|
|
#define CARBON_TOOLCHAIN_SEMANTICS_SEMANTICS_IR_H_
|
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
|
#include "llvm/ADT/SmallVector.h"
|
|
#include "toolchain/parser/parse_tree.h"
|
|
#include "toolchain/semantics/node_store.h"
|
|
|
|
namespace Carbon::Testing {
|
|
class SemanticsIRForTest;
|
|
} // namespace Carbon::Testing
|
|
|
|
namespace Carbon {
|
|
|
|
// Provides semantic analysis on a ParseTree.
|
|
class SemanticsIR {
|
|
public:
|
|
// File-level declarations.
|
|
auto root_block() const -> llvm::ArrayRef<Semantics::NodeRef> {
|
|
return root_block_;
|
|
}
|
|
|
|
// Prints the full IR.
|
|
auto Print(llvm::raw_ostream& out) const -> void;
|
|
|
|
// Prints the node information.
|
|
auto Print(llvm::raw_ostream& out, Semantics::NodeRef node_ref) const -> void;
|
|
|
|
private:
|
|
friend class SemanticsIRFactory;
|
|
friend class Testing::SemanticsIRForTest;
|
|
|
|
explicit SemanticsIR(const ParseTree& parse_tree)
|
|
: parse_tree_(&parse_tree) {}
|
|
|
|
Semantics::NodeStore nodes_;
|
|
llvm::SmallVector<Semantics::NodeRef, 0> root_block_;
|
|
|
|
const ParseTree* parse_tree_;
|
|
};
|
|
|
|
} // namespace Carbon
|
|
|
|
#endif // CARBON_TOOLCHAIN_SEMANTICS_SEMANTICS_IR_H_
|