Index: llvm/include/llvm/MC/MCExpr.h =================================================================== --- llvm/include/llvm/MC/MCExpr.h +++ llvm/include/llvm/MC/MCExpr.h @@ -134,15 +134,21 @@ //// Represent a constant integer expression. class MCConstantExpr : public MCExpr { int64_t Value; + bool PrintInHex = false; explicit MCConstantExpr(int64_t Value) : MCExpr(MCExpr::Constant, SMLoc()), Value(Value) {} + explicit MCConstantExpr(int64_t Value, bool PrintInHex) + : MCExpr(MCExpr::Constant, SMLoc()), Value(Value), + PrintInHex(PrintInHex) {} + public: /// \name Construction /// @{ - static const MCConstantExpr *create(int64_t Value, MCContext &Ctx); + static const MCConstantExpr *create(int64_t Value, MCContext &Ctx, + bool PrintInHex = false); /// @} /// \name Accessors @@ -150,6 +156,8 @@ int64_t getValue() const { return Value; } + bool useHexFormat() const { return PrintInHex; } + /// @} static bool classof(const MCExpr *E) { Index: llvm/include/llvm/MC/MCStreamer.h =================================================================== --- llvm/include/llvm/MC/MCStreamer.h +++ llvm/include/llvm/MC/MCStreamer.h @@ -626,6 +626,13 @@ /// to pass in a MCExpr for constant integers. virtual void EmitIntValue(uint64_t Value, unsigned Size); + /// Special case of EmitValue that avoids the client having to pass + /// in a MCExpr for constant integers & prints in Hex format for certain + /// modes. + virtual void EmitIntValueInHex(uint64_t Value, unsigned Size) { + EmitIntValue(Value, Size); + } + virtual void EmitULEB128Value(const MCExpr *Value); virtual void EmitSLEB128Value(const MCExpr *Value); Index: llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp =================================================================== --- llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp +++ llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp @@ -103,7 +103,7 @@ void EmitBytes(StringRef Data) { OS->EmitBytes(Data); } void EmitIntValue(uint64_t Value, unsigned Size) { - OS->EmitIntValue(Value, Size); + OS->EmitIntValueInHex(Value, Size); } void EmitBinaryData(StringRef Data) { OS->EmitBinaryData(Data); } Index: llvm/lib/MC/MCAsmStreamer.cpp =================================================================== --- llvm/lib/MC/MCAsmStreamer.cpp +++ llvm/lib/MC/MCAsmStreamer.cpp @@ -188,6 +188,7 @@ void EmitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc = SMLoc()) override; void EmitIntValue(uint64_t Value, unsigned Size) override; + void EmitIntValueInHex(uint64_t Value, unsigned Size) override; void EmitULEB128Value(const MCExpr *Value) override; @@ -923,6 +924,10 @@ EmitValue(MCConstantExpr::create(Value, getContext()), Size); } +void MCAsmStreamer::EmitIntValueInHex(uint64_t Value, unsigned Size) { + EmitValue(MCConstantExpr::create(Value, getContext(), true), Size); +} + void MCAsmStreamer::EmitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc) { assert(Size <= 8 && "Invalid size"); Index: llvm/lib/MC/MCExpr.cpp =================================================================== --- llvm/lib/MC/MCExpr.cpp +++ llvm/lib/MC/MCExpr.cpp @@ -8,6 +8,7 @@ #include "llvm/MC/MCExpr.h" #include "llvm/ADT/Statistic.h" +#include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/Config/llvm-config.h" #include "llvm/MC/MCAsmBackend.h" @@ -42,10 +43,15 @@ switch (getKind()) { case MCExpr::Target: return cast(this)->printImpl(OS, MAI); - case MCExpr::Constant: - OS << cast(*this).getValue(); + case MCExpr::Constant: { + auto Value = cast(*this).getValue(); + auto PrintInHex = cast(*this).useHexFormat(); + if (PrintInHex) + OS << "0x" << Twine::utohexstr(Value); + else + OS << Value; return; - + } case MCExpr::SymbolRef: { const MCSymbolRefExpr &SRE = cast(*this); const MCSymbol &Sym = SRE.getSymbol(); @@ -160,8 +166,9 @@ return new (Ctx) MCUnaryExpr(Opc, Expr, Loc); } -const MCConstantExpr *MCConstantExpr::create(int64_t Value, MCContext &Ctx) { - return new (Ctx) MCConstantExpr(Value); +const MCConstantExpr *MCConstantExpr::create(int64_t Value, MCContext &Ctx, + bool PrintInHex) { + return new (Ctx) MCConstantExpr(Value, PrintInHex); } /* *** */ Index: llvm/test/DebugInfo/COFF/types-basic.ll =================================================================== --- llvm/test/DebugInfo/COFF/types-basic.ll +++ llvm/test/DebugInfo/COFF/types-basic.ll @@ -352,10 +352,10 @@ ; ASM: .long 4 # Debug section magic ; ASM: .short 18 ; ASM: .short 4609 -; ASM: .long 3 # NumArgs -; ASM: .long 64 # Argument -; ASM: .long 65 # Argument -; ASM: .long 19 # Argument +; ASM: .long 0x3 # NumArgs +; ASM: .long 0x40 # Argument +; ASM: .long 0x41 # Argument +; ASM: .long 0x13 # Argument ; ASM: # ArgList (0x1000) { ; ASM: # TypeLeafKind: LF_ARGLIST (0x1201) ; ASM: # NumArgs: 3 @@ -367,11 +367,11 @@ ; ASM: # } ; ASM: .short 14 ; ASM: .short 4104 -; ASM: .long 3 # ReturnType -; ASM: .byte 0 # CallingConvention -; ASM: .byte 0 # FunctionOptions -; ASM: .short 3 # NumParameters -; ASM: .long 4096 # ArgListType +; ASM: .long 0x3 # ReturnType +; ASM: .byte 0x0 # CallingConvention +; ASM: .byte 0x0 # FunctionOptions +; ASM: .short 0x3 # NumParameters +; ASM: .long 0x1000 # ArgListType ; ASM: # Procedure (0x1001) { ; ASM: # TypeLeafKind: LF_PROCEDURE (0x1008) ; ASM: # ReturnType: void (0x3) @@ -383,8 +383,8 @@ ; ASM: # } ; ASM: .short 14 ; ASM: .short 5633 -; ASM: .long 0 # ParentScope -; ASM: .long 4097 # FunctionType +; ASM: .long 0x0 # ParentScope +; ASM: .long 0x1001 # FunctionType ; ASM: .asciz "f" # Name ; ASM: .byte 242 ; ASM: .byte 241 @@ -396,8 +396,8 @@ ; ASM: # } ; ASM: .short 10 ; ASM: .short 4097 -; ASM: .long 116 # ModifiedType -; ASM: .short 1 # Modifiers +; ASM: .long 0x74 # ModifiedType +; ASM: .short 0x1 # Modifiers ; ASM: .byte 242 ; ASM: .byte 241 ; ASM: # Modifier (0x1003) { @@ -409,8 +409,8 @@ ; ASM: # } ; ASM: .short 10 ; ASM: .short 4098 -; ASM: .long 4099 # PointeeType -; ASM: .long 65548 # Attributes +; ASM: .long 0x1003 # PointeeType +; ASM: .long 0x1000c # Attributes ; ASM: # Pointer (0x1004) { ; ASM: # TypeLeafKind: LF_POINTER (0x1002) ; ASM: # PointeeType: const int (0x1003) @@ -427,12 +427,12 @@ ; ASM: # } ; ASM: .short 22 ; ASM: .short 5381 -; ASM: .short 0 # MemberCount -; ASM: .short 128 # Properties -; ASM: .long 0 # FieldList -; ASM: .long 0 # DerivedFrom -; ASM: .long 0 # VShape -; ASM: .short 0 # SizeOf +; ASM: .short 0x0 # MemberCount +; ASM: .short 0x80 # Properties +; ASM: .long 0x0 # FieldList +; ASM: .long 0x0 # DerivedFrom +; ASM: .long 0x0 # VShape +; ASM: .short 0x0 # SizeOf ; ASM: .asciz "A" # Name ; ASM: # Struct (0x1005) { ; ASM: # TypeLeafKind: LF_STRUCTURE (0x1505) @@ -448,10 +448,10 @@ ; ASM: # } ; ASM: .short 18 ; ASM: .short 4098 -; ASM: .long 116 # PointeeType -; ASM: .long 32844 # Attributes -; ASM: .long 4101 # ClassType -; ASM: .short 4 # Representation +; ASM: .long 0x74 # PointeeType +; ASM: .long 0x804c # Attributes +; ASM: .long 0x1005 # ClassType +; ASM: .short 0x4 # Representation ; ASM: .byte 242 ; ASM: .byte 241 ; ASM: # Pointer (0x1006) { @@ -472,8 +472,8 @@ ; ASM: # } ; ASM: .short 10 ; ASM: .short 4098 -; ASM: .long 4101 # PointeeType -; ASM: .long 66572 # Attributes +; ASM: .long 0x1005 # PointeeType +; ASM: .long 0x1040c # Attributes ; ASM: # Pointer (0x1007) { ; ASM: # TypeLeafKind: LF_POINTER (0x1002) ; ASM: # PointeeType: A (0x1005) @@ -490,7 +490,7 @@ ; ASM: # } ; ASM: .short 6 ; ASM: .short 4609 -; ASM: .long 0 # NumArgs +; ASM: .long 0x0 # NumArgs ; ASM: # ArgList (0x1008) { ; ASM: # TypeLeafKind: LF_ARGLIST (0x1201) ; ASM: # NumArgs: 0 @@ -499,14 +499,14 @@ ; ASM: # } ; ASM: .short 26 ; ASM: .short 4105 -; ASM: .long 3 # ReturnType -; ASM: .long 4101 # ClassType -; ASM: .long 4103 # ThisType -; ASM: .byte 0 # CallingConvention -; ASM: .byte 0 # FunctionOptions -; ASM: .short 0 # NumParameters -; ASM: .long 4104 # ArgListType -; ASM: .long 0 # ThisAdjustment +; ASM: .long 0x3 # ReturnType +; ASM: .long 0x1005 # ClassType +; ASM: .long 0x1007 # ThisType +; ASM: .byte 0x0 # CallingConvention +; ASM: .byte 0x0 # FunctionOptions +; ASM: .short 0x0 # NumParameters +; ASM: .long 0x1008 # ArgListType +; ASM: .long 0x0 # ThisAdjustment ; ASM: # MemberFunction (0x1009) { ; ASM: # TypeLeafKind: LF_MFUNCTION (0x1009) ; ASM: # ReturnType: void (0x3) @@ -546,12 +546,12 @@ ; ASM: # } ; ASM: .short 22 ; ASM: .short 5381 -; ASM: .short 2 # MemberCount -; ASM: .short 0 # Properties -; ASM: .long 4106 # FieldList -; ASM: .long 0 # DerivedFrom -; ASM: .long 0 # VShape -; ASM: .short 4 # SizeOf +; ASM: .short 0x2 # MemberCount +; ASM: .short 0x0 # Properties +; ASM: .long 0x100a # FieldList +; ASM: .long 0x0 # DerivedFrom +; ASM: .long 0x0 # VShape +; ASM: .short 0x4 # SizeOf ; ASM: .asciz "A" # Name ; ASM: # Struct (0x100B) { ; ASM: # TypeLeafKind: LF_STRUCTURE (0x1505) @@ -566,7 +566,7 @@ ; ASM: # } ; ASM: .short 30 ; ASM: .short 5637 -; ASM: .long 0 # Id +; ASM: .long 0x0 # Id ; ASM: .asciz "D:\\src\\llvm\\build\\t.cpp" # StringData ; ASM: # StringId (0x100C) { ; ASM: # TypeLeafKind: LF_STRING_ID (0x1605) @@ -575,9 +575,9 @@ ; ASM: # } ; ASM: .short 14 ; ASM: .short 5638 -; ASM: .long 4107 # UDT -; ASM: .long 4108 # SourceFile -; ASM: .long 1 # LineNumber +; ASM: .long 0x100b # UDT +; ASM: .long 0x100c # SourceFile +; ASM: .long 0x1 # LineNumber ; ASM: # UdtSourceLine (0x100D) { ; ASM: # TypeLeafKind: LF_UDT_SRC_LINE (0x1606) ; ASM: # UDT: A (0x100B) @@ -586,10 +586,10 @@ ; ASM: # } ; ASM: .short 18 ; ASM: .short 4098 -; ASM: .long 4105 # PointeeType -; ASM: .long 65644 # Attributes -; ASM: .long 4101 # ClassType -; ASM: .short 8 # Representation +; ASM: .long 0x1009 # PointeeType +; ASM: .long 0x1006c # Attributes +; ASM: .long 0x1005 # ClassType +; ASM: .short 0x8 # Representation ; ASM: .byte 242 ; ASM: .byte 241 ; ASM: # Pointer (0x100E) { @@ -610,8 +610,8 @@ ; ASM: # } ; ASM: .short 10 ; ASM: .short 4097 -; ASM: .long 3 # ModifiedType -; ASM: .short 1 # Modifiers +; ASM: .long 0x3 # ModifiedType +; ASM: .short 0x1 # Modifiers ; ASM: .byte 242 ; ASM: .byte 241 ; ASM: # Modifier (0x100F) { @@ -623,8 +623,8 @@ ; ASM: # } ; ASM: .short 10 ; ASM: .short 4098 -; ASM: .long 4111 # PointeeType -; ASM: .long 65548 # Attributes +; ASM: .long 0x100f # PointeeType +; ASM: .long 0x1000c # Attributes ; ASM: # Pointer (0x1010) { ; ASM: # TypeLeafKind: LF_POINTER (0x1002) ; ASM: # PointeeType: const void (0x100F) @@ -641,11 +641,11 @@ ; ASM: # } ; ASM: .short 14 ; ASM: .short 4104 -; ASM: .long 3 # ReturnType -; ASM: .byte 0 # CallingConvention -; ASM: .byte 0 # FunctionOptions -; ASM: .short 0 # NumParameters -; ASM: .long 4104 # ArgListType +; ASM: .long 0x3 # ReturnType +; ASM: .byte 0x0 # CallingConvention +; ASM: .byte 0x0 # FunctionOptions +; ASM: .short 0x0 # NumParameters +; ASM: .long 0x1008 # ArgListType ; ASM: # Procedure (0x1011) { ; ASM: # TypeLeafKind: LF_PROCEDURE (0x1008) ; ASM: # ReturnType: void (0x3) @@ -657,8 +657,8 @@ ; ASM: # } ; ASM: .short 22 ; ASM: .short 5633 -; ASM: .long 0 # ParentScope -; ASM: .long 4113 # FunctionType +; ASM: .long 0x0 # ParentScope +; ASM: .long 0x1011 # FunctionType ; ASM: .asciz "CharTypes" # Name ; ASM: .byte 242 ; ASM: .byte 241 @@ -670,7 +670,7 @@ ; ASM: # } ; ASM: .short 26 ; ASM: .short 5637 -; ASM: .long 0 # Id +; ASM: .long 0x0 # Id ; ASM: .asciz "D:\\src\\llvm\\build" # StringData ; ASM: .byte 242 ; ASM: .byte 241 @@ -681,7 +681,7 @@ ; ASM: # } ; ASM: .short 14 ; ASM: .short 5637 -; ASM: .long 0 # Id +; ASM: .long 0x0 # Id ; ASM: .asciz "t.cpp" # StringData ; ASM: .byte 242 ; ASM: .byte 241 @@ -692,12 +692,12 @@ ; ASM: # } ; ASM: .short 26 ; ASM: .short 5635 -; ASM: .short 5 # NumArgs -; ASM: .long 4115 # Argument -; ASM: .long 0 # Argument -; ASM: .long 4116 # Argument -; ASM: .long 0 # Argument -; ASM: .long 0 # Argument +; ASM: .short 0x5 # NumArgs +; ASM: .long 0x1013 # Argument +; ASM: .long 0x0 # Argument +; ASM: .long 0x1014 # Argument +; ASM: .long 0x0 # Argument +; ASM: .long 0x0 # Argument ; ASM: .byte 242 ; ASM: .byte 241 ; ASM: # BuildInfo (0x1015) {