Changeset 128 for trunk/Target/UTargetInterpretter.pas
- Timestamp:
- Jan 17, 2022, 4:53:31 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Target/UTargetInterpretter.pas
r126 r128 46 46 procedure CommandMultiply; 47 47 procedure PrepareBreakPoints; 48 procedure CheckMemoryBounds(Address: Integer); 48 49 protected 49 50 procedure SetState(AValue: TRunState); override; 50 function GetTargetCode: string; override;51 procedure EmitTargetCode; 51 52 function GetExecutionPosition: Integer; override; 52 53 public … … 82 83 SProgramLowerLimit = 'Program run over lower limit'; 83 84 SProgramUpperLimit = 'Program run over upper limit'; 84 SJumpTableIn sistent = 'Jump table is inconsistent';85 SJumpTableInconsistent = 'Jump table is inconsistent'; 85 86 SJumpTableCollision = 'Jump table collision'; 86 87 SProgramNotRunning = 'Program not running'; … … 179 180 end; 180 181 end; 181 if Length(Loop) > 0 then raise Exception.Create(SJumpTableIn sistent);182 if Length(Loop) > 0 then raise Exception.Create(SJumpTableInconsistent); 182 183 end; 183 184 … … 242 243 procedure TTargetInterpretter.CommandPointerInc; 243 244 begin 244 if MemoryPosition < MemorySize then Inc(MemoryPosition, FProgram[FProgramIndex].Parameter) 245 if MemoryPosition < MemorySize then 246 Inc(MemoryPosition, FProgram[FProgramIndex].Parameter) 245 247 else raise Exception.Create(SProgramUpperLimit); 246 248 end; … … 248 250 procedure TTargetInterpretter.CommandPointerDec; 249 251 begin 250 if MemoryPosition > 0 then Dec(MemoryPosition, FProgram[FProgramIndex].Parameter) 252 if MemoryPosition > 0 then 253 Dec(MemoryPosition, FProgram[FProgramIndex].Parameter) 251 254 else raise Exception.Create(SProgramLowerLimit); 252 255 end; … … 257 260 begin 258 261 Addr := MemoryPosition + FProgram[FProgramIndex].RelIndex; 262 CheckMemoryBounds(Addr); 259 263 Memory[Addr] := FProgram[FProgramIndex].Parameter mod CellSize; 260 264 MemoryMaxUsedAddr := Max(Addr, MemoryMaxUsedAddr); … … 267 271 begin 268 272 Addr := MemoryPosition + FProgram[FProgramIndex].RelIndex; 273 CheckMemoryBounds(Addr); 269 274 Memory[Addr] := (Memory[Addr] + Memory[MemoryPosition] * 270 275 FProgram[FProgramIndex].Parameter) mod CellSize; … … 297 302 begin 298 303 inherited; 304 EmitTargetCode; 299 305 end; 300 306 … … 311 317 end; 312 318 313 function TTargetInterpretter.GetTargetCode: string; 319 procedure TTargetInterpretter.CheckMemoryBounds(Address: Integer); 320 begin 321 if Address < 0 then raise Exception.Create(SProgramLowerLimit); 322 if Address >= MemorySize then raise Exception.Create(SProgramUpperLimit); 323 end; 324 325 procedure TTargetInterpretter.EmitTargetCode; 314 326 var 315 327 I: Integer; 316 begin 317 Result := ''; 328 Code: string; 329 TargetIndex: Integer; 330 Step: TDebugStep; 331 begin 332 TargetIndex := 0; 333 FTargetCode := ''; 318 334 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)); 320 345 end; 321 346 end;
Note:
See TracChangeset
for help on using the changeset viewer.