Browse Source

* moved x86-specific tpointerdef functionality to architecture-specific
descendants

git-svn-id: trunk@27397 -

Jonas Maebe 11 years ago
parent
commit
338c064beb

+ 2 - 2
compiler/defcmp.pas

@@ -169,7 +169,7 @@ implementation
 
     uses
       verbose,systems,constexp,
-      symtable,symsym,
+      symtable,symsym,symcpu,
       defutil,symutil;
 
 
@@ -1302,7 +1302,7 @@ implementation
                    begin
 {$ifdef x86}
                      { check for far pointers }
-                     if (tpointerdef(def_from).x86pointertyp<>tpointerdef(def_to).x86pointertyp) then
+                     if (tcpupointerdef(def_from).x86pointertyp<>tcpupointerdef(def_to).x86pointertyp) then
                        begin
                          if fromtreetype=niln then
                            eq:=te_equal

+ 4 - 4
compiler/defutil.pas

@@ -342,7 +342,7 @@ interface
 implementation
 
     uses
-       verbose,cutils;
+       verbose,cutils,symcpu;
 
     { returns true, if def uses FPU }
     function is_fpu(def : tdef) : boolean;
@@ -1215,7 +1215,7 @@ implementation
             begin
 {$ifdef x86}
               if (def.typ=pointerdef) and
-                 (tpointerdef(def).x86pointertyp in [x86pt_far,x86pt_huge]) then
+                 (tcpupointerdef(def).x86pointertyp in [x86pt_far,x86pt_huge]) then
                 begin
                   {$if defined(i8086)}
                     result := OS_32;
@@ -1437,13 +1437,13 @@ implementation
     { true if p is a far pointer def }
     function is_farpointer(p : tdef) : boolean;
       begin
-        result:=(p.typ=pointerdef) and (tpointerdef(p).x86pointertyp=x86pt_far);
+        result:=(p.typ=pointerdef) and (tcpupointerdef(p).x86pointertyp=x86pt_far);
       end;
 
     { true if p is a huge pointer def }
     function is_hugepointer(p : tdef) : boolean;
       begin
-        result:=(p.typ=pointerdef) and (tpointerdef(p).x86pointertyp=x86pt_huge);
+        result:=(p.typ=pointerdef) and (tcpupointerdef(p).x86pointertyp=x86pt_huge);
       end;
 {$endif i8086}
 

+ 2 - 2
compiler/i386/n386mem.pas

@@ -47,7 +47,7 @@ implementation
     uses
       systems,
       cutils,verbose,
-      symconst,symdef,paramgr,
+      symconst,symdef,symcpu,paramgr,
       aasmtai,aasmdata,
       nld,ncon,nadd,
       cgutils,cgobj;
@@ -61,7 +61,7 @@ implementation
         if not(nf_typedaddr in flags) then
           resultdef:=voidnearfspointertype
         else
-          resultdef:=cpointerdef.createx86(left.resultdef,x86pt_near_fs);
+          resultdef:=tcpupointerdefclass(cpointerdef).createx86(left.resultdef,x86pt_near_fs);
       end;
 
 

+ 2 - 2
compiler/i386/symcpu.pas

@@ -26,7 +26,7 @@ unit symcpu;
 interface
 
 uses
-  symdef,symsym,symi86;
+  symdef,symsym,symx86,symi86;
 
 type
   { defs }
@@ -54,7 +54,7 @@ type
   end;
   tcpuerrordefclass = class of tcpuerrordef;
 
-  tcpupointerdef = class(tpointerdef)
+  tcpupointerdef = class(tx86pointerdef)
   end;
   tcpupointerdefclass = class of tcpupointerdef;
 

+ 3 - 3
compiler/i8086/n8086con.pas

@@ -41,7 +41,7 @@ implementation
 
     uses
       systems,globals,
-      symconst,symdef,
+      symconst,symdef,symcpu,
       defutil,
       cpubase,
       cga,cgx86,cgobj,cgbase,cgutils;
@@ -54,7 +54,7 @@ implementation
     constructor ti8086pointerconstnode.create(v: TConstPtrUInt; def: tdef);
       begin
         { truncate near pointers }
-        if (def.typ<>pointerdef) or not (tpointerdef(def).x86pointertyp in [x86pt_far,x86pt_huge]) then
+        if (def.typ<>pointerdef) or not (tcpupointerdef(def).x86pointertyp in [x86pt_far,x86pt_huge]) then
           v := Word(v);
         inherited create(v, def);
       end;
@@ -63,7 +63,7 @@ implementation
     procedure ti8086pointerconstnode.pass_generate_code;
       begin
         { far pointer? }
-        if (typedef.typ=pointerdef) and (tpointerdef(typedef).x86pointertyp in [x86pt_far,x86pt_huge]) then
+        if (typedef.typ=pointerdef) and (tcpupointerdef(typedef).x86pointertyp in [x86pt_far,x86pt_huge]) then
           begin
             location_reset(location,LOC_CONSTANT,OS_32);
             location.value:=longint(value);

+ 4 - 4
compiler/i8086/n8086mem.pas

@@ -46,7 +46,7 @@ implementation
     uses
       systems,globals,
       cutils,verbose,
-      symbase,symconst,symdef,symtable,symtype,symsym,
+      symbase,symconst,symdef,symtable,symtype,symsym,symcpu,
       parabase,paramgr,
       aasmtai,aasmdata,
       nld,ncon,nadd,
@@ -63,7 +63,7 @@ implementation
         if not(nf_typedaddr in flags) then
           resultdef:=voidfarpointertype
         else
-          resultdef:=cpointerdef.createx86(left.resultdef,x86pt_far);
+          resultdef:=tcpupointerdefclass(cpointerdef).createx86(left.resultdef,x86pt_far);
       end;
 
 
@@ -95,7 +95,7 @@ implementation
         st : tsymtable;
         tmpref: treference;
       begin
-        if tpointerdef(left.resultdef).x86pointertyp in [x86pt_far,x86pt_huge] then
+        if tcpupointerdef(left.resultdef).x86pointertyp in [x86pt_far,x86pt_huge] then
           begin
             secondpass(left);
             { assume natural alignment, except for packed records }
@@ -137,7 +137,7 @@ implementation
                (cs_checkpointer in current_settings.localswitches) and
                not(cs_compilesystem in current_settings.moduleswitches) and
    {$ifdef x86}
-               (tpointerdef(left.resultdef).x86pointertyp = default_x86_data_pointer_type) and
+               (tcpupointerdef(left.resultdef).x86pointertyp = tcpupointerdefclass(cpointerdef).default_x86_data_pointer_type) and
    {$endif x86}
                not(nf_no_checkpointer in flags) and
                { can be NR_NO in case of LOC_CONSTANT }

+ 23 - 2
compiler/i8086/symcpu.pas

@@ -27,7 +27,7 @@ interface
 
 uses
   globtype,
-  symtype,symdef,symsym,symi86;
+  symconst,symtype,symdef,symsym,symx86,symi86;
 
 type
   { defs }
@@ -55,7 +55,8 @@ type
   end;
   tcpuerrordefclass = class of tcpuerrordef;
 
-  tcpupointerdef = class(tpointerdef)
+  tcpupointerdef = class(tx86pointerdef)
+    class function default_x86_data_pointer_type: tx86pointertyp; override;
   end;
   tcpupointerdefclass = class of tcpupointerdef;
 
@@ -172,6 +173,26 @@ type
 
 implementation
 
+  uses
+    globals, cpuinfo;
+
+{****************************************************************************
+                             tcpupointerdef
+****************************************************************************}
+
+    class function tcpupointerdef.default_x86_data_pointer_type: tx86pointertyp;
+      begin
+        if current_settings.x86memorymodel in x86_far_data_models then
+          result:=x86pt_far
+        else
+          result:=inherited;
+      end;
+
+
+{****************************************************************************
+                             tcpuabsolutevarsym
+****************************************************************************}
+
   procedure tcpuabsolutevarsym.ppuload_platform(ppufile: tcompilerppufile);
     begin
       inherited;

+ 2 - 2
compiler/ncgmem.pas

@@ -81,7 +81,7 @@ implementation
     uses
       systems,
       cutils,cclasses,verbose,globals,constexp,
-      symconst,symbase,symtype,symdef,symsym,symtable,defutil,paramgr,
+      symconst,symbase,symtype,symdef,symsym,symcpu,symtable,defutil,paramgr,
       aasmbase,aasmtai,aasmdata,
       procinfo,pass_2,parabase,
       pass_1,nld,ncon,nadd,ncnv,nutils,
@@ -288,7 +288,7 @@ implementation
             (cs_checkpointer in current_settings.localswitches) and
             not(cs_compilesystem in current_settings.moduleswitches) and
 {$ifdef x86}
-            (tpointerdef(left.resultdef).x86pointertyp = default_x86_data_pointer_type) and
+            (tcpupointerdef(left.resultdef).x86pointertyp = tcpupointerdefclass(cpointerdef).default_x86_data_pointer_type) and
 {$endif x86}
             not(nf_no_checkpointer in flags) and
             { can be NR_NO in case of LOC_CONSTANT }

+ 10 - 10
compiler/pdecl.pas

@@ -56,7 +56,7 @@ implementation
        globals,tokens,verbose,widestr,constexp,
        systems,aasmdata,fmodule,
        { symtable }
-       symconst,symbase,symtype,symtable,symcreat,defutil,
+       symconst,symbase,symtype,symcpu,symtable,symcreat,defutil,
        { pass 1 }
        htypechk,ninl,ncon,nobj,ngenutil,
        { parser }
@@ -722,9 +722,9 @@ implementation
                     if try_to_consume(_FAR) then
                      begin
   {$if defined(i8086)}
-                       tpointerdef(hdef).x86pointertyp:=x86pt_far;
+                       tcpupointerdef(hdef).x86pointertyp:=x86pt_far;
   {$elseif defined(i386)}
-                       tpointerdef(hdef).x86pointertyp:=x86pt_near_fs;
+                       tcpupointerdef(hdef).x86pointertyp:=x86pt_near_fs;
   {$elseif defined(x86_64)}
                        { for compatibility with previous versions of fpc,
                          far pointer = regular pointer on x86_64 }
@@ -739,18 +739,18 @@ implementation
                            begin
                              segment_register:=get_stringconst;
                              case UpCase(segment_register) of
-                               'CS': tpointerdef(hdef).x86pointertyp:=x86pt_near_cs;
-                               'DS': tpointerdef(hdef).x86pointertyp:=x86pt_near_ds;
-                               'SS': tpointerdef(hdef).x86pointertyp:=x86pt_near_ss;
-                               'ES': tpointerdef(hdef).x86pointertyp:=x86pt_near_es;
-                               'FS': tpointerdef(hdef).x86pointertyp:=x86pt_near_fs;
-                               'GS': tpointerdef(hdef).x86pointertyp:=x86pt_near_gs;
+                               'CS': tcpupointerdef(hdef).x86pointertyp:=x86pt_near_cs;
+                               'DS': tcpupointerdef(hdef).x86pointertyp:=x86pt_near_ds;
+                               'SS': tcpupointerdef(hdef).x86pointertyp:=x86pt_near_ss;
+                               'ES': tcpupointerdef(hdef).x86pointertyp:=x86pt_near_es;
+                               'FS': tcpupointerdef(hdef).x86pointertyp:=x86pt_near_fs;
+                               'GS': tcpupointerdef(hdef).x86pointertyp:=x86pt_near_gs;
                                else
                                  Message(asmr_e_invalid_register);
                              end;
                            end
                          else
-                           tpointerdef(hdef).x86pointertyp:=x86pt_near;
+                           tcpupointerdef(hdef).x86pointertyp:=x86pt_near;
                          consume(_SEMICOLON);
                        end;
 {$else x86}

+ 16 - 16
compiler/psystem.pas

@@ -42,7 +42,7 @@ implementation
     uses
       globals,globtype,verbose,constexp,cpuinfo,
       systems,
-      symconst,symtype,symsym,symdef,symtable,
+      symconst,symtype,symsym,symdef,symcpu,symtable,
       aasmtai,aasmdata,aasmcpu,
       ncgutil,ncgrtti,fmodule,
       node,nbas,nflw,nset,ncon,ncnv,nld,nmem,ncal,nmat,nadd,ninl,nopt
@@ -284,26 +284,26 @@ implementation
         charpointertype:=cpointerdef.create(cansichartype);
         widecharpointertype:=cpointerdef.create(cwidechartype);
 {$ifdef i8086}
-        parentfpvoidpointertype:=cpointerdef.createx86(voidtype,x86pt_near);
+        parentfpvoidpointertype:=tcpupointerdefclass(cpointerdef).createx86(voidtype,x86pt_near);
 {$else i8086}
         parentfpvoidpointertype:=cpointerdef.create(voidtype);
 {$endif i8086}
 {$ifdef x86}
-        voidnearpointertype:=cpointerdef.createx86(voidtype,x86pt_near);
-        voidnearcspointertype:=cpointerdef.createx86(voidtype,x86pt_near_cs);
-        voidneardspointertype:=cpointerdef.createx86(voidtype,x86pt_near_ds);
-        voidnearsspointertype:=cpointerdef.createx86(voidtype,x86pt_near_ss);
-        voidnearespointertype:=cpointerdef.createx86(voidtype,x86pt_near_es);
-        voidnearfspointertype:=cpointerdef.createx86(voidtype,x86pt_near_fs);
-        voidneargspointertype:=cpointerdef.createx86(voidtype,x86pt_near_gs);
+        voidnearpointertype:=tcpupointerdefclass(cpointerdef).createx86(voidtype,x86pt_near);
+        voidnearcspointertype:=tcpupointerdefclass(cpointerdef).createx86(voidtype,x86pt_near_cs);
+        voidneardspointertype:=tcpupointerdefclass(cpointerdef).createx86(voidtype,x86pt_near_ds);
+        voidnearsspointertype:=tcpupointerdefclass(cpointerdef).createx86(voidtype,x86pt_near_ss);
+        voidnearespointertype:=tcpupointerdefclass(cpointerdef).createx86(voidtype,x86pt_near_es);
+        voidnearfspointertype:=tcpupointerdefclass(cpointerdef).createx86(voidtype,x86pt_near_fs);
+        voidneargspointertype:=tcpupointerdefclass(cpointerdef).createx86(voidtype,x86pt_near_gs);
   {$ifdef i8086}
-        voidfarpointertype:=cpointerdef.createx86(voidtype,x86pt_far);
-        voidhugepointertype:=cpointerdef.createx86(voidtype,x86pt_huge);
-        charnearpointertype:=cpointerdef.createx86(cansichartype,x86pt_near);
-        charfarpointertype:=cpointerdef.createx86(cansichartype,x86pt_far);
-        bytefarpointertype:=cpointerdef.createx86(u8inttype,x86pt_far);
-        wordfarpointertype:=cpointerdef.createx86(u16inttype,x86pt_far);
-        longintfarpointertype:=cpointerdef.createx86(s32inttype,x86pt_far);
+        voidfarpointertype:=tcpupointerdefclass(cpointerdef).createx86(voidtype,x86pt_far);
+        voidhugepointertype:=tcpupointerdefclass(cpointerdef).createx86(voidtype,x86pt_huge);
+        charnearpointertype:=tcpupointerdefclass(cpointerdef).createx86(cansichartype,x86pt_near);
+        charfarpointertype:=tcpupointerdefclass(cpointerdef).createx86(cansichartype,x86pt_far);
+        bytefarpointertype:=tcpupointerdefclass(cpointerdef).createx86(u8inttype,x86pt_far);
+        wordfarpointertype:=tcpupointerdefclass(cpointerdef).createx86(u16inttype,x86pt_far);
+        longintfarpointertype:=tcpupointerdefclass(cpointerdef).createx86(s32inttype,x86pt_far);
   {$endif i8086}
 {$endif x86}
         set_default_ptr_types;

+ 1 - 77
compiler/symdef.pas

@@ -218,14 +218,8 @@ interface
        { tpointerdef }
 
        tpointerdef = class(tabstractpointerdef)
-{$ifdef x86}
-          x86pointertyp : tx86pointertyp;
-{$endif x86}
           has_pointer_math : boolean;
           constructor create(def:tdef);virtual;
-{$ifdef x86}
-          constructor createx86(def:tdef;x86typ:tx86pointertyp);virtual;
-{$endif x86}
           function size:asizeint;override;
           function getcopy:tstoreddef;override;
           constructor ppuload(ppufile:tcompilerppufile);
@@ -1179,10 +1173,6 @@ interface
     function getansistringdef:tstringdef;
     function getparaencoding(def:tdef):tstringencoding; inline;
 
-{$ifdef x86}
-    function default_x86_data_pointer_type: tx86pointertyp;
-{$endif x86}
-
 implementation
 
     uses
@@ -3120,40 +3110,19 @@ implementation
     constructor tpointerdef.create(def:tdef);
       begin
         inherited create(pointerdef,def);
-{$ifdef x86}
-        x86pointertyp := default_x86_data_pointer_type;
-{$endif x86}
-        has_pointer_math:=cs_pointermath in current_settings.localswitches;
-      end;
-
-
-{$ifdef x86}
-    constructor tpointerdef.createx86(def: tdef; x86typ: tx86pointertyp);
-      begin
-        inherited create(pointerdef,def);
-        x86pointertyp := x86typ;
         has_pointer_math:=cs_pointermath in current_settings.localswitches;
       end;
-{$endif x86}
 
 
     function tpointerdef.size: asizeint;
       begin
-{$ifdef x86}
-        if x86pointertyp in [x86pt_far,x86pt_huge] then
-          result:=sizeof(pint)+2
-        else
-{$endif x86}
-          result:=sizeof(pint);
+        result:=sizeof(pint);
       end;
 
 
     constructor tpointerdef.ppuload(ppufile:tcompilerppufile);
       begin
          inherited ppuload(pointerdef,ppufile);
-{$ifdef x86}
-         x86pointertyp:=tx86pointertyp(ppufile.getbyte);
-{$endif x86}
          has_pointer_math:=(ppufile.getbyte<>0);
          ppuload_platform(ppufile);
       end;
@@ -3168,9 +3137,6 @@ implementation
           result:=cpointerdef.create(tforwarddef(pointeddef).getcopy)
         else
           result:=cpointerdef.create(pointeddef);
-{$ifdef x86}
-        tpointerdef(result).x86pointertyp:=x86pointertyp;
-{$endif x86}
         tpointerdef(result).has_pointer_math:=has_pointer_math;
         tpointerdef(result).savesize:=savesize;
       end;
@@ -3179,9 +3145,6 @@ implementation
     procedure tpointerdef.ppuwrite(ppufile:tcompilerppufile);
       begin
          inherited ppuwrite(ppufile);
-{$ifdef x86}
-         ppufile.putbyte(byte(x86pointertyp));
-{$endif x86}
          ppufile.putbyte(byte(has_pointer_math));
          writeentry(ppufile,ibpointerdef);
       end;
@@ -3199,33 +3162,6 @@ implementation
           GetTypeName:='^'+pointeddef.typename
         else
           GetTypeName:='^'+pointeddef.typesym.realname;
-{$ifdef x86}
-        if x86pointertyp<>default_x86_data_pointer_type then
-          begin
-            case x86pointertyp of
-              x86pt_near:
-                GetTypeName:=Result+';near';
-              x86pt_near_cs:
-                GetTypeName:=Result+';near ''CS''';
-              x86pt_near_ds:
-                GetTypeName:=Result+';near ''DS''';
-              x86pt_near_ss:
-                GetTypeName:=Result+';near ''SS''';
-              x86pt_near_es:
-                GetTypeName:=Result+';near ''ES''';
-              x86pt_near_fs:
-                GetTypeName:=Result+';near ''FS''';
-              x86pt_near_gs:
-                GetTypeName:=Result+';near ''GS''';
-              x86pt_far:
-                GetTypeName:=Result+';far';
-              x86pt_huge:
-                GetTypeName:=Result+';huge';
-              else
-                internalerror(2013050301);
-            end;
-          end;
-{$endif x86}
       end;
 
 
@@ -7506,16 +7442,4 @@ implementation
       end;
 
 
-{$ifdef x86}
-    function default_x86_data_pointer_type: tx86pointertyp;
-      begin
-{$ifdef i8086}
-        if current_settings.x86memorymodel in x86_far_data_models then
-          result:=x86pt_far
-        else
-{$endif i8086}
-          result:=x86pt_near;
-      end;
-{$endif x86}
-
 end.

+ 2 - 2
compiler/x86/nx86mem.pas

@@ -44,7 +44,7 @@ implementation
       cutils,verbose,
       aasmtai,aasmdata,
       cgutils,cgobj,
-      symconst,symdef;
+      symconst,symdef,symcpu;
 
 {*****************************************************************************
                            TX86DEREFNODE
@@ -53,7 +53,7 @@ implementation
      procedure tx86derefnode.pass_generate_code;
        begin
          inherited pass_generate_code;
-         case tpointerdef(left.resultdef).x86pointertyp of
+         case tcpupointerdef(left.resultdef).x86pointertyp of
            x86pt_near: ;
            x86pt_near_cs: location.reference.segment:=NR_CS;
            x86pt_near_ds: location.reference.segment:=NR_DS;

+ 2 - 2
compiler/x86_64/symcpu.pas

@@ -26,7 +26,7 @@ unit symcpu;
 interface
 
 uses
-  symdef,symsym;
+  symdef,symsym,symx86;
 
 type
   { defs }
@@ -54,7 +54,7 @@ type
   end;
   tcpuerrordefclass = class of tcpuerrordef;
 
-  tcpupointerdef = class(tpointerdef)
+  tcpupointerdef = class(tx86pointerdef)
   end;
   tcpupointerdefclass = class of tcpupointerdef;