Emitter = this->MCE.get();
SmallString<256> Code;
SmallVector<MCFixup, 4> Fixups;
- raw_svector_ostream VecOS(Code);
- Emitter->encodeInstruction(Inst, VecOS, Fixups, *STI);
+ Emitter->encodeInstruction(Inst, Code, Fixups, *STI);
return Code.size();
}
SmallString<256> Code;
SmallVector<MCFixup, 4> Fixups;
- raw_svector_ostream VecOS(Code);
- MCE->encodeInstruction(Inst, VecOS, Fixups, *STI);
+ MCE->encodeInstruction(Inst, Code, Fixups, *STI);
auto OutputSequence = ArrayRef<uint8_t>((uint8_t *)Code.data(), Code.size());
if (InputSequence != OutputSequence) {
if (opts::Verbosity > 1) {
// Emit the instruction using temp emitter and generate relocations.
SmallString<256> Code;
SmallVector<MCFixup, 4> Fixups;
- raw_svector_ostream VecOS(Code);
- Emitter.MCE->encodeInstruction(Instruction, VecOS, Fixups, *BC.STI);
+ Emitter.MCE->encodeInstruction(Instruction, Code, Fixups, *BC.STI);
// Create relocation for every fixup.
for (const MCFixup &Fixup : Fixups) {
protected: // Can only create subclasses.
MCCodeEmitter();
+ /// EncodeInstruction - Encode the given \p Inst to bytes on the output stream
+ /// \p OS. Allows for an implementation of encodeInstruction that uses streams
+ /// instead of a SmallVector.
+ virtual void encodeInstruction(const MCInst &Inst, raw_ostream &OS,
+ SmallVectorImpl<MCFixup> &Fixups,
+ const MCSubtargetInfo &STI) const {}
+
public:
MCCodeEmitter(const MCCodeEmitter &) = delete;
MCCodeEmitter &operator=(const MCCodeEmitter &) = delete;
/// \param OS output stream.
virtual void emitPrefix(const MCInst &Inst, raw_ostream &OS,
const MCSubtargetInfo &STI) const {}
- /// EncodeInstruction - Encode the given \p Inst to bytes on the output
- /// stream \p OS.
- virtual void encodeInstruction(const MCInst &Inst, raw_ostream &OS,
+ /// EncodeInstruction - Encode the given \p Inst to bytes and append to \p CB.
+ virtual void encodeInstruction(const MCInst &Inst, SmallVectorImpl<char> &CB,
SmallVectorImpl<MCFixup> &Fixups,
- const MCSubtargetInfo &STI) const = 0;
+ const MCSubtargetInfo &STI) const;
};
} // end namespace llvm
#include "llvm/MC/MCCodeEmitter.h"
#include "llvm/MC/MCInst.h"
#include "llvm/MC/MCSubtargetInfo.h"
-#include "llvm/Support/raw_ostream.h"
namespace llvm {
namespace mca {
const MCCodeEmitter &MCE;
SmallString<256> Code;
- raw_svector_ostream VecOS;
ArrayRef<MCInst> Sequence;
// An EncodingInfo pair stores <base, length> information. Base (i.e. first)
public:
CodeEmitter(const MCSubtargetInfo &ST, const MCAsmBackend &AB,
const MCCodeEmitter &CE, ArrayRef<MCInst> S)
- : STI(ST), MAB(AB), MCE(CE), VecOS(Code), Sequence(S),
- Encodings(S.size()) {}
+ : STI(ST), MAB(AB), MCE(CE), Sequence(S), Encodings(S.size()) {}
StringRef getEncoding(unsigned MCID) {
EncodingInfo EI = getOrCreateEncodingInfo(MCID);
raw_ostream &OS = getCommentOS();
SmallString<256> Code;
SmallVector<MCFixup, 4> Fixups;
- raw_svector_ostream VecOS(Code);
// If we have no code emitter, don't emit code.
if (!getAssembler().getEmitterPtr())
return;
- getAssembler().getEmitter().encodeInstruction(Inst, VecOS, Fixups, STI);
+ getAssembler().getEmitter().encodeInstruction(Inst, Code, Fixups, STI);
// If we are showing fixups, create symbolic markers in the encoded
// representation. We do this by making a per-bit map to the fixup item index,
// probably do so more efficiently in many cases.
SmallVector<MCFixup, 4> Fixups;
SmallString<256> Code;
- raw_svector_ostream VecOS(Code);
- getEmitter().encodeInstruction(Relaxed, VecOS, Fixups, *F.getSubtargetInfo());
+ getEmitter().encodeInstruction(Relaxed, Code, Fixups, *F.getSubtargetInfo());
// Update the fragment.
F.setInst(Relaxed);
//===----------------------------------------------------------------------===//
#include "llvm/MC/MCCodeEmitter.h"
+#include "llvm/Support/raw_ostream.h"
using namespace llvm;
MCCodeEmitter::MCCodeEmitter() = default;
MCCodeEmitter::~MCCodeEmitter() = default;
+
+void MCCodeEmitter::encodeInstruction(const MCInst &Inst,
+ SmallVectorImpl<char> &CB,
+ SmallVectorImpl<MCFixup> &Fixups,
+ const MCSubtargetInfo &STI) const {
+ raw_svector_ostream OS(CB);
+ encodeInstruction(Inst, OS, Fixups, STI);
+}
MCAssembler &Assembler = getAssembler();
SmallVector<MCFixup, 4> Fixups;
SmallString<256> Code;
- raw_svector_ostream VecOS(Code);
- Assembler.getEmitter().encodeInstruction(Inst, VecOS, Fixups, STI);
+ Assembler.getEmitter().encodeInstruction(Inst, Code, Fixups, STI);
for (auto &Fixup : Fixups)
fixSymbolsInTLSFixups(Fixup.getValue());
#include "llvm/MC/TargetRegistry.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/raw_ostream.h"
#include <cassert>
#include <vector>
SmallVector<MCFixup, 4> Fixups;
SmallString<256> Code;
- raw_svector_ostream VecOS(Code);
- getAssembler().getEmitter().encodeInstruction(Inst, VecOS, Fixups, STI);
+ getAssembler().getEmitter().encodeInstruction(Inst, Code, Fixups, STI);
// Add the fixups and data.
for (MCFixup &Fixup : Fixups) {
insert(IF);
SmallString<128> Code;
- raw_svector_ostream VecOS(Code);
- getAssembler().getEmitter().encodeInstruction(Inst, VecOS, IF->getFixups(),
+ getAssembler().getEmitter().encodeInstruction(Inst, Code, IF->getFixups(),
STI);
IF->getContents().append(Code.begin(), Code.end());
}
MCAssembler &Assembler = getAssembler();
SmallVector<MCFixup, 0> Fixups;
SmallString<256> Code;
- raw_svector_ostream VecOS(Code);
- Assembler.getEmitter().encodeInstruction(Inst, VecOS, Fixups, STI);
+ Assembler.getEmitter().encodeInstruction(Inst, Code, Fixups, STI);
// Append the encoded instruction to the current data fragment (or create a
// new such fragment if the current fragment is not a data fragment).
MCAssembler &Assembler = getAssembler();
SmallVector<MCFixup, 4> Fixups;
SmallString<256> Code;
- raw_svector_ostream VecOS(Code);
- Assembler.getEmitter().encodeInstruction(Inst, VecOS, Fixups, STI);
+ Assembler.getEmitter().encodeInstruction(Inst, Code, Fixups, STI);
for (auto &Fixup : Fixups)
fixSymbolsInTLSFixups(Fixup.getValue());
SmallVector<MCFixup, 4> Fixups;
SmallString<256> Code;
- raw_svector_ostream VecOS(Code);
- getAssembler().getEmitter().encodeInstruction(Inst, VecOS, Fixups, STI);
+ getAssembler().getEmitter().encodeInstruction(Inst, Code, Fixups, STI);
// Add the fixups and data.
for (unsigned i = 0, e = Fixups.size(); i != e; ++i) {
MCAssembler &Assembler = getAssembler();
SmallVector<MCFixup, 4> Fixups;
SmallString<256> Code;
- raw_svector_ostream VecOS(Code);
- Assembler.getEmitter().encodeInstruction(Inst, VecOS, Fixups, STI);
+ Assembler.getEmitter().encodeInstruction(Inst, Code, Fixups, STI);
// Add the fixups and data.
MCDataFragment *DF = getOrCreateDataFragment(&STI);
MAB.relaxInstruction(Relaxed, STI);
EI.first = Code.size();
- MCE.encodeInstruction(Relaxed, VecOS, Fixups, STI);
+ MCE.encodeInstruction(Relaxed, Code, Fixups, STI);
EI.second = Code.size() - EI.first;
return EI;
}
(!STI.hasOffset3fBug() || !MI->isBranch())) {
SmallVector<MCFixup, 4> Fixups;
SmallVector<char, 16> CodeBytes;
- raw_svector_ostream CodeStream(CodeBytes);
std::unique_ptr<MCCodeEmitter> InstEmitter(createSIMCCodeEmitter(
*STI.getInstrInfo(), OutContext));
- InstEmitter->encodeInstruction(TmpInst, CodeStream, Fixups, STI);
+ InstEmitter->encodeInstruction(TmpInst, CodeBytes, Fixups, STI);
assert(CodeBytes.size() == STI.getInstrInfo()->getInstSizeInBytes(*MI));
}
// Disassemble instruction/operands to hex representation.
SmallVector<MCFixup, 4> Fixups;
SmallVector<char, 16> CodeBytes;
- raw_svector_ostream CodeStream(CodeBytes);
DumpCodeInstEmitter->encodeInstruction(
- TmpInst, CodeStream, Fixups, MF->getSubtarget<MCSubtargetInfo>());
+ TmpInst, CodeBytes, Fixups, MF->getSubtarget<MCSubtargetInfo>());
HexLines.resize(HexLines.size() + 1);
std::string &HexLine = HexLines.back();
raw_string_ostream HexStream(HexLine);
MCInst &HMB) const {
SmallVector<MCFixup, 4> Fixups;
SmallString<256> Code;
- raw_svector_ostream VecOS(Code);
- E.encodeInstruction(HMB, VecOS, Fixups, *RF.getSubtargetInfo());
+ E.encodeInstruction(HMB, Code, Fixups, *RF.getSubtargetInfo());
// Update the fragment.
RF.setInst(HMB);
SmallVector<MCFixup, 4> Fixups;
SmallString<15> Code;
- raw_svector_ostream VecOS(Code);
- Emitter.encodeInstruction(Relaxed, VecOS, Fixups, *RF.getSubtargetInfo());
+ Emitter.encodeInstruction(Relaxed, Code, Fixups, *RF.getSubtargetInfo());
const unsigned OldSize = RF.getContents().size();
const unsigned NewSize = Code.size();
assert(NewSize >= OldSize && "size decrease during relaxation?");
if (InShadow) {
SmallString<256> Code;
SmallVector<MCFixup, 4> Fixups;
- raw_svector_ostream VecOS(Code);
- CodeEmitter->encodeInstruction(Inst, VecOS, Fixups, STI);
+ CodeEmitter->encodeInstruction(Inst, Code, Fixups, STI);
CurrentShadowSize += Code.size();
if (CurrentShadowSize >= RequiredShadowSize)
InShadow = false; // The shadow is big enough. Stop counting.
SmallString<256> Code;
if (!EmptyInst) {
SmallVector<MCFixup, 4> Fixups;
- raw_svector_ostream VecOS(Code);
- CodeEmitter->encodeInstruction(MCI, VecOS, Fixups, getSubtargetInfo());
+ CodeEmitter->encodeInstruction(MCI, Code, Fixups, getSubtargetInfo());
}
if (Code.size() < MinSize) {
#include "llvm/MC/MCFixup.h"
#include "llvm/MC/MCObjectFileInfo.h"
#include "llvm/MC/TargetRegistry.h"
-#include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Target/TargetOptions.h"
#include "llvm/TargetParser/Host.h"
*TheTargetMachine->getMCInstrInfo(), Context));
assert(CodeEmitter && "unable to create code emitter");
SmallVector<char, 16> Tmp;
- raw_svector_ostream OS(Tmp);
SmallVector<MCFixup, 4> Fixups;
- CodeEmitter->encodeInstruction(Inst, OS, Fixups,
+ CodeEmitter->encodeInstruction(Inst, Tmp, Fixups,
*TheTargetMachine->getMCSubtargetInfo());
return Tmp.size() > 0;
}