Ignore:
Timestamp:
Dec 4, 2014, 2:59:28 PM (9 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/UTargetJava.pas

    r60 r64  
    6666  FProgramIndex := 0;
    6767  while (FProgramIndex < Length(FProgram)) do begin
    68     case FProgram[FProgramIndex] of
    69       cmPointerInc: begin
    70         Sum := CheckOccurence(cmPointerInc);
    71         AddLine('Pos = Pos + ' + IntToStr(Sum) + ';');
    72       end;
    73       cmPointerDec: begin
    74         Sum := CheckOccurence(cmPointerDec);
    75         AddLine('Pos = Pos - ' + IntToStr(Sum) + ';');
    76       end;
    77       cmInc: begin
    78         Sum := CheckOccurence(cmInc);
    79         AddLine('Memory[Pos] = (char)((int)Memory[Pos] + ' + IntToStr(Sum) + ');');
    80       end;
    81       cmDec: begin
    82         Sum := CheckOccurence(cmDec);
    83         AddLine('Memory[Pos] = (char)((int)Memory[Pos] - ' + IntToStr(Sum) + ');');
    84       end;
     68    case FProgram[FProgramIndex].Command of
     69      cmPointerInc: AddLine('Pos = Pos + ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';');
     70      cmPointerDec: AddLine('Pos = Pos - ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';');
     71      cmInc: AddLine('Memory[Pos] = (char)((int)Memory[Pos] + ' + IntToStr(FProgram[FProgramIndex].Parameter) + ');');
     72      cmDec: AddLine('Memory[Pos] = (char)((int)Memory[Pos] - ' + IntToStr(FProgram[FProgramIndex].Parameter) + ');');
    8573      cmOutput: AddLine('System.out.print(Memory[Pos]);');
    8674      cmInput: AddLine('Memory[Pos] = (char)System.in.read();');
     75      cmSet: AddLine('Memory[Pos] = ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';');
    8776      cmLoopStart: begin
    88         if CheckClear then begin
    89           AddLine('Memory[Pos] = 0;');
    90           Inc(FProgramIndex, 2);
    91         end else begin
    92           AddLine('while(Memory[Pos] != 0)');
    93           AddLine('{');
    94           Inc(Indent);
    95         end;
     77        AddLine('while(Memory[Pos] != 0)');
     78        AddLine('{');
     79        Inc(Indent);
    9680      end;
    9781      cmLoopEnd: begin
Note: See TracChangeset for help on using the changeset viewer.