{****************************************************************************
Copyright (c) 1993,94 by Florian Klämpfl
****************************************************************************}
unit opt;
interface
uses
cobjects,globals,asmgen,codegen,symtable,strings;
{ führt nur einfache Optimierungen durch, wie Löschen von Sprüngen }
{ auf direkt folgendes Label... }
procedure simpljumpopt(var asml : tasmlist);
implementation
procedure simpljumpopt(var asml : tasmlist);
var
p,hp1,hp2 : pasmrec;
jump : boolean;
begin
{$ifdef tp}
if use_big then
exit;
{$endif}
p:=asml.wurzel;
while assigned(p) do
begin
jump:=false;
case p^.instruc of
JE,
JNE,
JL,
JG,
JLE,
JGE,
JNZ,
JNO,
JZ,
JS,
JNS,
JO : begin
jump:=true;
if (assigned(p^.next)) and
(p^.next^.instruc=JMP) and
(assigned(p^.next^.next)) and
(p^.next^.next^.instruc=A_LABEL) and
(p^.next^.next^.l=p^.l) then
begin
case p^.instruc of
JE : p^.instruc:=JNE;
JNE : p^.instruc:=JE;
JL : p^.instruc:=JGE;
JG : p^.instruc:=JLE;
JLE : p^.instruc:=JG;
JGE : p^.instruc:=JL;
JNZ : p^.instruc:=JZ;
JNO : p^.instruc:=JO;
JZ : p^.instruc:=JNZ;
JS : p^.instruc:=JNS;
JNS : p^.instruc:=JS;
JO : p^.instruc:=JNO;
JC : p^.instruc:=JNC;
JNC : p^.instruc:=JC;
JA : p^.instruc:=JBE;
JAE : p^.instruc:=JB;
JB : p^.instruc:=JAE;
JBE : p^.instruc:=JA;
end;
p^.next^.instruc:=A_NONE;
p^.l:=p^.next^.l;
end;
end;
JMP : begin
jump:=true;
end;
POP : begin
if (assigned(p^.next)) and
(p^.next^.instruc=PUSH) and
(strcomp(p^.t,p^.next^.t)=0) then
begin
p^.instruc:=A_NONE;
p^.next^.instruc:=A_NONE;
end;
end;
end;
if jump then
begin
if (assigned(p^.next)) and
(p^.next^.instruc=A_LABEL) and
(p^.next^.l=p^.l) then
p^.instruc:=A_NONE;
end;
p:=p^.next;
end;
end;
end.