xref: /freebsd/contrib/llvm-project/llvm/lib/MC/MCSPIRVStreamer.cpp (revision 06c3fb2749bda94cb5201f81ffdb8fa6c3161b2e)
181ad6265SDimitry Andric //===- lib/MC/MCSPIRVStreamer.cpp - SPIR-V Object Output ------*- C++ -*---===//
281ad6265SDimitry Andric //
381ad6265SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
481ad6265SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
581ad6265SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
681ad6265SDimitry Andric //
781ad6265SDimitry Andric //===----------------------------------------------------------------------===//
881ad6265SDimitry Andric //
981ad6265SDimitry Andric // This file assembles .s files and emits SPIR-V .o object files.
1081ad6265SDimitry Andric //
1181ad6265SDimitry Andric //===----------------------------------------------------------------------===//
1281ad6265SDimitry Andric 
1381ad6265SDimitry Andric #include "llvm/MC/MCSPIRVStreamer.h"
1481ad6265SDimitry Andric #include "llvm/MC/MCAssembler.h"
1581ad6265SDimitry Andric #include "llvm/MC/TargetRegistry.h"
1681ad6265SDimitry Andric 
1781ad6265SDimitry Andric using namespace llvm;
1881ad6265SDimitry Andric 
1981ad6265SDimitry Andric void MCSPIRVStreamer::emitInstToData(const MCInst &Inst,
2081ad6265SDimitry Andric                                      const MCSubtargetInfo &STI) {
2181ad6265SDimitry Andric   MCAssembler &Assembler = getAssembler();
2281ad6265SDimitry Andric   SmallVector<MCFixup, 0> Fixups;
2381ad6265SDimitry Andric   SmallString<256> Code;
24*06c3fb27SDimitry Andric   Assembler.getEmitter().encodeInstruction(Inst, Code, Fixups, STI);
2581ad6265SDimitry Andric 
2681ad6265SDimitry Andric   // Append the encoded instruction to the current data fragment (or create a
2781ad6265SDimitry Andric   // new such fragment if the current fragment is not a data fragment).
2881ad6265SDimitry Andric   MCDataFragment *DF = getOrCreateDataFragment();
2981ad6265SDimitry Andric 
3081ad6265SDimitry Andric   DF->setHasInstructions(STI);
3181ad6265SDimitry Andric   DF->getContents().append(Code.begin(), Code.end());
3281ad6265SDimitry Andric }
3381ad6265SDimitry Andric 
3481ad6265SDimitry Andric MCStreamer *llvm::createSPIRVStreamer(MCContext &Context,
3581ad6265SDimitry Andric                                       std::unique_ptr<MCAsmBackend> &&MAB,
3681ad6265SDimitry Andric                                       std::unique_ptr<MCObjectWriter> &&OW,
3781ad6265SDimitry Andric                                       std::unique_ptr<MCCodeEmitter> &&CE,
3881ad6265SDimitry Andric                                       bool RelaxAll) {
3981ad6265SDimitry Andric   MCSPIRVStreamer *S = new MCSPIRVStreamer(Context, std::move(MAB),
4081ad6265SDimitry Andric                                            std::move(OW), std::move(CE));
4181ad6265SDimitry Andric   if (RelaxAll)
4281ad6265SDimitry Andric     S->getAssembler().setRelaxAll(true);
4381ad6265SDimitry Andric   return S;
4481ad6265SDimitry Andric }
45