! Copyright (C) 2004, 2005 Slava Pestov. ! See http://factor.sf.net/license.txt for BSD license. IN: compiler-frontend USING: compiler-backend errors generic lists inference kernel math namespaces prettyprint sequences strings words ; SYMBOL: simple-labels GENERIC: linearize* ( node -- ) : linearize ( dataflow -- linear ) #! Transform dataflow IR into linear IR. This strips out #! stack flow information, and flattens conditionals into #! jumps and labels. [ { } clone simple-labels set %prologue , linearize* ] { } make ; : linearize-next node-successor linearize* ; M: f linearize* ( f -- ) drop ; M: node linearize* ( node -- ) linearize-next ; : simple-label? ( #label -- ? ) #! A simple label only contains tail calls to itself. dup node-param swap node-child [ dup #call-label? [ [ node-param = not ] keep node-successor #return? or ] [ 2drop t ] ifte ] all-nodes-with? ; : simple-label ( #label -- ) dup node-param %label , node-child linearize* ; M: #label linearize* ( node -- ) dup simple-label? [ dup node-param simple-labels get push dup simple-label ] [ dup