mirror of
https://github.com/JakeHillion/object-introspection.git
synced 2024-09-19 11:09:05 +01:00
03429f3da9
The TypeGraph class should only be responsible for storing Type nodes. Traversing the graph and tracking which nodes have been visited should not be included there. Passes now take a NodeTrackerHolder as an input parameter, which provides access to a zeroed-out NodeTracker.
78 lines
2.0 KiB
C++
78 lines
2.0 KiB
C++
/*
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
#include "PassManager.h"
|
|
|
|
#include <glog/logging.h>
|
|
|
|
#include <iostream>
|
|
#include <sstream>
|
|
|
|
#include "NodeTracker.h"
|
|
#include "Printer.h"
|
|
#include "TypeGraph.h"
|
|
|
|
template <typename T>
|
|
using ref = std::reference_wrapper<T>;
|
|
|
|
namespace oi::detail::type_graph {
|
|
|
|
void Pass::run(TypeGraph& typeGraph, NodeTrackerHolder tracker) {
|
|
fn_(typeGraph, tracker.get(typeGraph.size()));
|
|
}
|
|
|
|
void PassManager::addPass(Pass p) {
|
|
passes_.push_back(std::move(p));
|
|
}
|
|
|
|
namespace {
|
|
void print(const TypeGraph& typeGraph, NodeTrackerHolder tracker) {
|
|
if (!VLOG_IS_ON(1))
|
|
return;
|
|
std::stringstream out;
|
|
Printer printer{out, tracker.get(typeGraph.size()), typeGraph.size()};
|
|
for (const auto& type : typeGraph.rootTypes()) {
|
|
printer.print(type);
|
|
}
|
|
|
|
// Long strings will be truncated by glog, use std::cerr instead
|
|
std::cerr << "\n" << out.str();
|
|
}
|
|
} // namespace
|
|
|
|
const std::string separator = "----------------";
|
|
|
|
void PassManager::run(TypeGraph& typeGraph) {
|
|
NodeTracker tracker;
|
|
|
|
VLOG(1) << separator;
|
|
VLOG(1) << "Parsed Type Graph:";
|
|
VLOG(1) << separator;
|
|
print(typeGraph, tracker);
|
|
VLOG(1) << separator;
|
|
|
|
for (size_t i = 0; i < passes_.size(); i++) {
|
|
auto& pass = passes_[i];
|
|
LOG(INFO) << "Running pass (" << i + 1 << "/" << passes_.size()
|
|
<< "): " << pass.name();
|
|
pass.run(typeGraph, tracker);
|
|
VLOG(1) << separator;
|
|
print(typeGraph, tracker);
|
|
VLOG(1) << separator;
|
|
}
|
|
}
|
|
|
|
} // namespace oi::detail::type_graph
|