1*81ad6265SDimitry Andric //===- lib/MC/MCSPIRVStreamer.cpp - SPIR-V Object Output ------*- C++ -*---===// 2*81ad6265SDimitry Andric // 3*81ad6265SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*81ad6265SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5*81ad6265SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*81ad6265SDimitry Andric // 7*81ad6265SDimitry Andric //===----------------------------------------------------------------------===// 8*81ad6265SDimitry Andric // 9*81ad6265SDimitry Andric // This file assembles .s files and emits SPIR-V .o object files. 10*81ad6265SDimitry Andric // 11*81ad6265SDimitry Andric //===----------------------------------------------------------------------===// 12*81ad6265SDimitry Andric 13*81ad6265SDimitry Andric #include "llvm/MC/MCSPIRVStreamer.h" 14*81ad6265SDimitry Andric #include "llvm/MC/MCAssembler.h" 15*81ad6265SDimitry Andric #include "llvm/MC/TargetRegistry.h" 16*81ad6265SDimitry Andric 17*81ad6265SDimitry Andric using namespace llvm; 18*81ad6265SDimitry Andric 19*81ad6265SDimitry Andric void MCSPIRVStreamer::emitInstToData(const MCInst &Inst, 20*81ad6265SDimitry Andric const MCSubtargetInfo &STI) { 21*81ad6265SDimitry Andric MCAssembler &Assembler = getAssembler(); 22*81ad6265SDimitry Andric SmallVector<MCFixup, 0> Fixups; 23*81ad6265SDimitry Andric SmallString<256> Code; 24*81ad6265SDimitry Andric raw_svector_ostream VecOS(Code); 25*81ad6265SDimitry Andric Assembler.getEmitter().encodeInstruction(Inst, VecOS, Fixups, STI); 26*81ad6265SDimitry Andric 27*81ad6265SDimitry Andric // Append the encoded instruction to the current data fragment (or create a 28*81ad6265SDimitry Andric // new such fragment if the current fragment is not a data fragment). 29*81ad6265SDimitry Andric MCDataFragment *DF = getOrCreateDataFragment(); 30*81ad6265SDimitry Andric 31*81ad6265SDimitry Andric DF->setHasInstructions(STI); 32*81ad6265SDimitry Andric DF->getContents().append(Code.begin(), Code.end()); 33*81ad6265SDimitry Andric } 34*81ad6265SDimitry Andric 35*81ad6265SDimitry Andric MCStreamer *llvm::createSPIRVStreamer(MCContext &Context, 36*81ad6265SDimitry Andric std::unique_ptr<MCAsmBackend> &&MAB, 37*81ad6265SDimitry Andric std::unique_ptr<MCObjectWriter> &&OW, 38*81ad6265SDimitry Andric std::unique_ptr<MCCodeEmitter> &&CE, 39*81ad6265SDimitry Andric bool RelaxAll) { 40*81ad6265SDimitry Andric MCSPIRVStreamer *S = new MCSPIRVStreamer(Context, std::move(MAB), 41*81ad6265SDimitry Andric std::move(OW), std::move(CE)); 42*81ad6265SDimitry Andric if (RelaxAll) 43*81ad6265SDimitry Andric S->getAssembler().setRelaxAll(true); 44*81ad6265SDimitry Andric return S; 45*81ad6265SDimitry Andric } 46