Opened 2 years ago

#14134 new feature request

Implement enums for Cmm

Reported by: niteria Owned by:
Priority: low Milestone:
Component: Compiler (CodeGen) Version:
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

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 #defines.

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

Change History (0)

Note: See TracTickets for help on using tickets.