| 1 | unit UMainForm;
|
|---|
| 2 |
|
|---|
| 3 | {$mode Delphi}{$H+}
|
|---|
| 4 |
|
|---|
| 5 | interface
|
|---|
| 6 |
|
|---|
| 7 | uses
|
|---|
| 8 | Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
|
|---|
| 9 | StdCtrls, ComCtrls, SynHighlighterPas, SynEdit, SynHighlighterCpp,
|
|---|
| 10 | UCompilator, UOutputGenerator, UModelViewer, UPascalGenerator, UCGenerator,
|
|---|
| 11 | UZ80Generator;
|
|---|
| 12 |
|
|---|
| 13 | const
|
|---|
| 14 | SourceFileName = 'Example.void';
|
|---|
| 15 |
|
|---|
| 16 | type
|
|---|
| 17 |
|
|---|
| 18 | { TMainForm }
|
|---|
| 19 |
|
|---|
| 20 | TMainForm = class(TForm)
|
|---|
| 21 | ButtonCompile: TButton;
|
|---|
| 22 | ComboBox1: TComboBox;
|
|---|
| 23 | Label1: TLabel;
|
|---|
| 24 | Label2: TLabel;
|
|---|
| 25 | Label3: TLabel;
|
|---|
| 26 | Label4: TLabel;
|
|---|
| 27 | ListView1: TListView;
|
|---|
| 28 | SynCppSyn1: TSynCppSyn;
|
|---|
| 29 | SynEdit1: TSynEdit;
|
|---|
| 30 | SynEdit2: TSynEdit;
|
|---|
| 31 | SynPasSyn1: TSynPasSyn;
|
|---|
| 32 | TreeView1: TTreeView;
|
|---|
| 33 | procedure ButtonCompileClick(Sender: TObject);
|
|---|
| 34 | procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
|
|---|
| 35 | procedure FormCreate(Sender: TObject);
|
|---|
| 36 | procedure FormDestroy(Sender: TObject);
|
|---|
| 37 | procedure FormShow(Sender: TObject);
|
|---|
| 38 | procedure ListView1Click(Sender: TObject);
|
|---|
| 39 | private
|
|---|
| 40 | SourceCode: TMemoryStream;
|
|---|
| 41 | ModelViewer: TModelViewer;
|
|---|
| 42 | procedure CompilatorError(Text: string; var Terminate: Boolean;
|
|---|
| 43 | Position: TPoint);
|
|---|
| 44 | public
|
|---|
| 45 | Compilator: TCompilator;
|
|---|
| 46 | end;
|
|---|
| 47 |
|
|---|
| 48 | var
|
|---|
| 49 | MainForm: TMainForm;
|
|---|
| 50 |
|
|---|
| 51 | implementation
|
|---|
| 52 |
|
|---|
| 53 | { TMainForm }
|
|---|
| 54 |
|
|---|
| 55 | procedure TMainForm.FormShow(Sender: TObject);
|
|---|
| 56 | begin
|
|---|
| 57 | SynEdit1.Lines.LoadFromFile(SourceFileName);
|
|---|
| 58 | ButtonCompileClick(Self);
|
|---|
| 59 | end;
|
|---|
| 60 |
|
|---|
| 61 | procedure TMainForm.ListView1Click(Sender: TObject);
|
|---|
| 62 | begin
|
|---|
| 63 | if Assigned(ListView1.Selected) then begin
|
|---|
| 64 | SynEdit1.CaretXY := TErrorMessage(Compilator.ErrorMessages[
|
|---|
| 65 | ListView1.Selected.Index]).CodePosition;
|
|---|
| 66 | SynEdit1.SetFocus;
|
|---|
| 67 | end;
|
|---|
| 68 | end;
|
|---|
| 69 |
|
|---|
| 70 | procedure TMainForm.FormClose(Sender: TObject; var CloseAction: TCloseAction);
|
|---|
| 71 | begin
|
|---|
| 72 | SynEdit1.Lines.SaveToFile(SourceFileName);
|
|---|
| 73 | end;
|
|---|
| 74 |
|
|---|
| 75 | procedure TMainForm.FormCreate(Sender: TObject);
|
|---|
| 76 | begin
|
|---|
| 77 | Compilator := TCompilator.Create;
|
|---|
| 78 | Compilator.OnError := CompilatorError;
|
|---|
| 79 | ModelViewer := TModelViewer.Create;
|
|---|
| 80 | end;
|
|---|
| 81 |
|
|---|
| 82 | procedure TMainForm.FormDestroy(Sender: TObject);
|
|---|
| 83 | begin
|
|---|
| 84 | Compilator.Destroy;
|
|---|
| 85 | ModelViewer.Destroy;
|
|---|
| 86 | end;
|
|---|
| 87 |
|
|---|
| 88 | procedure TMainForm.ButtonCompileClick(Sender: TObject);
|
|---|
| 89 | var
|
|---|
| 90 | Code: string;
|
|---|
| 91 | OutputFileName: string;
|
|---|
| 92 | begin
|
|---|
| 93 | with Compilator do begin
|
|---|
| 94 | ListView1.Clear;
|
|---|
| 95 | Code := SynEdit1.Lines.Text;
|
|---|
| 96 | SourceCode.Size := 0;
|
|---|
| 97 | SourceCode.Write(Code[1], Length(Code));
|
|---|
| 98 | if Assigned(Generator) then Generator.Destroy;
|
|---|
| 99 | if ComboBox1.ItemIndex = 0 then begin
|
|---|
| 100 | Generator := TPascalGenerator.Create;
|
|---|
| 101 | SynEdit2.Highlighter := SynPasSyn1;
|
|---|
| 102 | OutputFileName := 'Output.dpr';
|
|---|
| 103 | end else
|
|---|
| 104 | if ComboBox1.ItemIndex = 1 then begin
|
|---|
| 105 | Generator := TCGenerator.Create;
|
|---|
| 106 | SynEdit2.Highlighter := SynCppSyn1;
|
|---|
| 107 | OutputFileName := 'Output.c';
|
|---|
| 108 | end else
|
|---|
| 109 | if ComboBox1.ItemIndex = 2 then begin
|
|---|
| 110 | Generator := TZ80Generator.Create;
|
|---|
| 111 | SynEdit2.Highlighter := SynCppSyn1;
|
|---|
| 112 | OutputFileName := 'Output.asm';
|
|---|
| 113 | end;
|
|---|
| 114 |
|
|---|
| 115 | try
|
|---|
| 116 | Compile;
|
|---|
| 117 | except
|
|---|
| 118 | end;
|
|---|
| 119 |
|
|---|
| 120 | SynEdit2.Lines.Assign(Generator.Output);
|
|---|
| 121 | SynEdit2.Lines.SaveToFile(OutputFileName);
|
|---|
| 122 | ModelViewer.Show(TreeView1);
|
|---|
| 123 | end;
|
|---|
| 124 | end;
|
|---|
| 125 |
|
|---|
| 126 | procedure TMainForm.CompilatorError(Text: string; var Terminate: Boolean;
|
|---|
| 127 | Position: TPoint);
|
|---|
| 128 | var
|
|---|
| 129 | NewItem: TListItem;
|
|---|
| 130 | begin
|
|---|
| 131 | Terminate := False;
|
|---|
| 132 | NewItem := ListView1.Items.Add;
|
|---|
| 133 | with NewItem do begin
|
|---|
| 134 | Caption := '';
|
|---|
| 135 | SubItems.Add(IntToStr(Position.X) + ', ' + IntToStr(Position.Y));
|
|---|
| 136 | SubItems.Add('Error: ' + Text);
|
|---|
| 137 | end;
|
|---|
| 138 | end;
|
|---|
| 139 |
|
|---|
| 140 | initialization
|
|---|
| 141 | {$I UMainForm.lrs}
|
|---|
| 142 |
|
|---|
| 143 | end.
|
|---|
| 144 |
|
|---|