m68k: improve getreferencestring function a bit

git-svn-id: trunk@35634 -
This commit is contained in:
Károly Balogh 2017-03-20 23:48:28 +00:00
parent 44c5fe99c9
commit a405b5a150

View File

@ -104,60 +104,66 @@ interface
function getreferencestring(var ref : treference) : string;
var
s,basestr,indexstr : string;
s: string absolute getreferencestring; { shortcut name to result }
basestr, indexstr : string;
begin
s:='';
with ref do
begin
basestr:=gas_regname(base);
indexstr:=gas_regname(index);
if assigned(symbol) then
s:=s+symbol.name;
s:='';
with ref do
begin
basestr:=gas_regname(base);
indexstr:=gas_regname(index);
if offset<0 then s:=s+tostr(offset)
else if (offset>0) then
begin
if (symbol=nil) then s:=tostr(offset)
else s:=s+'+'+tostr(offset);
end
else if (index=NR_NO) and (base=NR_NO) and not assigned(symbol) then
s:=s+'0';
if assigned(symbol) then
begin
s:=s+symbol.name;
if (offset <> 0) then
s:=s+tostr_with_plus(offset);
end
else
if (offset <> 0) or ((index=NR_NO) and (base=NR_NO)) then
s:=s+tostr(offset);
if (index<>NR_NO) and (base=NR_NO) and (direction=dir_none) then
case direction of
dir_none:
begin
if (scalefactor = 1) or (scalefactor = 0) then
s:=s+'('+indexstr+'.l)'
else
s:=s+'('+indexstr+'.l*'+tostr(scalefactor)+')'
end
else if (index=NR_NO) and (base<>NR_NO) and (direction=dir_inc) then
begin
if (scalefactor = 1) or (scalefactor = 0) then
s:=s+'('+basestr+')+'
else
InternalError(10002);
end
else if (index=NR_NO) and (base<>NR_NO) and (direction=dir_dec) then
begin
if (scalefactor = 1) or (scalefactor = 0) then
s:=s+'-('+basestr+')'
else
InternalError(10003);
end
else if (index=NR_NO) and (base<>NR_NO) and (direction=dir_none) then
begin
s:=s+'('+basestr+')'
end
else if (index<>NR_NO) and (base<>NR_NO) and (direction=dir_none) then
begin
if (scalefactor = 1) or (scalefactor = 0) then
s:=s+'('+basestr+','+indexstr+'.l)'
else
s:=s+'('+basestr+','+indexstr+'.l*'+tostr(scalefactor)+')';
if (base<>NR_NO) and (index=NR_NO) then
begin
if not (scalefactor in [0,1]) then
internalerror(2017011303);
s:=s+'('+basestr+')';
exit;
end;
if (base<>NR_NO) and (index<>NR_NO) then
begin
if scalefactor in [0,1] then
s:=s+'('+basestr+','+indexstr+'.l)'
else
s:=s+'('+basestr+','+indexstr+'.l*'+tostr(scalefactor)+')';
exit;
end;
if (base=NR_NO) and (index<>NR_NO) then
begin
if scalefactor in [0,1] then
s:=s+'('+indexstr+'.l)'
else
s:=s+'('+indexstr+'.l*'+tostr(scalefactor)+')';
exit;
end;
end;
end;
getreferencestring:=s;
dir_inc:
begin
if (base=NR_NO) or (index<>NR_NO) or not (scalefactor in [0,1]) then
internalerror(2017011301);
s:=s+'('+basestr+')+';
end;
dir_dec:
begin
if (base=NR_NO) or (index<>NR_NO) or not (scalefactor in [0,1]) then
internalerror(2017011302);
s:=s+'-('+basestr+')';
end;
end;
end;
end;