- Timestamp:
- May 18, 2019, 12:13:44 AM (6 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Forms/UFormMain.pas
r113 r114 226 226 AProgramShowExecutionPoint.Execute; 227 227 if Core.CurrentTarget.State = rsStopped then 228 Core.CurrentTarget.Messages.AddMessage(SProgramStopped);228 Core.CurrentTarget.Messages.AddMessage(SProgramStopped); 229 229 end; 230 230 … … 487 487 Core.ThemeManager.UseTheme(Self); 488 488 FormSourceCode.UpdateTheme; 489 Core.SaveToRegistry(Core.ApplicationInfo.GetRegistryContext); 490 SaveToRegistry(Core.ApplicationInfo.GetRegistryContext); 489 491 end; 490 492 finally … … 523 525 DebugStep := Core.CurrentTarget.DebugSteps.SearchBySourcePos(FormSourceCode.SynEditSource.SelStart - 1); 524 526 if Assigned(DebugStep) then begin 525 BreakPoint := Core.CurrentTarget.BreakPoints.SearchByTargetPos(DebugStep. TargetPosition);527 BreakPoint := Core.CurrentTarget.BreakPoints.SearchByTargetPos(DebugStep.ProgramPosition); 526 528 if Assigned(BreakPoint) then 527 529 Core.CurrentTarget.BreakPoints.Delete(Core.CurrentTarget.BreakPoints.IndexOf(BreakPoint)) 528 else Core.CurrentTarget.BreakPoints.AddItem(DebugStep. TargetPosition);530 else Core.CurrentTarget.BreakPoints.AddItem(DebugStep.ProgramPosition); 529 531 end; 530 532 end; … … 555 557 if not Core.CurrentTarget.Compiled then AProgramCompile.Execute; 556 558 DebugStep := Core.CurrentTarget.DebugSteps.SearchBySourcePos(FormSourceCode.SynEditSource.SelStart - 1); 557 Core.CurrentTarget.BreakPoints.SetSystem(DebugStep. TargetPosition);559 Core.CurrentTarget.BreakPoints.SetSystem(DebugStep.ProgramPosition); 558 560 AProgramRun.Execute; 559 561 end else begin 560 562 DebugStep := Core.CurrentTarget.DebugSteps.SearchBySourcePos(FormSourceCode.SynEditSource.SelStart - 1); 561 Core.CurrentTarget.RunToCursor(DebugStep. TargetPosition);563 Core.CurrentTarget.RunToCursor(DebugStep.ProgramPosition); 562 564 end; 563 565 end; … … 567 569 DebugStep: TDebugStep; 568 570 begin 569 DebugStep := Core.CurrentTarget.DebugSteps.SearchBy TargetPos(Core.CurrentTarget.ExecutionPosition);571 DebugStep := Core.CurrentTarget.DebugSteps.SearchByProgramPos(Core.CurrentTarget.ExecutionPosition); 570 572 FormSourceCode.SynEditSource.SelStart := DebugStep.SourcePosition + 1; 571 573 FormTargetCode.SynEditTarget.SelStart := DebugStep.TargetPosition + 1; … … 578 580 if Core.CurrentTarget.State = rsStopped then begin 579 581 if not Core.CurrentTarget.Compiled then AProgramCompile.Execute; 580 Core.CurrentTarget.BreakPoints.SetSystem(TDebugStep(Core.CurrentTarget.DebugSteps.First). TargetPosition);582 Core.CurrentTarget.BreakPoints.SetSystem(TDebugStep(Core.CurrentTarget.DebugSteps.First).ProgramPosition); 581 583 AProgramRun.Execute; 582 584 end else Core.CurrentTarget.StepInto; … … 592 594 if Core.CurrentTarget.State = rsStopped then begin 593 595 if not Core.CurrentTarget.Compiled then AProgramCompile.Execute; 594 Core.CurrentTarget.BreakPoints.SetSystem(TDebugStep(Core.CurrentTarget.DebugSteps.First). TargetPosition);596 Core.CurrentTarget.BreakPoints.SetSystem(TDebugStep(Core.CurrentTarget.DebugSteps.First).ProgramPosition); 595 597 AProgramRun.Execute; 596 598 end else Core.CurrentTarget.StepOver; -
trunk/Target/UTargetInterpretter.pas
r112 r114 76 76 end; 77 77 78 const79 BrainFuckCommandText: array[TMachineCommand] of Char = (80 ' ', '+', '-', '>', '<', '.', ',', '[', ']', '@', '=', '*');81 82 78 83 79 implementation … … 321 317 Result := ''; 322 318 for I := 0 to Length(FProgram) - 1 do begin 323 Result := Result + BrainFuckCommandText[FProgram[I].Command]; 324 if FProgram[I].Command in [cmInc, cmDec, cmPointerInc, cmPointerDec, 325 cmSet, cmMultipy] then begin 326 if FProgram[I].Parameter <> 1 then 327 Result := Result + IntToStr(FProgram[I].Parameter); 328 end; 329 if FProgram[I].RelIndex <> 0 then 330 Result := Result + 'R' + IntToStr(FProgram[I].RelIndex); 319 Result := Result + GetOperationText(FProgram[I]); 331 320 end; 332 321 end; … … 369 358 begin 370 359 if State = rsPaused then begin 371 Step := DebugSteps.SearchBy TargetPos(FProgramIndex);360 Step := DebugSteps.SearchByProgramPos(FProgramIndex); 372 361 if Step.Operation = soStepOut then begin 373 BreakPoints.SetSystem(Step. TargetPosition + 1);374 Step := DebugSteps.SearchBy TargetPos(FProgram[Step.TargetPosition].Parameter);375 BreakPoints.AddSystem(Step. TargetPosition);362 BreakPoints.SetSystem(Step.ProgramPosition + 1); 363 Step := DebugSteps.SearchByProgramPos(FProgram[Step.ProgramPosition].Parameter); 364 BreakPoints.AddSystem(Step.ProgramPosition); 376 365 end else 377 366 if Step.Operation = soStepIn then begin 378 BreakPoints.SetSystem(Step. TargetPosition + 1);379 Step := DebugSteps.SearchBy TargetPos(FProgram[Step.TargetPosition].Parameter);380 BreakPoints.AddSystem(Step. TargetPosition);381 end else BreakPoints.SetSystem(Step. TargetPosition + 1);367 BreakPoints.SetSystem(Step.ProgramPosition + 1); 368 Step := DebugSteps.SearchByProgramPos(FProgram[Step.ProgramPosition].Parameter); 369 BreakPoints.AddSystem(Step.ProgramPosition); 370 end else BreakPoints.SetSystem(Step.ProgramPosition + 1); 382 371 Run; 383 372 end else raise Exception.Create(SProgramNotRunning); … … 389 378 begin 390 379 if State = rsPaused then begin 391 Step := DebugSteps.SearchBy TargetPos(FProgramIndex);380 Step := DebugSteps.SearchByProgramPos(FProgramIndex); 392 381 if Step.Operation = soStepOut then begin 393 BreakPoints.SetSystem(Step. TargetPosition + 1);394 Step := DebugSteps.SearchBy TargetPos(FProgram[Step.TargetPosition].Parameter);395 BreakPoints.AddSystem(Step. TargetPosition);382 BreakPoints.SetSystem(Step.ProgramPosition + 1); 383 Step := DebugSteps.SearchByProgramPos(FProgram[Step.ProgramPosition].Parameter); 384 BreakPoints.AddSystem(Step.ProgramPosition); 396 385 end else 397 386 if Step.Operation = soStepIn then begin 398 Step := DebugSteps.SearchBy TargetPos(FProgram[Step.TargetPosition].Parameter);399 BreakPoints.SetSystem(Step. TargetPosition + 1);400 end else BreakPoints.SetSystem(Step. TargetPosition + 1);387 Step := DebugSteps.SearchByProgramPos(FProgram[Step.ProgramPosition].Parameter); 388 BreakPoints.SetSystem(Step.ProgramPosition + 1); 389 end else BreakPoints.SetSystem(Step.ProgramPosition + 1); 401 390 Run; 402 391 end else raise Exception.Create(SProgramNotRunning); … … 410 399 begin 411 400 if State = rsPaused then begin 412 Step := DebugSteps.SearchBy TargetPos(FProgramIndex);401 Step := DebugSteps.SearchByProgramPos(FProgramIndex); 413 402 StepIndex := DebugSteps.IndexOf(Step); 414 403 Nesting := 1; … … 419 408 end; 420 409 if StepIndex < DebugSteps.Count then begin 421 Breakpoints.SetSystem(TDebugStep(DebugSteps[StepIndex]). TargetPosition);410 Breakpoints.SetSystem(TDebugStep(DebugSteps[StepIndex]).ProgramPosition); 422 411 end; 423 412 Run; -
trunk/UBFTarget.pas
r112 r114 44 44 FProgram: array of TMachineOperation; 45 45 FProgramIndex: Integer; 46 function GetOperationText(Operation: TMachineOperation): string; virtual; 46 47 procedure LoadProgram; override; 47 48 public … … 55 56 end; 56 57 58 const 59 BrainFuckCommandText: array[TMachineCommand] of Char = ( 60 ' ', '+', '-', '>', '<', '.', ',', '[', ']', '@', '=', '*'); 61 57 62 58 63 implementation … … 98 103 NewProgram: array of TMachineOperation; 99 104 NewProgramIndex: Integer; 105 NewTargetPos: Integer; 106 FirstIndex: Integer; 100 107 begin 101 108 NewProgramIndex := 0; 109 NewTargetPos := 0; 102 110 SetLength(NewProgram, Length(FProgram)); 103 111 104 112 FProgramIndex := 0; 105 113 while (FProgramIndex < Length(FProgram)) do begin 114 FirstIndex := FProgramIndex; 106 115 case FProgram[FProgramIndex].Command of 107 116 cmPointerInc: begin … … 123 132 else NewProgram[NewProgramIndex] := FProgram[FProgramIndex]; 124 133 end; 125 DebugSteps.UpdateTargetPos(FProgramIndex, NewProgramIndex); 134 DebugSteps.UpdateTargetPos(FirstIndex, FProgramIndex, NewProgramIndex, NewTargetPos); 135 Inc(NewTargetPos, Length(GetOperationText(NewProgram[NewProgramIndex]))); 126 136 Inc(FProgramIndex); 127 137 Inc(NewProgramIndex); … … 139 149 NewProgramIndex: Integer; 140 150 PreviousCommand: TMachineCommand; 151 FirstIndex: Integer; 152 NewTextIndex: Integer; 141 153 begin 142 154 // Merge together cmInc, cmDec, cmSet … … 147 159 148 160 FProgramIndex := 0; 161 NewTextIndex := 0; 149 162 while (FProgramIndex < Length(FProgram)) do begin 163 FirstIndex := FProgramIndex; 150 164 case FProgram[FProgramIndex].Command of 151 165 cmPointerInc: begin … … 258 272 end; 259 273 PreviousCommand := FProgram[FProgramIndex].Command; 260 DebugSteps.UpdateTargetPos(FProgramIndex, NewProgramIndex); 274 DebugSteps.UpdateTargetPos(FirstIndex, FProgramIndex, NewProgramIndex, NewTextIndex); 275 Inc(NewTextIndex, Length(GetOperationText(NewProgram[NewProgramIndex]))); 261 276 Inc(FProgramIndex); 262 277 Inc(NewProgramIndex); … … 281 296 NewProgramIndex: Integer; 282 297 RelIndex: Integer; 298 FirstIndex: Integer; 299 NewTextIndex: Integer; 283 300 begin 284 301 NewProgramIndex := 0; … … 287 304 RelIndex := 0; 288 305 FProgramIndex := 0; 306 NewTextIndex := 0; 289 307 while (FProgramIndex < Length(FProgram)) do begin 308 FirstIndex := FProgramIndex; 290 309 case FProgram[FProgramIndex].Command of 291 310 cmPointerInc: begin … … 319 338 else raise Exception.Create(Format('Unsupported command %d', [FProgram[FProgramIndex].Command])); 320 339 end; 321 DebugSteps.UpdateTargetPos(FProgramIndex, NewProgramIndex); 340 DebugSteps.UpdateTargetPos(FirstIndex, FProgramIndex, NewProgramIndex, NewTextIndex); 341 Inc(NewTextIndex, Length(GetOperationText(NewProgram[NewProgramIndex]))); 322 342 Inc(FProgramIndex); 323 343 Inc(NewProgramIndex); … … 340 360 LoopStartIndex: Integer; 341 361 LoopStartIndexNew: Integer; 362 FirstIndex: Integer; 363 NewTextIndex: Integer; 342 364 begin 343 365 NewProgramIndex := 0; … … 347 369 ProcessLoop := False; 348 370 FProgramIndex := 0; 371 NewTextIndex := 0; 349 372 PointerChange := 0; 350 373 while (FProgramIndex < Length(FProgram)) do begin 374 FirstIndex := FProgramIndex; 351 375 case FProgram[FProgramIndex].Command of 352 376 cmPointerInc: begin … … 418 442 else raise Exception.Create(Format('Unsupported command %d', [FProgram[FProgramIndex].Command])); 419 443 end; 420 DebugSteps.UpdateTargetPos(FProgramIndex, NewProgramIndex); 444 DebugSteps.UpdateTargetPos(FirstIndex, FProgramIndex, NewProgramIndex, NewTextIndex); 445 Inc(NewTextIndex, Length(GetOperationText(NewProgram[NewProgramIndex]))); 421 446 Inc(FProgramIndex); 422 447 Inc(NewProgramIndex); … … 428 453 Move(Pointer(NewProgram)^, Pointer(FProgram)^, SizeOf(TMachineOperation) * 429 454 Length(NewProgram)); 455 end; 456 457 function TBFTarget.GetOperationText(Operation: TMachineOperation): string; 458 begin 459 Result := BrainFuckCommandText[Operation.Command]; 460 if Operation.Command in [cmInc, cmDec, cmPointerInc, cmPointerDec, 461 cmSet, cmMultipy] then begin 462 if Operation.Parameter <> 1 then 463 Result := Result + IntToStr(Operation.Parameter); 464 end; 465 if Operation.RelIndex <> 0 then 466 Result := Result + 'R' + IntToStr(Operation.RelIndex); 430 467 end; 431 468 -
trunk/UTarget.pas
r111 r114 22 22 TDebugStep = class 23 23 SourcePosition: Integer; 24 ProgramPosition: Integer; 24 25 TargetPosition: Integer; 25 26 Operation: TStepOperation; … … 30 31 TDebugStepList = class(TFPGObjectList<TDebugStep>) 31 32 function SearchBySourcePos(Pos: Integer): TDebugStep; 33 function SearchByProgramPos(Pos: Integer): TDebugStep; 32 34 function SearchByTargetPos(Pos: Integer): TDebugStep; 35 function SearchIndexByProgramPos(Pos: Integer): Integer; 33 36 procedure AddStep(SourcePos, TargetPos: Integer; Operation: TStepOperation); 34 procedure UpdateTargetPos(Old , New: Integer);37 procedure UpdateTargetPos(OldProgramFrom, OldProgramTo, NewProgram, NewTarget: Integer); 35 38 end; 36 39 … … 233 236 end; 234 237 238 function TDebugStepList.SearchByProgramPos(Pos: Integer): TDebugStep; 239 var 240 I: Integer; 241 begin 242 I := 0; 243 while (I < Count) and (TDebugStep(Items[I]).ProgramPosition < Pos) do Inc(I); 244 if I < Count then Result := TDebugStep(Items[I]) 245 else Result := nil; 246 end; 247 235 248 function TDebugStepList.SearchByTargetPos(Pos: Integer 236 249 ): TDebugStep; … … 244 257 end; 245 258 259 function TDebugStepList.SearchIndexByProgramPos(Pos: Integer): Integer; 260 var 261 I: Integer; 262 begin 263 I := 0; 264 while (I < Count) and (TDebugStep(Items[I]).ProgramPosition < Pos) do Inc(I); 265 if I < Count then Result := I 266 else Result := -1; 267 end; 268 246 269 procedure TDebugStepList.AddStep(SourcePos, TargetPos: Integer; 247 270 Operation: TStepOperation); … … 251 274 NewItem := TDebugStep.Create; 252 275 NewItem.SourcePosition := SourcePos; 276 NewItem.ProgramPosition := TargetPos; 253 277 NewItem.TargetPosition := TargetPos; 254 278 NewItem.Operation := Operation; … … 256 280 end; 257 281 258 procedure TDebugStepList.UpdateTargetPos(Old, New: Integer); 259 var 260 I: Integer; 261 begin 262 I := 0; 263 while (I < Count) do begin 264 if TDebugStep(Items[I]).TargetPosition = Old then 265 TDebugStep(Items[I]).TargetPosition := New; 266 Inc(I); 267 end; 282 procedure TDebugStepList.UpdateTargetPos(OldProgramFrom, OldProgramTo, NewProgram, NewTarget: Integer); 283 var 284 I: Integer; 285 First: Integer; 286 Last: Integer; 287 begin 288 First := SearchIndexByProgramPos(OldProgramFrom); 289 Last := SearchIndexByProgramPos(OldProgramTo); 290 for I := Last downto First + 1 do Delete(I); 291 TDebugStep(Items[First]).ProgramPosition := NewProgram; 292 TDebugStep(Items[First]).TargetPosition := NewTarget; 268 293 end; 269 294
Note:
See TracChangeset
for help on using the changeset viewer.