DAG.PAS the Directed Acyclic Graph that comes with the ORCA/C sources from ByteWorks When you climb, you must be aware of your capacities or skills or performances. When you climb, you must know by heart the route to the top or to the summit. When you climb, you must be honest with yourself - it must be clear cut. If you wan't to recode the Pascal DAG from ByteWorks you must know its characteristics : Statistiques de DAG.pas : Caractères : 146670 Mots : 16310 Lignes : 4795 Paragraphes : 4735 Pages : 112 So the route to recode DAG.pas in C is a project of nearly 5000 lines of C. Good luck... The texts below are very little pieces of the DAG.pas source file : {$optimize 7} unit DAG; interface {$segment 'cg'} {$LibPrefix 'O/obj'} uses CCommon, CGI, CGC, Gen; procedure DAG(code:icptr); {place an op code in a DAG or tree} {parameters : } { code-opcode} {--External unsigned math routines; imported from Expression.pas --} function udiv(x,y:longint):longint; function umod(x,y:longint):longint; function umul(x,y:longint):longint; procedure Generate; {generate the code for the current procedure} var op:icptr; {temp opcode pointers} procedure BasicBlocks; {Break the code up into basic blocks} var blast:blockPtr; {last block pointer} bp:blockPtr; {current block pointer} cb:icptr; {last code in block pointer} cp:icptr; {current code pointer} begin {BasicBlocks} cp:=DAGhead; DAGblocks:=nil; if cp<>nil then begin bp:=pointer(Calloc(sizeof(block))); DAGblocks:=bp; blast:=bp; bp^.code:=cp; cb:=cp; cp:=cp^.next; cb^.next:=nil; while cp<>nil do {labels start a new block} if cp^.opcode=dc_lab then begin Spin; bp:=pointer(Calloc(sizeof(block))); bp^.last:=blast; blast^.next:=bp; blast:=bp; bp^.code:=cp; cb:=cp; cp:=cp^.next; cb^.next:=nil; end {if} {conditionals are followed by a new block} elseif cp^.opcode in [pc_fjp, pc_tjp, pc_ujp, opc_ret, pc_xjp] then ... begin {Generate} if peepHole then repeat rescan:=false; PeepHoleOptimization(DAGhead); op:=DAGHead; while op^.next<>nil do begin Spin; PeepHoleOptimization(op^.next); op:=op^.next; end; {while} CheckLabels; until not rescan; BasicBlocks; {build the basic blocks} if CommonSubExpression or loopOptimizations then if not volatile then FlagIndirectUses; {create a list of all indirect uses} ... if CommonSubExpression or loopOptimizations then if not volatile then DisposeOpList(c_ind); {dispose of indirect use list} Gen(DAGblocks); {generate native code} if loopOptimizations then {dump and dynamic spice} if not volatile then DumpLoopLists; DAGhead:=nil; {reset the DAG pointers}