tomlokhorst / language-cil

Manipulating Common Intermediate Language AST in Haskell
Other
20 stars 8 forks source link

Aliases #14

Open dmcclean opened 13 years ago

dmcclean commented 13 years ago

There are a few aliases defined in the IL grammar in Partition VI, Annex C, Section C.1 et seq.

OPALIAS(CEE_BRNULL, "brnull", CEE_BRFALSE)
OPALIAS(CEE_BRNULL_S, "brnull.s", CEE_BRFALSE_S)
OPALIAS(CEE_BRZERO, "brzero", CEE_BRFALSE)
OPALIAS(CEE_BRZERO_S, "brzero.s", CEE_BRFALSE_S)
OPALIAS(CEE_BRINST, "brinst", CEE_BRTRUE)
OPALIAS(CEE_BRINST_S, "brinst.s", CEE_BRTRUE_S)
OPALIAS(CEE_LDIND_U8, "ldind.u8", CEE_LDIND_I8)
OPALIAS(CEE_LDELEM_U8, "ldelem.u8", CEE_LDELEM_I8)
OPALIAS(CEE_LDC_I4_M1x, "ldc.i4.M1", CEE_LDC_I4_M1)
OPALIAS(CEE_ENDFAULT, "endfault", CEE_ENDFINALLY)

Aside from the ldc.i4.M1 alias for ldc.i4.m1, which I figure is pretty useless, should we include these as alternatives in OpCode (burdening analysis, at least by requiring a canonicalization function) or omit them (burdening parsing, and preventing a round-trip-able parser/pretty-printer).

We presently have Ldelem_U8, but not Ldind_U8 or any of the others.

I lean toward including them all (except the M1 one), so that the parser and printer are preserve the useful-as-a-hint-to-humans differences between these and what they alias. Even moreso because I think it makes sense to have a simplification function before most analyses anyway, along the lines of:

simplify :: OpCode -> OpCode
simplify (Br_s Label) = Br Label
simplify (Ldc_i4_3) = Ldc_i4 3
simplify (Endfault) = Endfinally

and so forth.