1 | unit Target;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils, StrUtils, Registry, RegistryEx, fgl, Dialogs,
|
---|
7 | FileUtil, Process, Menus, LazFileUtils;
|
---|
8 |
|
---|
9 | type
|
---|
10 | TCompilerOptimization = (coNone, coNormal);
|
---|
11 |
|
---|
12 | TTargetCapability = (tcRun, tcPause, tcStop, tcStepOut, tcStepOver, tcStepInto,
|
---|
13 | tcRunToCursor, tcCompile, tcBreakpoint);
|
---|
14 | TTargetCapabilities = set of TTargetCapability;
|
---|
15 |
|
---|
16 | TRunState = (rsStopped, rsPaused, rsRunning, rsCompiling);
|
---|
17 |
|
---|
18 | TStepOperation = (soNormal, soStepIn, soStepOut);
|
---|
19 |
|
---|
20 | TDebugStep = class
|
---|
21 | SourcePosition: Integer;
|
---|
22 | ProgramPosition: Integer;
|
---|
23 | TargetPosition: Integer;
|
---|
24 | Operation: TStepOperation;
|
---|
25 | end;
|
---|
26 |
|
---|
27 | { TDebugSteps }
|
---|
28 |
|
---|
29 | TDebugSteps = class(TFPGObjectList<TDebugStep>)
|
---|
30 | function SearchBySourcePos(Pos: Integer): TDebugStep;
|
---|
31 | function SearchByProgramPos(Pos: Integer): TDebugStep;
|
---|
32 | function SearchByTargetPos(Pos: Integer): TDebugStep;
|
---|
33 | function SearchIndexByProgramPos(Pos: Integer): Integer;
|
---|
34 | procedure AddStep(SourcePos, TargetPos: Integer; Operation: TStepOperation);
|
---|
35 | procedure UpdateTargetPos(OldProgramFrom, OldProgramTo, NewProgramFrom,
|
---|
36 | NewProgramTo: Integer; NewTarget: Integer = 0);
|
---|
37 | end;
|
---|
38 |
|
---|
39 | TBreakPoint = class
|
---|
40 | TargetAddress: Integer;
|
---|
41 | System: Boolean;
|
---|
42 | end;
|
---|
43 |
|
---|
44 | { TBreakPoints }
|
---|
45 |
|
---|
46 | TBreakPoints = class(TFPGObjectList<TBreakPoint>)
|
---|
47 | procedure AddItem(TargetAddress: Integer);
|
---|
48 | procedure SetSystem(TargetAddress: Integer);
|
---|
49 | procedure AddSystem(TargetAddress: Integer);
|
---|
50 | procedure ClearSystem;
|
---|
51 | function SearchByTargetPos(Pos: Integer): TBreakPoint;
|
---|
52 | end;
|
---|
53 |
|
---|
54 | TMessage = class
|
---|
55 | Text: string;
|
---|
56 | Position: TPoint;
|
---|
57 | end;
|
---|
58 |
|
---|
59 | { TMessages }
|
---|
60 |
|
---|
61 | TMessages = class(TFPGObjectList<TMessage>)
|
---|
62 | private
|
---|
63 | FOnChange: TNotifyEvent;
|
---|
64 | procedure DoChange;
|
---|
65 | public
|
---|
66 | procedure AddMessage(Text: string);
|
---|
67 | procedure AppendMessage(Text: string);
|
---|
68 | property OnChange: TNotifyEvent read FOnChange write FOnChange;
|
---|
69 | end;
|
---|
70 |
|
---|
71 | TLogEvent = procedure (Lines: TStrings) of object;
|
---|
72 | TMessageEvent = procedure (Text: string) of object;
|
---|
73 |
|
---|
74 | { TTarget }
|
---|
75 |
|
---|
76 | TTarget = class
|
---|
77 | private
|
---|
78 | FOnLog: TLogEvent;
|
---|
79 | FOnMessage: TMessageEvent;
|
---|
80 | protected
|
---|
81 | FCompiledExtension: string;
|
---|
82 | FRunExtension: string;
|
---|
83 | FSourceExtension: string;
|
---|
84 | FName: string;
|
---|
85 | FImageIndex: Integer;
|
---|
86 | FCapabilities: TTargetCapabilities;
|
---|
87 | FCompiled: Boolean;
|
---|
88 | function SourceReadNext: Char;
|
---|
89 | protected
|
---|
90 | FSourceCode: string;
|
---|
91 | FTargetCode: string;
|
---|
92 | FTargetIndex: Integer;
|
---|
93 | Indent: Integer;
|
---|
94 | FState: TRunState;
|
---|
95 | FOnChangeState: TNotifyEvent;
|
---|
96 | procedure LoadProgram; virtual;
|
---|
97 | procedure SetSourceCode(AValue: string); virtual;
|
---|
98 | function GetTargetCode: string; virtual;
|
---|
99 | procedure AddLine(Text: string = '');
|
---|
100 | function LongFileName(FileName: string): string;
|
---|
101 | function GetExecutionPosition: Integer; virtual;
|
---|
102 | procedure SetState(AValue: TRunState); virtual;
|
---|
103 | public
|
---|
104 | ProgramName: string;
|
---|
105 | OptimizationLevel: TCompilerOptimization;
|
---|
106 | CompilerPath: string;
|
---|
107 | ExecutorPath: string;
|
---|
108 | ProjectFileName: string;
|
---|
109 | BreakPoints: TBreakPoints;
|
---|
110 | DebugSteps: TDebugSteps;
|
---|
111 | DebugEnabled: Boolean;
|
---|
112 | Selected: Boolean;
|
---|
113 | procedure SendMessage(Text: string);
|
---|
114 | constructor Create; virtual;
|
---|
115 | destructor Destroy; override;
|
---|
116 | procedure Reset; virtual;
|
---|
117 | procedure OptimizeSource; virtual;
|
---|
118 | procedure Compile; virtual;
|
---|
119 | procedure CompileToFile; virtual;
|
---|
120 | procedure RunFromFile; virtual;
|
---|
121 | procedure Run; virtual;
|
---|
122 | procedure Pause; virtual;
|
---|
123 | procedure Stop; virtual;
|
---|
124 | procedure StepOver; virtual;
|
---|
125 | procedure StepInto; virtual;
|
---|
126 | procedure StepOut; virtual;
|
---|
127 | procedure RunToCursor(Pos: Integer); virtual;
|
---|
128 | procedure LoadFromRegistry(Context: TRegistryContext); virtual;
|
---|
129 | procedure SaveToRegistry(Context: TRegistryContext); virtual;
|
---|
130 | property SourceExtension: string read FSourceExtension;
|
---|
131 | property RunExtension: string read FRunExtension;
|
---|
132 | property CompiledExtension: string read FCompiledExtension;
|
---|
133 | property Name: string read FName;
|
---|
134 | property ImageIndex: Integer read FImageIndex;
|
---|
135 | property State: TRunState read FState write SetState;
|
---|
136 | property SourceCode: string write SetSourceCode;
|
---|
137 | property TargetCode: string read GetTargetCode;
|
---|
138 | property Compiled: Boolean read FCompiled write FCompiled;
|
---|
139 | property ExecutionPosition: Integer read GetExecutionPosition;
|
---|
140 | property Capabilities: TTargetCapabilities read FCapabilities;
|
---|
141 | property OnChangeState: TNotifyEvent read FOnChangeState write FOnChangeState;
|
---|
142 | property OnLog: TLogEvent read FOnLog write FOnLog;
|
---|
143 | property OnMessage: TMessageEvent read FOnMessage write FOnMessage;
|
---|
144 | end;
|
---|
145 |
|
---|
146 | { TTargets }
|
---|
147 |
|
---|
148 | TTargets = class(TFPGObjectList<TTarget>)
|
---|
149 | procedure LoadFromRegistry(Context: TRegistryContext);
|
---|
150 | procedure SaveToRegistry(Context: TRegistryContext);
|
---|
151 | function FindByName(Name: string): TTarget;
|
---|
152 | procedure LoadToMenuItem(MenuItem: TMenuItem; Action: TNotifyEvent;
|
---|
153 | CurrentTarget: TTarget);
|
---|
154 | end;
|
---|
155 |
|
---|
156 |
|
---|
157 | resourcestring
|
---|
158 | SCompilerNotFound = 'Compiler "%s" not found';
|
---|
159 | SExecutorNotFound = 'Executor "%s" not found';
|
---|
160 | SCompiledFileNotFound = 'Program compiled file "%s" not found';
|
---|
161 | SStopped = 'Stopped';
|
---|
162 | SPaused = 'Paused';
|
---|
163 | SRunning = 'Running';
|
---|
164 | SCompiling = 'Compiling';
|
---|
165 | SNone = 'None';
|
---|
166 | SNormal = 'Normal';
|
---|
167 | SProgramIndexError = 'Old program index higher than new (old: %d, new: %d)';
|
---|
168 | SFirstIndexHigherThanLastIndex = 'First index higher than last index';
|
---|
169 | SFirstIndexOutOfRange = 'First index out of range';
|
---|
170 | SLastIndexOutOfRange = 'Last index out of range';
|
---|
171 |
|
---|
172 | const
|
---|
173 | CompiledDir = 'compiled';
|
---|
174 |
|
---|
175 | var
|
---|
176 | RunStateText: array[TRunState] of string = (SStopped, SPaused, SRunning,
|
---|
177 | SCompiling);
|
---|
178 | CompilerOptimizationText: array[TCompilerOptimization] of string = (SNone, SNormal);
|
---|
179 |
|
---|
180 | procedure UpdateTranslation;
|
---|
181 |
|
---|
182 |
|
---|
183 | implementation
|
---|
184 |
|
---|
185 | procedure UpdateTranslation;
|
---|
186 | begin
|
---|
187 | RunStateText[rsStopped] := SStopped;
|
---|
188 | RunStateText[rsPaused] := SPaused;
|
---|
189 | RunStateText[rsRunning] := SRunning;
|
---|
190 | RunStateText[rsCompiling] := SCompiling;
|
---|
191 | CompilerOptimizationText[coNone] := SNone;
|
---|
192 | CompilerOptimizationText[coNormal] := SNormal;
|
---|
193 | end;
|
---|
194 |
|
---|
195 | { TMessages }
|
---|
196 |
|
---|
197 | procedure TMessages.DoChange;
|
---|
198 | begin
|
---|
199 | if Assigned(FOnChange) then FOnChange(Self);
|
---|
200 | end;
|
---|
201 |
|
---|
202 | procedure TMessages.AddMessage(Text: string);
|
---|
203 | var
|
---|
204 | NewItem: TMessage;
|
---|
205 | begin
|
---|
206 | NewItem := TMessage.Create;
|
---|
207 | NewItem.Text := Text;
|
---|
208 | Add(NewItem);
|
---|
209 | DoChange;
|
---|
210 | end;
|
---|
211 |
|
---|
212 | procedure TMessages.AppendMessage(Text: string);
|
---|
213 | begin
|
---|
214 | if Count > 0 then begin
|
---|
215 | Last.Text := Last.Text + Text;
|
---|
216 | DoChange;
|
---|
217 | end else AddMessage(Text);
|
---|
218 | end;
|
---|
219 |
|
---|
220 | { TBreakPoints }
|
---|
221 |
|
---|
222 | procedure TBreakPoints.AddItem(TargetAddress: Integer);
|
---|
223 | var
|
---|
224 | NewItem: TBreakPoint;
|
---|
225 | begin
|
---|
226 | NewItem := TBreakPoint.Create;
|
---|
227 | NewItem.TargetAddress := TargetAddress;
|
---|
228 | Add(NewItem);
|
---|
229 | end;
|
---|
230 |
|
---|
231 | procedure TBreakPoints.SetSystem(TargetAddress: Integer);
|
---|
232 | begin
|
---|
233 | ClearSystem;
|
---|
234 | AddSystem(TargetAddress);
|
---|
235 | end;
|
---|
236 |
|
---|
237 | procedure TBreakPoints.AddSystem(TargetAddress: Integer);
|
---|
238 | var
|
---|
239 | NewItem: TBreakPoint;
|
---|
240 | begin
|
---|
241 | NewItem := TBreakPoint.Create;
|
---|
242 | NewItem.TargetAddress := TargetAddress;
|
---|
243 | NewItem.System := True;
|
---|
244 | Add(NewItem);
|
---|
245 | end;
|
---|
246 |
|
---|
247 | procedure TBreakPoints.ClearSystem;
|
---|
248 | var
|
---|
249 | I: Integer;
|
---|
250 | begin
|
---|
251 | for I := Count - 1 downto 0 do
|
---|
252 | if Items[I].System then Delete(I);
|
---|
253 | end;
|
---|
254 |
|
---|
255 | function TBreakPoints.SearchByTargetPos(Pos: Integer): TBreakPoint;
|
---|
256 | var
|
---|
257 | I: Integer;
|
---|
258 | begin
|
---|
259 | I := 0;
|
---|
260 | while (I < Count) and (Items[I].TargetAddress < Pos) do Inc(I);
|
---|
261 | if I < Count then Result := Items[I]
|
---|
262 | else Result := nil;
|
---|
263 | end;
|
---|
264 |
|
---|
265 | { TDebugSteps }
|
---|
266 |
|
---|
267 | function TDebugSteps.SearchBySourcePos(Pos: Integer
|
---|
268 | ): TDebugStep;
|
---|
269 | var
|
---|
270 | I: Integer;
|
---|
271 | begin
|
---|
272 | I := 0;
|
---|
273 | while (I < Count) and (Items[I].SourcePosition < Pos) do Inc(I);
|
---|
274 | if I < Count then Result := Items[I]
|
---|
275 | else Result := nil;
|
---|
276 | end;
|
---|
277 |
|
---|
278 | function TDebugSteps.SearchByProgramPos(Pos: Integer): TDebugStep;
|
---|
279 | var
|
---|
280 | I: Integer;
|
---|
281 | begin
|
---|
282 | I := 0;
|
---|
283 | while (I < Count) and (Items[I].ProgramPosition < Pos) do Inc(I);
|
---|
284 | if I < Count then Result := Items[I]
|
---|
285 | else Result := nil;
|
---|
286 | end;
|
---|
287 |
|
---|
288 | function TDebugSteps.SearchByTargetPos(Pos: Integer
|
---|
289 | ): TDebugStep;
|
---|
290 | var
|
---|
291 | I: Integer;
|
---|
292 | begin
|
---|
293 | I := 0;
|
---|
294 | while (I < Count) and (Items[I].TargetPosition < Pos) do Inc(I);
|
---|
295 | if I < Count then Result := Items[I]
|
---|
296 | else Result := nil;
|
---|
297 | end;
|
---|
298 |
|
---|
299 | function TDebugSteps.SearchIndexByProgramPos(Pos: Integer): Integer;
|
---|
300 | var
|
---|
301 | I: Integer;
|
---|
302 | begin
|
---|
303 | I := 0;
|
---|
304 | while (I < Count) and (Items[I].ProgramPosition < Pos) do Inc(I);
|
---|
305 | if I < Count then Result := I
|
---|
306 | else Result := -1;
|
---|
307 | end;
|
---|
308 |
|
---|
309 | procedure TDebugSteps.AddStep(SourcePos, TargetPos: Integer;
|
---|
310 | Operation: TStepOperation);
|
---|
311 | var
|
---|
312 | NewItem: TDebugStep;
|
---|
313 | begin
|
---|
314 | NewItem := TDebugStep.Create;
|
---|
315 | NewItem.SourcePosition := SourcePos;
|
---|
316 | NewItem.ProgramPosition := TargetPos;
|
---|
317 | NewItem.TargetPosition := TargetPos;
|
---|
318 | NewItem.Operation := Operation;
|
---|
319 | Add(NewItem);
|
---|
320 | end;
|
---|
321 |
|
---|
322 | procedure TDebugSteps.UpdateTargetPos(OldProgramFrom, OldProgramTo, NewProgramFrom,
|
---|
323 | NewProgramTo: Integer; NewTarget: Integer = 0);
|
---|
324 | var
|
---|
325 | I: Integer;
|
---|
326 | First: Integer;
|
---|
327 | Last: Integer;
|
---|
328 | begin
|
---|
329 | First := SearchIndexByProgramPos(OldProgramFrom);
|
---|
330 | Last := SearchIndexByProgramPos(OldProgramTo);
|
---|
331 | if (First <> -1) and (Last <> -1) then begin
|
---|
332 | if First > Last then
|
---|
333 | raise Exception.Create(SFirstIndexHigherThanLastIndex);
|
---|
334 | if (First < 0) or (First >= Count) then
|
---|
335 | raise Exception.Create(SFirstIndexOutOfRange);
|
---|
336 | if (Last < 0) or (Last >= Count) then
|
---|
337 | raise Exception.Create(SLastIndexOutOfRange);
|
---|
338 | for I := Last downto First + 1 do Delete(I);
|
---|
339 |
|
---|
340 | if NewProgramTo - NewProgramFrom = 0 then begin
|
---|
341 | Delete(First);
|
---|
342 | end else
|
---|
343 | if NewProgramTo > NewProgramFrom then begin
|
---|
344 | Items[First].ProgramPosition := NewProgramFrom;
|
---|
345 | Items[First].TargetPosition := NewTarget;
|
---|
346 | end else
|
---|
347 | raise Exception.Create(Format(SProgramIndexError, [SProgramIndexError, NewProgramTo]));
|
---|
348 | end;
|
---|
349 | end;
|
---|
350 |
|
---|
351 | { TTargets }
|
---|
352 |
|
---|
353 | procedure TTargets.LoadFromRegistry(Context: TRegistryContext);
|
---|
354 | var
|
---|
355 | I: Integer;
|
---|
356 | begin
|
---|
357 | with TRegistryEx.Create do
|
---|
358 | try
|
---|
359 | CurrentContext := Context;
|
---|
360 | for I := 0 to Count - 1 do
|
---|
361 | Items[I].LoadFromRegistry(TRegistryContext.Create(Context.RootKey, Context.Key + '\' + TTarget(Items[I]).Name));
|
---|
362 | finally
|
---|
363 | Free;
|
---|
364 | end;
|
---|
365 | end;
|
---|
366 |
|
---|
367 | procedure TTargets.SaveToRegistry(Context: TRegistryContext);
|
---|
368 | var
|
---|
369 | I: Integer;
|
---|
370 | begin
|
---|
371 | with TRegistryEx.Create do
|
---|
372 | try
|
---|
373 | CurrentContext := Context;
|
---|
374 | for I := 0 to Count - 1 do
|
---|
375 | with Items[I] do
|
---|
376 | Items[I].SaveToRegistry(TRegistryContext.Create(Context.RootKey, Context.Key + '\' + TTarget(Items[I]).Name));
|
---|
377 | finally
|
---|
378 | Free;
|
---|
379 | end;
|
---|
380 | end;
|
---|
381 |
|
---|
382 | function TTargets.FindByName(Name: string): TTarget;
|
---|
383 | var
|
---|
384 | I: Integer;
|
---|
385 | begin
|
---|
386 | I := 0;
|
---|
387 | while (I < Count) and (Items[I].Name <> Name) do Inc(I);
|
---|
388 | if I < Count then Result := Items[I]
|
---|
389 | else Result := nil;
|
---|
390 | end;
|
---|
391 |
|
---|
392 | procedure TTargets.LoadToMenuItem(MenuItem: TMenuItem; Action: TNotifyEvent
|
---|
393 | ; CurrentTarget: TTarget);
|
---|
394 | var
|
---|
395 | NewMenuItem: TMenuItem;
|
---|
396 | I: Integer;
|
---|
397 | begin
|
---|
398 | if Assigned(MenuItem) then begin
|
---|
399 | while MenuItem.Count > Count do
|
---|
400 | MenuItem.Delete(MenuItem.Count - 1);
|
---|
401 | while MenuItem.Count < Count do begin
|
---|
402 | NewMenuItem := TMenuItem.Create(MenuItem);
|
---|
403 | MenuItem.Add(NewMenuItem);
|
---|
404 | end;
|
---|
405 | for I := 0 to Count - 1 do begin
|
---|
406 | MenuItem.Items[I].Caption := Items[I].Name;
|
---|
407 | MenuItem.Items[I].OnClick := Action;
|
---|
408 | MenuItem.Items[I].ImageIndex := Items[I].ImageIndex;
|
---|
409 | if Items[I] = CurrentTarget then MenuItem.Items[I].Checked := True;
|
---|
410 | end;
|
---|
411 | end;
|
---|
412 | end;
|
---|
413 |
|
---|
414 | { TTarget }
|
---|
415 |
|
---|
416 | function TTarget.GetTargetCode: string;
|
---|
417 | begin
|
---|
418 | Result := FTargetCode;
|
---|
419 | end;
|
---|
420 |
|
---|
421 | function TTarget.GetExecutionPosition: Integer;
|
---|
422 | begin
|
---|
423 | Result := 0;
|
---|
424 | end;
|
---|
425 |
|
---|
426 | procedure TTarget.SetState(AValue: TRunState);
|
---|
427 | begin
|
---|
428 | if FState = AValue then Exit;
|
---|
429 | FState := AValue;
|
---|
430 | end;
|
---|
431 |
|
---|
432 | procedure TTarget.SendMessage(Text: string);
|
---|
433 | begin
|
---|
434 | if Assigned(FOnMessage) then
|
---|
435 | FOnMessage(Text);
|
---|
436 | end;
|
---|
437 |
|
---|
438 | procedure TTarget.SetSourceCode(AValue: string);
|
---|
439 | begin
|
---|
440 | FSourceCode := AValue;
|
---|
441 | end;
|
---|
442 |
|
---|
443 | procedure TTarget.AddLine(Text: string = '');
|
---|
444 | begin
|
---|
445 | FTargetCode := FTargetCode + DupeString(' ', Indent) + Text + LineEnding;
|
---|
446 | end;
|
---|
447 |
|
---|
448 | function TTarget.LongFileName(FileName: string): string;
|
---|
449 | begin
|
---|
450 | Result := FileName;
|
---|
451 | {$IFDEF WINDOWS}
|
---|
452 | Result := '"' + FileName + '"';
|
---|
453 | {$ENDIF}
|
---|
454 | {$IFDEF UNIX}
|
---|
455 | Result := StringReplace(FileName, ' ', '\ ', [rfReplaceAll]);
|
---|
456 | {$ENDIF}
|
---|
457 | end;
|
---|
458 |
|
---|
459 | constructor TTarget.Create;
|
---|
460 | begin
|
---|
461 | inherited;
|
---|
462 | OptimizationLevel := coNormal;
|
---|
463 | BreakPoints := TBreakPoints.Create;
|
---|
464 | DebugSteps := TDebugSteps.Create;
|
---|
465 | end;
|
---|
466 |
|
---|
467 | destructor TTarget.Destroy;
|
---|
468 | begin
|
---|
469 | FreeAndNil(DebugSteps);
|
---|
470 | FreeAndNil(BreakPoints);
|
---|
471 | inherited;
|
---|
472 | end;
|
---|
473 |
|
---|
474 | procedure TTarget.Reset;
|
---|
475 | begin
|
---|
476 | end;
|
---|
477 |
|
---|
478 | procedure TTarget.OptimizeSource;
|
---|
479 | begin
|
---|
480 | end;
|
---|
481 |
|
---|
482 | procedure TTarget.Compile;
|
---|
483 | begin
|
---|
484 | LoadProgram;
|
---|
485 | if OptimizationLevel = coNormal then OptimizeSource;
|
---|
486 | Compiled := True;
|
---|
487 | end;
|
---|
488 |
|
---|
489 | procedure TTarget.CompileToFile;
|
---|
490 | var
|
---|
491 | Process: TProcess;
|
---|
492 | CompiledFile: string;
|
---|
493 | Lines: TStringList;
|
---|
494 | I: Integer;
|
---|
495 | begin
|
---|
496 | CompiledFile := ExtractFilePath(ProjectFileName) +
|
---|
497 | CompiledDir + DirectorySeparator + Name + DirectorySeparator +
|
---|
498 | ExtractFileNameOnly(ProjectFileName) + SourceExtension;
|
---|
499 | ForceDirectories(ExtractFilePath(CompiledFile));
|
---|
500 | with TStringList.Create do
|
---|
501 | try
|
---|
502 | Text := FTargetCode;
|
---|
503 | SaveToFile(CompiledFile);
|
---|
504 | finally
|
---|
505 | Free;
|
---|
506 | end;
|
---|
507 | if CompilerPath <> '' then begin;
|
---|
508 | if FileExists(CompilerPath) then
|
---|
509 | try
|
---|
510 | Process := TProcess.Create(nil);
|
---|
511 | Process.CurrentDirectory := ExtractFilePath(CompiledFile);
|
---|
512 | Process.Executable := LongFileName(CompilerPath);
|
---|
513 | Process.Parameters.Add(LongFileName(CompiledFile));
|
---|
514 | for I := 0 to GetEnvironmentVariableCount - 1 do
|
---|
515 | Process.Environment.Add(GetEnvironmentString(I));
|
---|
516 | Process.Options := [poWaitOnExit, poUsePipes];
|
---|
517 | Process.Execute;
|
---|
518 | if Assigned(FOnLog) then begin
|
---|
519 | Lines := TStringList.Create;
|
---|
520 | Lines.LoadFromStream(Process.Output);
|
---|
521 | Lines.Insert(0, Process.Executable + ' ' + Process.Parameters.Text);
|
---|
522 | FOnLog(Lines);
|
---|
523 | Lines.Free;
|
---|
524 | end;
|
---|
525 | finally
|
---|
526 | Process.Free;
|
---|
527 | end else raise Exception.Create(Format(SCompilerNotFound, [CompilerPath]));
|
---|
528 | end;
|
---|
529 | end;
|
---|
530 |
|
---|
531 | procedure TTarget.RunFromFile;
|
---|
532 | var
|
---|
533 | Process: TProcess;
|
---|
534 | CompiledFile: string;
|
---|
535 | RunFile: string;
|
---|
536 | begin
|
---|
537 | if ExecutorPath = '' then Exit;
|
---|
538 |
|
---|
539 | CompiledFile := ExtractFilePath(ProjectFileName) +
|
---|
540 | CompiledDir + DirectorySeparator + Name + DirectorySeparator +
|
---|
541 | ExtractFileNameOnly(ProjectFileName) + CompiledExtension;
|
---|
542 | RunFile := ExtractFilePath(ProjectFileName) +
|
---|
543 | CompiledDir + DirectorySeparator + Name + DirectorySeparator +
|
---|
544 | ExtractFileNameOnly(ProjectFileName) + RunExtension;
|
---|
545 | if not FileExists(ExecutorPath) then
|
---|
546 | raise Exception.Create(Format(SExecutorNotFound, [ExecutorPath]));
|
---|
547 | if FileExists(CompiledFile) then
|
---|
548 | try
|
---|
549 | Process := TProcess.Create(nil);
|
---|
550 | if ExecutorPath <> '' then begin
|
---|
551 | Process.Executable := LongFileName(ExecutorPath);
|
---|
552 | Process.Parameters.Add(LongFileName(RunFile));
|
---|
553 | end else Process.Executable := LongFileName(RunFile);
|
---|
554 | Process.ShowWindow := swoShow;
|
---|
555 | Process.Options := [poWaitOnExit, poNewConsole];
|
---|
556 | Process.Execute;
|
---|
557 | finally
|
---|
558 | Process.Free;
|
---|
559 | end else raise Exception.Create(Format(SCompiledFileNotFound, [CompiledFile]));
|
---|
560 | end;
|
---|
561 |
|
---|
562 | procedure TTarget.Run;
|
---|
563 | begin
|
---|
564 | end;
|
---|
565 |
|
---|
566 | procedure TTarget.Pause;
|
---|
567 | begin
|
---|
568 | end;
|
---|
569 |
|
---|
570 | procedure TTarget.Stop;
|
---|
571 | begin
|
---|
572 | end;
|
---|
573 |
|
---|
574 | procedure TTarget.StepOver;
|
---|
575 | begin
|
---|
576 | end;
|
---|
577 |
|
---|
578 | procedure TTarget.StepInto;
|
---|
579 | begin
|
---|
580 | end;
|
---|
581 |
|
---|
582 | procedure TTarget.StepOut;
|
---|
583 | begin
|
---|
584 | end;
|
---|
585 |
|
---|
586 | procedure TTarget.RunToCursor(Pos: Integer);
|
---|
587 | begin
|
---|
588 | end;
|
---|
589 |
|
---|
590 | procedure TTarget.LoadFromRegistry(Context: TRegistryContext);
|
---|
591 | begin
|
---|
592 | with TRegistryEx.Create do
|
---|
593 | try
|
---|
594 | CurrentContext := Context;
|
---|
595 | CompilerPath := ReadStringWithDefault('CompilerPath', CompilerPath);
|
---|
596 | ExecutorPath := ReadStringWithDefault('ExecutorPath', ExecutorPath);
|
---|
597 | Selected := ReadBoolWithDefault('Selected', Selected);
|
---|
598 | finally
|
---|
599 | Free;
|
---|
600 | end;
|
---|
601 | end;
|
---|
602 |
|
---|
603 | procedure TTarget.SaveToRegistry(Context: TRegistryContext);
|
---|
604 | begin
|
---|
605 | with TRegistryEx.Create do
|
---|
606 | try
|
---|
607 | CurrentContext := Context;
|
---|
608 | WriteString('CompilerPath', CompilerPath);
|
---|
609 | WriteString('ExecutorPath', ExecutorPath);
|
---|
610 | WriteBool('Selected', Selected);
|
---|
611 | finally
|
---|
612 | Free;
|
---|
613 | end;
|
---|
614 | end;
|
---|
615 |
|
---|
616 | procedure TTarget.LoadProgram;
|
---|
617 | begin
|
---|
618 | end;
|
---|
619 |
|
---|
620 | function TTarget.SourceReadNext: Char;
|
---|
621 | begin
|
---|
622 | Result := ' ';
|
---|
623 | end;
|
---|
624 |
|
---|
625 | end.
|
---|
626 |
|
---|