[GHC] #14134: Implement enums for Cmm

GHC ghc-devs at haskell.org
Thu Aug 17 12:44:15 UTC 2017


#14134: Implement enums for Cmm
-------------------------------------+-------------------------------------
           Reporter:  niteria        |             Owner:  (none)
               Type:  feature        |            Status:  new
  request                            |
           Priority:  low            |         Milestone:
          Component:  Compiler       |           Version:
  (CodeGen)                          |
           Keywords:                 |  Operating System:  Unknown/Multiple
       Architecture:                 |   Type of failure:  None/Unknown
  Unknown/Multiple                   |
          Test Case:                 |        Blocked By:
           Blocking:                 |   Related Tickets:
Differential Rev(s):                 |         Wiki Page:
-------------------------------------+-------------------------------------
 Using ANSI C enums is documented as a preferred way of defining constants:
 https://ghc.haskell.org/trac/ghc/wiki/Commentary/Rts/Conventions#Syntacticdetails

 Basically instead of writing:
 {{{
 #define INVALID_OBJECT 0
 #define CONSTR 1
 }}}

 you would write:
 {{{
 typedef enum {
  INVALID_OBJECT = 0,
  CONSTR = 1
 } ClosureType;
 }}}

 What you get is easier debugging in gdb, perhaps even better type
 checking.

 Unfortunately some files (most vexingly `rts/storage/ClosureTypes.h`) are
 included in both C and Cmm and Cmm doesn't support this syntax. As far as
 I can tell all constants in Cmm are defined with preprocessor `#define`s.

 Implementing enums/constants may seem like an overkill, but I haven't
 found a good workaround for this.

-- 
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14134>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list