[WebAssembly] Use bitfield types in wasm YAML representation

Differential Revision: https://reviews.llvm.org/D41202

llvm-svn: 320642
This commit is contained in:
Sam Clegg 2017-12-13 22:02:25 +00:00
parent 580bc3c8fa
commit 0fc5599f52
17 changed files with 90 additions and 53 deletions

View File

@ -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<WasmYAML::Global> {
static void mapping(IO &IO, WasmYAML::Global &Global);
};
template <> struct ScalarBitSetTraits<WasmYAML::LimitFlags> {
static void bitset(IO &IO, WasmYAML::LimitFlags &Value);
};
template <> struct ScalarBitSetTraits<WasmYAML::SymbolFlags> {
static void bitset(IO &IO, WasmYAML::SymbolFlags &Value);
};
template <> struct ScalarBitSetTraits<WasmYAML::SegmentFlags> {
static void bitset(IO &IO, WasmYAML::SegmentFlags &Value);
};
template <> struct ScalarEnumerationTraits<WasmYAML::SectionType> {
static void enumeration(IO &IO, WasmYAML::SectionType &Type);
};

View File

@ -365,6 +365,28 @@ void MappingTraits<WasmYAML::SymbolInfo>::mapping(IO &IO,
IO.mapRequired("Flags", Info.Flags);
}
void ScalarBitSetTraits<WasmYAML::LimitFlags>::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<WasmYAML::SegmentFlags>::bitset(
IO &IO, WasmYAML::SegmentFlags &Value) {
}
void ScalarBitSetTraits<WasmYAML::SymbolFlags>::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<WasmYAML::ValueType>::enumeration(
IO &IO, WasmYAML::ValueType &Type) {
#define ECase(X) IO.enumCase(Type, #X, wasm::WASM_TYPE_##X);

View File

@ -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: ...

View File

@ -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: ...

View File

@ -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: ...

View File

@ -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: ...

View File

@ -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: ...

View File

@ -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: ...

View File

@ -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:

View File

@ -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: ...

View File

@ -7,7 +7,7 @@ Sections:
Tables:
- ElemType: ANYFUNC
Limits:
Flags: 0x00000001
Flags: [ HAS_MAX ]
Initial: 0x00000010
Maximum: 0x00000011
- Type: ELEM

View File

@ -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: ...

View File

@ -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: ...

View File

@ -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

View File

@ -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: ...

View File

@ -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 ]

View File

@ -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