itx86int.pas 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. This unit contains the i386 AT&T instruction tables
  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 itx86int;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. cgbase;
  22. function masm_regnum_search(const s:string):Tregister;
  23. function masm_regname(r:Tregister):string;
  24. implementation
  25. uses
  26. cutils,verbose,
  27. cpubase;
  28. const
  29. {$if defined(x86_64)}
  30. int_regname_table : array[tregisterindex] of string[7] = (
  31. {$i r8664int.inc}
  32. );
  33. int_regname_index : array[tregisterindex] of tregisterindex = (
  34. {$i r8664iri.inc}
  35. );
  36. {$elseif defined(i386)}
  37. int_regname_table : array[tregisterindex] of string[7] = (
  38. {$i r386int.inc}
  39. );
  40. int_regname_index : array[tregisterindex] of tregisterindex = (
  41. {$i r386iri.inc}
  42. );
  43. {$elseif defined(i8086)}
  44. int_regname_table : array[tregisterindex] of string[7] = (
  45. {$i r8086int.inc}
  46. );
  47. int_regname_index : array[tregisterindex] of tregisterindex = (
  48. {$i r8086iri.inc}
  49. );
  50. {$endif}
  51. function findreg_by_intname(const s:string):integer;
  52. var
  53. l,r,m: integer;
  54. begin
  55. {Binary search.}
  56. l := 0;
  57. r := high(tregisterindex) + 1;
  58. while l < r do
  59. begin
  60. m := (l + r) div 2;
  61. if int_regname_table[int_regname_index[m]] < s then l := m + 1
  62. else r := m;
  63. end;
  64. if (r<=high(tregisterindex)) and (int_regname_table[int_regname_index[r]]=s) then
  65. findreg_by_intname:=int_regname_index[r]
  66. else
  67. findreg_by_intname:=0;
  68. end;
  69. function masm_regnum_search(const s:string):Tregister;
  70. begin
  71. result:=regnumber_table[findreg_by_intname(s)];
  72. end;
  73. function masm_regname(r:Tregister):string;
  74. var
  75. p : tregisterindex;
  76. begin
  77. p:=findreg_by_number(r);
  78. if p<>0 then
  79. result:=int_regname_table[p]
  80. else
  81. result:=generic_regname(r);
  82. end;
  83. end.