Bladeren bron

+ added a 'producers' custom section to WebAssembly object modules, containing the FPC version

Nikolay Nikolov 3 jaren geleden
bovenliggende
commit
1dd80d596d
2 gewijzigde bestanden met toevoegingen van 19 en 3 verwijderingen
  1. 15 1
      compiler/ogwasm.pas
  2. 4 2
      compiler/wasmbase.pas

+ 15 - 1
compiler/ogwasm.pas

@@ -169,7 +169,7 @@ interface
 implementation
 
     uses
-      verbose;
+      verbose,version;
 
     procedure WriteUleb5(d: tdynamicarray; v: uint64);
       var
@@ -1655,6 +1655,18 @@ implementation
         Writer.write(WasmModuleMagic,SizeOf(WasmModuleMagic));
         Writer.write(WasmVersion,SizeOf(WasmVersion));
 
+        { Write the producers section:
+          https://github.com/WebAssembly/tool-conventions/blob/main/ProducersSection.md }
+        WriteUleb(FWasmCustomSections[wcstProducers],2);
+        WriteName(FWasmCustomSections[wcstProducers],'language');
+        WriteUleb(FWasmCustomSections[wcstProducers],1);
+        WriteName(FWasmCustomSections[wcstProducers],'Pascal');
+        WriteName(FWasmCustomSections[wcstProducers],'');
+        WriteName(FWasmCustomSections[wcstProducers],'processed-by');
+        WriteUleb(FWasmCustomSections[wcstProducers],1);
+        WriteName(FWasmCustomSections[wcstProducers],'Free Pascal Compiler (FPC)');
+        WriteName(FWasmCustomSections[wcstProducers],full_version_string+' ['+date_string+'] for '+target_cpu_string+' - '+target_info.shortname);
+
         code_section_nr:=-1;
         data_section_nr:=-1;
         section_nr:=0;
@@ -1708,6 +1720,8 @@ implementation
             WriteWasmCustomSection(wcstRelocData);
             Inc(section_nr);
           end;
+        WriteWasmCustomSection(wcstProducers);
+        Inc(section_nr);
 
         result:=true;
       end;

+ 4 - 2
compiler/wasmbase.pas

@@ -49,13 +49,15 @@ type
   TWasmCustomSectionType = (
     wcstLinking,
     wcstRelocCode,
-    wcstRelocData);
+    wcstRelocData,
+    wcstProducers);
 
 const
   WasmCustomSectionName: array [TWasmCustomSectionType] of string =
     ('linking',
      'reloc.CODE',
-     'reloc.DATA');
+     'reloc.DATA',
+     'producers');
 
 type
   TWasmRelocationType = (