Browse Source

enum widths default to 8 bits

Pat Hickey 9 years ago
parent
commit
43871f4fd8
2 changed files with 5 additions and 3 deletions
  1. 1 1
      src/Gidl/Parse.hs
  2. 4 2
      tests/example.idl

+ 1 - 1
src/Gidl/Parse.hs

@@ -242,7 +242,7 @@ tEnumDecl = asList go
 
 tEnumName :: Parse (Identifier, Bits)
 tEnumName (L [name, size]) = (,) <$> tSymbol name <*> tBits size
-tEnumName name             = (,) <$> tSymbol name <*> return Bits32
+tEnumName name             = (,) <$> tSymbol name <*> return Bits8
 
 tEnumBody :: Parse (Identifier, Integer)
 tEnumBody e =

+ 4 - 2
tests/example.idl

@@ -16,7 +16,7 @@
 
 -- Enums are pairs of names and integer values. Must be a one-to-one
 -- mapping: names are not repeated, values are not repeated.
+-- Enums default to 8 bit width if you don't really care.
 -- N.B. we should probably change it to default to the smallest
 -- width that fits the values the user declared.
 (def-enum mode_t
@@ -25,9 +25,10 @@
 
 -- The user can specify a bit width for enums with the
 -- following syntax. 8, 16, 32, 64 bit widths are valid.
-(def-enum (armed_t 8)
+-- Integer literals can use any haskell integer literal format
+(def-enum (armed_t 32)
  (disarmed 0)
- (armed 1))
+ (armed 0x80000000))
 
 -- Structures are a set of pairs of names and types. All
 -- names must be distinct. All types must be atomic, enum,