|
| 1 | +#pragma once |
| 2 | + |
| 3 | +#include <llvm/IR/Instructions.h> |
| 4 | +#include <unordered_map> |
| 5 | + |
| 6 | +namespace llvm { |
| 7 | + |
| 8 | +class Module; |
| 9 | +class Function; |
| 10 | +class BasicBlock; |
| 11 | +class Instruction; |
| 12 | +class ReturnInst; |
| 13 | + |
| 14 | +} // namespace llvm |
| 15 | + |
| 16 | +namespace llvm2graphml { |
| 17 | + |
| 18 | +class Builder; |
| 19 | +class Node; |
| 20 | + |
| 21 | +class Emitter { |
| 22 | +public: |
| 23 | + explicit Emitter(Builder &builder); |
| 24 | + void emit(const llvm::Module *module); |
| 25 | + |
| 26 | +private: |
| 27 | + Builder &builder; |
| 28 | + std::unordered_map<const llvm::Value *, Node *> emittedValues; |
| 29 | + |
| 30 | + void dispatchInstruction(const llvm::Instruction *instruction, Node *node); |
| 31 | + Node *emit(const llvm::Value *value); |
| 32 | + |
| 33 | + /// Extension points |
| 34 | + |
| 35 | + void fillIn(const llvm::Module *module, Node *node); |
| 36 | + void fillIn(const llvm::Function *function, Node *node); |
| 37 | + void fillIn(const llvm::BasicBlock *basicBlock, Node *node); |
| 38 | + |
| 39 | + void fillIn(const llvm::Argument *argument, Node *node); |
| 40 | + void fillIn(const llvm::ConstantInt *constant, Node *node); |
| 41 | + void fillIn(const llvm::ConstantFP *constant, Node *node); |
| 42 | + void fillIn(const llvm::ConstantPointerNull *constant, Node *node); |
| 43 | + void fillIn(const llvm::ConstantTokenNone *constant, Node *node); |
| 44 | + void fillIn(const llvm::UndefValue *undefValue, Node *node); |
| 45 | + void fillIn(const llvm::InlineAsm *inlineAsm, Node *node); |
| 46 | + void fillIn(const llvm::MetadataAsValue *metadataAsValue, llvm2graphml::Node *node); |
| 47 | + void fillIn(const llvm::BlockAddress *blockAddress, llvm2graphml::Node *node); |
| 48 | + void fillIn(const llvm::ConstantArray *constantArray, llvm2graphml::Node *node); |
| 49 | + void fillIn(const llvm::ConstantDataArray *constantArray, llvm2graphml::Node *node); |
| 50 | + void fillIn(const llvm::GlobalAlias *globalAlias, llvm2graphml::Node *node); |
| 51 | + void fillIn(const llvm::GlobalIFunc *globalIFunc, llvm2graphml::Node *node); |
| 52 | + void fillIn(const llvm::GlobalVariable *globalVariable, llvm2graphml::Node *node); |
| 53 | + void fillIn(const llvm::ConstantExpr *constantExpr, llvm2graphml::Node *node); |
| 54 | + void fillIn(const llvm::ConstantStruct *constantStruct, llvm2graphml::Node *node); |
| 55 | + void fillIn(const llvm::ConstantVector *constantVector, llvm2graphml::Node *node); |
| 56 | + void fillIn(const llvm::ConstantAggregateZero *constantZero, llvm2graphml::Node *node); |
| 57 | + void fillIn(const llvm::ConstantDataVector *constantVector, llvm2graphml::Node *node); |
| 58 | + |
| 59 | + void fillIn(const llvm::Instruction *instruction, Node *node); |
| 60 | + void fillIn(const llvm::ReturnInst *instruction, Node *node); |
| 61 | + void fillIn(const llvm::BranchInst *instruction, Node *node); |
| 62 | + void fillIn(const llvm::SwitchInst *instruction, Node *node); |
| 63 | + void fillIn(const llvm::IndirectBrInst *instruction, Node *node); |
| 64 | + void fillIn(const llvm::InvokeInst *instruction, Node *node); |
| 65 | + void fillIn(const llvm::ResumeInst *instruction, Node *node); |
| 66 | + void fillIn(const llvm::UnreachableInst *instruction, Node *node); |
| 67 | + void fillIn(const llvm::CleanupReturnInst *instruction, Node *node); |
| 68 | + void fillIn(const llvm::CatchReturnInst *instruction, Node *node); |
| 69 | + void fillIn(const llvm::CatchSwitchInst *instruction, Node *node); |
| 70 | + void fillIn(const llvm::CallBrInst *instruction, Node *node); |
| 71 | + void fillIn(const llvm::UnaryOperator *instruction, Node *node); |
| 72 | + void fillIn(const llvm::BinaryOperator *instruction, Node *node); |
| 73 | + void fillIn(const llvm::AllocaInst *instruction, Node *node); |
| 74 | + void fillIn(const llvm::LoadInst *instruction, Node *node); |
| 75 | + void fillIn(const llvm::StoreInst *instruction, Node *node); |
| 76 | + void fillIn(const llvm::GetElementPtrInst *instruction, Node *node); |
| 77 | + void fillIn(const llvm::FenceInst *instruction, Node *node); |
| 78 | + void fillIn(const llvm::AtomicCmpXchgInst *instruction, Node *node); |
| 79 | + void fillIn(const llvm::AtomicRMWInst *instruction, Node *node); |
| 80 | + void fillIn(const llvm::TruncInst *instruction, Node *node); |
| 81 | + void fillIn(const llvm::ZExtInst *instruction, Node *node); |
| 82 | + void fillIn(const llvm::SExtInst *instruction, Node *node); |
| 83 | + void fillIn(const llvm::FPToUIInst *instruction, Node *node); |
| 84 | + void fillIn(const llvm::FPToSIInst *instruction, Node *node); |
| 85 | + void fillIn(const llvm::UIToFPInst *instruction, Node *node); |
| 86 | + void fillIn(const llvm::SIToFPInst *instruction, Node *node); |
| 87 | + void fillIn(const llvm::FPTruncInst *instruction, Node *node); |
| 88 | + void fillIn(const llvm::FPExtInst *instruction, Node *node); |
| 89 | + void fillIn(const llvm::PtrToIntInst *instruction, Node *node); |
| 90 | + void fillIn(const llvm::IntToPtrInst *instruction, Node *node); |
| 91 | + void fillIn(const llvm::BitCastInst *instruction, Node *node); |
| 92 | + void fillIn(const llvm::AddrSpaceCastInst *instruction, Node *node); |
| 93 | + void fillIn(const llvm::CleanupPadInst *instruction, Node *node); |
| 94 | + void fillIn(const llvm::CatchPadInst *instruction, Node *node); |
| 95 | + void fillIn(const llvm::ICmpInst *instruction, Node *node); |
| 96 | + void fillIn(const llvm::FCmpInst *instruction, Node *node); |
| 97 | + void fillIn(const llvm::PHINode *instruction, Node *node); |
| 98 | + void fillIn(const llvm::CallInst *instruction, Node *node); |
| 99 | + void fillIn(const llvm::SelectInst *instruction, Node *node); |
| 100 | + void fillIn(const llvm::VAArgInst *instruction, Node *node); |
| 101 | + void fillIn(const llvm::ExtractElementInst *instruction, Node *node); |
| 102 | + void fillIn(const llvm::InsertElementInst *instruction, Node *node); |
| 103 | + void fillIn(const llvm::ShuffleVectorInst *instruction, Node *node); |
| 104 | + void fillIn(const llvm::ExtractValueInst *instruction, Node *node); |
| 105 | + void fillIn(const llvm::InsertValueInst *instruction, Node *node); |
| 106 | + void fillIn(const llvm::LandingPadInst *instruction, Node *node); |
| 107 | +}; |
| 108 | + |
| 109 | +} // namespace llvm2graphml |
0 commit comments