brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.9 KiB · 3fc09bc Raw
109 lines · c
1//=- SystemZTargetStreamer.h - SystemZ Target Streamer ----------*- C++ -*-===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZTARGETSTREAMER_H10#define LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZTARGETSTREAMER_H11 12#include "llvm/ADT/StringRef.h"13#include "llvm/MC/MCContext.h"14#include "llvm/MC/MCExpr.h"15#include "llvm/MC/MCInst.h"16#include "llvm/MC/MCStreamer.h"17#include "llvm/MC/MCSymbol.h"18#include "llvm/Support/FormattedStream.h"19#include <map>20#include <utility>21 22namespace llvm {23class SystemZHLASMAsmStreamer;24 25class SystemZTargetStreamer : public MCTargetStreamer {26public:27  SystemZTargetStreamer(MCStreamer &S) : MCTargetStreamer(S) {}28 29  typedef std::pair<MCInst, const MCSubtargetInfo *> MCInstSTIPair;30  struct CmpMCInst {31    bool operator()(const MCInstSTIPair &MCI_STI_A,32                    const MCInstSTIPair &MCI_STI_B) const {33      if (MCI_STI_A.second != MCI_STI_B.second)34        return uintptr_t(MCI_STI_A.second) < uintptr_t(MCI_STI_B.second);35      const MCInst &A = MCI_STI_A.first;36      const MCInst &B = MCI_STI_B.first;37      assert(A.getNumOperands() == B.getNumOperands() &&38             A.getNumOperands() == 5 && A.getOperand(2).getImm() == 1 &&39             B.getOperand(2).getImm() == 1 && "Unexpected EXRL target MCInst");40      if (A.getOpcode() != B.getOpcode())41        return A.getOpcode() < B.getOpcode();42      if (A.getOperand(0).getReg() != B.getOperand(0).getReg())43        return A.getOperand(0).getReg() < B.getOperand(0).getReg();44      if (A.getOperand(1).getImm() != B.getOperand(1).getImm())45        return A.getOperand(1).getImm() < B.getOperand(1).getImm();46      if (A.getOperand(3).getReg() != B.getOperand(3).getReg())47        return A.getOperand(3).getReg() < B.getOperand(3).getReg();48      if (A.getOperand(4).getImm() != B.getOperand(4).getImm())49        return A.getOperand(4).getImm() < B.getOperand(4).getImm();50      return false;51    }52  };53  typedef std::map<MCInstSTIPair, MCSymbol *, CmpMCInst> EXRLT2SymMap;54  EXRLT2SymMap EXRLTargets2Sym;55 56  void emitConstantPools() override;57 58  virtual void emitMachine(StringRef CPUOrCommand) {};59 60  virtual void emitExtern(StringRef Str) {};61  virtual void emitEnd() {};62 63  virtual const MCExpr *createWordDiffExpr(MCContext &Ctx, const MCSymbol *Hi,64                                           const MCSymbol *Lo) {65    return nullptr;66  }67};68 69class SystemZTargetGOFFStreamer : public SystemZTargetStreamer {70public:71  SystemZTargetGOFFStreamer(MCStreamer &S) : SystemZTargetStreamer(S) {}72  const MCExpr *createWordDiffExpr(MCContext &Ctx, const MCSymbol *Hi,73                                   const MCSymbol *Lo) override;74};75 76class SystemZTargetHLASMStreamer : public SystemZTargetStreamer {77  formatted_raw_ostream &OS;78 79public:80  SystemZTargetHLASMStreamer(MCStreamer &S, formatted_raw_ostream &OS)81      : SystemZTargetStreamer(S), OS(OS) {}82  SystemZHLASMAsmStreamer &getHLASMStreamer();83  void emitExtern(StringRef Sym) override;84  void emitEnd() override;85  const MCExpr *createWordDiffExpr(MCContext &Ctx, const MCSymbol *Hi,86                                   const MCSymbol *Lo) override;87};88 89class SystemZTargetELFStreamer : public SystemZTargetStreamer {90public:91  SystemZTargetELFStreamer(MCStreamer &S) : SystemZTargetStreamer(S) {}92  void emitMachine(StringRef CPUOrCommand) override {}93};94 95class SystemZTargetGNUStreamer : public SystemZTargetStreamer {96  formatted_raw_ostream &OS;97 98public:99  SystemZTargetGNUStreamer(MCStreamer &S, formatted_raw_ostream &OS)100      : SystemZTargetStreamer(S), OS(OS) {}101  void emitMachine(StringRef CPUOrCommand) override {102    OS << "\t.machine " << CPUOrCommand << "\n";103  }104};105 106} // end namespace llvm107 108#endif // LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZTARGETSTREAMER_H109