/compiler/x86/itx86int.pas

https://github.com/slibre/freepascal · Pascal · 99 lines · 51 code · 18 blank · 30 comment · 5 complexity · 957f759519bf312120d50bb04301c3da MD5 · raw file

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