|
|
@@ -10,6 +10,7 @@
|
|
|
#include "llvm/ADT/APInt.h"
|
|
|
#include "llvm/ADT/DenseMap.h"
|
|
|
#include "llvm/ADT/SmallVector.h"
|
|
|
+#include "llvm/Support/YAMLParser.h"
|
|
|
#include "toolchain/base/index_base.h"
|
|
|
|
|
|
namespace Carbon {
|
|
|
@@ -80,7 +81,7 @@ constexpr StringId StringId::Invalid(StringId::InvalidIndex);
|
|
|
// A simple wrapper for accumulating values, providing IDs to later retrieve the
|
|
|
// value. This does not do deduplication.
|
|
|
template <typename IdT>
|
|
|
-class ValueStore {
|
|
|
+class ValueStore : public Printable<ValueStore<IdT>> {
|
|
|
public:
|
|
|
// Stores the value and returns an ID to reference it.
|
|
|
auto Add(typename IdT::IndexedType value) -> IdT {
|
|
|
@@ -96,6 +97,14 @@ class ValueStore {
|
|
|
return values_[id.index];
|
|
|
}
|
|
|
|
|
|
+ auto Print(llvm::raw_ostream& out) const -> void { Print(out, 0); }
|
|
|
+ auto Print(llvm::raw_ostream& out, int indent) const -> void {
|
|
|
+ for (const auto& value : values_) {
|
|
|
+ out.indent(indent);
|
|
|
+ out << "- " << value << "\n";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private:
|
|
|
llvm::SmallVector<typename IdT::IndexedType> values_;
|
|
|
};
|
|
|
@@ -103,7 +112,7 @@ class ValueStore {
|
|
|
// Storage for StringRefs. The caller is responsible for ensuring storage is
|
|
|
// allocated.
|
|
|
template <>
|
|
|
-class ValueStore<StringId> {
|
|
|
+class ValueStore<StringId> : public Printable<ValueStore<StringId>> {
|
|
|
public:
|
|
|
// Returns an ID to reference the value. May return an existing ID if the
|
|
|
// string was previously added.
|
|
|
@@ -122,6 +131,14 @@ class ValueStore<StringId> {
|
|
|
return values_[id.index];
|
|
|
}
|
|
|
|
|
|
+ auto Print(llvm::raw_ostream& out) const -> void { Print(out, 0); }
|
|
|
+ auto Print(llvm::raw_ostream& out, int indent) const -> void {
|
|
|
+ for (auto value : values_) {
|
|
|
+ out.indent(indent);
|
|
|
+ out << "- \"" << llvm::yaml::escape(value) << "\"\n";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private:
|
|
|
llvm::DenseMap<llvm::StringRef, StringId> map_;
|
|
|
llvm::SmallVector<llvm::StringRef> values_;
|
|
|
@@ -129,7 +146,7 @@ class ValueStore<StringId> {
|
|
|
|
|
|
// Stores that will be used across compiler steps. This is provided mainly so
|
|
|
// that they don't need to be passed separately.
|
|
|
-class SharedValueStores {
|
|
|
+class SharedValueStores : public Printable<SharedValueStores> {
|
|
|
public:
|
|
|
auto integers() -> ValueStore<IntegerId>& { return integers_; }
|
|
|
auto integers() const -> const ValueStore<IntegerId>& { return integers_; }
|
|
|
@@ -138,6 +155,16 @@ class SharedValueStores {
|
|
|
auto strings() -> ValueStore<StringId>& { return strings_; }
|
|
|
auto strings() const -> const ValueStore<StringId>& { return strings_; }
|
|
|
|
|
|
+ auto Print(llvm::raw_ostream& out) const -> void {
|
|
|
+ out << "shared_values:\n"
|
|
|
+ << " - integers:\n";
|
|
|
+ integers_.Print(out, 6);
|
|
|
+ out << " - reals:\n";
|
|
|
+ reals_.Print(out, 6);
|
|
|
+ out << " - strings:\n";
|
|
|
+ strings_.Print(out, 6);
|
|
|
+ }
|
|
|
+
|
|
|
private:
|
|
|
ValueStore<IntegerId> integers_;
|
|
|
ValueStore<RealId> reals_;
|