Files
carbon-lang/toolchain/semantics/semantics_node.cpp
T
Jon Ross-Perkins 0755598fa8 Refactor semantics to provide a more block-y IR (#2349)
As a step towards builtins, provide more blocks. The intent is that any significant scope change will become its own NodeBlock. Builtins should produce the first set of node blocks.

Note, SemanticsIR as set up here isn't handling ordering of import processing -- I haven't thought that through much beyond that we probably want some lighter-weight processing of the parse tree to achieve it. But I think the essence of loading builtins first as their own IR block is... probably right?
2022-10-25 17:23:04 -07:00

52 lines
1.5 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/semantics/semantics_node.h"
namespace Carbon {
static auto PrintArgs(llvm::raw_ostream& /*out*/,
const SemanticsNodeArgs::None /*no_args*/) {}
static auto PrintArgs(llvm::raw_ostream& out, SemanticsNodeId one_node) {
out << one_node;
}
static auto PrintArgs(llvm::raw_ostream& out, SemanticsTwoNodeIds two_nodes) {
out << two_nodes.nodes[0] << ", " << two_nodes.nodes[1];
}
static auto PrintArgs(llvm::raw_ostream& out,
SemanticsIdentifierId identifier) {
out << identifier;
}
static auto PrintArgs(llvm::raw_ostream& out,
SemanticsIntegerLiteralId integer_literal) {
out << integer_literal;
}
static auto PrintArgs(llvm::raw_ostream& out, SemanticsNodeBlockId node_block) {
out << node_block;
}
static auto PrintArgs(llvm::raw_ostream& out,
SemanticsNodeIdAndNodeBlockId node_and_node_block) {
out << node_and_node_block.node << ", " << node_and_node_block.node_block;
}
void SemanticsNode::Print(llvm::raw_ostream& out) const {
out << kind_ << "(";
switch (kind_) {
#define CARBON_SEMANTICS_NODE_KIND(Name, Args) \
case SemanticsNodeKind::Name(): \
PrintArgs(out, one_of_args_.Args); \
break;
#include "toolchain/semantics/semantics_node_kind.def"
}
out << ")";
}
} // namespace Carbon