MCSPIRVStreamer.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. //===- lib/MC/MCSPIRVStreamer.cpp - SPIR-V Object Output ------*- C++ -*---===//
  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. // This file assembles .s files and emits SPIR-V .o object files.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #include "llvm/MC/MCSPIRVStreamer.h"
  13. #include "llvm/MC/MCAssembler.h"
  14. #include "llvm/MC/TargetRegistry.h"
  15. using namespace llvm;
  16. void MCSPIRVStreamer::emitInstToData(const MCInst &Inst,
  17. const MCSubtargetInfo &STI) {
  18. MCAssembler &Assembler = getAssembler();
  19. SmallVector<MCFixup, 0> Fixups;
  20. SmallString<256> Code;
  21. raw_svector_ostream VecOS(Code);
  22. Assembler.getEmitter().encodeInstruction(Inst, VecOS, Fixups, STI);
  23. // Append the encoded instruction to the current data fragment (or create a
  24. // new such fragment if the current fragment is not a data fragment).
  25. MCDataFragment *DF = getOrCreateDataFragment();
  26. DF->setHasInstructions(STI);
  27. DF->getContents().append(Code.begin(), Code.end());
  28. }
  29. MCStreamer *llvm::createSPIRVStreamer(MCContext &Context,
  30. std::unique_ptr<MCAsmBackend> &&MAB,
  31. std::unique_ptr<MCObjectWriter> &&OW,
  32. std::unique_ptr<MCCodeEmitter> &&CE,
  33. bool RelaxAll) {
  34. MCSPIRVStreamer *S = new MCSPIRVStreamer(Context, std::move(MAB),
  35. std::move(OW), std::move(CE));
  36. if (RelaxAll)
  37. S->getAssembler().setRelaxAll(true);
  38. return S;
  39. }