Path: blob/main/contrib/llvm-project/llvm/tools/llvm-diff/lib/DiffConsumer.h
35291 views
//===-- DiffConsumer.h - Difference Consumer --------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This header defines the interface to the LLVM difference Consumer9//10//===----------------------------------------------------------------------===//1112#ifndef LLVM_TOOLS_LLVM_DIFF_DIFFCONSUMER_H13#define LLVM_TOOLS_LLVM_DIFF_DIFFCONSUMER_H1415#include "DiffLog.h"16#include "llvm/ADT/DenseMap.h"17#include "llvm/ADT/SmallVector.h"18#include "llvm/IR/Value.h"19#include "llvm/Support/Casting.h"20#include "llvm/Support/raw_ostream.h"2122namespace llvm {23class StringRef;24class Module;25class Value;26class Function;2728/// The interface for consumers of difference data.29class Consumer {30virtual void anchor();31public:32/// Record that a local context has been entered. Left and33/// Right are IR "containers" of some sort which are being34/// considered for structural equivalence: global variables,35/// functions, blocks, instructions, etc.36virtual void enterContext(const Value *Left, const Value *Right) = 0;3738/// Record that a local context has been exited.39virtual void exitContext() = 0;4041/// Record a difference within the current context.42virtual void log(StringRef Text) = 0;4344/// Record a formatted difference within the current context.45virtual void logf(const LogBuilder &Log) = 0;4647/// Record a line-by-line instruction diff.48virtual void logd(const DiffLogBuilder &Log) = 0;4950protected:51virtual ~Consumer() {}52};5354class DiffConsumer : public Consumer {55private:56struct DiffContext {57DiffContext(const Value *L, const Value *R)58: L(L), R(R), Differences(false), IsFunction(isa<Function>(L)) {}59const Value *L;60const Value *R;61bool Differences;62bool IsFunction;63DenseMap<const Value *, unsigned> LNumbering;64DenseMap<const Value *, unsigned> RNumbering;65};6667raw_ostream &out;68SmallVector<DiffContext, 5> contexts;69bool Differences;70unsigned Indent;7172void printValue(const Value *V, bool isL);73void header();74void indent();7576public:77DiffConsumer()78: out(errs()), Differences(false), Indent(0) {}7980void reset();81bool hadDifferences() const;82void enterContext(const Value *L, const Value *R) override;83void exitContext() override;84void log(StringRef text) override;85void logf(const LogBuilder &Log) override;86void logd(const DiffLogBuilder &Log) override;87};88}8990#endif919293