rabase.pas 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. {
  2. $Id$
  3. Copyright (c) 1998-2003 by Peter Vreman, Florian Klaempfl and Carl Eric Codere
  4. Basic stuff for assembler readers
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit rabase;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. cclasses,
  23. systems;
  24. type
  25. tbaseasmreader = class
  26. constructor create;virtual;
  27. { the real return type is taasmoutput, but this would introduce too much unit circles }
  28. function Assemble: tlinkedlist;virtual;abstract;
  29. end;
  30. tcbaseasmreader = class of tbaseasmreader;
  31. pasmmodeinfo = ^tasmmodeinfo;
  32. tasmmodeinfo = record
  33. id : tasmmode;
  34. idtxt : string[8];
  35. casmreader : tcbaseasmreader;
  36. end;
  37. var
  38. asmmodeinfos : array[tasmmode] of pasmmodeinfo;
  39. function SetAsmReadMode(const s:string;var t:tasmmode):boolean;
  40. procedure RegisterAsmMode(const r:tasmmodeinfo);
  41. implementation
  42. uses
  43. cutils;
  44. procedure RegisterAsmmode(const r:tasmmodeinfo);
  45. var
  46. t : tasmmode;
  47. begin
  48. t:=r.id;
  49. if assigned(asmmodeinfos[t]) then
  50. writeln('Warning: Asmmode is already registered!')
  51. else
  52. Getmem(asmmodeinfos[t],sizeof(tasmmodeinfo));
  53. asmmodeinfos[t]^:=r;
  54. end;
  55. function SetAsmReadMode(const s:string;var t:tasmmode):boolean;
  56. var
  57. hs : string;
  58. ht : tasmmode;
  59. begin
  60. result:=false;
  61. { this should be case insensitive !! PM }
  62. hs:=upper(s);
  63. for ht:=low(tasmmode) to high(tasmmode) do
  64. if assigned(asmmodeinfos[ht]) and
  65. (asmmodeinfos[ht]^.idtxt=hs) then
  66. begin
  67. t:=asmmodeinfos[ht]^.id;
  68. result:=true;
  69. end;
  70. end;
  71. constructor tbaseasmreader.create;
  72. begin
  73. inherited create;
  74. end;
  75. var
  76. asmmode : tasmmode;
  77. finalization
  78. for asmmode:=low(tasmmode) to high(tasmmode) do
  79. if assigned(asmmodeinfos[asmmode]) then
  80. begin
  81. freemem(asmmodeinfos[asmmode],sizeof(tasmmodeinfo));
  82. asmmodeinfos[asmmode]:=nil;
  83. end;
  84. end.
  85. {
  86. $Log$
  87. Revision 1.4 2004-06-20 08:55:30 florian
  88. * logs truncated
  89. Revision 1.3 2004/01/30 13:42:03 florian
  90. * fixed more alignment issues
  91. }