Changeset 128 for trunk/Target


Ignore:
Timestamp:
Jan 17, 2022, 4:53:31 PM (3 years ago)
Author:
chronos
Message:
  • Added: Two more code examples.
  • Added: Allow to disable debugging support.
  • Added: Remember last opened tab in options form.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Target/UTargetInterpretter.pas

    r126 r128  
    4646    procedure CommandMultiply;
    4747    procedure PrepareBreakPoints;
     48    procedure CheckMemoryBounds(Address: Integer);
    4849  protected
    4950    procedure SetState(AValue: TRunState); override;
    50     function GetTargetCode: string; override;
     51    procedure EmitTargetCode;
    5152    function GetExecutionPosition: Integer; override;
    5253  public
     
    8283  SProgramLowerLimit = 'Program run over lower limit';
    8384  SProgramUpperLimit = 'Program run over upper limit';
    84   SJumpTableInsistent = 'Jump table is inconsistent';
     85  SJumpTableInconsistent = 'Jump table is inconsistent';
    8586  SJumpTableCollision = 'Jump table collision';
    8687  SProgramNotRunning = 'Program not running';
     
    179180    end;
    180181  end;
    181   if Length(Loop) > 0 then raise Exception.Create(SJumpTableInsistent);
     182  if Length(Loop) > 0 then raise Exception.Create(SJumpTableInconsistent);
    182183end;
    183184
     
    242243procedure TTargetInterpretter.CommandPointerInc;
    243244begin
    244   if MemoryPosition < MemorySize then Inc(MemoryPosition, FProgram[FProgramIndex].Parameter)
     245  if MemoryPosition < MemorySize then
     246    Inc(MemoryPosition, FProgram[FProgramIndex].Parameter)
    245247    else raise Exception.Create(SProgramUpperLimit);
    246248end;
     
    248250procedure TTargetInterpretter.CommandPointerDec;
    249251begin
    250   if MemoryPosition > 0 then Dec(MemoryPosition, FProgram[FProgramIndex].Parameter)
     252  if MemoryPosition > 0 then
     253    Dec(MemoryPosition, FProgram[FProgramIndex].Parameter)
    251254    else raise Exception.Create(SProgramLowerLimit);
    252255end;
     
    257260begin
    258261  Addr := MemoryPosition + FProgram[FProgramIndex].RelIndex;
     262  CheckMemoryBounds(Addr);
    259263  Memory[Addr] := FProgram[FProgramIndex].Parameter mod CellSize;
    260264  MemoryMaxUsedAddr := Max(Addr, MemoryMaxUsedAddr);
     
    267271begin
    268272  Addr := MemoryPosition + FProgram[FProgramIndex].RelIndex;
     273  CheckMemoryBounds(Addr);
    269274  Memory[Addr] := (Memory[Addr] + Memory[MemoryPosition] *
    270275    FProgram[FProgramIndex].Parameter) mod CellSize;
     
    297302begin
    298303  inherited;
     304  EmitTargetCode;
    299305end;
    300306
     
    311317end;
    312318
    313 function TTargetInterpretter.GetTargetCode: string;
     319procedure TTargetInterpretter.CheckMemoryBounds(Address: Integer);
     320begin
     321  if Address < 0 then raise Exception.Create(SProgramLowerLimit);
     322  if Address >= MemorySize then raise Exception.Create(SProgramUpperLimit);
     323end;
     324
     325procedure TTargetInterpretter.EmitTargetCode;
    314326var
    315327  I: Integer;
    316 begin
    317   Result := '';
     328  Code: string;
     329  TargetIndex: Integer;
     330  Step: TDebugStep;
     331begin
     332  TargetIndex := 0;
     333  FTargetCode := '';
    318334  for I := 0 to FProgram.Count - 1 do begin
    319     Result := Result + GetOperationText(FProgram[I]);
     335    Code := GetOperationText(FProgram[I]);
     336    FTargetCode := FTargetCode + Code;
     337    if DebugEnabled then begin
     338      Step := DebugSteps.SearchByProgramPos(I);
     339      if Assigned(Step) then begin
     340        Step.TargetPosition := TargetIndex;
     341      end;// else
     342      // raise Exception.Create(Format('Program index %d missing debug step.', [I]));
     343    end;
     344    Inc(TargetIndex, Length(Code));
    320345  end;
    321346end;
Note: See TracChangeset for help on using the changeset viewer.