| 1 | //==-- SystemZTargetStreamer.cpp - SystemZ Target Streamer Methods ----------=// |
| 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-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | /// |
| 9 | /// \file |
| 10 | /// This file defines SystemZ-specific target streamer classes. |
| 11 | /// These are for implementing support for target-specific assembly directives. |
| 12 | /// |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "SystemZTargetStreamer.h" |
| 16 | #include "SystemZHLASMAsmStreamer.h" |
| 17 | #include "llvm/MC/MCAsmInfo.h" |
| 18 | #include "llvm/MC/MCGOFFStreamer.h" |
| 19 | #include "llvm/MC/MCObjectFileInfo.h" |
| 20 | |
| 21 | using namespace llvm; |
| 22 | |
| 23 | void SystemZTargetStreamer::emitConstantPools() { |
| 24 | // Emit EXRL target instructions. |
| 25 | if (EXRLTargets2Sym.empty()) |
| 26 | return; |
| 27 | // Switch to the .text section. |
| 28 | const MCObjectFileInfo &OFI = *Streamer.getContext().getObjectFileInfo(); |
| 29 | Streamer.switchSection(Section: OFI.getTextSection()); |
| 30 | for (auto &I : EXRLTargets2Sym) { |
| 31 | Streamer.emitLabel(Symbol: I.second); |
| 32 | const MCInstSTIPair &MCI_STI = I.first; |
| 33 | Streamer.emitInstruction(Inst: MCI_STI.first, STI: *MCI_STI.second); |
| 34 | } |
| 35 | EXRLTargets2Sym.clear(); |
| 36 | } |
| 37 | |
| 38 | SystemZHLASMAsmStreamer &SystemZTargetHLASMStreamer::getHLASMStreamer() { |
| 39 | return static_cast<SystemZHLASMAsmStreamer &>(getStreamer()); |
| 40 | } |
| 41 | |
| 42 | // HLASM statements can only perform a single operation at a time |
| 43 | const MCExpr *SystemZTargetHLASMStreamer::createWordDiffExpr( |
| 44 | MCContext &Ctx, const MCSymbol *Hi, const MCSymbol *Lo) { |
| 45 | assert(Hi && Lo && "Symbols required to calculate expression" ); |
| 46 | MCSymbol *Temp = Ctx.createTempSymbol(); |
| 47 | OS << Temp->getName() << " EQU " ; |
| 48 | const MCBinaryExpr *TempExpr = MCBinaryExpr::createSub( |
| 49 | LHS: MCSymbolRefExpr::create(Symbol: Hi, Ctx), RHS: MCSymbolRefExpr::create(Symbol: Lo, Ctx), Ctx); |
| 50 | Ctx.getAsmInfo()->printExpr(OS, *TempExpr); |
| 51 | OS << "\n" ; |
| 52 | return MCBinaryExpr::createLShr(LHS: MCSymbolRefExpr::create(Symbol: Temp, Ctx), |
| 53 | RHS: MCConstantExpr::create(Value: 1, Ctx), Ctx); |
| 54 | } |
| 55 | |
| 56 | const MCExpr *SystemZTargetGOFFStreamer::createWordDiffExpr( |
| 57 | MCContext &Ctx, const MCSymbol *Hi, const MCSymbol *Lo) { |
| 58 | assert(Hi && Lo && "Symbols required to calculate expression" ); |
| 59 | return MCBinaryExpr::createLShr( |
| 60 | LHS: MCBinaryExpr::createSub(LHS: MCSymbolRefExpr::create(Symbol: Hi, Ctx), |
| 61 | RHS: MCSymbolRefExpr::create(Symbol: Lo, Ctx), Ctx), |
| 62 | RHS: MCConstantExpr::create(Value: 1, Ctx), Ctx); |
| 63 | } |
| 64 | |