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/MCObjectFileInfo.h" 19 20 using namespace llvm; 21 22 void SystemZTargetStreamer::emitConstantPools() { 23 // Emit EXRL target instructions. 24 if (EXRLTargets2Sym.empty()) 25 return; 26 // Switch to the .text section. 27 const MCObjectFileInfo &OFI = *Streamer.getContext().getObjectFileInfo(); 28 Streamer.switchSection(OFI.getTextSection()); 29 for (auto &I : EXRLTargets2Sym) { 30 Streamer.emitLabel(I.second); 31 const MCInstSTIPair &MCI_STI = I.first; 32 Streamer.emitInstruction(MCI_STI.first, *MCI_STI.second); 33 } 34 EXRLTargets2Sym.clear(); 35 } 36 37 SystemZHLASMAsmStreamer &SystemZTargetHLASMStreamer::getHLASMStreamer() { 38 return static_cast<SystemZHLASMAsmStreamer &>(getStreamer()); 39 } 40 41 void SystemZTargetHLASMStreamer::emitExtern(StringRef Sym) { 42 getStreamer().emitRawText(Twine(" EXTRN ") + Twine(Sym)); 43 } 44 45 void SystemZTargetHLASMStreamer::emitEnd() { getHLASMStreamer().emitEnd(); } 46 47 // HLASM statements can only perform a single operation at a time 48 const MCExpr *SystemZTargetHLASMStreamer::createWordDiffExpr( 49 MCContext &Ctx, const MCSymbol *Hi, const MCSymbol *Lo) { 50 assert(Hi && Lo && "Symbols required to calculate expression"); 51 MCSymbol *Temp = Ctx.createTempSymbol(); 52 OS << Temp->getName() << " EQU "; 53 const MCBinaryExpr *TempExpr = MCBinaryExpr::createSub( 54 MCSymbolRefExpr::create(Hi, Ctx), MCSymbolRefExpr::create(Lo, Ctx), Ctx); 55 Ctx.getAsmInfo()->printExpr(OS, *TempExpr); 56 OS << "\n"; 57 return MCBinaryExpr::createLShr(MCSymbolRefExpr::create(Temp, Ctx), 58 MCConstantExpr::create(1, Ctx), Ctx); 59 } 60 61 const MCExpr *SystemZTargetGOFFStreamer::createWordDiffExpr( 62 MCContext &Ctx, const MCSymbol *Hi, const MCSymbol *Lo) { 63 assert(Hi && Lo && "Symbols required to calculate expression"); 64 return MCBinaryExpr::createLShr( 65 MCBinaryExpr::createSub(MCSymbolRefExpr::create(Hi, Ctx), 66 MCSymbolRefExpr::create(Lo, Ctx), Ctx), 67 MCConstantExpr::create(1, Ctx), Ctx); 68 } 69