Browse Source

+ compiler support for a new target: wasip1threads

Nikolay Nikolov 5 months ago
parent
commit
4340d03ba9
4 changed files with 85 additions and 3 deletions
  1. 3 0
      compiler/options.pas
  2. 2 1
      compiler/systems.inc
  3. 4 2
      compiler/systems.pas
  4. 76 0
      compiler/systems/i_wasi.pas

+ 3 - 0
compiler/options.pas

@@ -4956,6 +4956,9 @@ begin
   if tf_x86_far_procs_push_odd_bp in target_info.flags then
   if tf_x86_far_procs_push_odd_bp in target_info.flags then
     if not UpdateTargetSwitchStr('FARPROCSPUSHODDBP', init_settings.targetswitches, true) then
     if not UpdateTargetSwitchStr('FARPROCSPUSHODDBP', init_settings.targetswitches, true) then
       InternalError(2013092802);
       InternalError(2013092802);
+  if tf_wasm_threads in target_info.flags then
+    if not UpdateTargetSwitchStr('WASMTHREADS', init_settings.targetswitches, true) then
+      InternalError(2025022701);
 
 
   { Use standard Android NDK prefixes when cross-compiling }
   { Use standard Android NDK prefixes when cross-compiling }
   if (source_info.system<>target_info.system) and (target_info.system in systems_android) then
   if (source_info.system<>target_info.system) and (target_info.system in systems_android) then

+ 2 - 1
compiler/systems.inc

@@ -215,7 +215,8 @@
              system_loongarch64_linux,  { 120 }
              system_loongarch64_linux,  { 120 }
              system_aarch64_iphonesim,  { 121 }
              system_aarch64_iphonesim,  { 121 }
              system_m68k_human68k,      { 122 }
              system_m68k_human68k,      { 122 }
-             system_mipsel_ps1          { 123 }
+             system_mipsel_ps1,         { 123 }
+             system_wasm32_wasip1threads { 124 }
        );
        );
 
 
      type
      type

+ 4 - 2
compiler/systems.pas

@@ -181,14 +181,16 @@ interface
             { units are initialized by direct calls and not table driven,
             { units are initialized by direct calls and not table driven,
               in particular for a small amount of units, this results in smaller
               in particular for a small amount of units, this results in smaller
               executables }
               executables }
-            tf_init_final_units_by_calls
+            tf_init_final_units_by_calls,
+            { indicates that the default value of the ts_wasm_threads target switch is 'on' for this target }
+            tf_wasm_threads
        );
        );
 
 
        psysteminfo = ^tsysteminfo;
        psysteminfo = ^tsysteminfo;
        { using packed causes bus errors on processors which require alignment }
        { using packed causes bus errors on processors which require alignment }
        tsysteminfo = record
        tsysteminfo = record
           system       : tsystem;
           system       : tsystem;
-          name         : string[53];
+          name         : string[88];
           shortname    : string[12];
           shortname    : string[12];
           flags        : set of tsystemflags;
           flags        : set of tsystemflags;
           cpu          : tsystemcpu;
           cpu          : tsystemcpu;

+ 76 - 0
compiler/systems/i_wasi.pas

@@ -101,6 +101,79 @@ unit i_wasi;
           );
           );
 
 
 
 
+        system_wasm32_wasip1threads_info : tsysteminfo =
+          (
+            system       : system_wasm32_wasip1threads;
+            name         : 'The WebAssembly System Interface Preview 1 with Multithreading (WASI 0.1 + wasi-threads)';
+            shortname    : 'Wasip1threads';
+            flags        : [tf_under_development,tf_needs_symbol_size,tf_needs_symbol_type,
+                            tf_files_case_sensitive,
+                            tf_smartlink_sections,tf_has_winlike_resources,
+                            { avoid the creation of threadvar tables }
+                            tf_section_threadvars,
+                            tf_wasm_threads];
+            cpu          : cpu_wasm32;
+            unit_env     : '';
+            extradefines : 'WASI;WASIP1';
+            exeext       : '.wasm';
+            defext       : '.def';
+            scriptext    : '.sh';
+            smartext     : '.sl';
+            unitext      : '.ppu';
+            unitlibext   : '.ppl';
+            asmext       : '.wat';
+            objext       : '.o';
+            resext       : '';
+            resobjext    : '.or';
+            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_wasm;
+            assemextern  : as_wasm32_llvm_mc;
+            link         : ld_int_wasi;
+            linkextern   : ld_wasi;
+            ar           : ar_none;
+            res          : res_wasm;
+            dbg          : dbg_dwarf2;
+            script       : script_unix;
+            endian       : endian_little;
+            alignment    :
+              (
+                procalign       : 0;
+                loopalign       : 0;
+                jumpalign       : 0;
+                jumpalignskipmax    : 0;
+                coalescealign   : 0;
+                coalescealignskipmax: 0;
+                constalignmin   : 4;
+                constalignmax   : 16;
+                varalignmin     : 4;
+                varalignmax     : 16;
+                localalignmin   : 4;
+                localalignmax   : 16;
+                recordalignmin  : 0;
+                recordalignmax  : 16;
+                maxCrecordalign : 16
+              );
+            first_parm_offset : 0;
+            stacksize   : 8*1024*1024;
+            stackalign   : 16;
+            abi          : abi_default;
+            llvmdatalayout : 'todo';
+          );
+
+
   implementation
   implementation
 
 
 initialization
 initialization
@@ -108,5 +181,8 @@ initialization
   {$ifdef wasip1}
   {$ifdef wasip1}
     set_source_info(system_wasm32_wasip1_info);
     set_source_info(system_wasm32_wasip1_info);
   {$endif wasip1}
   {$endif wasip1}
+  {$ifdef wasip1threads}
+    set_source_info(system_wasm32_wasip1threads_info);
+  {$endif wasip1threads}
 {$endif CPUWASM32}
 {$endif CPUWASM32}
 end.
 end.