itx86int.pas 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. {$ifdef 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. {$else x86_64}
  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. {$endif x86_64}
  44. function findreg_by_intname(const s:string):integer;
  45. var
  46. i,p : integer;
  47. s1: string;
  48. l,r,m: integer;
  49. begin
  50. {Binary search.}
  51. p:=0;
  52. i := (high(tregisterindex) + 1) shr 1;
  53. l := 0;
  54. r := high(tregisterindex) + 1;
  55. while l < r do
  56. begin
  57. m := (l + r) div 2;
  58. if int_regname_table[int_regname_index[m]] < s then l := m + 1
  59. else r := m;
  60. end;
  61. if int_regname_table[int_regname_index[r]]=s then
  62. findreg_by_intname:=int_regname_index[r]
  63. else
  64. findreg_by_intname:=0;
  65. end;
  66. function masm_regnum_search(const s:string):Tregister;
  67. begin
  68. result:=regnumber_table[findreg_by_intname(s)];
  69. end;
  70. function masm_regname(r:Tregister):string;
  71. var
  72. p : tregisterindex;
  73. begin
  74. p:=findreg_by_number(r);
  75. if p<>0 then
  76. result:=int_regname_table[p]
  77. else
  78. result:=generic_regname(r);
  79. end;
  80. end.