rabase.pas 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 rabase;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. cclasses,
  22. systems;
  23. type
  24. tbaseasmreader = class
  25. constructor create;virtual;
  26. { the real return type is TAsmList, but this would introduce too much unit circles }
  27. function Assemble: tlinkedlist;virtual;abstract;
  28. end;
  29. tcbaseasmreader = class of tbaseasmreader;
  30. pasmmodeinfo = ^tasmmodeinfo;
  31. tasmmodeinfo = record
  32. id : tasmmode;
  33. idtxt : string[12];
  34. casmreader : tcbaseasmreader;
  35. end;
  36. var
  37. asmmodeinfos : array[tasmmode] of pasmmodeinfo;
  38. function SetAsmReadMode(const s:string;var t:tasmmode):boolean;
  39. procedure RegisterAsmMode(const r:tasmmodeinfo);
  40. implementation
  41. uses
  42. cutils;
  43. procedure RegisterAsmmode(const r:tasmmodeinfo);
  44. var
  45. t : tasmmode;
  46. begin
  47. t:=r.id;
  48. if assigned(asmmodeinfos[t]) then
  49. writeln('Warning: Asmmode is already registered!')
  50. else
  51. Getmem(asmmodeinfos[t],sizeof(tasmmodeinfo));
  52. asmmodeinfos[t]^:=r;
  53. end;
  54. function SetAsmReadMode(const s:string;var t:tasmmode):boolean;
  55. var
  56. hs : string;
  57. ht : tasmmode;
  58. begin
  59. result:=false;
  60. hs:=upper(s);
  61. { Support Default as an alias for Standard }
  62. if hs='DEFAULT' then
  63. hs:='STANDARD';
  64. for ht:=low(tasmmode) to high(tasmmode) do
  65. if assigned(asmmodeinfos[ht]) and
  66. (asmmodeinfos[ht]^.idtxt=hs) then
  67. begin
  68. t:=asmmodeinfos[ht]^.id;
  69. result:=true;
  70. end;
  71. end;
  72. constructor tbaseasmreader.create;
  73. begin
  74. inherited create;
  75. end;
  76. var
  77. asmmode : tasmmode;
  78. finalization
  79. for asmmode:=low(tasmmode) to high(tasmmode) do
  80. if assigned(asmmodeinfos[asmmode]) then
  81. begin
  82. freemem(asmmodeinfos[asmmode],sizeof(tasmmodeinfo));
  83. asmmodeinfos[asmmode]:=nil;
  84. end;
  85. end.