本文整理汇总了C++中MCStreamer类的典型用法代码示例。如果您正苦于以下问题:C++ MCStreamer类的具体用法?C++ MCStreamer怎么用?C++ MCStreamer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MCStreamer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: writeStringsAndOffsets
static void
writeStringsAndOffsets(MCStreamer &Out, StringMap<uint32_t> &Strings,
uint32_t &StringOffset, MCSection *StrSection,
MCSection *StrOffsetSection, StringRef CurStrSection,
StringRef CurStrOffsetSection) {
// Could possibly produce an error or warning if one of these was non-null but
// the other was null.
if (CurStrSection.empty() || CurStrOffsetSection.empty())
return;
DenseMap<uint32_t, uint32_t> OffsetRemapping;
DataExtractor Data(CurStrSection, true, 0);
uint32_t LocalOffset = 0;
uint32_t PrevOffset = 0;
while (const char *s = Data.getCStr(&LocalOffset)) {
StringRef Str(s, LocalOffset - PrevOffset - 1);
auto Pair = Strings.insert(std::make_pair(Str, StringOffset));
if (Pair.second) {
Out.SwitchSection(StrSection);
Out.EmitBytes(
StringRef(Pair.first->getKeyData(), Pair.first->getKeyLength() + 1));
StringOffset += Str.size() + 1;
}
OffsetRemapping[PrevOffset] = Pair.first->second;
PrevOffset = LocalOffset;
}
Data = DataExtractor(CurStrOffsetSection, true, 0);
Out.SwitchSection(StrOffsetSection);
uint32_t Offset = 0;
uint64_t Size = CurStrOffsetSection.size();
while (Offset < Size) {
auto OldOffset = Data.getU32(&Offset);
auto NewOffset = OffsetRemapping[OldOffset];
Out.EmitIntValue(NewOffset, 4);
}
}
示例2: MatchAndEmitInstruction
bool SystemZAsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
OperandVector &Operands,
MCStreamer &Out,
unsigned &ErrorInfo,
bool MatchingInlineAsm) {
MCInst Inst;
unsigned MatchResult;
MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo,
MatchingInlineAsm);
switch (MatchResult) {
default: break;
case Match_Success:
Inst.setLoc(IDLoc);
Out.EmitInstruction(Inst, STI);
return false;
case Match_MissingFeature: {
assert(ErrorInfo && "Unknown missing feature!");
// Special case the error message for the very common case where only
// a single subtarget feature is missing
std::string Msg = "instruction requires:";
unsigned Mask = 1;
for (unsigned I = 0; I < sizeof(ErrorInfo) * 8 - 1; ++I) {
if (ErrorInfo & Mask) {
Msg += " ";
Msg += getSubtargetFeatureName(ErrorInfo & Mask);
}
Mask <<= 1;
}
return Error(IDLoc, Msg);
}
case Match_InvalidOperand: {
SMLoc ErrorLoc = IDLoc;
if (ErrorInfo != ~0U) {
if (ErrorInfo >= Operands.size())
return Error(IDLoc, "too few operands for instruction");
ErrorLoc = ((SystemZOperand &)*Operands[ErrorInfo]).getStartLoc();
if (ErrorLoc == SMLoc())
ErrorLoc = IDLoc;
}
return Error(ErrorLoc, "invalid operand for instruction");
}
case Match_MnemonicFail:
return Error(IDLoc, "invalid instruction");
}
llvm_unreachable("Unexpected match type");
}
示例3: emitNonLazySymbolPointer
static void
emitNonLazySymbolPointer(MCStreamer &OutStreamer, MCSymbol *StubLabel,
MachineModuleInfoImpl::StubValueTy &MCSym) {
// L_foo$stub:
OutStreamer.EmitLabel(StubLabel);
// .indirect_symbol _foo
OutStreamer.EmitSymbolAttribute(MCSym.getPointer(), MCSA_IndirectSymbol);
if (MCSym.getInt())
// External to current translation unit.
OutStreamer.EmitIntValue(0, 4/*size*/);
else
// Internal to current translation unit.
//
// When we place the LSDA into the TEXT section, the type info
// pointers need to be indirect and pc-rel. We accomplish this by
// using NLPs; however, sometimes the types are local to the file.
// We need to fill in the value for the NLP in those cases.
OutStreamer.EmitValue(
MCSymbolRefExpr::create(MCSym.getPointer(), OutStreamer.getContext()),
4 /*size*/);
}
示例4: EmitRet
static void EmitRet(const MCOperand *AmtOp, bool Is64Bit, MCStreamer &Out) {
MCInst POPInst;
POPInst.setOpcode(Is64Bit ? X86::POP64r : X86::POP32r);
POPInst.addOperand(MCOperand::CreateReg(Is64Bit ? X86::RCX : X86::ECX));
Out.EmitInstruction(POPInst);
if (AmtOp) {
assert(!Is64Bit);
MCInst ADDInst;
unsigned ADDReg = X86::ESP;
ADDInst.setOpcode(X86::ADD32ri);
ADDInst.addOperand(MCOperand::CreateReg(ADDReg));
ADDInst.addOperand(MCOperand::CreateReg(ADDReg));
ADDInst.addOperand(*AmtOp);
Out.EmitInstruction(ADDInst);
}
MCInst JMPInst;
JMPInst.setOpcode(Is64Bit ? X86::NACL_JMP64r : X86::NACL_JMP32r);
JMPInst.addOperand(MCOperand::CreateReg(X86::ECX));
Out.EmitInstruction(JMPInst);
}
示例5: writeIndex
static void writeIndex(MCStreamer &Out, MCSection *Section,
ArrayRef<unsigned> ContributionOffsets,
ArrayRef<UnitIndexEntry> IndexEntries) {
unsigned Columns = 0;
for (auto &C : ContributionOffsets)
if (C)
++Columns;
std::vector<unsigned> Buckets(NextPowerOf2(3 * IndexEntries.size() / 2));
uint64_t Mask = Buckets.size() - 1;
for (size_t i = 0; i != IndexEntries.size(); ++i) {
auto S = IndexEntries[i].Signature;
auto H = S & Mask;
while (Buckets[H]) {
assert(S != IndexEntries[Buckets[H] - 1].Signature &&
"Duplicate type unit");
H += ((S >> 32) & Mask) | 1;
}
Buckets[H] = i + 1;
}
Out.SwitchSection(Section);
Out.EmitIntValue(2, 4); // Version
Out.EmitIntValue(Columns, 4); // Columns
Out.EmitIntValue(IndexEntries.size(), 4); // Num Units
Out.EmitIntValue(Buckets.size(), 4); // Num Buckets
// Write the signatures.
for (const auto &I : Buckets)
Out.EmitIntValue(I ? IndexEntries[I - 1].Signature : 0, 8);
// Write the indexes.
for (const auto &I : Buckets)
Out.EmitIntValue(I, 4);
// Write the column headers (which sections will appear in the table)
for (size_t i = 0; i != ContributionOffsets.size(); ++i)
if (ContributionOffsets[i])
Out.EmitIntValue(i + DW_SECT_INFO, 4);
// Write the offsets.
writeIndexTable(Out, ContributionOffsets, IndexEntries,
&DWARFUnitIndex::Entry::SectionContribution::Offset);
// Write the lengths.
writeIndexTable(Out, ContributionOffsets, IndexEntries,
&DWARFUnitIndex::Entry::SectionContribution::Length);
}
示例6: MatchAndEmitInstruction
bool SparcAsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
OperandVector &Operands,
MCStreamer &Out,
uint64_t &ErrorInfo,
bool MatchingInlineAsm) {
MCInst Inst;
SmallVector<MCInst, 8> Instructions;
unsigned MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo,
MatchingInlineAsm);
switch (MatchResult) {
case Match_Success: {
switch (Inst.getOpcode()) {
default:
Inst.setLoc(IDLoc);
Instructions.push_back(Inst);
break;
case SP::SET:
if (expandSET(Inst, IDLoc, Instructions))
return true;
break;
}
for (const MCInst &I : Instructions) {
Out.EmitInstruction(I, getSTI());
}
return false;
}
case Match_MissingFeature:
return Error(IDLoc,
"instruction requires a CPU feature not currently enabled");
case Match_InvalidOperand: {
SMLoc ErrorLoc = IDLoc;
if (ErrorInfo != ~0ULL) {
if (ErrorInfo >= Operands.size())
return Error(IDLoc, "too few operands for instruction");
ErrorLoc = ((SparcOperand &)*Operands[ErrorInfo]).getStartLoc();
if (ErrorLoc == SMLoc())
ErrorLoc = IDLoc;
}
return Error(ErrorLoc, "invalid operand for instruction");
}
case Match_MnemonicFail:
return Error(IDLoc, "invalid instruction mnemonic");
}
llvm_unreachable("Implement any new match types added!");
}
示例7: LowerSTATEPOINT
static void LowerSTATEPOINT(MCStreamer &OS, StackMaps &SM,
const MachineInstr &MI, bool Is64Bit,
const TargetMachine& TM,
const MCSubtargetInfo& STI,
X86MCInstLower &MCInstLowering) {
assert(Is64Bit && "Statepoint currently only supports X86-64");
// Lower call target and choose correct opcode
const MachineOperand &call_target = StatepointOpers(&MI).getCallTarget();
MCOperand call_target_mcop;
unsigned call_opcode;
switch (call_target.getType()) {
case MachineOperand::MO_GlobalAddress:
case MachineOperand::MO_ExternalSymbol:
call_target_mcop = MCInstLowering.LowerSymbolOperand(
call_target,
MCInstLowering.GetSymbolFromOperand(call_target));
call_opcode = X86::CALL64pcrel32;
// Currently, we only support relative addressing with statepoints.
// Otherwise, we'll need a scratch register to hold the target
// address. You'll fail asserts during load & relocation if this
// symbol is to far away. (TODO: support non-relative addressing)
break;
case MachineOperand::MO_Immediate:
call_target_mcop = MCOperand::CreateImm(call_target.getImm());
call_opcode = X86::CALL64pcrel32;
// Currently, we only support relative addressing with statepoints.
// Otherwise, we'll need a scratch register to hold the target
// immediate. You'll fail asserts during load & relocation if this
// address is to far away. (TODO: support non-relative addressing)
break;
case MachineOperand::MO_Register:
call_target_mcop = MCOperand::CreateReg(call_target.getReg());
call_opcode = X86::CALL64r;
break;
default:
llvm_unreachable("Unsupported operand type in statepoint call target");
break;
}
// Emit call
MCInst call_inst;
call_inst.setOpcode(call_opcode);
call_inst.addOperand(call_target_mcop);
OS.EmitInstruction(call_inst, STI);
// Record our statepoint node in the same section used by STACKMAP
// and PATCHPOINT
SM.recordStatepoint(MI);
}
示例8: addAllTypes
static void addAllTypes(MCStreamer &Out,
std::vector<UnitIndexEntry> &TypeIndexEntries,
MCSection *OutputTypes, StringRef Types,
const UnitIndexEntry &CUEntry, uint32_t &TypesOffset) {
if (Types.empty())
return;
Out.SwitchSection(OutputTypes);
uint32_t Offset = 0;
DataExtractor Data(Types, true, 0);
while (Data.isValidOffset(Offset)) {
UnitIndexEntry Entry = CUEntry;
// Zero out the debug_info contribution
Entry.Contributions[0] = {};
auto &C = Entry.Contributions[DW_SECT_TYPES - DW_SECT_INFO];
C.Offset = TypesOffset;
auto PrevOffset = Offset;
// Length of the unit, including the 4 byte length field.
C.Length = Data.getU32(&Offset) + 4;
Data.getU16(&Offset); // Version
Data.getU32(&Offset); // Abbrev offset
Data.getU8(&Offset); // Address size
Entry.Signature = Data.getU64(&Offset);
Offset = PrevOffset + C.Length;
if (any_of(TypeIndexEntries, [&](const UnitIndexEntry &E) {
return E.Signature == Entry.Signature;
}))
continue;
Out.EmitBytes(Types.substr(PrevOffset, C.Length));
TypesOffset += C.Length;
TypeIndexEntries.push_back(Entry);
}
}
示例9: EmitDirectCall
static void EmitDirectCall(const MCOperand &Op, bool Is64Bit,
MCStreamer &Out) {
const bool HideSandboxBase = (FlagHideSandboxBase &&
Is64Bit && !FlagUseZeroBasedSandbox);
if (HideSandboxBase) {
// For NaCl64, the sequence
// call target
// return_addr:
// is changed to
// push return_addr
// jmp target
// .align 32
// return_addr:
// This avoids exposing the sandbox base address via the return
// address on the stack.
MCContext &Context = Out.getContext();
// Generate a label for the return address.
MCSymbol *RetTarget = CreateTempLabel(Context, "DirectCallRetAddr");
const MCExpr *RetTargetExpr = MCSymbolRefExpr::Create(RetTarget, Context);
// push return_addr
MCInst PUSHInst;
PUSHInst.setOpcode(X86::PUSH64i32);
PUSHInst.addOperand(MCOperand::CreateExpr(RetTargetExpr));
Out.EmitInstruction(PUSHInst);
// jmp target
MCInst JMPInst;
JMPInst.setOpcode(X86::JMP_4);
JMPInst.addOperand(Op);
Out.EmitInstruction(JMPInst);
Out.EmitCodeAlignment(kNaClX86InstructionBundleSize);
Out.EmitLabel(RetTarget);
} else {
Out.EmitBundleLock(true);
MCInst CALLInst;
CALLInst.setOpcode(Is64Bit ? X86::CALL64pcrel32 : X86::CALLpcrel32);
CALLInst.addOperand(Op);
Out.EmitInstruction(CALLInst);
Out.EmitBundleUnlock();
}
}
示例10: EmitRegFix
// Fix a register after being truncated to 32-bits.
static void EmitRegFix(unsigned Reg64, MCStreamer &Out) {
// lea (%rsp, %r15, 1), %rsp
// We do not need to add the R15 base for the zero-based sandbox model
if (!FlagUseZeroBasedSandbox) {
MCInst Tmp;
Tmp.setOpcode(X86::LEA64r);
Tmp.addOperand(MCOperand::CreateReg(Reg64)); // DestReg
Tmp.addOperand(MCOperand::CreateReg(Reg64)); // BaseReg
Tmp.addOperand(MCOperand::CreateImm(1)); // Scale
Tmp.addOperand(MCOperand::CreateReg(X86::R15)); // IndexReg
Tmp.addOperand(MCOperand::CreateImm(0)); // Offset
Tmp.addOperand(MCOperand::CreateReg(0)); // SegmentReg
Out.EmitInstruction(Tmp);
}
}
示例11: EmitTST
static void EmitTST(MCStreamer &Out, unsigned Reg) {
// tst \reg, #\MASK typically 0xc0000000
const unsigned Mask = 0xC0000000;
MCInst TSTInst;
TSTInst.setOpcode(ARM::TSTri);
TSTInst.addOperand(MCOperand::CreateReg(Reg)); // rS
if (FlagSfiZeroMask) {
TSTInst.addOperand(MCOperand::CreateImm(0)); // imm
} else {
TSTInst.addOperand(MCOperand::CreateImm(Mask)); // imm
}
TSTInst.addOperand(MCOperand::CreateImm((int64_t)ARMCC::AL)); // Always
TSTInst.addOperand(MCOperand::CreateImm(0)); // flag out
Out.EmitInstruction(TSTInst);
}
示例12: EmitTLSAddr32
static void EmitTLSAddr32(const MCInst &Inst, MCStreamer &Out) {
Out.EmitBundleLock(true);
MCInst LeaInst;
LeaInst.setOpcode(X86::LEA32r);
LeaInst.addOperand(MCOperand::CreateReg(X86::EAX)); // DestReg
LeaInst.addOperand(Inst.getOperand(0)); // BaseReg
LeaInst.addOperand(Inst.getOperand(1)); // Scale
LeaInst.addOperand(Inst.getOperand(2)); // IndexReg
LeaInst.addOperand(Inst.getOperand(3)); // Offset
LeaInst.addOperand(Inst.getOperand(4)); // SegmentReg
Out.EmitInstruction(LeaInst);
MCInst CALLInst;
CALLInst.setOpcode(X86::CALLpcrel32);
MCContext &context = Out.getContext();
const MCSymbolRefExpr *expr =
MCSymbolRefExpr::Create(
context.GetOrCreateSymbol(StringRef("___tls_get_addr")),
MCSymbolRefExpr::VK_PLT, context);
CALLInst.addOperand(MCOperand::CreateExpr(expr));
Out.EmitInstruction(CALLInst);
Out.EmitBundleUnlock();
}
示例13: EmitTrap
static void EmitTrap(bool Is64Bit, MCStreamer &Out) {
// Rewrite to:
// X86-32: mov $0, 0
// X86-64: mov $0, (%r15)
unsigned BaseReg = Is64Bit && !FlagUseZeroBasedSandbox ? X86::R15 : 0;
MCInst Tmp;
Tmp.setOpcode(X86::MOV32mi);
Tmp.addOperand(MCOperand::CreateReg(BaseReg)); // BaseReg
Tmp.addOperand(MCOperand::CreateImm(1)); // Scale
Tmp.addOperand(MCOperand::CreateReg(0)); // IndexReg
Tmp.addOperand(MCOperand::CreateImm(0)); // Offset
Tmp.addOperand(MCOperand::CreateReg(0)); // SegmentReg
Tmp.addOperand(MCOperand::CreateImm(0)); // Value
Out.EmitInstruction(Tmp);
}
示例14: EmitBICMask
static void EmitBICMask(MCStreamer &Out,
unsigned Addr, int64_t Pred, unsigned Mask) {
// bic\Pred \Addr, \Addr, #Mask
MCInst BICInst;
BICInst.setOpcode(ARM::BICri);
BICInst.addOperand(MCOperand::CreateReg(Addr)); // rD
BICInst.addOperand(MCOperand::CreateReg(Addr)); // rS
if (FlagSfiZeroMask) {
BICInst.addOperand(MCOperand::CreateImm(0)); // imm
} else {
BICInst.addOperand(MCOperand::CreateImm(Mask)); // imm
}
BICInst.addOperand(MCOperand::CreateImm(Pred)); // predicate
BICInst.addOperand(MCOperand::CreateReg(ARM::CPSR)); // CPSR
BICInst.addOperand(MCOperand::CreateReg(0)); // flag out
Out.EmitInstruction(BICInst);
}
示例15: PrintInsts
static bool PrintInsts(const MCDisassembler &DisAsm,
const ByteArrayTy &Bytes,
SourceMgr &SM, raw_ostream &Out,
MCStreamer &Streamer, bool InAtomicBlock,
const MCSubtargetInfo &STI) {
ArrayRef<uint8_t> Data(Bytes.first.data(), Bytes.first.size());
// Disassemble it to strings.
uint64_t Size;
uint64_t Index;
for (Index = 0; Index < Bytes.first.size(); Index += Size) {
MCInst Inst;
MCDisassembler::DecodeStatus S;
S = DisAsm.getInstruction(Inst, Size, Data.slice(Index), Index,
/*REMOVE*/ nulls(), nulls());
switch (S) {
case MCDisassembler::Fail:
SM.PrintMessage(SMLoc::getFromPointer(Bytes.second[Index]),
SourceMgr::DK_Warning,
"invalid instruction encoding");
// Don't try to resynchronise the stream in a block
if (InAtomicBlock)
return true;
if (Size == 0)
Size = 1; // skip illegible bytes
break;
case MCDisassembler::SoftFail:
SM.PrintMessage(SMLoc::getFromPointer(Bytes.second[Index]),
SourceMgr::DK_Warning,
"potentially undefined instruction encoding");
LLVM_FALLTHROUGH;
case MCDisassembler::Success:
Streamer.EmitInstruction(Inst, STI);
break;
}
}
return false;
}