16c69427eSIlia Diachkov //===- lib/MC/MCSPIRVStreamer.cpp - SPIR-V Object Output ------*- C++ -*---===// 26c69427eSIlia Diachkov // 36c69427eSIlia Diachkov // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 46c69427eSIlia Diachkov // See https://llvm.org/LICENSE.txt for license information. 56c69427eSIlia Diachkov // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 66c69427eSIlia Diachkov // 76c69427eSIlia Diachkov //===----------------------------------------------------------------------===// 86c69427eSIlia Diachkov // 96c69427eSIlia Diachkov // This file assembles .s files and emits SPIR-V .o object files. 106c69427eSIlia Diachkov // 116c69427eSIlia Diachkov //===----------------------------------------------------------------------===// 126c69427eSIlia Diachkov 136c69427eSIlia Diachkov #include "llvm/MC/MCSPIRVStreamer.h" 146c69427eSIlia Diachkov #include "llvm/MC/MCAssembler.h" 156c69427eSIlia Diachkov #include "llvm/MC/TargetRegistry.h" 166c69427eSIlia Diachkov 176c69427eSIlia Diachkov using namespace llvm; 186c69427eSIlia Diachkov 196c69427eSIlia Diachkov void MCSPIRVStreamer::emitInstToData(const MCInst &Inst, 206c69427eSIlia Diachkov const MCSubtargetInfo &STI) { 216c69427eSIlia Diachkov MCAssembler &Assembler = getAssembler(); 226c69427eSIlia Diachkov SmallVector<MCFixup, 0> Fixups; 236c69427eSIlia Diachkov SmallString<256> Code; 240c049ea6SAlexis Engelke Assembler.getEmitter().encodeInstruction(Inst, Code, Fixups, STI); 256c69427eSIlia Diachkov 266c69427eSIlia Diachkov // Append the encoded instruction to the current data fragment (or create a 276c69427eSIlia Diachkov // new such fragment if the current fragment is not a data fragment). 286c69427eSIlia Diachkov MCDataFragment *DF = getOrCreateDataFragment(); 296c69427eSIlia Diachkov 306c69427eSIlia Diachkov DF->setHasInstructions(STI); 31*3fa5b527SFangrui Song DF->appendContents(Code); 326c69427eSIlia Diachkov } 336c69427eSIlia Diachkov 346c69427eSIlia Diachkov MCStreamer *llvm::createSPIRVStreamer(MCContext &Context, 356c69427eSIlia Diachkov std::unique_ptr<MCAsmBackend> &&MAB, 366c69427eSIlia Diachkov std::unique_ptr<MCObjectWriter> &&OW, 374e340356SFangrui Song std::unique_ptr<MCCodeEmitter> &&CE) { 386c69427eSIlia Diachkov MCSPIRVStreamer *S = new MCSPIRVStreamer(Context, std::move(MAB), 396c69427eSIlia Diachkov std::move(OW), std::move(CE)); 406c69427eSIlia Diachkov return S; 416c69427eSIlia Diachkov } 42