Ignore:
Timestamp:
Dec 4, 2014, 2:59:28 PM (10 years ago)
Author:
chronos
Message:
  • Modified: Now commands cmInc, cmDec, cmPointerInc, cmPointerDec and cmSet use numeric parameter to merge multiple small steps to one unary operation with numeric parameter. Optimization is done on TTarget side and not on each specific targets.
  • Added: Optimization to eliminate redundant source code.
  • Added: Optimization level option in Options dialog.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Target/UTargetDelphi.pas

    r60 r64  
    5959  FProgramIndex := 0;
    6060  while (FProgramIndex < Length(FProgram)) do begin
    61     case FProgram[FProgramIndex] of
    62       cmPointerInc: begin
    63         Sum := CheckOccurence(cmPointerInc);
    64         AddLine('Inc(Pos, ' + IntToStr(Sum) + ');');
    65       end;
    66       cmPointerDec: begin
    67         Sum := CheckOccurence(cmPointerDec);
    68         AddLine('Dec(Pos, ' + IntToStr(Sum) + ');');
    69       end;
    70       cmInc: begin
    71         Sum := CheckOccurence(cmInc);
    72         AddLine('Memory[Pos] := Memory[Pos] + ' + IntToStr(Sum) + ';');
    73       end;
    74       cmDec: begin
    75         Sum := CheckOccurence(cmDec);
    76         AddLine('Memory[Pos] := Memory[Pos] - ' + IntToStr(Sum) + ';');
    77       end;
     61    case FProgram[FProgramIndex].Command of
     62      cmPointerInc: AddLine('Inc(Pos, ' + IntToStr(FProgram[FProgramIndex].Parameter) + ');');
     63      cmPointerDec: AddLine('Dec(Pos, ' + IntToStr(FProgram[FProgramIndex].Parameter) + ');');
     64      cmInc: AddLine('Memory[Pos] := Memory[Pos] + ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';');
     65      cmDec: AddLine('Memory[Pos] := Memory[Pos] - ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';');
     66      cmSet: AddLine('Memory[Pos] := ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';');
    7867      cmOutput: AddLine('Write(Chr(Memory[Pos]));');
    7968      cmInput: AddLine('Read(ReadChar); Memory[Pos] := Ord(ReadChar);');
    8069      cmLoopStart: begin
    81         if CheckClear then begin
    82           AddLine('Memory[Pos] := 0;');
    83           Inc(FProgramIndex, 2);
    84         end else begin
    85           AddLine('while Memory[Pos] <> 0 do begin');
    86           Inc(Indent);
    87         end;
     70        AddLine('while Memory[Pos] <> 0 do begin');
     71        Inc(Indent);
    8872      end;
    8973      cmLoopEnd: begin
Note: See TracChangeset for help on using the changeset viewer.