From 0fc5599f529067a311bb39d19589d53b572d524d Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Wed, 13 Dec 2017 22:02:25 +0000 Subject: [PATCH] [WebAssembly] Use bitfield types in wasm YAML representation Differential Revision: https://reviews.llvm.org/D41202 llvm-svn: 320642 --- llvm/include/llvm/ObjectYAML/WasmYAML.h | 21 +++++++++++++++--- llvm/lib/ObjectYAML/WasmYAML.cpp | 22 +++++++++++++++++++ llvm/test/MC/WebAssembly/array-fill.ll | 4 ++-- llvm/test/MC/WebAssembly/bss.ll | 8 +++---- llvm/test/MC/WebAssembly/explicit-sections.ll | 6 ++--- llvm/test/MC/WebAssembly/init-fini-array.ll | 6 ++--- llvm/test/MC/WebAssembly/unnamed-data.ll | 12 +++++----- llvm/test/MC/WebAssembly/visibility.ll | 2 +- llvm/test/MC/WebAssembly/weak-alias.ll | 12 +++++----- llvm/test/MC/WebAssembly/weak.ll | 4 ++-- llvm/test/ObjectYAML/wasm/elem_section.yaml | 2 +- llvm/test/ObjectYAML/wasm/import_section.yaml | 8 +++---- .../test/ObjectYAML/wasm/linking_section.yaml | 12 +++++----- llvm/test/ObjectYAML/wasm/memory_section.yaml | 4 ++-- llvm/test/ObjectYAML/wasm/table_section.yaml | 4 ++-- llvm/test/ObjectYAML/wasm/weak_symbols.yaml | 8 +++---- .../test/tools/llvm-nm/wasm/weak-symbols.yaml | 8 +++---- 17 files changed, 90 insertions(+), 53 deletions(-) diff --git a/llvm/include/llvm/ObjectYAML/WasmYAML.h b/llvm/include/llvm/ObjectYAML/WasmYAML.h index d26faa148623..c37aa9c07717 100644 --- a/llvm/include/llvm/ObjectYAML/WasmYAML.h +++ b/llvm/include/llvm/ObjectYAML/WasmYAML.h @@ -34,13 +34,16 @@ LLVM_YAML_STRONG_TYPEDEF(int32_t, SignatureForm) LLVM_YAML_STRONG_TYPEDEF(uint32_t, ExportKind) LLVM_YAML_STRONG_TYPEDEF(uint32_t, Opcode) LLVM_YAML_STRONG_TYPEDEF(uint32_t, RelocType) +LLVM_YAML_STRONG_TYPEDEF(uint32_t, SymbolFlags); +LLVM_YAML_STRONG_TYPEDEF(uint32_t, SegmentFlags); +LLVM_YAML_STRONG_TYPEDEF(uint32_t, LimitFlags); struct FileHeader { yaml::Hex32 Version; }; struct Limits { - yaml::Hex32 Flags; + LimitFlags Flags; yaml::Hex32 Initial; yaml::Hex32 Maximum; }; @@ -113,7 +116,7 @@ struct SegmentInfo { uint32_t Index; StringRef Name; uint32_t Alignment; - uint32_t Flags; + SegmentFlags Flags; }; struct Signature { @@ -125,7 +128,7 @@ struct Signature { struct SymbolInfo { StringRef Name; - uint32_t Flags; + SymbolFlags Flags; }; struct Section { @@ -334,6 +337,18 @@ template <> struct MappingTraits { static void mapping(IO &IO, WasmYAML::Global &Global); }; +template <> struct ScalarBitSetTraits { + static void bitset(IO &IO, WasmYAML::LimitFlags &Value); +}; + +template <> struct ScalarBitSetTraits { + static void bitset(IO &IO, WasmYAML::SymbolFlags &Value); +}; + +template <> struct ScalarBitSetTraits { + static void bitset(IO &IO, WasmYAML::SegmentFlags &Value); +}; + template <> struct ScalarEnumerationTraits { static void enumeration(IO &IO, WasmYAML::SectionType &Type); }; diff --git a/llvm/lib/ObjectYAML/WasmYAML.cpp b/llvm/lib/ObjectYAML/WasmYAML.cpp index 2f961cf68a04..c206a682b83b 100644 --- a/llvm/lib/ObjectYAML/WasmYAML.cpp +++ b/llvm/lib/ObjectYAML/WasmYAML.cpp @@ -365,6 +365,28 @@ void MappingTraits::mapping(IO &IO, IO.mapRequired("Flags", Info.Flags); } +void ScalarBitSetTraits::bitset( + IO &IO, WasmYAML::LimitFlags &Value) { +#define BCase(X) IO.bitSetCase(Value, #X, wasm::WASM_LIMITS_FLAG_##X) + BCase(HAS_MAX); +#undef BCase +} + +void ScalarBitSetTraits::bitset( + IO &IO, WasmYAML::SegmentFlags &Value) { +} + +void ScalarBitSetTraits::bitset( + IO &IO, WasmYAML::SymbolFlags &Value) { +#define BCaseMask(M, X) IO.maskedBitSetCase(Value, #X, wasm::WASM_SYMBOL_##X, wasm::WASM_SYMBOL_##M) + //BCaseMask(BINDING_MASK, BINDING_GLOBAL); + BCaseMask(BINDING_MASK, BINDING_WEAK); + BCaseMask(BINDING_MASK, BINDING_LOCAL); + //BCaseMask(VISIBILITY_MASK, VISIBILITY_DEFAULT); + BCaseMask(VISIBILITY_MASK, VISIBILITY_HIDDEN); +#undef BCaseMask +} + void ScalarEnumerationTraits::enumeration( IO &IO, WasmYAML::ValueType &Type) { #define ECase(X) IO.enumCase(Type, #X, wasm::WASM_TYPE_##X); diff --git a/llvm/test/MC/WebAssembly/array-fill.ll b/llvm/test/MC/WebAssembly/array-fill.ll index a85d4702964a..7f392c4ca47a 100644 --- a/llvm/test/MC/WebAssembly/array-fill.ll +++ b/llvm/test/MC/WebAssembly/array-fill.ll @@ -17,10 +17,10 @@ target triple = "wasm32-unknown-unknown-wasm" ; CHECK-NEXT: DataSize: 2 ; CHECK-NEXT: SymbolInfo: ; CHECK-NEXT: - Name: gBd -; CHECK-NEXT: Flags: 4 +; CHECK-NEXT: Flags: [ VISIBILITY_HIDDEN ] ; CHECK-NEXT: SegmentInfo: ; CHECK-NEXT: - Index: 0 ; CHECK-NEXT: Name: .data ; CHECK-NEXT: Alignment: 1 -; CHECK-NEXT: Flags: 0 +; CHECK-NEXT: Flags: [ ] ; CHECK-NEXT: ... diff --git a/llvm/test/MC/WebAssembly/bss.ll b/llvm/test/MC/WebAssembly/bss.ll index 9ac83c49cdbd..66fad935fd82 100644 --- a/llvm/test/MC/WebAssembly/bss.ll +++ b/llvm/test/MC/WebAssembly/bss.ll @@ -76,17 +76,17 @@ ; CHECK-NEXT: - Index: 0 ; CHECK-NEXT: Name: .bss.g0 ; CHECK-NEXT: Alignment: 4 -; CHECK-NEXT: Flags: 0 +; CHECK-NEXT: Flags: [ ] ; CHECK-NEXT: - Index: 1 ; CHECK-NEXT: Name: .bss.g1 ; CHECK-NEXT: Alignment: 4 -; CHECK-NEXT: Flags: 0 +; CHECK-NEXT: Flags: [ ] ; CHECK-NEXT: - Index: 2 ; CHECK-NEXT: Name: .bss.foo ; CHECK-NEXT: Alignment: 1 -; CHECK-NEXT: Flags: 0 +; CHECK-NEXT: Flags: [ ] ; CHECK-NEXT: - Index: 3 ; CHECK-NEXT: Name: .bss.bar ; CHECK-NEXT: Alignment: 1 -; CHECK-NEXT: Flags: 0 +; CHECK-NEXT: Flags: [ ] ; CHECK-NEXT: ... diff --git a/llvm/test/MC/WebAssembly/explicit-sections.ll b/llvm/test/MC/WebAssembly/explicit-sections.ll index 876adf0be3b5..87a2c6bcf03d 100644 --- a/llvm/test/MC/WebAssembly/explicit-sections.ll +++ b/llvm/test/MC/WebAssembly/explicit-sections.ll @@ -71,13 +71,13 @@ ; CHECK-NEXT: - Index: 0 ; CHECK-NEXT: Name: .data.global0 ; CHECK-NEXT: Alignment: 8 -; CHECK-NEXT: Flags: 0 +; CHECK-NEXT: Flags: [ ] ; CHECK-NEXT: - Index: 1 ; CHECK-NEXT: Name: .sec1 ; CHECK-NEXT: Alignment: 8 -; CHECK-NEXT: Flags: 0 +; CHECK-NEXT: Flags: [ ] ; CHECK-NEXT: - Index: 2 ; CHECK-NEXT: Name: .sec2 ; CHECK-NEXT: Alignment: 8 -; CHECK-NEXT: Flags: 0 +; CHECK-NEXT: Flags: [ ] ; CHECK-NEXT: ... diff --git a/llvm/test/MC/WebAssembly/init-fini-array.ll b/llvm/test/MC/WebAssembly/init-fini-array.ll index b7a1826bdc47..0a809a226c40 100644 --- a/llvm/test/MC/WebAssembly/init-fini-array.ll +++ b/llvm/test/MC/WebAssembly/init-fini-array.ll @@ -92,14 +92,14 @@ declare void @func2() ; CHECK-NEXT: - Index: 0 ; CHECK-NEXT: Name: .data.global1 ; CHECK-NEXT: Alignment: 8 -; CHECK-NEXT: Flags: 0 +; CHECK-NEXT: Flags: [ ] ; CHECK-NEXT: - Index: 1 ; CHECK-NEXT: Name: .init_array ; CHECK-NEXT: Alignment: 4 -; CHECK-NEXT: Flags: 0 +; CHECK-NEXT: Flags: [ ] ; CHECK-NEXT: - Index: 2 ; CHECK-NEXT: Name: .fini_array ; CHECK-NEXT: Alignment: 4 -; CHECK-NEXT: Flags: 0 +; CHECK-NEXT: Flags: [ ] ; CHECK-NEXT: ... diff --git a/llvm/test/MC/WebAssembly/unnamed-data.ll b/llvm/test/MC/WebAssembly/unnamed-data.ll index 88b39102a774..98e7a81c1962 100644 --- a/llvm/test/MC/WebAssembly/unnamed-data.ll +++ b/llvm/test/MC/WebAssembly/unnamed-data.ll @@ -81,24 +81,24 @@ ; CHECK-NEXT: DataSize: 28 ; CHECK-NEXT: SymbolInfo: ; CHECK-NEXT: - Name: .L.str1 -; CHECK-NEXT: Flags: 2 +; CHECK-NEXT: Flags: [ BINDING_LOCAL ] ; CHECK-NEXT: - Name: .L.str2 -; CHECK-NEXT: Flags: 2 +; CHECK-NEXT: Flags: [ BINDING_LOCAL ] ; CHECK-NEXT: SegmentInfo: ; CHECK-NEXT: - Index: 0 ; CHECK-NEXT: Name: .rodata..L.str1 ; CHECK-NEXT: Alignment: 1 -; CHECK-NEXT: Flags: 0 +; CHECK-NEXT: Flags: [ ] ; CHECK-NEXT: - Index: 1 ; CHECK-NEXT: Name: .rodata..L.str2 ; CHECK-NEXT: Alignment: 1 -; CHECK-NEXT: Flags: 0 +; CHECK-NEXT: Flags: [ ] ; CHECK-NEXT: - Index: 2 ; CHECK-NEXT: Name: .data.a ; CHECK-NEXT: Alignment: 8 -; CHECK-NEXT: Flags: 0 +; CHECK-NEXT: Flags: [ ] ; CHECK-NEXT: - Index: 3 ; CHECK-NEXT: Name: .data.b ; CHECK-NEXT: Alignment: 8 -; CHECK-NEXT: Flags: 0 +; CHECK-NEXT: Flags: [ ] ; CHECK_NEXT: ... diff --git a/llvm/test/MC/WebAssembly/visibility.ll b/llvm/test/MC/WebAssembly/visibility.ll index b445bf45e29a..7e57848f96db 100644 --- a/llvm/test/MC/WebAssembly/visibility.ll +++ b/llvm/test/MC/WebAssembly/visibility.ll @@ -19,5 +19,5 @@ entry: ; CHECK-NEXT: DataSize: 0 ; CHECK-NEXT: SymbolInfo: ; CHECK-NEXT: - Name: hiddenVis -; CHECK-NEXT: Flags: 4 +; CHECK-NEXT: Flags: [ VISIBILITY_HIDDEN ] ; CHECK-NEXT: ... diff --git a/llvm/test/MC/WebAssembly/weak-alias.ll b/llvm/test/MC/WebAssembly/weak-alias.ll index 5c85fc09b03f..5f5d9b447c71 100644 --- a/llvm/test/MC/WebAssembly/weak-alias.ll +++ b/llvm/test/MC/WebAssembly/weak-alias.ll @@ -109,22 +109,22 @@ entry: ; CHECK-NEXT: DataSize: 12 ; CHECK-NEXT: SymbolInfo: ; CHECK-NEXT: - Name: call_alias -; CHECK-NEXT: Flags: 4 +; CHECK-NEXT: Flags: [ VISIBILITY_HIDDEN ] ; CHECK-NEXT: - Name: foo -; CHECK-NEXT: Flags: 4 +; CHECK-NEXT: Flags: [ VISIBILITY_HIDDEN ] ; CHECK-NEXT: - Name: foo_alias -; CHECK-NEXT: Flags: 5 +; CHECK-NEXT: Flags: [ BINDING_WEAK, VISIBILITY_HIDDEN ] ; CHECK-NEXT: - Name: bar_alias -; CHECK-NEXT: Flags: 5 +; CHECK-NEXT: Flags: [ BINDING_WEAK, VISIBILITY_HIDDEN ] ; CHECK-NEXT: SegmentInfo: ; CHECK-NEXT: - Index: 0 ; CHECK-NEXT: Name: .data.bar ; CHECK-NEXT: Alignment: 8 -; CHECK-NEXT: Flags: 0 +; CHECK-NEXT: Flags: [ ] ; CHECK-NEXT: - Index: 1 ; CHECK-NEXT: Name: .data.bar_alias_address ; CHECK-NEXT: Alignment: 8 -; CHECK-NEXT: Flags: 0 +; CHECK-NEXT: Flags: [ ] ; CHECK-NEXT: ... ; CHECK-SYMS: SYMBOL TABLE: diff --git a/llvm/test/MC/WebAssembly/weak.ll b/llvm/test/MC/WebAssembly/weak.ll index af177b53595d..b5e894b41c47 100644 --- a/llvm/test/MC/WebAssembly/weak.ll +++ b/llvm/test/MC/WebAssembly/weak.ll @@ -33,7 +33,7 @@ entry: ; CHECK-NEXT: DataSize: 0 ; CHECK-NEXT: SymbolInfo: ; CHECK-NEXT: - Name: weak_external_data -; CHECK-NEXT: Flags: 1 +; CHECK-NEXT: Flags: [ BINDING_WEAK ] ; CHECK-NEXT: - Name: weak_function -; CHECK-NEXT: Flags: 5 +; CHECK-NEXT: Flags: [ BINDING_WEAK, VISIBILITY_HIDDEN ] ; CHECK-NEXT: ... diff --git a/llvm/test/ObjectYAML/wasm/elem_section.yaml b/llvm/test/ObjectYAML/wasm/elem_section.yaml index c55e94ce2d07..684256e0a9ef 100644 --- a/llvm/test/ObjectYAML/wasm/elem_section.yaml +++ b/llvm/test/ObjectYAML/wasm/elem_section.yaml @@ -7,7 +7,7 @@ Sections: Tables: - ElemType: ANYFUNC Limits: - Flags: 0x00000001 + Flags: [ HAS_MAX ] Initial: 0x00000010 Maximum: 0x00000011 - Type: ELEM diff --git a/llvm/test/ObjectYAML/wasm/import_section.yaml b/llvm/test/ObjectYAML/wasm/import_section.yaml index 115d4cc0bd6b..000b4c270c37 100644 --- a/llvm/test/ObjectYAML/wasm/import_section.yaml +++ b/llvm/test/ObjectYAML/wasm/import_section.yaml @@ -23,7 +23,7 @@ Sections: Field: imported_memory Kind: MEMORY Memory: - Flags: 0x00000001 + Flags: [ HAS_MAX ] Initial: 0x00000010 Maximum: 0x00000011 - Module: foo @@ -32,7 +32,7 @@ Sections: Table: ElemType: ANYFUNC Limits: - Flags: 0x00000001 + Flags: [ HAS_MAX ] Initial: 0x00000020 Maximum: 0x00000022 ... @@ -55,7 +55,7 @@ Sections: # CHECK: Field: imported_memory # CHECK: Kind: MEMORY # CHECK: Memory: -# CHECK: Flags: 0x00000001 +# CHECK: Flags: [ HAS_MAX ] # CHECK: Initial: 0x00000010 # CHECK: Maximum: 0x00000011 # CHECK: - Module: foo @@ -64,7 +64,7 @@ Sections: # CHECK: Table: # CHECK: ElemType: ANYFUNC # CHECK: Limits: -# CHECK: Flags: 0x00000001 +# CHECK: Flags: [ HAS_MAX ] # CHECK: Initial: 0x00000020 # CHECK: Maximum: 0x00000022 # CHECK: ... diff --git a/llvm/test/ObjectYAML/wasm/linking_section.yaml b/llvm/test/ObjectYAML/wasm/linking_section.yaml index 534d0c335544..3494a9adddcf 100644 --- a/llvm/test/ObjectYAML/wasm/linking_section.yaml +++ b/llvm/test/ObjectYAML/wasm/linking_section.yaml @@ -31,15 +31,15 @@ Sections: DataSize: 999 SymbolInfo: - Name: bar - Flags: 1 + Flags: [ BINDING_WEAK ] SegmentInfo: - Index: 0 Alignment: 4 - Flags: 0 + Flags: [ ] Name: mydata - Index: 1 Alignment: 2 - Flags: 1 + Flags: [ ] Name: moredata ... # CHECK: - Type: CUSTOM @@ -47,14 +47,14 @@ Sections: # CHECK-NEXT: DataSize: 999 # CHECK-NEXT: SymbolInfo: # CHECK-NEXT: - Name: bar -# CHECK-NEXT: Flags: 1 +# CHECK-NEXT: Flags: [ BINDING_WEAK ] # CHECK-NEXT: SegmentInfo: # CHECK-NEXT: - Index: 0 # CHECK-NEXT: Name: mydata # CHECK-NEXT: Alignment: 4 -# CHECK-NEXT: Flags: 0 +# CHECK-NEXT: Flags: [ ] # CHECK-NEXT: - Index: 1 # CHECK-NEXT: Name: moredata # CHECK-NEXT: Alignment: 2 -# CHECK-NEXT: Flags: 1 +# CHECK-NEXT: Flags: [ ] # CHECK-NEXT: ... diff --git a/llvm/test/ObjectYAML/wasm/memory_section.yaml b/llvm/test/ObjectYAML/wasm/memory_section.yaml index 83aae05871db..9ab05241dd85 100644 --- a/llvm/test/ObjectYAML/wasm/memory_section.yaml +++ b/llvm/test/ObjectYAML/wasm/memory_section.yaml @@ -5,7 +5,7 @@ FileHeader: Sections: - Type: MEMORY Memories: - - Flags: 0x00000001 + - Flags: [ HAS_MAX ] Initial: 0x00000002 Maximum: 0x000000FF - Initial: 0x00000003 @@ -16,7 +16,7 @@ Sections: # CHECK: Sections: # CHECK: - Type: MEMORY # CHECK: Memories: -# CHECK: - Flags: 0x00000001 +# CHECK: - Flags: [ HAS_MAX ] # CHECK: Initial: 0x00000002 # CHECK: Maximum: 0x000000FF # CHECK: - Initial: 0x00000003 diff --git a/llvm/test/ObjectYAML/wasm/table_section.yaml b/llvm/test/ObjectYAML/wasm/table_section.yaml index d8b1df25e043..5996b63e1328 100644 --- a/llvm/test/ObjectYAML/wasm/table_section.yaml +++ b/llvm/test/ObjectYAML/wasm/table_section.yaml @@ -7,7 +7,7 @@ Sections: Tables: - ElemType: ANYFUNC Limits: - Flags: 0x00000001 + Flags: [ HAS_MAX ] Initial: 0x00000010 Maximum: 0x00000011 ... @@ -19,7 +19,7 @@ Sections: # CHECK: Tables: # CHECK: - ElemType: ANYFUNC # CHECK: Limits: -# CHECK: Flags: 0x00000001 +# CHECK: Flags: [ HAS_MAX ] # CHECK: Initial: 0x00000010 # CHECK: Maximum: 0x00000011 # CHECK: ... diff --git a/llvm/test/ObjectYAML/wasm/weak_symbols.yaml b/llvm/test/ObjectYAML/wasm/weak_symbols.yaml index d821b34b67df..9af2e54fe58d 100644 --- a/llvm/test/ObjectYAML/wasm/weak_symbols.yaml +++ b/llvm/test/ObjectYAML/wasm/weak_symbols.yaml @@ -29,9 +29,9 @@ Sections: DataSize: 10 SymbolInfo: - Name: function_export - Flags: 1 + Flags: [ BINDING_WEAK ] - Name: global_export - Flags: 1 + Flags: [ BINDING_WEAK ] ... # CHECK: --- !WASM # CHECK: FileHeader: @@ -50,6 +50,6 @@ Sections: # CHECK: DataSize: 10 # CHECK: SymbolInfo: # CHECK: - Name: function_export -# CHECK: Flags: 1 +# CHECK: Flags: [ BINDING_WEAK ] # CHECK: - Name: global_export -# CHECK: Flags: 1 +# CHECK: Flags: [ BINDING_WEAK ] diff --git a/llvm/test/tools/llvm-nm/wasm/weak-symbols.yaml b/llvm/test/tools/llvm-nm/wasm/weak-symbols.yaml index 0500c2d6df38..254fb4ddf683 100644 --- a/llvm/test/tools/llvm-nm/wasm/weak-symbols.yaml +++ b/llvm/test/tools/llvm-nm/wasm/weak-symbols.yaml @@ -55,13 +55,13 @@ Sections: DataSize: 0 SymbolInfo: - Name: weak_global_func - Flags: 1 + Flags: [ BINDING_WEAK ] - Name: weak_global_data - Flags: 1 + Flags: [ BINDING_WEAK ] - Name: weak_import_func - Flags: 1 + Flags: [ BINDING_WEAK ] - Name: weak_import_data - Flags: 1 + Flags: [ BINDING_WEAK ] # CHECK: 00000400 W weak_global_data # CHECK: 00000004 W weak_global_func