소스 검색

m68k: improve getreferencestring function a bit

git-svn-id: trunk@35634 -
Károly Balogh 8 년 전
부모
커밋
a405b5a150
1개의 변경된 파일53개의 추가작업 그리고 47개의 파일을 삭제
  1. 53 47
      compiler/m68k/ag68kgas.pas

+ 53 - 47
compiler/m68k/ag68kgas.pas

@@ -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
-                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
+            case direction of
+              dir_none:
                 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
+                  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;
+              dir_inc:
                 begin
-                  s:=s+'('+basestr+')'
-                end
-                  else if (index<>NR_NO) and (base<>NR_NO) and (direction=dir_none) then
+                  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 (scalefactor = 1) or (scalefactor = 0) then
-                    s:=s+'('+basestr+','+indexstr+'.l)'
-                  else
-                    s:=s+'('+basestr+','+indexstr+'.l*'+tostr(scalefactor)+')';
+                  if (base=NR_NO) or (index<>NR_NO) or not (scalefactor in [0,1]) then
+                    internalerror(2017011302);
+                  s:=s+'-('+basestr+')';
                 end;
-          end;
-         getreferencestring:=s;
+            end;
+        end;
       end;