PageRenderTime 40ms CodeModel.GetById 20ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/compiler/x86/itx86int.pas

https://github.com/slibre/freepascal
Pascal | 99 lines | 51 code | 18 blank | 30 comment | 5 complexity | 957f759519bf312120d50bb04301c3da MD5 | raw file
Possible License(s): LGPL-2.0, LGPL-2.1, LGPL-3.0
 1{
 2    Copyright (c) 1998-2002 by Florian Klaempfl
 3
 4    This unit contains the i386 AT&T instruction tables
 5
 6    This program is free software; you can redistribute it and/or modify
 7    it under the terms of the GNU General Public License as published by
 8    the Free Software Foundation; either version 2 of the License, or
 9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
20 ****************************************************************************
21}
22unit itx86int;
23
24{$i fpcdefs.inc}
25
26interface
27
28    uses
29      cgbase;
30
31    function masm_regnum_search(const s:string):Tregister;
32    function masm_regname(r:Tregister):string;
33
34
35implementation
36
37    uses
38      cutils,verbose,
39      cpubase;
40
41    const
42    {$ifdef x86_64}
43      int_regname_table : array[tregisterindex] of string[7] = (
44        {$i r8664int.inc}
45      );
46
47      int_regname_index : array[tregisterindex] of tregisterindex = (
48        {$i r8664iri.inc}
49      );
50    {$else x86_64}
51      int_regname_table : array[tregisterindex] of string[7] = (
52        {$i r386int.inc}
53      );
54
55      int_regname_index : array[tregisterindex] of tregisterindex = (
56        {$i r386iri.inc}
57      );
58    {$endif x86_64}
59
60
61    function findreg_by_intname(const s:string):integer;
62      var
63        l,r,m: integer;
64      begin
65        {Binary search.}
66        l := 0;
67        r := high(tregisterindex) + 1;
68        while l < r do
69          begin
70            m := (l + r) div 2;
71            if int_regname_table[int_regname_index[m]] < s then l := m + 1
72            else r := m;
73          end;
74
75        if int_regname_table[int_regname_index[r]]=s then
76          findreg_by_intname:=int_regname_index[r]
77        else
78          findreg_by_intname:=0;
79      end;
80
81
82    function masm_regnum_search(const s:string):Tregister;
83      begin
84        result:=regnumber_table[findreg_by_intname(s)];
85      end;
86
87
88    function masm_regname(r:Tregister):string;
89      var
90        p : tregisterindex;
91      begin
92        p:=findreg_by_number(r);
93        if p<>0 then
94          result:=int_regname_table[p]
95        else
96          result:=generic_regname(r);
97      end;
98
99end.