Changeset 25 for branches/AS8051toC/UMainForm.pas
- Timestamp:
- Oct 15, 2012, 12:00:21 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/AS8051toC/UMainForm.pas
r23 r25 17 17 ButtonConvert: TButton; 18 18 EditPath: TEdit; 19 OpenDialog1: TOpenDialog; 19 20 SynCppSyn1: TSynCppSyn; 20 21 SynMemo1: TSynMemo; … … 26 27 procedure FormShow(Sender: TObject); 27 28 private 28 Parser: TParser ;29 Parser: TParserASM51; 29 30 public 30 31 MainFile: TStringList; … … 32 33 Output: string; 33 34 Macros: TStringList; 35 function IsHexNumber(Text: string): Boolean; 36 function CheckInstructionParameter: Boolean; 34 37 procedure Emit(Text: string); 35 38 procedure Error(Text: string); … … 66 69 67 70 procedure TFormMain.ButtonConvertClick(Sender: TObject); 68 var 69 Path: string; 70 begin 71 Path := 'h:\Projekty\E341\Repository\trunk'; 72 MainFile.LoadFromFile(Path + DirectorySeparator + 'main.a51'); 71 begin 72 MainFile.LoadFromFile(EditPath.Text); 73 73 Parser.Source := LowerCase(MainFile.Text); 74 74 Parser.Position := 1; … … 76 76 Parse; 77 77 MainFileOut.Text := Output; 78 ForceDirectoriesUTF8( Path+ DirectorySeparator + 'C');79 MainFileOut.SaveToFile( Path+ DirectorySeparator + 'C' +78 ForceDirectoriesUTF8(ExtractFileDir(EditPath.Text) + DirectorySeparator + 'C'); 79 MainFileOut.SaveToFile(ExtractFileDir(EditPath.Text) + DirectorySeparator + 'C' + 80 80 DirectorySeparator + 'main.c'); 81 81 SynMemo1.Lines.Assign(MainFileOut); … … 86 86 Dir: string; 87 87 begin 88 if SelectDirectory('Výběr adresáře', EditPath.Text, Dir) then 89 EditPath.Text := Dir; 88 OpenDialog1.FileName := EditPath.Text; 89 if OpenDialog1.Execute then begin 90 EditPath.Text := OpenDialog1.FileName; 91 end; 90 92 end; 91 93 92 94 procedure TFormMain.FormCreate(Sender: TObject); 93 95 begin 94 Parser := TParser .Create;96 Parser := TParserASM51.Create; 95 97 Parser.OnError := Error; 96 98 MainFile := TStringList.Create; … … 111 113 ButtonConvertClick(Self); 112 114 //Close; 115 end; 116 117 function TFormMain.IsHexNumber(Text: string): Boolean; 118 begin 119 Result := (LowerCase(Copy(Text, Length(Text), 1)) = 'h') and 120 (Parser.IsHexNumber(Copy(Text, 1, Length(Text) - 1))); 121 end; 122 123 function TFormMain.CheckInstructionParameter: Boolean; 124 begin 125 Text := Parser.GetNext; 126 Result := False; 127 if Parser.IsNumber(Text) then Result := True 128 else if Text = '#' then begin 129 Result := True; 130 Parser.Expect('#'); 131 if IsHexNumber(Parser.GetNext) then Emit(Parser.ReadNext) 132 else if Parser.IsNumber(Parser.GetNext) then Emit(Parser.ReadNext) 133 else Error('Invalid parameter'); 134 end 135 else if Copy(Text, 1, 1) = '@' then begin 136 if IsHexNumber(Copy(Text, 2, Length(Text))) then Result := True; 137 Emit(Parser.ReadNext); 138 end; 113 139 end; 114 140 … … 176 202 end 177 203 else if ParseComment then 178 else if ParseMacro then179 204 else if ParseKeywords then 180 205 else if ParseInstruction then … … 200 225 end else Error('Unexpected token "' + Variable + '"'); 201 226 end 227 else if ParseMacro then 228 else if ParseMacroUsage then 202 229 else Error('Unexpected token "' + GetNext + '"'); 203 230 Emit(LineEnding); … … 208 235 var 209 236 MacroName: string; 210 begin 211 with Parser do begin 237 OldPos: Integer; 238 begin 239 with Parser do begin 240 OldPos := Position; 212 241 if GetNext = '%' then begin 213 242 Result := True; … … 269 298 Expect('('); 270 299 end; 271 end;// else Error('Unknown macro: ' + ReadNext); 300 end else begin 301 Position := OldPos; 302 Result := False; 303 end; 272 304 end else Result := False; 273 305 end; … … 299 331 Expect('('); 300 332 Emit('('); 301 if ParseMacroUsage then302 333 ParseDbExpression; 334 //else Emit(ReadNext); 303 335 while GetNext = ',' do begin 304 336 Expect(','); 305 337 Emit(','); 306 if ParseMacroUsage then 307 else Emit(ReadNext); 338 ParseDbExpression; 339 //if ParseMacroUsage then 340 //else if GetNext <> ')' then Emit(ReadNext); 308 341 end; 309 342 Emit(')'); … … 339 372 ReadNext; 340 373 end; 374 end else 375 if GetNext = 'using' then begin 376 Result := True; 377 Expect('using'); 378 Value := ReadNext; 379 Emit('// using reg bank ' + Value); 341 380 end else 342 381 if GetNext = 'cseg' then begin … … 411 450 Emit(';'); 412 451 end else 452 if GetNext = 'mov' then begin 453 Expect('mov'); 454 Result := True; 455 Emit('MOV('); 456 ParseDbExpression; 457 Expect(','); 458 Emit(','); 459 ParseDbExpression; 460 Emit(');'); 461 end else 413 462 if GetNext = 'reti' then begin 414 463 Result := True; … … 457 506 Emit('&& '); 458 507 end else 459 Error('Unknown operand "' + ReadNext + '"');508 Error('Unknown operand "' + ReadNext + '"'); 460 509 if ParseMacroUsage then 461 510 else if IsNumber(GetNext) then Emit(ReadNext) … … 482 531 end 483 532 else if GetNext = '''' then Emit('"' + ParseString + '"') 484 else if IsNumber(GetNext) then Emit(ReadNext) 485 else if IsIdentificator(GetNext) then Emit(ReadNext) 486 else Error('Unknown IF parameter "' + GetNext + '"'); 533 else if CheckInstructionParameter then 534 else if IsIdentificator(GetNext) then begin 535 Emit(ReadNext); 536 if ParseMacroUsage then ; 537 end else Error('Unknown IF parameter "' + GetNext + '"'); 487 538 488 539 if GetNext = '+' then begin … … 504 555 Expect('/'); 505 556 Emit('/'); 557 ParseDbExpression; 558 end else 559 if GetNext = 'shl' then begin 560 Expect('shl'); 561 Emit('<< '); 562 ParseDbExpression; 563 end else 564 if GetNext = 'shr' then begin 565 Expect('shr'); 566 Emit('>> '); 506 567 ParseDbExpression; 507 568 end else
Note:
See TracChangeset
for help on using the changeset viewer.