rasm.pas 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. aasmdata,
  25. cpubase,
  26. cgbase;
  27. type
  28. tasmreader = class(tbaseasmreader)
  29. firsttoken : boolean;
  30. _asmsorted : boolean;
  31. curlist : TAsmList;
  32. c : char;
  33. actasmpattern : string;
  34. actopcode : tasmop;
  35. actasmregister : tregister;
  36. actcondition : tasmcond;
  37. iasmops : TFPHashList;
  38. locallabels : TFPHashObjectList;
  39. constructor create;override;
  40. destructor destroy;override;
  41. function createlocallabel(const s: string; var hl: tasmlabel; emit: boolean): boolean;
  42. procedure checklocallabels;
  43. end;
  44. implementation
  45. uses
  46. verbose;
  47. type
  48. TLocalLabel = class(TFPHashObject)
  49. emitted: boolean;
  50. lab: tasmlabel;
  51. function Gettasmlabel: tasmlabel;
  52. end;
  53. function TLocalLabel.Gettasmlabel:tasmlabel;
  54. begin
  55. if not assigned(lab) then
  56. begin
  57. current_asmdata.getjumplabel(lab);
  58. { this label is forced to be used so it's always written }
  59. lab.increfs;
  60. end;
  61. result:=lab;
  62. end;
  63. constructor tasmreader.create;
  64. begin
  65. inherited create;
  66. firsttoken:=true;
  67. locallabels:=TFPHashObjectList.create;
  68. end;
  69. destructor tasmreader.destroy;
  70. begin
  71. locallabels.Free;
  72. iasmops.Free;
  73. inherited destroy;
  74. end;
  75. function tasmreader.createlocallabel(const s: string; var hl: tasmlabel; emit:boolean):boolean;
  76. var
  77. lab: TLocalLabel;
  78. begin
  79. result:=true;
  80. { Check if it already is defined }
  81. lab:=TLocalLabel(locallabels.Find(s));
  82. if not assigned(lab) then
  83. lab:=TLocalLabel.Create(locallabels,s);
  84. { set emitted flag and check for dup syms }
  85. if emit then
  86. begin
  87. if lab.Emitted then
  88. begin
  89. Message1(asmr_e_dup_local_sym,lab.Name);
  90. result:=false;
  91. end;
  92. lab.Emitted:=true;
  93. end;
  94. hl:=lab.Gettasmlabel;
  95. end;
  96. procedure tasmreader.checklocallabels;
  97. var
  98. i: longint;
  99. lab: TLocalLabel;
  100. begin
  101. for i:=0 to locallabels.Count-1 do
  102. begin
  103. lab:=TLocalLabel(locallabels[i]);
  104. if not lab.emitted then
  105. Message1(asmr_e_unknown_label_identifier,lab.name);
  106. end;
  107. locallabels.Clear;
  108. end;
  109. end.