Bläddra i källkod

+ produce a target_features section when compiling with -CTwasmthreads

Nikolay Nikolov 3 år sedan
förälder
incheckning
7cd082ba5f
2 ändrade filer med 23 tillägg och 3 borttagningar
  1. 19 1
      compiler/ogwasm.pas
  2. 4 2
      compiler/wasmbase.pas

+ 19 - 1
compiler/ogwasm.pas

@@ -169,7 +169,7 @@ interface
 implementation
 
     uses
-      verbose,version;
+      verbose,version,globals;
 
     procedure WriteUleb5(d: tdynamicarray; v: uint64);
       var
@@ -1655,6 +1655,19 @@ implementation
         Writer.write(WasmModuleMagic,SizeOf(WasmModuleMagic));
         Writer.write(WasmVersion,SizeOf(WasmVersion));
 
+        if ts_wasm_threads in current_settings.targetswitches then
+          begin
+            WriteUleb(FWasmCustomSections[wcstTargetFeatures],4);
+            WriteUleb(FWasmCustomSections[wcstTargetFeatures],$2B);
+            WriteName(FWasmCustomSections[wcstTargetFeatures],'atomics');
+            WriteUleb(FWasmCustomSections[wcstTargetFeatures],$2B);
+            WriteName(FWasmCustomSections[wcstTargetFeatures],'bulk-memory');
+            WriteUleb(FWasmCustomSections[wcstTargetFeatures],$2B);
+            WriteName(FWasmCustomSections[wcstTargetFeatures],'mutable-globals');
+            WriteUleb(FWasmCustomSections[wcstTargetFeatures],$2B);
+            WriteName(FWasmCustomSections[wcstTargetFeatures],'sign-ext');
+          end;
+
         { Write the producers section:
           https://github.com/WebAssembly/tool-conventions/blob/main/ProducersSection.md }
         WriteUleb(FWasmCustomSections[wcstProducers],2);
@@ -1722,6 +1735,11 @@ implementation
           end;
         WriteWasmCustomSection(wcstProducers);
         Inc(section_nr);
+        if ts_wasm_threads in current_settings.targetswitches then
+          begin
+            WriteWasmCustomSection(wcstTargetFeatures);
+            Inc(section_nr);
+          end;
 
         result:=true;
       end;

+ 4 - 2
compiler/wasmbase.pas

@@ -50,14 +50,16 @@ type
     wcstLinking,
     wcstRelocCode,
     wcstRelocData,
-    wcstProducers);
+    wcstProducers,
+    wcstTargetFeatures);
 
 const
   WasmCustomSectionName: array [TWasmCustomSectionType] of string =
     ('linking',
      'reloc.CODE',
      'reloc.DATA',
-     'producers');
+     'producers',
+     'target_features');
 
 type
   TWasmRelocationType = (