[go: up one dir, main page]

Skip to content

add new mw ast pass to reduce ast

function fib, 1
    arg n
    label 0
        goto 1
    label 1
        a = 0
        b = 1
        i = 1
        goto begin
    label begin
        if (i == n) goto end
        goto 4
    label end
        ret b
    label 4
        t = b
        b = a + b
        a = t
        i = i + 1
        goto begin

Transform this unoptimized AST to something like

function fib, 1
    arg n
    a = 0
    b = 1
    i = 1
    goto begin
    label begin
        if (i == n) goto end
        t = b
        b = a + b
        a = t
        i = i + 1
        goto begin
    label end
        ret b