rasm.pas 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. {
  2. Copyright (c) 1998-2003 by Peter Vreman, Florian Klaempfl and Carl Eric Codere
  3. Basic stuff for assembler readers
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit rasm;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. cclasses,
  22. rabase,
  23. aasmbase,
  24. aasmtai,aasmdata,
  25. systems,
  26. cpubase,
  27. cgbase;
  28. type
  29. tasmreader = class(tbaseasmreader)
  30. firsttoken : boolean;
  31. _asmsorted : boolean;
  32. curlist : TAsmList;
  33. c : char;
  34. actasmpattern : string;
  35. actopcode : tasmop;
  36. actasmregister : tregister;
  37. actcondition : tasmcond;
  38. iasmops : TFPHashList;
  39. locallabels : TFPHashObjectList;
  40. constructor create;override;
  41. destructor destroy;override;
  42. function createlocallabel(const s: string; var hl: tasmlabel; emit: boolean): boolean;
  43. procedure checklocallabels;
  44. end;
  45. implementation
  46. uses
  47. verbose;
  48. type
  49. TLocalLabel = class(TFPHashObject)
  50. emitted: boolean;
  51. lab: tasmlabel;
  52. function Gettasmlabel: tasmlabel;
  53. end;
  54. function TLocalLabel.Gettasmlabel:tasmlabel;
  55. begin
  56. if not assigned(lab) then
  57. begin
  58. current_asmdata.getjumplabel(lab);
  59. { this label is forced to be used so it's always written }
  60. lab.increfs;
  61. end;
  62. result:=lab;
  63. end;
  64. constructor tasmreader.create;
  65. begin
  66. inherited create;
  67. firsttoken:=true;
  68. locallabels:=TFPHashObjectList.create;
  69. end;
  70. destructor tasmreader.destroy;
  71. begin
  72. locallabels.Free;
  73. iasmops.Free;
  74. inherited destroy;
  75. end;
  76. function tasmreader.createlocallabel(const s: string; var hl: tasmlabel; emit:boolean):boolean;
  77. var
  78. lab: TLocalLabel;
  79. begin
  80. result:=true;
  81. { Check if it already is defined }
  82. lab:=TLocalLabel(locallabels.Find(s));
  83. if not assigned(lab) then
  84. lab:=TLocalLabel.Create(locallabels,s);
  85. { set emitted flag and check for dup syms }
  86. if emit then
  87. begin
  88. if lab.Emitted then
  89. begin
  90. Message1(asmr_e_dup_local_sym,lab.Name);
  91. result:=false;
  92. end;
  93. lab.Emitted:=true;
  94. end;
  95. hl:=lab.Gettasmlabel;
  96. end;
  97. procedure tasmreader.checklocallabels;
  98. var
  99. i: longint;
  100. lab: TLocalLabel;
  101. begin
  102. for i:=0 to locallabels.Count-1 do
  103. begin
  104. lab:=TLocalLabel(locallabels[i]);
  105. if not lab.emitted then
  106. Message1(asmr_e_unknown_label_identifier,lab.name);
  107. end;
  108. locallabels.Clear;
  109. end;
  110. end.