Changeset 35 for trunk/Target


Ignore:
Timestamp:
Feb 19, 2012, 12:03:21 AM (13 years ago)
Author:
chronos
Message:
  • Added: Function to show execution point in code if program is paused.
  • Added: Some partial stepping implementation.
Location:
trunk/Target
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Target/UTarget.pas

    r34 r35  
    4949    procedure AddLine(Text: string);
    5050    function LongFileName(FileName: string): string;
     51    function GetExecutionPosition: Integer; virtual;
    5152  public
    5253    Name: string;
     
    5859    ProjectFileName: string;
    5960    Capabilities: TTargetCapabilities;
    60     BreakPointers: TListInteger;
     61    BreakPoints: TListInteger;
    6162    DebugSteps: TDebugStepList;
    6263    constructor Create; virtual;
     
    7172    procedure StepInto; virtual;
    7273    procedure StepOut; virtual;
    73     procedure RunToCursor; virtual;
     74    procedure RunToCursor(Pos: Integer); virtual;
    7475    procedure LoadFromRegistry(Root: HKEY; Key: string); virtual;
    7576    procedure SaveToRegistry(Root: HKEY; Key: string); virtual;
     
    7980    property TargetCode: string read GetTargetCode;
    8081    property Compiled: Boolean read FCompiled write FCompiled;
     82    property ExecutionPosition: Integer read GetExecutionPosition;
    8183  end;
    8284
     
    184186begin
    185187  Result := FTargetCode;
     188end;
     189
     190function TTarget.GetExecutionPosition: Integer;
     191begin
     192
    186193end;
    187194
     
    211218  inherited;
    212219  Optimization := coNormal;
    213   BreakPointers := TListInteger.Create;
     220  BreakPoints := TListInteger.Create;
    214221  DebugSteps := TDebugStepList.Create;
    215222end;
     
    218225begin
    219226  DebugSteps.Free;;
    220   BreakPointers.Free;
     227  BreakPoints.Free;
    221228  inherited Destroy;
    222229end;
     
    303310end;
    304311
    305 procedure TTarget.RunToCursor;
     312procedure TTarget.RunToCursor(Pos: Integer);
    306313begin
    307314
  • trunk/Target/UTargetC.pas

    r34 r35  
    5757
    5858begin
     59  inherited;
    5960  Indent := 0;
    6061  FTargetCode := '';
  • trunk/Target/UTargetDelphi.pas

    r34 r35  
    5252
    5353begin
     54  inherited;
    5455  Indent := 0;
    5556  FTargetCode := '';
  • trunk/Target/UTargetInterpretter.pas

    r33 r35  
    4545    procedure CommandLoopStart;
    4646    procedure CommandLoopEnd;
    47     procedure SingleStep;
    4847    procedure Reset;
     48    procedure PrepareBreakPoints;
    4949  protected
    5050    function GetTargetCode: string; override;
     51    function GetExecutionPosition: Integer; override;
    5152  public
    5253    FProgram: array of TBrainFuckCommand;
     54    FProgramBreakpoints: array of Boolean;
    5355    SourceJump: array of Integer;
    5456    SourcePosition: Integer;
     
    6466    procedure Pause; override;
    6567    procedure Stop; override;
     68    procedure StepInto; override;
     69    procedure StepOver; override;
     70    procedure StepOut; override;
     71    procedure RunToCursor(Pos: Integer); override;
    6672    constructor Create; override;
    6773    destructor Destroy; override;
     
    9298procedure TTargetInterpretterThread.Execute;
    9399begin
     100  with Parent do
    94101  repeat
    95     while (Parent.SourcePosition < Length(Parent.FProgram)) and (Parent.State <> rsStopped) do begin
    96       Parent.SingleStep;
    97       while Parent.State = rsPaused do begin
    98         Sleep(1);
    99       end;
     102    while (SourcePosition < Length(FProgram)) and (State <> rsStopped) do begin
     103      if State = rsRunning then begin
     104        if FProgramBreakpoints[SourcePosition] then begin
     105          FProgramBreakpoints[SourcePosition] := False;
     106          SetState(rsPaused);
     107        end else begin
     108          FCommandTable[FProgram[SourcePosition]];
     109          Inc(SourcePosition);
     110          Inc(FStepCount);
     111        end;
     112      end else
     113      if State = rsPaused then Sleep(1);
    100114    end;
    101     Parent.SetState(rsStopped);
    102   until Terminated or (Parent.State = rsStopped);
     115    SetState(rsStopped);
     116  until Terminated or (State = rsStopped);
    103117end;
    104118
     
    127141  Pos: Integer;
    128142begin
     143  inherited;
    129144  DebugSteps.Clear;
    130145  SetLength(FProgram, Length(FSourceCode));
     
    282297end;
    283298
     299procedure TTargetInterpretter.PrepareBreakPoints;
     300var
     301  I: Integer;
     302begin
     303  SetLength(FProgramBreakpoints, Length(FProgram));
     304  for I := 0 to High(FProgramBreakpoints) do
     305    FProgramBreakpoints[I] := False;
     306  for I := 0 to BreakPoints.Count - 1 do
     307    FProgramBreakpoints[BreakPoints[I]] := True;
     308end;
     309
    284310function TTargetInterpretter.GetTargetCode: string;
    285311var
     
    291317end;
    292318
    293 procedure TTargetInterpretter.SingleStep;
    294 begin
    295   FCommandTable[FProgram[SourcePosition]];
    296   Inc(SourcePosition);
    297   Inc(FStepCount);
     319function TTargetInterpretter.GetExecutionPosition: Integer;
     320begin
     321  Result := SourcePosition;
    298322end;
    299323
     
    302326  SetState(rsRunning);
    303327  Reset;
     328  PrepareBreakPoints;
    304329  SetThread(False);
    305330  SetThread(True);
     
    314339begin
    315340  SetState(rsStopped);
     341end;
     342
     343procedure TTargetInterpretter.StepInto;
     344var
     345  Step: TDebugStep;
     346begin
     347  Step := DebugSteps.SearchByTargetPos(SourcePosition);
     348  FProgramBreakpoints[Step.TargetPosition + 1] := True;
     349end;
     350
     351procedure TTargetInterpretter.StepOver;
     352var
     353  Step: TDebugStep;
     354begin
     355end;
     356
     357procedure TTargetInterpretter.StepOut;
     358begin
     359  inherited StepOut;
     360end;
     361
     362procedure TTargetInterpretter.RunToCursor(Pos: Integer);
     363begin
     364  FProgramBreakpoints[Pos] := True;
    316365end;
    317366
  • trunk/Target/UTargetPHP.pas

    r34 r35  
    5555
    5656begin
     57  inherited;
    5758  Indent := 0;
    5859  FTargetCode := '';
Note: See TracChangeset for help on using the changeset viewer.