kekyo / IL2C

IL2C - A translator for ECMA-335 CIL/MSIL to C language.
Apache License 2.0
401 stars 36 forks source link

Improvement for evaluation stack handling. #29

Closed kekyo closed 6 years ago

kekyo commented 6 years ago
    int32_t stack0_0;
    intptr_t stack0_1;
    int32_t stack1_0;
    intptr_t stack1_1;
    int32_t stack2_0;

    // Body...

Combined to:

    union {
        int32_t slot0;
        intptr_t slot1;
    } stack0;
    union {
        int32_t slot0;
        intptr_t slot1;
    } stack1;
    int32_t stack2_0;

    // Body...

If contained OR:

    union {
        int32_t slot0;
        intptr_t slot1;
    } stack0;
    union {
        int32_t slot0;
        intptr_t slot1;
    } stack1;
    System_String* stack1_2;   // Have to NOT combined into stack1.
    int32_t stack2_0;

    // Body...

Because GC's required trackable for OR.

Pros:

Cons:

kekyo commented 6 years ago

fc0e82dfca0194c6fd4b1b71f148a49d1d4b102c

Finally, I changed stack storage from one by one definition to aggregated at one structure for objrefs. For example (TypeSystems/DelegateTypes/Base_Int32ToString):

    struct /* IL2C_EXECUTION_FRAME */
    {
        uint8_t objRefCount__;
        uint8_t objRefRefCount__;
        IL2C_EXECUTION_FRAME* pNext__;
        System_String* local0__;
        System_String* stack0_1__;
        System_String* stack1_0__;
        IL2C_TypeSystems_DelegateTypesWithVirtual_Base* stack2_0__;
        System_String* stack2_2__;
    } frame__ = { 5, 0 };

    il2c_link_execution_frame(&frame__);

The frame__ is unnamed structure for the new EXECUTION_FRAME format. It contains the local variables and evaluation stacks for objrefs.

It has advantage for:

The disadvantages are:

"Unioning" cancelled. Because the union members are maybe disable the optimization target for C compiler.