Переглянути джерело

* the wasm target (now 'embedded') moved to the i_embed/t_embed units

git-svn-id: branches/wasm@48365 -
nickysn 4 роки тому
батько
коміт
f77ae51751

+ 0 - 2
.gitattributes

@@ -878,7 +878,6 @@ compiler/systems/i_sinclairql.pas svneol=native#text/plain
 compiler/systems/i_sunos.pas svneol=native#text/plain
 compiler/systems/i_symbian.pas svneol=native#text/plain
 compiler/systems/i_wasi.pas svneol=native#text/plain
-compiler/systems/i_wasm.pas svneol=native#text/plain
 compiler/systems/i_watcom.pas svneol=native#text/plain
 compiler/systems/i_wdosx.pas svneol=native#text/plain
 compiler/systems/i_wii.pas svneol=native#text/plain
@@ -916,7 +915,6 @@ compiler/systems/t_sinclairql.pas svneol=native#text/plain
 compiler/systems/t_sunos.pas svneol=native#text/plain
 compiler/systems/t_symbian.pas svneol=native#text/plain
 compiler/systems/t_wasi.pas svneol=native#text/plain
-compiler/systems/t_wasm.pas svneol=native#text/plain
 compiler/systems/t_watcom.pas svneol=native#text/plain
 compiler/systems/t_wdosx.pas svneol=native#text/plain
 compiler/systems/t_wii.pas svneol=native#text/plain

+ 71 - 0
compiler/systems/i_embed.pas

@@ -784,6 +784,77 @@ unit i_embed;
             llvmdatalayout : 'todo';
           );
 
+       system_wasm32_embedded_info : tsysteminfo =
+          (
+            system       : system_wasm32_embedded;
+            name         : 'Embedded';
+            shortname    : 'embedded';
+            flags        : [tf_under_development,tf_needs_symbol_size,tf_needs_symbol_type,
+                            tf_files_case_sensitive,tf_no_generic_stackcheck,
+                            tf_smartlink_sections,
+                            { avoid the creation of threadvar tables }
+                            tf_section_threadvars];
+            cpu          : cpu_wasm32;
+            unit_env     : '';
+            extradefines : '';
+            exeext       : '.wasm';
+            defext       : '.def';
+            scriptext    : '.sh';
+            smartext     : '.sl';
+            unitext      : '.ppu';
+            unitlibext   : '.ppl';
+            asmext       : '.wat';
+            objext       : '.o';
+            resext       : '';
+            resobjext    : '.o';
+            sharedlibext : ''; // keep it empty! The sharedlibext drives the export module name
+                               // if this is populated, then the name should be cleared when generating import
+            staticlibext : '.a';
+            staticlibprefix : '';
+            sharedlibprefix : '';
+            sharedClibext : '.wasm';
+            staticClibext : '.wasm';
+            staticClibprefix : '';
+            sharedClibprefix : '';
+            importlibprefix : '';
+            importlibext : '.wasm';
+            Cprefix      : '';
+            newline      : #10;
+            dirsep       : '/';
+            assem        : as_wasm32_llvm_mc;
+            assemextern  : as_wasm32_llvm_mc;
+            link         : ld_none;
+            linkextern   : ld_wasm; // there's no linker, only object files for WASM
+            ar           : ar_none;
+            res          : res_none;
+            dbg          : dbg_none;
+            script       : script_unix;
+            endian       : endian_little;
+            alignment    :
+              (
+                procalign       : 4;
+                loopalign       : 4;
+                jumpalign       : 0;
+                jumpalignskipmax    : 0;
+                coalescealign   : 0;
+                coalescealignskipmax: 0;
+                constalignmin   : 0;
+                constalignmax   : 4;
+                varalignmin     : 4;
+                varalignmax     : 4;
+                localalignmin   : 4;
+                localalignmax   : 4;
+                recordalignmin  : 0;
+                recordalignmax  : 2;
+                maxCrecordalign : 4
+              );
+            first_parm_offset : 0;
+            stacksize   : 262144;
+            stackalign   : 4;
+            abi          : abi_default;
+            llvmdatalayout : 'todo';
+          );
+
  implementation
 
 initialization

+ 0 - 117
compiler/systems/i_wasm.pas

@@ -1,117 +0,0 @@
-{
-    Copyright (c) 2019 by Dmitry Boyarintsev
-
-    This unit implements support information structures for WebAssembly
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- ****************************************************************************
-}
-
-unit i_wasm;
-
-{$i fpcdefs.inc}
-
-  interface
-
-    uses
-       systems,rescmn;
-
-    const
-       res_wasmraw_info : tresinfo =
-           (
-             id     : res_none; // todo: not implemented. but could be as memory
-             resbin : 'fpcwasmres';
-             rescmd : '-o $OBJ $DBG';
-             rcbin  : '';
-             rccmd  : '';
-             resourcefileclass : nil;
-             resflags : [res_no_compile];
-           );
-
-        system_wasm32_embedded_info : tsysteminfo =
-          (
-            system       : system_wasm32_embedded;
-            name         : 'Embedded';
-            shortname    : 'embedded';
-            flags        : [tf_under_development,tf_needs_symbol_size,tf_needs_symbol_type,
-                            tf_files_case_sensitive,tf_no_generic_stackcheck,
-                            tf_smartlink_sections,
-                            { avoid the creation of threadvar tables }
-                            tf_section_threadvars];
-            cpu          : cpu_wasm32;
-            unit_env     : '';
-            extradefines : '';
-            exeext       : '.wasm';
-            defext       : '.def';
-            scriptext    : '.sh';
-            smartext     : '.sl';
-            unitext      : '.ppu';
-            unitlibext   : '.ppl';
-            asmext       : '.wat';
-            objext       : '.o';
-            resext       : '';
-            resobjext    : '.o';
-            sharedlibext : ''; // keep it empty! The sharedlibext drives the export module name
-                               // if this is populated, then the name should be cleared when generating import
-            staticlibext : '.a';
-            staticlibprefix : '';
-            sharedlibprefix : '';
-            sharedClibext : '.wasm';
-            staticClibext : '.wasm';
-            staticClibprefix : '';
-            sharedClibprefix : '';
-            importlibprefix : '';
-            importlibext : '.wasm';
-            Cprefix      : '';
-            newline      : #10;
-            dirsep       : '/';
-            assem        : as_wasm32_llvm_mc;
-            assemextern  : as_wasm32_llvm_mc;
-            link         : ld_none;
-            linkextern   : ld_wasm; // there's no linker, only object files for WASM
-            ar           : ar_none;
-            res          : res_none;
-            dbg          : dbg_none;
-            script       : script_unix;
-            endian       : endian_little;
-            alignment    :
-              (
-                procalign       : 4;
-                loopalign       : 4;
-                jumpalign       : 0;
-                jumpalignskipmax    : 0;
-                coalescealign   : 0;
-                coalescealignskipmax: 0;
-                constalignmin   : 0;
-                constalignmax   : 4;
-                varalignmin     : 4;
-                varalignmax     : 4;
-                localalignmin   : 4;
-                localalignmax   : 4;
-                recordalignmin  : 0;
-                recordalignmax  : 2;
-                maxCrecordalign : 4
-              );
-            first_parm_offset : 0;
-            stacksize   : 262144;
-            stackalign   : 4;
-            abi          : abi_default;
-            llvmdatalayout : 'todo';
-          );
-
-
-  implementation
-
-end.

+ 98 - 1
compiler/systems/t_embed.pas

@@ -33,7 +33,10 @@ implementation
        SysUtils,
        cutils,cfileutl,cclasses,
        globtype,globals,systems,verbose,comphook,cscript,fmodule,i_embed,link,
-       cpuinfo;
+{$ifdef wasm32}
+       t_wasi,import,export,
+{$endif wasm32}
+       cpuinfo,aasmbase;
 
     type
        TlinkerEmbedded=class(texternallinker)
@@ -58,6 +61,17 @@ implementation
 {          function postprocessexecutable(const fn : string;isdll:boolean):boolean;}
        end;
 
+       { TLinkerEmbedded_Wasm }
+
+       TLinkerEmbedded_Wasm=class(texternallinker)
+       public
+         constructor Create;override;
+         procedure SetDefaultInfo;override;
+
+         //function  MakeExecutable:boolean;override;
+         function  MakeSharedLibrary:boolean;override;
+       end;
+
 
 
 {*****************************************************************************
@@ -1918,6 +1932,82 @@ function TlinkerEmbedded_SdccSdld.MakeExecutable: boolean;
     MakeExecutable:=success;   { otherwise a recursive call to link method }
   end;
 
+{*****************************************************************************
+                              TlinkerEmbedded_Wasm
+*****************************************************************************}
+
+constructor TLinkerEmbedded_Wasm.Create;
+  begin
+    inherited Create;
+  end;
+
+procedure TLinkerEmbedded_Wasm.SetDefaultInfo;
+  begin
+    Info.DllCmd[1] := 'wasm-ld $SONAME $GCSECTIONS -o $EXE';
+    //Info.DllCmd[2] := 'wasmtool --exportrename $INPUT $EXE';
+  end;
+
+function TLinkerEmbedded_Wasm.MakeSharedLibrary: boolean;
+  var
+    GCSectionsStr  : ansistring;
+    binstr, cmdstr : Tcmdstr;
+    InitStr,
+    FiniStr,
+    SoNameStr      : string[80];
+    mapstr,ltostr  : TCmdStr;
+    success        : Boolean;
+
+    tmp : TCmdStrListItem;
+    tempFileName : ansistring;
+  begin
+    //Result := true;
+    //Result:=inherited MakeSharedLibrary;
+    if (cs_link_smart in current_settings.globalswitches) and
+       create_smartlink_sections then
+     GCSectionsStr:='--gc-sections'
+    else
+      GCSectionsStr:='';
+
+    SoNameStr:='';
+    SplitBinCmd(Info.DllCmd[1],binstr,cmdstr);
+    Replace(cmdstr,'$EXE',maybequoted(current_module.exefilename));
+
+    tmp := TCmdStrListItem(ObjectFiles.First);
+    while Assigned(tmp) do begin
+      cmdstr := tmp.Str+ ' ' + cmdstr;
+      tmp := TCmdStrListItem(tmp.Next);
+    end;
+
+    if HasExports then
+      cmdstr := cmdstr + ' --export-dynamic'; //' --export-dynamic';
+
+    cmdstr := cmdstr + ' --no-entry --allow-undefined';
+
+    if (cs_link_strip in current_settings.globalswitches) then
+     begin
+       { only remove non global symbols and debugging info for a library }
+       cmdstr := cmdstr + ' --strip-all';
+     end;
+
+    //Replace(cmdstr,'$OPT',Info.ExtraOptions);
+    //Replace(cmdstr,'$RES',maybequoted(outputexedir+Info.ResName));
+    //Replace(cmdstr,'$INIT',InitStr);
+    //Replace(cmdstr,'$FINI',FiniStr);
+    Replace(cmdstr,'$SONAME',SoNameStr);
+    //Replace(cmdstr,'$MAP',mapstr);
+    //Replace(cmdstr,'$LTO',ltostr);
+    Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
+    writeln(utilsprefix+binstr,' ',cmdstr);
+    success:=DoExec(FindUtil(utilsprefix+binstr),cmdstr,true,false);
+
+    //SplitBinCmd(Info.DllCmd[2],binstr,cmdstr);
+    //Replace(cmdstr,'$INPUT',current_module.objfilename );
+    //Replace(cmdstr,'$EXE',maybequoted(current_module.exefilename));
+    //DoExec(FindUtil(utilsprefix+binstr),cmdstr,false,false);
+
+    MakeSharedLibrary:=success;
+  end;
+
 
 {*****************************************************************************
                                      Initialize
@@ -1981,4 +2071,11 @@ initialization
   RegisterLinker(ld_embedded,TlinkerEmbedded_SdccSdld);
   RegisterTarget(system_z80_embedded_info);
 {$endif z80}
+
+{$ifdef wasm32}
+  RegisterTarget(system_wasm32_embedded_info);
+  RegisterImport(system_wasm32_embedded, timportlibwasi);
+  RegisterExport(system_wasm32_embedded, texportlibwasi);
+  RegisterLinker(ld_wasm, TLinkerEmbedded_Wasm);
+{$endif wasm32}
 end.

+ 0 - 166
compiler/systems/t_wasm.pas

@@ -1,166 +0,0 @@
-unit t_wasm;
-
-{$i fpcdefs.inc}
-
-interface
-
-uses
-  systems,
-
-  globtype, globals,
-  aasmbase,
-  cfileutl, cutils, cclasses,
-
-  import, export, aasmdata, aasmcpu,
-  fmodule, ogbase,
-
-  symsym, symdef,
-
-  link,
-
-  i_wasm, tgcpu;
-
-type
-
-  { texportlibwasm }
-
-  texportlibwasm=class(texportlib)
-      procedure preparelib(const s : string);override;
-      procedure exportprocedure(hp : texported_item);override;
-      procedure exportvar(hp : texported_item);override;
-      procedure generatelib;override;
-    end;
-
-  { timportlibwasm }
-  timportlibwasm = class(timportlib)
-      procedure generatelib;override;
-    end;
-
-  { tlinkerjvm }
-
-  { tlinkerwasm }
-
-  tlinkerwasm=class(texternallinker)
-  public
-    constructor Create;override;
-    procedure SetDefaultInfo;override;
-
-    //function  MakeExecutable:boolean;override;
-    function  MakeSharedLibrary:boolean;override;
-  end;
-
-
-implementation
-
-{ timportlibwasm }
-
-  procedure timportlibwasm.generatelib;
-    begin
-    end;
-
-{ tlinkerwasm }
-
-constructor tlinkerwasm.Create;
-begin
-  inherited Create;
-end;
-
-procedure tlinkerwasm.SetDefaultInfo;
-begin
-  Info.DllCmd[1] := 'wasm-ld $SONAME $GCSECTIONS -o $EXE';
-  //Info.DllCmd[2] := 'wasmtool --exportrename $INPUT $EXE';
-end;
-
-function tlinkerwasm.MakeSharedLibrary: boolean;
-var
-  GCSectionsStr  : ansistring;
-  binstr, cmdstr : Tcmdstr;
-  InitStr,
-  FiniStr,
-  SoNameStr      : string[80];
-  mapstr,ltostr  : TCmdStr;
-  success        : Boolean;
-
-  tmp : TCmdStrListItem;
-  tempFileName : ansistring;
-begin
-  //Result := true;
-  //Result:=inherited MakeSharedLibrary;
-  if (cs_link_smart in current_settings.globalswitches) and
-     create_smartlink_sections then
-   GCSectionsStr:='--gc-sections'
-  else
-    GCSectionsStr:='';
-
-  SoNameStr:='';
-  SplitBinCmd(Info.DllCmd[1],binstr,cmdstr);
-  Replace(cmdstr,'$EXE',maybequoted(current_module.exefilename));
-
-  tmp := TCmdStrListItem(ObjectFiles.First);
-  while Assigned(tmp) do begin
-    cmdstr := tmp.Str+ ' ' + cmdstr;
-    tmp := TCmdStrListItem(tmp.Next);
-  end;
-
-  if HasExports then
-    cmdstr := cmdstr + ' --export-dynamic'; //' --export-dynamic';
-
-  cmdstr := cmdstr + ' --no-entry --allow-undefined';
-
-  if (cs_link_strip in current_settings.globalswitches) then
-   begin
-     { only remove non global symbols and debugging info for a library }
-     cmdstr := cmdstr + ' --strip-all';
-   end;
-
-  //Replace(cmdstr,'$OPT',Info.ExtraOptions);
-  //Replace(cmdstr,'$RES',maybequoted(outputexedir+Info.ResName));
-  //Replace(cmdstr,'$INIT',InitStr);
-  //Replace(cmdstr,'$FINI',FiniStr);
-  Replace(cmdstr,'$SONAME',SoNameStr);
-  //Replace(cmdstr,'$MAP',mapstr);
-  //Replace(cmdstr,'$LTO',ltostr);
-  Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
-  writeln(utilsprefix+binstr,' ',cmdstr);
-  success:=DoExec(FindUtil(utilsprefix+binstr),cmdstr,true,false);
-
-  //SplitBinCmd(Info.DllCmd[2],binstr,cmdstr);
-  //Replace(cmdstr,'$INPUT',current_module.objfilename );
-  //Replace(cmdstr,'$EXE',maybequoted(current_module.exefilename));
-  //DoExec(FindUtil(utilsprefix+binstr),cmdstr,false,false);
-
-  MakeSharedLibrary:=success;
-end;
-
-{ texportlibwasm }
-
-procedure texportlibwasm.preparelib(const s: string);
-begin
-  //nothing to happen. wasm files are modules
-end;
-
-procedure texportlibwasm.exportprocedure(hp: texported_item);
-var
-  nm : TSymStr;
-begin
-  nm := tprocdef(tprocsym(hp.sym).ProcdefList[0]).mangledname;
-  current_asmdata.asmlists[al_exports].Concat(tai_impexp.create(hp.name^, nm, ie_Func));
-end;
-
-procedure texportlibwasm.exportvar(hp: texported_item);
-begin
-  //inherited exportvar(hp);
-end;
-
-procedure texportlibwasm.generatelib;
-begin
-  //inherited generatelib;
-end;
-
-initialization
-  RegisterTarget(system_wasm32_embedded_info);
-  RegisterImport(system_wasm32_embedded, timportlibwasm);
-  RegisterExport(system_wasm32_embedded, texportlibwasm);
-  RegisterLinker(ld_wasm, tlinkerwasm);
-
-end.

+ 1 - 1
compiler/wasm32/cputarg.pas

@@ -38,7 +38,7 @@ implementation
 {**************************************
              Targets
 **************************************}
-      ,t_wasm
+      ,t_embed
       ,t_wasi
 
 {**************************************