Pārlūkot izejas kodu

* synchronized with trunk

git-svn-id: branches/z80@44694 -
nickysn 5 gadi atpakaļ
vecāks
revīzija
116f344050

+ 2 - 0
compiler/hlcgobj.pas

@@ -4354,7 +4354,9 @@ implementation
                    LOC_FLAGS :
                      begin
                        a_jmp_flags(list,p.location.resflags,truelabel);
+{$ifndef xtensa}
                        a_reg_dealloc(list,NR_DEFAULTFLAGS);
+{$endif xtensa}
                        a_jmp_always(list,falselabel);
                      end;
 {$endif cpuflags}

+ 0 - 4
compiler/ncgutil.pas

@@ -332,11 +332,7 @@ implementation
                      LOC_FLAGS :
                        begin
                          cg.a_jmp_flags(list,p.location.resflags,truelabel);
-
-                         { e.g. xtensa has no default flags but uses a boolean register }
-{$ifndef xtensa}
                          cg.a_reg_dealloc(list,NR_DEFAULTFLAGS);
-{$endif xtensa}
                          cg.a_jmp_always(list,falselabel);
                        end;
 {$endif cpuflags}

+ 25 - 3
compiler/xtensa/cgcpu.pas

@@ -144,6 +144,9 @@ implementation
         rg[R_FPUREGISTER]:=trgcpu.create(R_FPUREGISTER,R_SUBNONE,
             [RS_F0,RS_F1,RS_F2,RS_F3,RS_F4,RS_F5,RS_F6,RS_F7,RS_F8,RS_F9,
              RS_F10,RS_F11,RS_F12,RS_F13,RS_F14,RS_F15],first_fpu_imreg,[]);
+        rg[R_SPECIALREGISTER]:=trgcpu.create(R_SPECIALREGISTER,R_SUBNONE,
+            [RS_B0,RS_B1,RS_B2,RS_B3,RS_B4,RS_B5,RS_B6,RS_B7,RS_B8,RS_B9,
+             RS_B10,RS_B11,RS_B12,RS_B13,RS_B14,RS_B15],first_flag_imreg,[]);
       end;
 
 
@@ -151,6 +154,7 @@ implementation
       begin
         rg[R_INTREGISTER].free;
         rg[R_FPUREGISTER].free;
+        rg[R_SPECIALREGISTER].free;
         inherited done_register_allocators;
       end;
 
@@ -175,14 +179,26 @@ implementation
                   list.concat(taicpu.op_reg_reg_const_const(A_EXTUI,reg2,reg1,0,8));
                 OS_S8:
                   begin
-                    list.concat(taicpu.op_reg_reg_const(A_SEXT,reg2,reg1,7));
+                    if CPUXTENSA_HAS_SEXT in cpu_capabilities[current_settings.cputype] then
+                      list.concat(taicpu.op_reg_reg_const(A_SEXT,reg2,reg1,7))
+                    else
+                      begin
+                        list.concat(taicpu.op_reg_reg_const(A_SLLI,reg2,reg1,24));
+                        list.concat(taicpu.op_reg_reg_const(A_SRAI,reg2,reg2,24));
+                      end;
                     if tosize=OS_16 then
                       list.concat(taicpu.op_reg_reg_const_const(A_EXTUI,reg2,reg2,0,16));
                   end;
                 OS_16:
                   list.concat(taicpu.op_reg_reg_const_const(A_EXTUI,reg2,reg1,0,16));
                 OS_S16:
-                  list.concat(taicpu.op_reg_reg_const(A_SEXT,reg2,reg1,15));
+                  if CPUXTENSA_HAS_SEXT in cpu_capabilities[current_settings.cputype] then
+                    list.concat(taicpu.op_reg_reg_const(A_SEXT,reg2,reg1,15))
+                  else
+                    begin
+                      list.concat(taicpu.op_reg_reg_const(A_SLLI,reg2,reg1,16));
+                      list.concat(taicpu.op_reg_reg_const(A_SRAI,reg2,reg2,16));
+                    end;
                 else
                   conv_done:=false;
               end;
@@ -266,7 +282,13 @@ implementation
         list.concat(taicpu.op_reg_ref(op,reg,href));
 
         if (fromsize=OS_S8) and not(tosize in [OS_S8,OS_8]) then
-          list.concat(taicpu.op_reg_reg_const(A_SEXT,reg,reg,7));
+          if CPUXTENSA_HAS_SEXT in cpu_capabilities[current_settings.cputype] then
+            list.concat(taicpu.op_reg_reg_const(A_SEXT,reg,reg,7))
+          else
+            begin
+              list.concat(taicpu.op_reg_reg_const(A_SLLI,reg,reg,24));
+              list.concat(taicpu.op_reg_reg_const(A_SRAI,reg,reg,24));
+            end;
         if (fromsize<>tosize) and (not (tosize in [OS_SINT,OS_INT])) then
           a_load_reg_reg(list,fromsize,tosize,reg,reg);
       end;

+ 6 - 2
compiler/xtensa/cpubase.pas

@@ -84,6 +84,9 @@ unit cpubase;
       first_mm_supreg    = RS_INVALID;
       first_mm_imreg     = $30;
 
+      { firs flag imaginary register }
+      first_flag_imreg     = $10;
+
       { TODO: Calculate bsstart}
       regnumber_count_bsstart = 16;
 
@@ -223,8 +226,9 @@ unit cpubase;
       { Offset where the parent framepointer is pushed }
       PARENT_FRAMEPOINTER_OFFSET = 0;
 
-      NR_DEFAULTFLAGS = NR_INVALID;
-      RS_DEFAULTFLAGS = RS_INVALID;
+      { we consider B0 as the default flag }
+      NR_DEFAULTFLAGS = NR_B0;
+      RS_DEFAULTFLAGS = RS_B0;
 
 {*****************************************************************************
                        GCC /ABI linking information

+ 3 - 2
compiler/xtensa/cpuinfo.pas

@@ -135,7 +135,8 @@ Const
  type
    tcpuflags =
       (
-        CPUXTENSA_REGWINDOW
+        CPUXTENSA_REGWINDOW,
+        CPUXTENSA_HAS_SEXT
       );
 
    tfpuflags =
@@ -149,7 +150,7 @@ Const
      (
        { cpu_none     } [],
        { cpu_lx106    } [],
-       { cpu_lx6      } [CPUXTENSA_REGWINDOW]
+       { cpu_lx6      } [CPUXTENSA_REGWINDOW, CPUXTENSA_HAS_SEXT]
      );
 
    fpu_capabilities : array[tfputype] of set of tfpuflags =

+ 6 - 1
compiler/xtensa/ncpuadd.pas

@@ -152,6 +152,10 @@ interface
     function TCPUAddNode.pass_1 : tnode;
       begin
         result:=inherited pass_1;
+        if not(assigned(result)) and (nodetype in [equaln,unequaln,ltn,lten,gtn,gten]) and
+          not((FPUXTENSA_SINGLE in fpu_capabilities[current_settings.fputype]) and
+            is_single(left.resultdef) and (nodetype<>slashn)) then
+          expectloc:=LOC_JUMP;
 {$ifdef dummy}
         if not(assigned(result)) then
           begin
@@ -283,7 +287,8 @@ interface
         { emit the actual operation }
         if cmpop then
           begin
-            current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg_reg(op,location.register,left.location.register,right.location.register));
+            cg.getcpuregister(current_asmdata.CurrAsmList,location.resflags.register);
+            current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg_reg(op,location.resflags.register,left.location.register,right.location.register));
             cg.maybe_check_for_fpu_exception(current_asmdata.CurrAsmList);
 
             if inv then

+ 1 - 0
compiler/xtensa/xtensaatt.inc

@@ -48,6 +48,7 @@
 'sll',
 'slli',
 'sra',
+'srai',
 'srl',
 'srli',
 'ssi',

+ 1 - 0
compiler/xtensa/xtensaop.inc

@@ -48,6 +48,7 @@ A_SEXT,
 A_SLL,
 A_SLLI,
 A_SRA,
+A_SRAI,
 A_SRL,
 A_SRLI,
 A_SSI,

+ 74 - 25
packages/fcl-js/src/jswriter.pp

@@ -1228,9 +1228,46 @@ procedure TJSWriter.WriteStatementList(El: TJSStatementList);
 
 Var
   C : Boolean;
-  B : Boolean;
   LastEl: TJSElement;
+  ElStack: array of TJSElement;
+  ElStackIndex: integer;
+
+  procedure WriteNonListEl(CurEl: TJSElement);
+  begin
+    if IsEmptyStatement(CurEl) then exit;
+    if (LastEl<>nil) then
+      begin
+      if FLastChar<>';' then
+        Write(';');
+      if C then
+        Write(' ')
+      else
+        Writeln('');
+      end;
+    WriteJS(CurEl);
+    LastEl:=CurEl;
+  end;
+
+  procedure Push(CurEl: TJSElement);
+  begin
+    if CurEl=nil then exit;
+    if ElStackIndex=length(ElStack) then
+      SetLength(ElStack,ElStackIndex+8);
+    ElStack[ElStackIndex]:=CurEl;
+    inc(ElStackIndex);
+  end;
 
+  function Pop: TJSElement;
+  begin
+    if ElStackIndex=0 then exit(nil);
+    dec(ElStackIndex);
+    Result:=ElStack[ElStackIndex];
+  end;
+
+var
+  B : Boolean;
+  CurEl: TJSElement;
+  List: TJSStatementList;
 begin
   //write('TJSWriter.WriteStatementList '+BoolToStr(FSkipCurlyBrackets,true));
   //if El.A<>nil then write(' El.A='+El.A.ClassName) else write(' El.A=nil');
@@ -1239,43 +1276,55 @@ begin
 
   C:=(woCompact in Options);
   B:= Not FSkipCurlyBrackets;
+  FSkipCurlyBrackets:=True;
   if B then
     begin
     Write('{');
     Indent;
     if not C then writeln('');
     end;
-  if not IsEmptyStatement(El.A) then
+
+  // traverse statementlist using a heap stack to avoid large stack depths
+  LastEl:=nil;
+  ElStackIndex:=0;
+  CurEl:=El;
+  while CurEl<>nil do
     begin
-    WriteJS(El.A);
-    LastEl:=El.A;
-    if Assigned(El.B) then
+    if CurEl is TJSStatementList then
       begin
-      if not (LastEl is TJSStatementList) then
+      List:=TJSStatementList(CurEl);
+      if List.A is TJSStatementList then
         begin
-        if FLastChar<>';' then
-          Write(';');
-        if C then
-          Write(' ')
+        Push(List.B);
+        CurEl:=List.A;
+        end
+      else
+        begin
+        WriteNonListEl(List.A);
+        if List.B is TJSStatementList then
+          CurEl:=List.B
         else
-          Writeln('');
+          begin
+          WriteNonListEl(List.B);
+          CurEl:=nil;
+          end;
         end;
-      FSkipCurlyBrackets:=True;
-      WriteJS(El.B);
-      LastEl:=El.B;
+      end
+    else
+      begin
+      WriteNonListEl(CurEl);
+      CurEl:=nil;
       end;
-    if (not C) and not (LastEl is TJSStatementList) then
-      writeln(';');
-    end
-  else if Assigned(El.B) and not IsEmptyStatement(El.B) then
-    begin
-    WriteJS(El.B);
-    if (not C) and not (El.B is TJSStatementList) then
-      if FLastChar=';' then
-        writeln('')
-      else
-        writeln(';');
+    if CurEl=nil then
+      CurEl:=Pop;
     end;
+
+  if (LastEl<>nil) and not C then
+    if FLastChar=';' then
+      writeln('')
+    else
+      writeln(';');
+
   if B then
     begin
     Undent;

+ 24 - 0
packages/fcl-js/tests/tcwriter.pp

@@ -157,6 +157,7 @@ type
     Procedure TestStatementListOneStatementCompact;
     Procedure TestStatementListTwoStatements;
     Procedure TestStatementListTwoStatementsCompact;
+    Procedure TestStatementListTree4;
     Procedure TestStatementListFor;
     Procedure TestEmptyFunctionDef;
     Procedure TestEmptyFunctionDefCompact;
@@ -1696,6 +1697,29 @@ begin
   AssertWrite('Statement list','{a=b; a=b}',S);
 end;
 
+procedure TTestStatementWriter.TestStatementListTree4;
+var
+  S1, S11, S12: TJSStatementList;
+begin
+  Writer.Options:=[woUseUTF8];
+  S1:=TJSStatementList.Create(0,0);
+  S11:=TJSStatementList.Create(0,0);
+  S1.A:=S11;
+  S12:=TJSStatementList.Create(0,0);
+  S1.B:=S12;
+  S11.A:=CreateAssignment(nil);
+  S11.B:=CreateAssignment(nil);
+  S12.A:=CreateAssignment(nil);
+  S12.B:=CreateAssignment(nil);
+  AssertWrite('Statement list',
+     '{'+sLineBreak
+    +'a = b;'+sLineBreak
+    +'a = b;'+sLineBreak
+    +'a = b;'+sLineBreak
+    +'a = b;'+sLineBreak
+    +'}',S1);
+end;
+
 procedure TTestStatementWriter.TestStatementListFor;
 Var
   S : TJSStatementList;

+ 1 - 1
packages/libgd/fpmake.pp

@@ -20,7 +20,7 @@ begin
 {$endif ALLPACKAGES}
     P.Version:='3.3.1';
     P.SourcePath.Add('src');
-    P.OSes := P.OSes - [embedded,nativent,msdos,wii,win16,atari,macos,palmos,symbian];
+    P.OSes := P.OSes - [embedded,nativent,msdos,wii,win16,atari,macos,palmos,symbian,freertos];
     if Defaults.CPU=jvm then
       P.OSes := P.OSes - [java,android];
 

+ 3 - 3
packages/rtl-extra/fpmake.pp

@@ -21,9 +21,9 @@ Const
 
   PrinterOSes   = [go32v2,msdos,os2,win32,win64]+unixlikes-[beos,haiku,morphos];
   SerialOSes    = [android,linux,netbsd,openbsd,win32,win64];
-  UComplexOSes  = [atari,embedded,emx,gba,go32v2,msdos,nativent,nds,netware,netwlibc,os2,symbian,watcom,wii,wince,win32,win64]+UnixLikes+AllAmigaLikeOSes;
-  MatrixOSes    = [atari,embedded,emx,gba,go32v2,msdos,nativent,nds,netware,netwlibc,os2,symbian,watcom,wii,win32,win64,wince]+UnixLikes+AllAmigaLikeOSes;
-  ObjectsOSes   = [atari,embedded,emx,gba,go32v2,macos,msdos,nds,netware,netwlibc,os2,symbian,watcom,wii,win16,win32,win64,wince]+UnixLikes+AllAmigaLikeOSes;
+  UComplexOSes  = [atari,embedded,emx,gba,go32v2,msdos,nativent,nds,netware,netwlibc,os2,symbian,watcom,wii,wince,win32,win64,freertos]+UnixLikes+AllAmigaLikeOSes;
+  MatrixOSes    = [atari,embedded,emx,gba,go32v2,msdos,nativent,nds,netware,netwlibc,os2,symbian,watcom,wii,win32,win64,wince,freertos]+UnixLikes+AllAmigaLikeOSes;
+  ObjectsOSes   = [atari,embedded,emx,gba,go32v2,macos,msdos,nds,netware,netwlibc,os2,symbian,watcom,wii,win16,win32,win64,wince,freertos]+UnixLikes+AllAmigaLikeOSes;
   WinsockOSes   = [win32,win64,wince,os2,emx,netware,netwlibc];
   WinSock2OSes  = [win32,win64,wince];
   SocketsOSes   = UnixLikes+AllAmigaLikeOSes+[netware,netwlibc,os2,emx,wince,win32,win64];

+ 11 - 11
packages/rtl-objpas/fpmake.pp

@@ -15,22 +15,22 @@ Const
 //  AllUnixOSes  = [Linux,FreeBSD,NetBSD,OpenBSD,Darwin,QNX,BeOS,Solaris,Haiku,iphonesim,aix,Android];
 //    unixlikes-[beos];
 //
-  StrUtilsOSes  = [atari,emx,gba,go32v2,msdos,nds,netware,wince,nativent,os2,netwlibc,symbian,watcom,wii,win32,win64]+UnixLikes+AllAmigaLikeOSes;
-  VarUtilsOSes  = [atari,emx,gba,go32v2,msdos,nds,netware,wince,nativent,os2,netwlibc,symbian,watcom,wii,win32,win64]+UnixLikes+AllAmigaLikeOSes;
+  StrUtilsOSes  = [atari,emx,gba,go32v2,msdos,nds,netware,wince,nativent,os2,netwlibc,symbian,watcom,wii,win32,win64,freertos]+UnixLikes+AllAmigaLikeOSes;
+  VarUtilsOSes  = [atari,emx,gba,go32v2,msdos,nds,netware,wince,nativent,os2,netwlibc,symbian,watcom,wii,win32,win64,freertos]+UnixLikes+AllAmigaLikeOSes;
   ConvUtilsOSes = [nativent,netware,netwlibc,win32,win64,wince]+AllAmigaLikeOSes+UnixLikes-[BeOS];
-  ConvUtilOSes  = [atari,Go32v2,msdos,os2,emx];
-  DateUtilsOSes = [gba,nativent,nds,netware,netwlibc,symbian,wii,win32,win64,wince]+UnixLikes+AllAmigaLikeOSes;
-  DateUtilOSes  = [atari,Go32v2,msdos,os2,emx];
-  StdConvsOSes  = [NativeNT,Win32,win64,os2,msdos,go32v2]+UnixLikes-[BeOS];
-  FmtBCDOSes    = [atari,emx,gba,go32v2,msdos,nativent,nds,netware,netwlibc,os2,symbian,watcom,wii,win32,win64,wince]+UnixLikes+AllAmigaLikeOSes;
-  VariantsOSes  = [atari,emx,gba,go32v2,msdos,nativent,nds,netware,netwlibc,os2,symbian,watcom,wii,win32,win64,wince]+UnixLikes+AllAmigaLikeOSes;
-  RttiOSes      = [atari,emx,gba,go32v2,msdos,nativent,nds,netware,netwlibc,os2,watcom,wii,win32,win64,wince]+UnixLikes+AllAmigaLikeOSes;
-  UItypesOSes   = [atari,emx,gba,go32v2,msdos,nativent,nds,netware,netwlibc,os2,watcom,wii,win32,win64,wince]+UnixLikes+AllAmigaLikeOSes-ConvUtilOSes;
+  ConvUtilOSes  = [atari,Go32v2,msdos,os2,emx,freertos];
+  DateUtilsOSes = [gba,nativent,nds,netware,netwlibc,symbian,wii,win32,win64,wince,freertos]+UnixLikes+AllAmigaLikeOSes;
+  DateUtilOSes  = [atari,Go32v2,msdos,os2,emx,freertos];
+  StdConvsOSes  = [NativeNT,Win32,win64,os2,msdos,go32v2,freertos]+UnixLikes-[BeOS];
+  FmtBCDOSes    = [atari,emx,gba,go32v2,msdos,nativent,nds,netware,netwlibc,os2,symbian,watcom,wii,win32,win64,wince,freertos]+UnixLikes+AllAmigaLikeOSes;
+  VariantsOSes  = [atari,emx,gba,go32v2,msdos,nativent,nds,netware,netwlibc,os2,symbian,watcom,wii,win32,win64,wince,freertos]+UnixLikes+AllAmigaLikeOSes;
+  RttiOSes      = [atari,emx,gba,go32v2,msdos,nativent,nds,netware,netwlibc,os2,watcom,wii,win32,win64,wince,freertos]+UnixLikes+AllAmigaLikeOSes;
+  UItypesOSes   = [atari,emx,gba,go32v2,msdos,nativent,nds,netware,netwlibc,os2,watcom,wii,win32,win64,wince,freertos]+UnixLikes+AllAmigaLikeOSes-ConvUtilOSes;
   AllTargetsObjPas = DateUtilsOses +DateUtilOSes+
                   VarutilsOses + ConvutilsOSes + ConvutilOSes + StdConvsOSes+
                   FmtBCDOSes + StrUtilsOSes + UITypesOSes;
 
-  CommonSrcOSes = [atari,emx,gba,go32v2,msdos,nds,netware,wince,nativent,os2,netwlibc,symbian,watcom,wii]+UnixLikes+AllAmigaLikeOSes;
+  CommonSrcOSes = [atari,emx,gba,go32v2,msdos,nds,netware,wince,nativent,os2,netwlibc,symbian,watcom,wii,freertos]+UnixLikes+AllAmigaLikeOSes;
 
 Var
   P : TPackage;

+ 2 - 2
packages/rtl-unicode/fpmake.pp

@@ -12,8 +12,8 @@ Const
   // in workable state atm.
   UnixLikes = AllUnixOSes -[QNX];
 
-  CollationOSes = [aix,android,darwin,emx,freebsd,go32v2,linux,netbsd,openbsd,os2,solaris,win32,win64,dragonfly,haiku];
-  CPUnits       = [aix,amiga,aros,android,beos,darwin,iphonesim,emx,gba,nds,freebsd,go32v2,haiku,linux,morphos,netbsd,netware,netwlibc,openbsd,os2,solaris,watcom,wii,win32,win64,wince,dragonfly];
+  CollationOSes = [aix,android,darwin,emx,freebsd,go32v2,linux,netbsd,openbsd,os2,solaris,win32,win64,dragonfly,haiku,freertos];
+  CPUnits       = [aix,amiga,aros,android,beos,darwin,iphonesim,emx,gba,nds,freebsd,go32v2,haiku,linux,morphos,netbsd,netware,netwlibc,openbsd,os2,solaris,watcom,wii,win32,win64,wince,dragonfly,freertos];
   utf8bidiOSes  = [netware,netwlibc];
   freebidiOSes  = [netware,netwlibc];
 

+ 1 - 1
packages/sdl/fpmake.pp

@@ -24,7 +24,7 @@ begin
     P.Dependencies.Add('morphunits',[morphos]);
     if Defaults.CPU=arm then
        P.OSes := P.OSes - [darwin];
-    P.OSes := P.OSes - [iphonesim,java,os2,emx,go32v2,watcom,netware,netwlibc,nativent,embedded,android,amiga,aros,msdos,gba,nds,win16,atari,macos,palmos,symbian,wii];
+    P.OSes := P.OSes - [iphonesim,java,os2,emx,go32v2,watcom,netware,netwlibc,nativent,embedded,android,amiga,aros,msdos,gba,nds,win16,atari,macos,palmos,symbian,wii,freertos];
 
     T:=P.Targets.AddUnit('logger.pas');
       with T.Dependencies do

+ 4 - 0
rtl/freertos/Makefile

@@ -2955,8 +2955,12 @@ define CPU_UNITS_RULE
 ifeq ($(ARCH),avr)
 $(1)$(PPUEXT): $(ARCH)/$(1).pp intrinsics$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
 else
+ifeq ($(ARCH),xtensa)
+$(1)$(PPUEXT): $(ARCH)/$(1).pp consoleio$(PPUEXT) heapmgr$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
+else
 $(1)$(PPUEXT): $(ARCH)/$(1).pp $(SYSTEMUNIT)$(PPUEXT)
 endif
+endif
 endef
 $(foreach unit,$(CPU_UNITS),$(eval $(call CPU_UNITS_RULE,$(unit))))
 $(addsuffix $(PPUEXT),$(CPU_UNITS)):

+ 4 - 0
rtl/freertos/Makefile.fpc

@@ -396,8 +396,12 @@ define CPU_UNITS_RULE
 ifeq ($(ARCH),avr)
 $(1)$(PPUEXT): $(ARCH)/$(1).pp intrinsics$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
 else
+ifeq ($(ARCH),xtensa)
+$(1)$(PPUEXT): $(ARCH)/$(1).pp consoleio$(PPUEXT) heapmgr$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
+else
 $(1)$(PPUEXT): $(ARCH)/$(1).pp $(SYSTEMUNIT)$(PPUEXT)
 endif
+endif
 endef
 
 $(foreach unit,$(CPU_UNITS),$(eval $(call CPU_UNITS_RULE,$(unit))))