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/UTargetFPC.pas

    r60 r64  
    4444
    4545procedure TTargetFPC.Compile;
    46 var
    47   Sum: Integer;
    4846begin
    4947  inherited;
     
    6260  FProgramIndex := 0;
    6361  while (FProgramIndex < Length(FProgram)) do begin
    64     case FProgram[FProgramIndex] of
    65       cmPointerInc: begin
    66         Sum := CheckOccurence(cmPointerInc);
    67         AddLine('Inc(Pos, ' + IntToStr(Sum) + ');');
    68       end;
    69       cmPointerDec: begin
    70         Sum := CheckOccurence(cmPointerDec);
    71         AddLine('Dec(Pos, ' + IntToStr(Sum) + ');');
    72       end;
    73       cmInc: begin
    74         Sum := CheckOccurence(cmInc);
    75         AddLine('Memory[Pos] := Memory[Pos] + ' + IntToStr(Sum) + ';');
    76       end;
    77       cmDec: begin
    78         Sum := CheckOccurence(cmDec);
    79         AddLine('Memory[Pos] := Memory[Pos] - ' + IntToStr(Sum) + ';');
    80       end;
     62    case FProgram[FProgramIndex].Command of
     63      cmPointerInc: AddLine('Inc(Pos, ' + IntToStr(FProgram[FProgramIndex].Parameter) + ');');
     64      cmPointerDec: AddLine('Dec(Pos, ' + IntToStr(FProgram[FProgramIndex].Parameter) + ');');
     65      cmInc: AddLine('Memory[Pos] := Memory[Pos] + ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';');
     66      cmDec: AddLine('Memory[Pos] := Memory[Pos] - ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';');
     67      cmSet: AddLine('Memory[Pos] := ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';');
    8168      cmOutput: AddLine('Write(Chr(Memory[Pos]));');
    8269      cmInput: AddLine('Read(ReadChar); Memory[Pos] := Ord(ReadChar);');
    8370      cmLoopStart: begin
    84         if CheckClear then begin
    85           AddLine('Memory[Pos] := 0;');
    86           Inc(FProgramIndex, 2);
    87         end else begin
    88           AddLine('while Memory[Pos] <> 0 do begin');
    89           Inc(Indent);
    90         end;
     71        AddLine('while Memory[Pos] <> 0 do begin');
     72        Inc(Indent);
    9173      end;
    9274      cmLoopEnd: begin
Note: See TracChangeset for help on using the changeset viewer.