本文整理汇总了C++中llvm::Twine方法的典型用法代码示例。如果您正苦于以下问题:C++ llvm::Twine方法的具体用法?C++ llvm::Twine怎么用?C++ llvm::Twine使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类llvm
的用法示例。
在下文中一共展示了llvm::Twine方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ShortName
std::string tesla::ShortName(const Location& Loc) {
return (Twine()
+ Loc.filename()
+ ":"
+ Twine(Loc.line())
+ "#"
+ Twine(Loc.counter())
).str();
}
示例2: Twine
static std::string ConstantName(const tesla::Argument* A) {
assert(A->type() == tesla::Argument::Constant);
if (A->has_name())
return A->name();
else
return Twine(A->value()).str();
}
示例3: fromBinary
//.........这里部分代码省略.........
0xBB, 0xC1, 0xFF, 0xF8, 0x4E, 0x80, 0x00, 0x20,
0x68, 0x65, 0x6C, 0x6C, 0x6F, 0x0A, 0x00, 0x00,
0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x01, 0xD3,
0xAB, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x44,
0xA1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18,
0xAC, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x44,
0xA1, 0x00, 0x00, 0x2C, 0x00, 0x00, 0x00, 0x18,
0x00, 0x00, 0x00, 0x01, 0x0F, 0x01, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x5F, 0x6D, 0x61, 0x69, 0x6E, 0x00, 0x5F,
0x70, 0x72, 0x69, 0x6E, 0x74, 0x66, 0x00, 0x00
};
std::unique_ptr<NormalizedFile> f =
fromBinary(fileBytes, sizeof(fileBytes), "ppc");
EXPECT_EQ(f->arch, lld::MachOLinkingContext::arch_ppc);
EXPECT_EQ((int)(f->fileType), MH_OBJECT);
EXPECT_EQ((int)(f->flags), MH_SUBSECTIONS_VIA_SYMBOLS);
EXPECT_EQ(f->sections.size(), 2UL);
const Section& text = f->sections[0];
EXPECT_TRUE(text.segmentName.equals("__TEXT"));
EXPECT_TRUE(text.sectionName.equals("__text"));
EXPECT_EQ(text.type, S_REGULAR);
EXPECT_EQ(text.attributes,SectionAttr(S_ATTR_PURE_INSTRUCTIONS
| S_ATTR_SOME_INSTRUCTIONS));
EXPECT_EQ((uint16_t)text.alignment, 4U);
EXPECT_EQ(text.address, Hex64(0x0));
EXPECT_EQ(text.content.size(), 68UL);
EXPECT_EQ((int)(text.content[0]), 0x7C);
EXPECT_EQ((int)(text.content[1]), 0x08);
EXPECT_TRUE(text.indirectSymbols.empty());
EXPECT_EQ(text.relocations.size(), 5UL);
const Relocation& bl = text.relocations[0];
EXPECT_EQ(bl.offset, Hex32(0x24));
EXPECT_EQ(bl.type, PPC_RELOC_BR24);
EXPECT_EQ(bl.length, 2);
EXPECT_EQ(bl.isExtern, true);
EXPECT_EQ(bl.symbol, 1U);
const Relocation& lo = text.relocations[1];
EXPECT_EQ(lo.offset, Hex32(0x20));
EXPECT_EQ(lo.scattered, true);
EXPECT_EQ(lo.type, PPC_RELOC_LO16_SECTDIFF);
EXPECT_EQ(lo.length, 2);
EXPECT_EQ(lo.value, Hex32(0x44));
const Relocation& loPair = text.relocations[2];
EXPECT_EQ(loPair.offset, Hex32(0x0));
EXPECT_EQ(loPair.scattered, true);
EXPECT_EQ(loPair.type, PPC_RELOC_PAIR);
EXPECT_EQ(loPair.length, 2);
EXPECT_EQ(loPair.value, Hex32(0x18));
const Relocation& ha = text.relocations[3];
EXPECT_EQ(ha.offset, Hex32(0x1C));
EXPECT_EQ(ha.scattered, true);
EXPECT_EQ(ha.type, PPC_RELOC_HA16_SECTDIFF);
EXPECT_EQ(ha.length, 2);
EXPECT_EQ(ha.value, Hex32(0x44));
const Relocation& haPair = text.relocations[4];
EXPECT_EQ(haPair.offset, Hex32(0x2c));
EXPECT_EQ(haPair.scattered, true);
EXPECT_EQ(haPair.type, PPC_RELOC_PAIR);
EXPECT_EQ(haPair.length, 2);
EXPECT_EQ(haPair.value, Hex32(0x18));
const Section& cstring = f->sections[1];
EXPECT_TRUE(cstring.segmentName.equals("__TEXT"));
EXPECT_TRUE(cstring.sectionName.equals("__cstring"));
EXPECT_EQ(cstring.type, S_CSTRING_LITERALS);
EXPECT_EQ(cstring.attributes, SectionAttr(0));
EXPECT_EQ((uint16_t)cstring.alignment, 4U);
EXPECT_EQ(cstring.address, Hex64(0x044));
EXPECT_EQ(cstring.content.size(), 7UL);
EXPECT_EQ((int)(cstring.content[0]), 0x68);
EXPECT_EQ((int)(cstring.content[1]), 0x65);
EXPECT_EQ((int)(cstring.content[2]), 0x6c);
EXPECT_TRUE(cstring.indirectSymbols.empty());
EXPECT_TRUE(cstring.relocations.empty());
EXPECT_EQ(f->localSymbols.size(), 0UL);
EXPECT_EQ(f->globalSymbols.size(), 1UL);
const Symbol& mainLabel = f->globalSymbols[0];
EXPECT_TRUE(mainLabel.name.equals("_main"));
EXPECT_EQ(mainLabel.type, N_SECT);
EXPECT_EQ(mainLabel.sect, 1);
EXPECT_EQ(mainLabel.scope, SymbolScope(N_EXT));
EXPECT_EQ(mainLabel.value, Hex64(0x0));
EXPECT_EQ(f->undefinedSymbols.size(), 1UL);
const Symbol& printfLabel = f->undefinedSymbols[0];
EXPECT_TRUE(printfLabel.name.equals("_printf"));
EXPECT_EQ(printfLabel.type, N_UNDF);
EXPECT_EQ(printfLabel.scope, SymbolScope(N_EXT));
SmallString<128> tmpFl;
std::error_code ec =
llvm::sys::fs::createTemporaryFile(Twine("xx"), "o", tmpFl);
EXPECT_FALSE(ec);
llvm::Error ec2 = writeBinary(*f, tmpFl);
EXPECT_FALSE(ec2);
llvm::sys::fs::remove(tmpFl);
}
示例4: SectionAttr
TEST(BinaryWriterTest, obj_relocs_ppc) {
SmallString<128> tmpFl;
{
NormalizedFile f;
f.arch = lld::MachOLinkingContext::arch_ppc;
f.fileType = MH_OBJECT;
f.flags = MH_SUBSECTIONS_VIA_SYMBOLS;
f.os = lld::MachOLinkingContext::OS::macOSX;
f.sections.resize(1);
Section& text = f.sections.front();
text.segmentName = "__TEXT";
text.sectionName = "__text";
text.type = S_REGULAR;
text.attributes = SectionAttr(S_ATTR_PURE_INSTRUCTIONS
| S_ATTR_SOME_INSTRUCTIONS);
text.alignment = 4;
text.address = 0;
const uint8_t textBytes[] = {
0x48, 0x00, 0x00, 0x01, 0x40, 0x82, 0xff, 0xfc,
0x3c, 0x62, 0x00, 0x00, 0x3c, 0x62, 0x00, 0x00,
0x80, 0x63, 0x00, 0x24, 0x80, 0x63, 0x00, 0x24,
0x3c, 0x40, 0x00, 0x00, 0x3c, 0x60, 0x00, 0x00,
0x80, 0x42, 0x00, 0x28, 0x80, 0x63, 0x00, 0x28,
0x60, 0x00, 0x00, 0x00 };
text.content = llvm::makeArrayRef(textBytes, sizeof(textBytes));
text.relocations.push_back(makeReloc(0x00, true, true,
PPC_RELOC_BR24, 2));
text.relocations.push_back(makeReloc(0x04, true, true,
PPC_RELOC_BR14, 2));
text.relocations.push_back(makeScatReloc(0x08,
PPC_RELOC_HI16_SECTDIFF, 0x28));
text.relocations.push_back(makeScatReloc(0x24,
PPC_RELOC_PAIR, 0x4));
text.relocations.push_back(makeScatReloc(0x0C,
PPC_RELOC_HA16_SECTDIFF, 0x28));
text.relocations.push_back(makeScatReloc(0x24,
PPC_RELOC_PAIR, 0x4));
text.relocations.push_back(makeScatReloc(0x10,
PPC_RELOC_LO16_SECTDIFF, 0x28));
text.relocations.push_back(makeScatReloc(0x00,
PPC_RELOC_PAIR, 0x4));
text.relocations.push_back(makeScatReloc(0x14,
PPC_RELOC_LO14_SECTDIFF, 0x28));
text.relocations.push_back(makeScatReloc(0x00,
PPC_RELOC_PAIR, 0x4));
text.relocations.push_back(makeReloc(0x18, false, false,
PPC_RELOC_HI16, 1));
text.relocations.push_back(makeReloc(0x28, false, false,
PPC_RELOC_PAIR, 0));
text.relocations.push_back(makeReloc(0x1C, false, false,
PPC_RELOC_HA16, 1));
text.relocations.push_back(makeReloc(0x28, false, false,
PPC_RELOC_PAIR, 0));
text.relocations.push_back(makeReloc(0x20, false, false,
PPC_RELOC_LO16, 1));
text.relocations.push_back(makeReloc(0x00, false, false,
PPC_RELOC_PAIR, 0));
text.relocations.push_back(makeReloc(0x24, false, false,
PPC_RELOC_LO14, 1));
text.relocations.push_back(makeReloc(0x00, false, false,
PPC_RELOC_PAIR, 0));
f.globalSymbols.push_back(makeSymbol("_foo", 0x00));
f.globalSymbols.push_back(makeSymbol("_foo2", 0x28));
f.undefinedSymbols.push_back(makeUndefSymbol("_bar"));
std::error_code ec =
llvm::sys::fs::createTemporaryFile(Twine("xx"), "o", tmpFl);
EXPECT_FALSE(ec);
llvm::Error ec2 = writeBinary(f, tmpFl);
EXPECT_FALSE(ec2);
}
std::unique_ptr<MemoryBuffer> bufferOwner;
std::unique_ptr<NormalizedFile> f2;
fromBinary(tmpFl, bufferOwner, f2, "ppc");
EXPECT_EQ(lld::MachOLinkingContext::arch_ppc, f2->arch);
EXPECT_EQ(MH_OBJECT, f2->fileType);
EXPECT_EQ(FileFlags(MH_SUBSECTIONS_VIA_SYMBOLS), f2->flags);
EXPECT_TRUE(f2->localSymbols.empty());
EXPECT_EQ(2UL, f2->globalSymbols.size());
const Symbol& fooDef = f2->globalSymbols[0];
EXPECT_TRUE(fooDef.name.equals("_foo"));
EXPECT_EQ(N_SECT, fooDef.type);
EXPECT_EQ(1, fooDef.sect);
EXPECT_EQ(SymbolScope(N_EXT), fooDef.scope);
const Symbol& foo2Def = f2->globalSymbols[1];
EXPECT_TRUE(foo2Def.name.equals("_foo2"));
EXPECT_EQ(N_SECT, foo2Def.type);
EXPECT_EQ(1, foo2Def.sect);
EXPECT_EQ(SymbolScope(N_EXT), foo2Def.scope);
EXPECT_EQ(1UL, f2->undefinedSymbols.size());
const Symbol& barUndef = f2->undefinedSymbols[0];
EXPECT_TRUE(barUndef.name.equals("_bar"));
EXPECT_EQ(N_UNDF, barUndef.type);
EXPECT_EQ(SymbolScope(N_EXT), barUndef.scope);
//.........这里部分代码省略.........