瀏覽代碼

* fixed support of nSparcInline

mazen 23 年之前
父節點
當前提交
eca8ef3436
共有 3 個文件被更改,包括 86 次插入60 次删除
  1. 35 2
      compiler/sparc/cgcpu.pas
  2. 8 17
      compiler/sparc/cpunode.pas
  3. 43 41
      compiler/sparc/cpupara.pas

+ 35 - 2
compiler/sparc/cgcpu.pas

@@ -40,6 +40,9 @@ specific processor ABI. It is overriden for each CPU target.
     procedure a_paramaddr_ref(list:TAasmOutput;CONST r:TReference;CONST LocPara:TParaLocation);override;
     procedure a_paramaddr_ref(list:TAasmOutput;CONST r:TReference;CONST LocPara:TParaLocation);override;
     procedure a_call_name(list:TAasmOutput;CONST s:string);override;
     procedure a_call_name(list:TAasmOutput;CONST s:string);override;
     procedure a_call_ref(list:TAasmOutput;CONST ref:TReference);override;
     procedure a_call_ref(list:TAasmOutput;CONST ref:TReference);override;
+    {Branch Instruction}
+    procedure a_jmp_always(List:TAasmOutput;l:TAsmLabel);override;
+    {General purpose instyructions}
     procedure a_op_const_reg(list:TAasmOutput;Op:TOpCG;a:AWord;reg:TRegister);override;
     procedure a_op_const_reg(list:TAasmOutput;Op:TOpCG;a:AWord;reg:TRegister);override;
     procedure a_op_const_ref(list:TAasmOutput;Op:TOpCG;size:TCGSize;a:AWord;CONST ref:TReference);override;
     procedure a_op_const_ref(list:TAasmOutput;Op:TOpCG;size:TCGSize;a:AWord;CONST ref:TReference);override;
     procedure a_op_reg_reg(list:TAasmOutput;Op:TOpCG;size:TCGSize;src, dst:TRegister);override;
     procedure a_op_reg_reg(list:TAasmOutput;Op:TOpCG;size:TCGSize;src, dst:TRegister);override;
@@ -71,6 +74,7 @@ specific processor ABI. It is overriden for each CPU target.
     procedure a_jmp_cond(list:TAasmOutput;cond:TOpCmp;l:tasmlabel);{ override;}
     procedure a_jmp_cond(list:TAasmOutput;cond:TOpCmp;l:tasmlabel);{ override;}
     procedure a_jmp_flags(list:TAasmOutput;CONST f:TResFlags;l:tasmlabel);override;
     procedure a_jmp_flags(list:TAasmOutput;CONST f:TResFlags;l:tasmlabel);override;
     procedure g_flags2reg(list:TAasmOutput;Size:TCgSize;CONST f:tresflags;reg:TRegister);override;
     procedure g_flags2reg(list:TAasmOutput;Size:TCgSize;CONST f:tresflags;reg:TRegister);override;
+    procedure g_overflowCheck(List:TAasmOutput;const p:TNode);override;
     procedure g_stackframe_entry(list:TAasmOutput;localsize:LongInt);override;
     procedure g_stackframe_entry(list:TAasmOutput;localsize:LongInt);override;
     procedure g_restore_frame_pointer(list:TAasmOutput);override;
     procedure g_restore_frame_pointer(list:TAasmOutput);override;
     procedure g_return_from_proc(list:TAasmOutput;parasize:aword);override;
     procedure g_return_from_proc(list:TAasmOutput;parasize:aword);override;
@@ -205,6 +209,11 @@ procedure tcgSPARC.a_call_ref(list:TAasmOutput;CONST ref:TReference);
     list.concat(taicpu.op_ref(A_CALL,ref));
     list.concat(taicpu.op_ref(A_CALL,ref));
     list.concat(taicpu.op_none(A_NOP));
     list.concat(taicpu.op_none(A_NOP));
   END;
   END;
+{********************** branch instructions ********************}
+procedure TCgSPARC.a_jmp_always(List:TAasmOutput;l:TAsmLabel);
+  begin
+    List.Concat(TAiCpu.op_sym(A_BA,S_NO,objectlibrary.newasmsymbol(l.name)));
+  end;
 {********************** load instructions ********************}
 {********************** load instructions ********************}
 procedure tcgSPARC.a_load_const_reg(list:TAasmOutput;size:TCGSize;a:aword;reg:TRegister);
 procedure tcgSPARC.a_load_const_reg(list:TAasmOutput;size:TCGSize;a:aword;reg:TRegister);
   BEGIN
   BEGIN
@@ -803,7 +812,28 @@ procedure tcgSPARC.g_flags2reg(list:TAasmOutput;Size:TCgSize;CONST f:tresflags;r
     THEN
     THEN
       a_load_reg_reg(list,OS_8,OS_8,hreg,reg);
       a_load_reg_reg(list,OS_8,OS_8,hreg,reg);
   END;
   END;
-
+procedure TCgSparc.g_overflowCheck(List:TAasmOutput;const p:TNode);
+  var
+    hl:TAsmLabel;
+  begin
+    if not(cs_check_overflow in aktlocalswitches)
+    then
+      exit;
+    objectlibrary.getlabel(hl);
+    if not((p.resulttype.def.deftype=pointerdef) or
+       ((p.resulttype.def.deftype=orddef) and
+        (torddef(p.resulttype.def).typ in [u64bit,u16bit,u32bit,u8bit,uchar,
+                                         bool8bit,bool16bit,bool32bit])))
+    then
+      begin
+        list.concat(taicpu.op_reg(A_NONE,R_NONE));
+        a_jmp_always(list,hl)
+      end
+    else
+      a_jmp_cond(list,OC_NONE,hl);
+      a_call_name(list,'FPC_OVERFLOW');
+      a_label(list,hl);
+    end;
 { *********** entry/exit code and address loading ************ }
 { *********** entry/exit code and address loading ************ }
 
 
 procedure tcgSPARC.g_stackframe_entry(list:TAasmOutput;LocalSize:LongInt);
 procedure tcgSPARC.g_stackframe_entry(list:TAasmOutput;LocalSize:LongInt);
@@ -1253,7 +1283,10 @@ BEGIN
 END.
 END.
 {
 {
   $Log$
   $Log$
-  Revision 1.25  2002-11-25 17:43:28  peter
+  Revision 1.26  2002-11-25 19:21:49  mazen
+  * fixed support of nSparcInline
+
+  Revision 1.25  2002/11/25 17:43:28  peter
     * splitted defbase in defutil,symutil,defcmp
     * splitted defbase in defutil,symutil,defcmp
     * merged isconvertable and is_equal into compare_defs(_ext)
     * merged isconvertable and is_equal into compare_defs(_ext)
     * made operator search faster by walking the list only once
     * made operator search faster by walking the list only once

+ 8 - 17
compiler/sparc/cpunode.pas

@@ -1,13 +1,4 @@
-{*****************************************************************************}
-{ File                   : cpunode.pas                                        }
-{ Author                 : Mazen NEIFER                                       }
-{ Project                : Free Pascal Compiler (FPC)                         }
-{ Creation date          : 2002\26\26                                         }
-{ Last modification date : 2002\07\14                                         }
-{ Licence                : GPL                                                }
-{ Bug report             : [email protected]                        }
-{*****************************************************************************}
-{
+{******************************************************************************
     $Id$
     $Id$
     Copyright (c) 2000 by Florian Klaempfl
     Copyright (c) 2000 by Florian Klaempfl
 
 
@@ -27,18 +18,18 @@
     along with this program; if not, write to the Free Software
     along with this program; if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
 
- ****************************************************************************}
-UNIT cpunode;
+ *****************************************************************************}
+unit CpuNode;
 {$INCLUDE fpcdefs.inc}
 {$INCLUDE fpcdefs.inc}
-INTERFACE
+interface
 {This unit is used to define the specific CPU implementations. All needed
 {This unit is used to define the specific CPU implementations. All needed
 actions are included in the INITALIZATION part of these units. This explains
 actions are included in the INITALIZATION part of these units. This explains
 the behaviour of such a unit having just a USES clause!}
 the behaviour of such a unit having just a USES clause!}
-IMPLEMENTATION
-USES
+implementation
+uses
   ncgbas,ncgflw,ncgcnv,ncgld,ncgmem,ncgcon,{ncgset,}
   ncgbas,ncgflw,ncgcnv,ncgld,ncgmem,ncgcon,{ncgset,}
   naddcpu,ncpucall,{n386con,n386cnv,n386flw,n386mat,n386mem,}
   naddcpu,ncpucall,{n386con,n386cnv,n386flw,n386mat,n386mem,}
-  {n386set,n386inl,n386opt,}ncpucnv,
+  {n386set,}ncpuinline,{n386opt,}ncpucnv,
   { this not really a node }
   { this not really a node }
   {nSPARCobj,}rgcpu;
   {nSPARCobj,}rgcpu;
-END.
+end.

+ 43 - 41
compiler/sparc/cpupara.pas

@@ -40,7 +40,6 @@ type
 implementation
 implementation
 uses
 uses
   verbose,
   verbose,
-  globtype,
   cpuinfo,cginfo,cgbase,
   cpuinfo,cginfo,cgbase,
   defutil;
   defutil;
 function TSparcParaManager.GetIntParaLoc(nr:longint):TParaLocation;
 function TSparcParaManager.GetIntParaLoc(nr:longint):TParaLocation;
@@ -123,15 +122,14 @@ push_addr_param for the def is true}
 procedure TSparcParaManager.create_param_loc_info(p:tabstractprocdef);
 procedure TSparcParaManager.create_param_loc_info(p:tabstractprocdef);
   var
   var
     nextintreg,nextfloatreg:tregister;
     nextintreg,nextfloatreg:tregister;
-    stack_offset : aword;
-    hp : tparaitem;
-    loc : tloc;
-    is_64bit: boolean;
+    stack_offset:aword;
+    hp:tparaitem;
+    loc:tloc;
+    is_64bit:boolean;
   begin
   begin
-    nextintreg:=R_i0;
+    nextintreg:=R_O0;
     nextfloatreg:=R_F0;
     nextfloatreg:=R_F0;
     stack_offset:=92;
     stack_offset:=92;
-WriteLn('***********************************************');
     hp:=TParaItem(p.para.First);
     hp:=TParaItem(p.para.First);
     while assigned(hp) do
     while assigned(hp) do
       begin
       begin
@@ -147,7 +145,6 @@ WriteLn('***********************************************');
               if NextIntReg<=TRegister(ord(R_i5)-ord(is_64bit))
               if NextIntReg<=TRegister(ord(R_i5)-ord(is_64bit))
               then
               then
                 begin
                 begin
-                  WriteLn('Allocating ',std_reg2str[NextIntReg]);
                   hp.paraloc.loc:=LOC_REGISTER;
                   hp.paraloc.loc:=LOC_REGISTER;
                   hp.paraloc.registerlow:=NextIntReg;
                   hp.paraloc.registerlow:=NextIntReg;
                   inc(NextIntReg);
                   inc(NextIntReg);
@@ -173,36 +170,39 @@ WriteLn('***********************************************');
             end;
             end;
           LOC_FPUREGISTER:
           LOC_FPUREGISTER:
             begin
             begin
-                      if hp.paratyp in [vs_var,vs_out] then
-                        begin
-                            if nextintreg<=R_O5 then
-                             begin
-                                hp.paraloc.size:=OS_ADDR;
-                                hp.paraloc.loc:=LOC_REGISTER;
-                                hp.paraloc.register:=nextintreg;
-                                inc(nextintreg);
-                             end
-                           else
-                              begin
-                                 {!!!!!!!}
-                                 hp.paraloc.size:=def_cgsize(hp.paratype.def);
-                                 internalerror(2002071006);
-                             end;
-                        end
-                      else if nextfloatreg<=R_F10 then
-                        begin
-                           hp.paraloc.size:=def_cgsize(hp.paratype.def);
-                           hp.paraloc.loc:=LOC_FPUREGISTER;
-                           hp.paraloc.register:=nextfloatreg;
-                           inc(nextfloatreg);
-                        end
-                      else
-                         begin
-                            {!!!!!!!}
-                             hp.paraloc.size:=def_cgsize(hp.paratype.def);
-                            internalerror(2002071004);
-                        end;
-                   end;
+              if hp.paratyp in [vs_var,vs_out]
+              then
+                begin
+                  if NextIntReg<=R_O5
+                  then
+                    begin
+                      hp.paraloc.size:=OS_ADDR;
+                      hp.paraloc.loc:=LOC_REGISTER;
+                      hp.paraloc.register:=nextintreg;
+                      inc(nextintreg);
+                    end
+                  else
+                    begin
+                      {!!!!!!!}
+                      WriteLn('NextIntReg=',std_reg2str[NextIntReg]);
+                      hp.paraloc.size:=def_cgsize(hp.paratype.def);
+                      internalerror(2002071006);
+                    end;
+                end
+              else if nextfloatreg<=R_F10 then
+                begin
+                  hp.paraloc.size:=def_cgsize(hp.paratype.def);
+                  hp.paraloc.loc:=LOC_FPUREGISTER;
+                  hp.paraloc.register:=nextfloatreg;
+                  inc(nextfloatreg);
+                end
+              else
+                begin
+                  {!!!!!!!}
+                  hp.paraloc.size:=def_cgsize(hp.paratype.def);
+                  internalerror(2002071004);
+                end;
+            end;
                  LOC_REFERENCE:
                  LOC_REFERENCE:
                    begin
                    begin
                       hp.paraloc.size:=OS_ADDR;
                       hp.paraloc.size:=OS_ADDR;
@@ -242,9 +242,8 @@ function tSparcParaManager.GetFuncRetParaLoc(p:TAbstractProcDef):TParaLocation;
       case p.rettype.def.deftype of
       case p.rettype.def.deftype of
         orddef,enumdef:
         orddef,enumdef:
           begin
           begin
-            WriteLn('Allocating i0 as return register');
             loc:=LOC_REGISTER;
             loc:=LOC_REGISTER;
-            register:=R_I0;
+            register:=return_result_reg;
             size:=def_cgsize(p.rettype.def);
             size:=def_cgsize(p.rettype.def);
             if size in [OS_S64,OS_64]
             if size in [OS_S64,OS_64]
             then
             then
@@ -283,7 +282,10 @@ begin
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.11  2002-11-25 17:43:28  peter
+  Revision 1.12  2002-11-25 19:21:49  mazen
+  * fixed support of nSparcInline
+
+  Revision 1.11  2002/11/25 17:43:28  peter
     * splitted defbase in defutil,symutil,defcmp
     * splitted defbase in defutil,symutil,defcmp
     * merged isconvertable and is_equal into compare_defs(_ext)
     * merged isconvertable and is_equal into compare_defs(_ext)
     * made operator search faster by walking the list only once
     * made operator search faster by walking the list only once