Skip to content

Commit 692e0c9

Browse files
committed
[MC] Add MCStreamer::emitInt{8,16,32,64}
Similar to AsmPrinter::emitInt{8,16,32,64}.
1 parent 93184a8 commit 692e0c9

24 files changed

+402
-402
lines changed

llvm/include/llvm/MC/MCStreamer.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,11 @@ class MCStreamer {
663663
emitIntValue(Value, Size);
664664
}
665665

666+
void emitInt8(uint64_t Value) { emitIntValue(Value, 1); }
667+
void emitInt16(uint64_t Value) { emitIntValue(Value, 2); }
668+
void emitInt32(uint64_t Value) { emitIntValue(Value, 4); }
669+
void emitInt64(uint64_t Value) { emitIntValue(Value, 8); }
670+
666671
/// Special case of EmitValue that avoids the client having to pass
667672
/// in a MCExpr for constant integers & prints in Hex format for certain
668673
/// modes, pads the field with leading zeros to Size width

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2162,23 +2162,17 @@ void AsmPrinter::emitModuleCommandLines(Module &M) {
21622162

21632163
/// Emit a byte directive and value.
21642164
///
2165-
void AsmPrinter::emitInt8(int Value) const {
2166-
OutStreamer->emitIntValue(Value, 1);
2167-
}
2165+
void AsmPrinter::emitInt8(int Value) const { OutStreamer->emitInt8(Value); }
21682166

21692167
/// Emit a short directive and value.
2170-
void AsmPrinter::emitInt16(int Value) const {
2171-
OutStreamer->emitIntValue(Value, 2);
2172-
}
2168+
void AsmPrinter::emitInt16(int Value) const { OutStreamer->emitInt16(Value); }
21732169

21742170
/// Emit a long directive and value.
2175-
void AsmPrinter::emitInt32(int Value) const {
2176-
OutStreamer->emitIntValue(Value, 4);
2177-
}
2171+
void AsmPrinter::emitInt32(int Value) const { OutStreamer->emitInt32(Value); }
21782172

21792173
/// Emit a long long directive and value.
21802174
void AsmPrinter::emitInt64(uint64_t Value) const {
2181-
OutStreamer->emitIntValue(Value, 8);
2175+
OutStreamer->emitInt64(Value);
21822176
}
21832177

21842178
/// Emit something like ".long Hi-Lo" where the size in bytes of the directive

llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ void CodeViewDebug::maybeRecordLocation(const DebugLoc &DL,
551551
void CodeViewDebug::emitCodeViewMagicVersion() {
552552
OS.emitValueToAlignment(4);
553553
OS.AddComment("Debug section magic");
554-
OS.emitIntValue(COFF::DEBUG_SECTION_MAGIC, 4);
554+
OS.emitInt32(COFF::DEBUG_SECTION_MAGIC);
555555
}
556556

557557
void CodeViewDebug::endModule() {
@@ -676,11 +676,11 @@ void CodeViewDebug::emitTypeGlobalHashes() {
676676

677677
OS.emitValueToAlignment(4);
678678
OS.AddComment("Magic");
679-
OS.emitIntValue(COFF::DEBUG_HASHES_SECTION_MAGIC, 4);
679+
OS.emitInt32(COFF::DEBUG_HASHES_SECTION_MAGIC);
680680
OS.AddComment("Section Version");
681-
OS.emitIntValue(0, 2);
681+
OS.emitInt16(0);
682682
OS.AddComment("Hash Algorithm");
683-
OS.emitIntValue(uint16_t(GlobalTypeHashAlg::SHA1_8), 2);
683+
OS.emitInt16(uint16_t(GlobalTypeHashAlg::SHA1_8));
684684

685685
TypeIndex TI(TypeIndex::FirstNonSimpleIndex);
686686
for (const auto &GHR : TypeTable.hashes()) {
@@ -775,16 +775,16 @@ void CodeViewDebug::emitCompilerInformation() {
775775
// TODO: Figure out which other flags need to be set.
776776

777777
OS.AddComment("Flags and language");
778-
OS.emitIntValue(Flags, 4);
778+
OS.emitInt32(Flags);
779779

780780
OS.AddComment("CPUType");
781-
OS.emitIntValue(static_cast<uint64_t>(TheCPU), 2);
781+
OS.emitInt16(static_cast<uint64_t>(TheCPU));
782782

783783
StringRef CompilerVersion = CU->getProducer();
784784
Version FrontVer = parseVersion(CompilerVersion);
785785
OS.AddComment("Frontend version");
786786
for (int N = 0; N < 4; ++N)
787-
OS.emitIntValue(FrontVer.Part[N], 2);
787+
OS.emitInt16(FrontVer.Part[N]);
788788

789789
// Some Microsoft tools, like Binscope, expect a backend version number of at
790790
// least 8.something, so we'll coerce the LLVM version into a form that
@@ -797,7 +797,7 @@ void CodeViewDebug::emitCompilerInformation() {
797797
Version BackVer = {{ Major, 0, 0, 0 }};
798798
OS.AddComment("Backend version");
799799
for (int N = 0; N < 4; ++N)
800-
OS.emitIntValue(BackVer.Part[N], 2);
800+
OS.emitInt16(BackVer.Part[N]);
801801

802802
OS.AddComment("Null-terminated compiler version string");
803803
emitNullTerminatedSymbolName(OS, CompilerVersion);
@@ -841,7 +841,7 @@ void CodeViewDebug::emitBuildInfo() {
841841
MCSymbol *BISubsecEnd = beginCVSubsection(DebugSubsectionKind::Symbols);
842842
MCSymbol *BIEnd = beginSymbolRecord(SymbolKind::S_BUILDINFO);
843843
OS.AddComment("LF_BUILDINFO index");
844-
OS.emitIntValue(BuildInfoIndex.getIndex(), 4);
844+
OS.emitInt32(BuildInfoIndex.getIndex());
845845
endSymbolRecord(BIEnd);
846846
endCVSubsection(BISubsecEnd);
847847
}
@@ -858,7 +858,7 @@ void CodeViewDebug::emitInlineeLinesSubsection() {
858858
// for instance, will display a warning that the breakpoints are not valid if
859859
// the pdb does not match the source.
860860
OS.AddComment("Inlinee lines signature");
861-
OS.emitIntValue(unsigned(InlineeLinesSignature::Normal), 4);
861+
OS.emitInt32(unsigned(InlineeLinesSignature::Normal));
862862

863863
for (const DISubprogram *SP : InlinedSubprograms) {
864864
assert(TypeIndices.count({SP, nullptr}));
@@ -870,11 +870,11 @@ void CodeViewDebug::emitInlineeLinesSubsection() {
870870
SP->getFilename() + Twine(':') + Twine(SP->getLine()));
871871
OS.AddBlankLine();
872872
OS.AddComment("Type index of inlined function");
873-
OS.emitIntValue(InlineeIdx.getIndex(), 4);
873+
OS.emitInt32(InlineeIdx.getIndex());
874874
OS.AddComment("Offset into filechecksum table");
875875
OS.EmitCVFileChecksumOffsetDirective(FileId);
876876
OS.AddComment("Starting line number");
877-
OS.emitIntValue(SP->getLine(), 4);
877+
OS.emitInt32(SP->getLine());
878878
}
879879

880880
endCVSubsection(InlineEnd);
@@ -890,11 +890,11 @@ void CodeViewDebug::emitInlinedCallSite(const FunctionInfo &FI,
890890
MCSymbol *InlineEnd = beginSymbolRecord(SymbolKind::S_INLINESITE);
891891

892892
OS.AddComment("PtrParent");
893-
OS.emitIntValue(0, 4);
893+
OS.emitInt32(0);
894894
OS.AddComment("PtrEnd");
895-
OS.emitIntValue(0, 4);
895+
OS.emitInt32(0);
896896
OS.AddComment("Inlinee type index");
897-
OS.emitIntValue(InlineeIdx.getIndex(), 4);
897+
OS.emitInt32(InlineeIdx.getIndex());
898898

899899
unsigned FileId = maybeRecordFile(Site.Inlinee->getFile());
900900
unsigned StartLineNum = Site.Inlinee->getLine();
@@ -953,19 +953,19 @@ void CodeViewDebug::emitDebugInfoForThunk(const Function *GV,
953953
// Emit S_THUNK32
954954
MCSymbol *ThunkRecordEnd = beginSymbolRecord(SymbolKind::S_THUNK32);
955955
OS.AddComment("PtrParent");
956-
OS.emitIntValue(0, 4);
956+
OS.emitInt32(0);
957957
OS.AddComment("PtrEnd");
958-
OS.emitIntValue(0, 4);
958+
OS.emitInt32(0);
959959
OS.AddComment("PtrNext");
960-
OS.emitIntValue(0, 4);
960+
OS.emitInt32(0);
961961
OS.AddComment("Thunk section relative address");
962962
OS.EmitCOFFSecRel32(Fn, /*Offset=*/0);
963963
OS.AddComment("Thunk section index");
964964
OS.EmitCOFFSectionIndex(Fn);
965965
OS.AddComment("Code size");
966966
OS.emitAbsoluteSymbolDiff(FI.End, Fn, 2);
967967
OS.AddComment("Ordinal");
968-
OS.emitIntValue(unsigned(ordinal), 1);
968+
OS.emitInt8(unsigned(ordinal));
969969
OS.AddComment("Function name");
970970
emitNullTerminatedSymbolName(OS, FuncName);
971971
// Additional fields specific to the thunk ordinal would go here.
@@ -1023,27 +1023,27 @@ void CodeViewDebug::emitDebugInfoForFunction(const Function *GV,
10231023

10241024
// These fields are filled in by tools like CVPACK which run after the fact.
10251025
OS.AddComment("PtrParent");
1026-
OS.emitIntValue(0, 4);
1026+
OS.emitInt32(0);
10271027
OS.AddComment("PtrEnd");
1028-
OS.emitIntValue(0, 4);
1028+
OS.emitInt32(0);
10291029
OS.AddComment("PtrNext");
1030-
OS.emitIntValue(0, 4);
1030+
OS.emitInt32(0);
10311031
// This is the important bit that tells the debugger where the function
10321032
// code is located and what's its size:
10331033
OS.AddComment("Code size");
10341034
OS.emitAbsoluteSymbolDiff(FI.End, Fn, 4);
10351035
OS.AddComment("Offset after prologue");
1036-
OS.emitIntValue(0, 4);
1036+
OS.emitInt32(0);
10371037
OS.AddComment("Offset before epilogue");
1038-
OS.emitIntValue(0, 4);
1038+
OS.emitInt32(0);
10391039
OS.AddComment("Function type index");
1040-
OS.emitIntValue(getFuncIdForSubprogram(GV->getSubprogram()).getIndex(), 4);
1040+
OS.emitInt32(getFuncIdForSubprogram(GV->getSubprogram()).getIndex());
10411041
OS.AddComment("Function section relative address");
10421042
OS.EmitCOFFSecRel32(Fn, /*Offset=*/0);
10431043
OS.AddComment("Function section index");
10441044
OS.EmitCOFFSectionIndex(Fn);
10451045
OS.AddComment("Flags");
1046-
OS.emitIntValue(0, 1);
1046+
OS.emitInt8(0);
10471047
// Emit the function display name as a null-terminated string.
10481048
OS.AddComment("Function name");
10491049
// Truncate the name so we won't overflow the record length field.
@@ -1053,19 +1053,19 @@ void CodeViewDebug::emitDebugInfoForFunction(const Function *GV,
10531053
MCSymbol *FrameProcEnd = beginSymbolRecord(SymbolKind::S_FRAMEPROC);
10541054
// Subtract out the CSR size since MSVC excludes that and we include it.
10551055
OS.AddComment("FrameSize");
1056-
OS.emitIntValue(FI.FrameSize - FI.CSRSize, 4);
1056+
OS.emitInt32(FI.FrameSize - FI.CSRSize);
10571057
OS.AddComment("Padding");
1058-
OS.emitIntValue(0, 4);
1058+
OS.emitInt32(0);
10591059
OS.AddComment("Offset of padding");
1060-
OS.emitIntValue(0, 4);
1060+
OS.emitInt32(0);
10611061
OS.AddComment("Bytes of callee saved registers");
1062-
OS.emitIntValue(FI.CSRSize, 4);
1062+
OS.emitInt32(FI.CSRSize);
10631063
OS.AddComment("Exception handler offset");
1064-
OS.emitIntValue(0, 4);
1064+
OS.emitInt32(0);
10651065
OS.AddComment("Exception handler section");
1066-
OS.emitIntValue(0, 2);
1066+
OS.emitInt16(0);
10671067
OS.AddComment("Flags (defines frame register)");
1068-
OS.emitIntValue(uint32_t(FI.FrameProcOpts), 4);
1068+
OS.emitInt32(uint32_t(FI.FrameProcOpts));
10691069
endSymbolRecord(FrameProcEnd);
10701070

10711071
emitLocalVariableList(FI, FI.Locals);
@@ -1089,7 +1089,7 @@ void CodeViewDebug::emitDebugInfoForFunction(const Function *GV,
10891089
OS.EmitCOFFSecRel32(Label, /*Offset=*/0);
10901090
// FIXME: Make sure we don't overflow the max record size.
10911091
OS.EmitCOFFSectionIndex(Label);
1092-
OS.emitIntValue(Strs->getNumOperands(), 2);
1092+
OS.emitInt16(Strs->getNumOperands());
10931093
for (Metadata *MD : Strs->operands()) {
10941094
// MDStrings are null terminated, so we can do EmitBytes and get the
10951095
// nice .asciz directive.
@@ -1112,7 +1112,7 @@ void CodeViewDebug::emitDebugInfoForFunction(const Function *GV,
11121112
OS.AddComment("Call instruction length");
11131113
OS.emitAbsoluteSymbolDiff(EndLabel, BeginLabel, 2);
11141114
OS.AddComment("Type index");
1115-
OS.emitIntValue(getCompleteTypeIndex(DITy).getIndex(), 4);
1115+
OS.emitInt32(getCompleteTypeIndex(DITy).getIndex());
11161116
endSymbolRecord(HeapAllocEnd);
11171117
}
11181118

@@ -2626,9 +2626,9 @@ void CodeViewDebug::emitLocalVariable(const FunctionInfo &FI,
26262626
TypeIndex TI = Var.UseReferenceType
26272627
? getTypeIndexForReferenceTo(Var.DIVar->getType())
26282628
: getCompleteTypeIndex(Var.DIVar->getType());
2629-
OS.emitIntValue(TI.getIndex(), 4);
2629+
OS.emitInt32(TI.getIndex());
26302630
OS.AddComment("Flags");
2631-
OS.emitIntValue(static_cast<uint16_t>(Flags), 2);
2631+
OS.emitInt16(static_cast<uint16_t>(Flags));
26322632
// Truncate the name so we won't overflow the record length field.
26332633
emitNullTerminatedSymbolName(OS, Var.DIVar->getName());
26342634
endSymbolRecord(LocalEnd);
@@ -2705,9 +2705,9 @@ void CodeViewDebug::emitLexicalBlock(const LexicalBlock &Block,
27052705
const FunctionInfo& FI) {
27062706
MCSymbol *RecordEnd = beginSymbolRecord(SymbolKind::S_BLOCK32);
27072707
OS.AddComment("PtrParent");
2708-
OS.emitIntValue(0, 4); // PtrParent
2708+
OS.emitInt32(0); // PtrParent
27092709
OS.AddComment("PtrEnd");
2710-
OS.emitIntValue(0, 4); // PtrEnd
2710+
OS.emitInt32(0); // PtrEnd
27112711
OS.AddComment("Code size");
27122712
OS.emitAbsoluteSymbolDiff(Block.End, Block.Begin, 4); // Code Size
27132713
OS.AddComment("Function section relative address");
@@ -2915,7 +2915,7 @@ void CodeViewDebug::beginInstruction(const MachineInstr *MI) {
29152915
MCSymbol *CodeViewDebug::beginCVSubsection(DebugSubsectionKind Kind) {
29162916
MCSymbol *BeginLabel = MMI->getContext().createTempSymbol(),
29172917
*EndLabel = MMI->getContext().createTempSymbol();
2918-
OS.emitIntValue(unsigned(Kind), 4);
2918+
OS.emitInt32(unsigned(Kind));
29192919
OS.AddComment("Subsection size");
29202920
OS.emitAbsoluteSymbolDiff(EndLabel, BeginLabel, 4);
29212921
OS.emitLabel(BeginLabel);
@@ -2943,7 +2943,7 @@ MCSymbol *CodeViewDebug::beginSymbolRecord(SymbolKind SymKind) {
29432943
OS.emitLabel(BeginLabel);
29442944
if (OS.isVerboseAsm())
29452945
OS.AddComment("Record kind: " + getSymbolName(SymKind));
2946-
OS.emitIntValue(unsigned(SymKind), 2);
2946+
OS.emitInt16(unsigned(SymKind));
29472947
return EndLabel;
29482948
}
29492949

@@ -2958,10 +2958,10 @@ void CodeViewDebug::endSymbolRecord(MCSymbol *SymEnd) {
29582958

29592959
void CodeViewDebug::emitEndSymbolRecord(SymbolKind EndKind) {
29602960
OS.AddComment("Record length");
2961-
OS.emitIntValue(2, 2);
2961+
OS.emitInt16(2);
29622962
if (OS.isVerboseAsm())
29632963
OS.AddComment("Record kind: " + getSymbolName(EndKind));
2964-
OS.emitIntValue(unsigned(EndKind), 2); // Record Kind
2964+
OS.emitInt16(uint16_t(EndKind)); // Record Kind
29652965
}
29662966

29672967
void CodeViewDebug::emitDebugInfoForUDTs(
@@ -2972,7 +2972,7 @@ void CodeViewDebug::emitDebugInfoForUDTs(
29722972

29732973
MCSymbol *UDTRecordEnd = beginSymbolRecord(SymbolKind::S_UDT);
29742974
OS.AddComment("Type");
2975-
OS.emitIntValue(getCompleteTypeIndex(T).getIndex(), 4);
2975+
OS.emitInt32(getCompleteTypeIndex(T).getIndex());
29762976
emitNullTerminatedSymbolName(OS, UDT.first);
29772977
endSymbolRecord(UDTRecordEnd);
29782978
}
@@ -3088,7 +3088,7 @@ void CodeViewDebug::emitDebugInfoForGlobal(const CVGlobalVariable &CVGV) {
30883088
: SymbolKind::S_GDATA32);
30893089
MCSymbol *DataEnd = beginSymbolRecord(DataSym);
30903090
OS.AddComment("Type");
3091-
OS.emitIntValue(getCompleteTypeIndex(DIGV->getType()).getIndex(), 4);
3091+
OS.emitInt32(getCompleteTypeIndex(DIGV->getType()).getIndex());
30923092
OS.AddComment("DataOffset");
30933093
OS.EmitCOFFSecRel32(GVSym, /*Offset=*/0);
30943094
OS.AddComment("Segment");
@@ -3107,7 +3107,7 @@ void CodeViewDebug::emitDebugInfoForGlobal(const CVGlobalVariable &CVGV) {
31073107

31083108
MCSymbol *SConstantEnd = beginSymbolRecord(SymbolKind::S_CONSTANT);
31093109
OS.AddComment("Type");
3110-
OS.emitIntValue(getTypeIndex(DIGV->getType()).getIndex(), 4);
3110+
OS.emitInt32(getTypeIndex(DIGV->getType()).getIndex());
31113111
OS.AddComment("Value");
31123112

31133113
// Encoded integers shouldn't need more than 10 bytes.

0 commit comments

Comments
 (0)