MCInstrAnalysis.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. //===-- llvm/MC/MCInstrAnalysis.h - InstrDesc target hooks ------*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file defines the MCInstrAnalysis class which the MCTargetDescs can
  11. // derive from to give additional information to MC.
  12. //
  13. //===----------------------------------------------------------------------===//
  14. #ifndef LLVM_MC_MCINSTRANALYSIS_H
  15. #define LLVM_MC_MCINSTRANALYSIS_H
  16. #include "llvm/MC/MCInst.h"
  17. #include "llvm/MC/MCInstrDesc.h"
  18. #include "llvm/MC/MCInstrInfo.h"
  19. namespace llvm {
  20. class MCInstrAnalysis {
  21. protected:
  22. friend class Target;
  23. const MCInstrInfo *Info;
  24. public:
  25. MCInstrAnalysis(const MCInstrInfo *Info) : Info(Info) {}
  26. virtual ~MCInstrAnalysis() {}
  27. virtual bool isBranch(const MCInst &Inst) const {
  28. return Info->get(Inst.getOpcode()).isBranch();
  29. }
  30. virtual bool isConditionalBranch(const MCInst &Inst) const {
  31. return Info->get(Inst.getOpcode()).isConditionalBranch();
  32. }
  33. virtual bool isUnconditionalBranch(const MCInst &Inst) const {
  34. return Info->get(Inst.getOpcode()).isUnconditionalBranch();
  35. }
  36. virtual bool isIndirectBranch(const MCInst &Inst) const {
  37. return Info->get(Inst.getOpcode()).isIndirectBranch();
  38. }
  39. virtual bool isCall(const MCInst &Inst) const {
  40. return Info->get(Inst.getOpcode()).isCall();
  41. }
  42. virtual bool isReturn(const MCInst &Inst) const {
  43. return Info->get(Inst.getOpcode()).isReturn();
  44. }
  45. virtual bool isTerminator(const MCInst &Inst) const {
  46. return Info->get(Inst.getOpcode()).isTerminator();
  47. }
  48. /// \brief Given a branch instruction try to get the address the branch
  49. /// targets. Return true on success, and the address in Target.
  50. virtual bool
  51. evaluateBranch(const MCInst &Inst, uint64_t Addr, uint64_t Size,
  52. uint64_t &Target) const;
  53. };
  54. } // End llvm namespace
  55. #endif