itx86att.pas 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. This unit contains the i386 AT&T instruction tables
  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 itx86att;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. cgbase,cpubase;
  23. type
  24. TAttSuffix = (AttSufNONE,AttSufINT,AttSufFPU,AttSufFPUint);
  25. const
  26. {$ifdef x86_64}
  27. {x86att.inc contains the name for each x86-64 mnemonic}
  28. gas_op2str:op2strtable={$i x64att.inc}
  29. gas_needsuffix:array[tasmop] of TAttSuffix={$i x64atts.inc}
  30. {$else x86_64}
  31. {x86att.inc contains the name for each i386 mnemonic}
  32. gas_op2str:op2strtable={$i i386att.inc}
  33. gas_needsuffix:array[tasmop] of TAttSuffix={$i i386atts.inc}
  34. {$endif x86_64}
  35. {$ifdef x86_64}
  36. gas_opsize2str : array[topsize] of string[2] = ('',
  37. 'b','w','l','bw','bl','wl','bq','wq','lq',
  38. 's','l','q',
  39. 's','l','t','d','q','v','x',
  40. '','',''
  41. );
  42. {$else x86_64}
  43. gas_opsize2str : array[topsize] of string[2] = ('',
  44. 'b','w','l','bw','bl','wl',
  45. 's','l','q',
  46. 's','l','t','d','q','v','',
  47. '','',''
  48. );
  49. {$endif x86_64}
  50. function gas_regnum_search(const s:string):Tregister;
  51. function gas_regname(r:Tregister):string;
  52. implementation
  53. uses
  54. cutils,verbose;
  55. const
  56. {$ifdef x86_64}
  57. att_regname_table : array[tregisterindex] of string[7] = (
  58. {r8664att.inc contains the AT&T name of each register.}
  59. {$i r8664att.inc}
  60. );
  61. att_regname_index : array[tregisterindex] of tregisterindex = (
  62. {r8664ari.inc contains an index which sorts att_regname_table by
  63. ATT name.}
  64. {$i r8664ari.inc}
  65. );
  66. {$else x86_64}
  67. att_regname_table : array[tregisterindex] of string[7] = (
  68. {r386att.inc contains the AT&T name of each register.}
  69. {$i r386att.inc}
  70. );
  71. att_regname_index : array[tregisterindex] of tregisterindex = (
  72. {r386ari.inc contains an index which sorts att_regname_table by
  73. ATT name.}
  74. {$i r386ari.inc}
  75. );
  76. {$endif x86_64}
  77. function findreg_by_attname(const s:string):byte;
  78. var
  79. i,p : tregisterindex;
  80. begin
  81. {Binary search.}
  82. p:=0;
  83. i:=regnumber_count_bsstart;
  84. repeat
  85. if (p+i<=high(tregisterindex)) and (att_regname_table[att_regname_index[p+i]]<=s) then
  86. p:=p+i;
  87. i:=i shr 1;
  88. until i=0;
  89. if att_regname_table[att_regname_index[p]]=s then
  90. findreg_by_attname:=att_regname_index[p]
  91. else
  92. findreg_by_attname:=0;
  93. end;
  94. function gas_regnum_search(const s:string):Tregister;
  95. begin
  96. result:=regnumber_table[findreg_by_attname(s)];
  97. end;
  98. function gas_regname(r:Tregister):string;
  99. var
  100. p : tregisterindex;
  101. begin
  102. p:=findreg_by_number(r);
  103. if p<>0 then
  104. result:=att_regname_table[p]
  105. else
  106. result:='%'+generic_regname(r);
  107. end;
  108. end.
  109. {
  110. $Log$
  111. Revision 1.6 2003-10-01 20:34:51 peter
  112. * procinfo unit contains tprocinfo
  113. * cginfo renamed to cgbase
  114. * moved cgmessage to verbose
  115. * fixed ppc and sparc compiles
  116. Revision 1.5 2003/09/24 17:12:36 florian
  117. * x86-64 adaptions
  118. Revision 1.4 2003/09/03 15:55:02 peter
  119. * NEWRA branch merged
  120. Revision 1.3.2.6 2003/08/31 15:46:26 peter
  121. * more updates for tregister
  122. Revision 1.3.2.5 2003/08/31 13:50:16 daniel
  123. * Remove sorting and use pregenerated indexes
  124. * Some work on making things compile
  125. Revision 1.3.2.4 2003/08/29 17:29:00 peter
  126. * next batch of updates
  127. Revision 1.3.2.3 2003/08/29 09:41:25 daniel
  128. * Further mkx86reg development
  129. Revision 1.3.2.2 2003/08/28 18:35:08 peter
  130. * tregister changed to cardinal
  131. Revision 1.3.2.1 2003/08/27 19:55:54 peter
  132. * first tregister patch
  133. Revision 1.3 2003/08/18 11:49:47 daniel
  134. * Made ATT asm writer work with -sr
  135. Revision 1.2 2003/07/06 15:31:21 daniel
  136. * Fixed register allocator. *Lots* of fixes.
  137. Revision 1.1 2003/05/22 21:33:08 peter
  138. * i386 att instruction table moved to separate unit
  139. }