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

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