{ Copyright (C) 2022 Loongson Technology Corporation Limited. Convert loongarchreg.dat to a .inc file for usage with the Free pascal compiler See the file COPYING.FPC, included in this distribution, for details about the copyright. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. **********************************************************************} {$mode objfpc} program mkloongarchreg; const Version = '1.0'; max_regcount = 512; var nr_regs : word; srcfile : text; names,abinames,stdnames : array[0..max_regcount] of string; regtypes,subtypes,values,stabs,dwarf,std_regname_index,regnumber_index : array[0..max_regcount] of word; numbers : array[0..max_regcount] of longint; procedure bug(errormsg : string); begin writeln(errormsg); close(srcfile); halt; end; function str2word(s : string) : word; var v,errcode : integer; begin val(s,v,errcode); if (errcode<>0) or (v>65535) or (v<0) then str2word:=0 else str2word:=word(v); end; procedure readdatfile; var i,last,idx : longint; s,subs : string; begin assign(srcfile, '../loongarch64/loongarchreg.dat'); reset(srcfile); nr_regs:=0; while not(eof(srcfile)) do begin readln(srcfile,s); if (s='') or (s[1]=';') then continue; { ,,,,,,, } last:=length(s)+1; idx:=1; for i:=length(s) downto 0 do begin if (i=0) then begin if (idx<>8) then bug('Incomplete tables'); names[nr_regs]:=copy(s,1,last-1); continue; end; if (s[i]<>',') then continue; subs:=copy(s,i+1,last-i-1); case (idx) of 1: dwarf[nr_regs]:=str2word(subs); 2: stabs[nr_regs]:=str2word(subs); 3: stdnames[nr_regs]:=subs; 4: abinames[nr_regs]:=subs; 5: values[nr_regs]:=str2word(subs); 6: subtypes[nr_regs]:=str2word(subs); 7: regtypes[nr_regs]:=str2word(subs); 8: bug('Overflow tables'); end; idx:=idx+1; last:=i; end; nr_regs:=nr_regs+1; end; end; type SWAP_FUNC=procedure (i,j : longint; p : pointer); CMPR_FUNC=function (i,j : longint; p :pointer) : boolean; procedure qsort(l,r : longint; p : pointer; s : SWAP_FUNC; c : CMPR_FUNC); var i,j : longint; begin if l>=r then exit; i:=l; j:=r; while i