From 5df473f7de85b3a5cd284451ae262407cd54c5be Mon Sep 17 00:00:00 2001 From: nickysn Date: Wed, 29 Jul 2020 19:23:50 +0000 Subject: [PATCH] [PATCH 83/83] using wasa assembler instead of wat2wasm. using assembler symbols to identify weak symbols (sub functions and __stack_top for regular units). Getting rid of wasmtool use wabt text output alignment with tabs From 11b08b2747e7e11ef6f18a70eca2bb94009c8d3d Mon Sep 17 00:00:00 2001 From: Dmitry Boyarintsev Date: Thu, 9 Apr 2020 13:48:36 -0400 git-svn-id: branches/wasm@45960 - --- compiler/systems/t_wasm.pas | 10 +++++----- compiler/wasm/agwat.pas | 22 ++++++++++++++++------ 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/compiler/systems/t_wasm.pas b/compiler/systems/t_wasm.pas index cbcfce1cee..b8f3f83651 100644 --- a/compiler/systems/t_wasm.pas +++ b/compiler/systems/t_wasm.pas @@ -68,7 +68,7 @@ end; procedure tlinkerwasm.SetDefaultInfo; begin Info.DllCmd[1] := 'wasm-ld $SONAME $GCSECTIONS -o $EXE'; - Info.DllCmd[2] := 'wasmtool --exportrename $INPUT $EXE'; + //Info.DllCmd[2] := 'wasmtool --exportrename $INPUT $EXE'; end; function tlinkerwasm.MakeSharedLibrary: boolean; @@ -124,10 +124,10 @@ begin 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); + //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; diff --git a/compiler/wasm/agwat.pas b/compiler/wasm/agwat.pas index 06cbd84f7a..6e0a3de604 100644 --- a/compiler/wasm/agwat.pas +++ b/compiler/wasm/agwat.pas @@ -241,7 +241,7 @@ implementation begin //writer.AsmWriteLn('instr'); cpu := taicpu(hp); - writer.AsmWrite(#9); + writer.AsmWrite(#9#9); writer.AsmWrite(wasm_op2str[cpu.opcode] ); if (cpu.opcode = a_call_indirect) then begin @@ -303,7 +303,13 @@ implementation begin exit; end; - writer.AsmWrite('(func '); + + writer.AsmWriteLn(''); + if stub and stubUnreachable then begin + writer.AsmWriteLn(#9';;.weak'); + end; + + writer.AsmWrite(#9'(func '); writer.AsmWrite( GetWasmName( pd.mangledname )); //procsym.RealName )); @@ -342,7 +348,7 @@ implementation for i:=0 to pd.paras.Count-1 do begin prm := tcpuparavarsym(pd.paras[i]); - writer.AsmWrite(#9'(param'#9); + writer.AsmWrite(#9#9'(param'#9); case prm.paraloc[callerside].Size of OS_8..OS_32, OS_S8..OS_S32: writer.AsmWrite('i32'); @@ -373,7 +379,7 @@ implementation if not defToWasmBasic(pd.returndef, bt) then bt := wbt_i32; - writer.AsmWrite(#9'(result'#9); + writer.AsmWrite(#9#9'(result'#9); case bt of wbt_i64: writer.AsmWrite('i64'); wbt_f32: writer.AsmWrite('f32'); @@ -614,7 +620,7 @@ implementation ait_local : begin - writer.AsmWrite(#9'(local '); + writer.AsmWrite(#9#9'(local '); if tai_local(hp).name <> '' then begin writer.AsmWrite(' '); @@ -649,6 +655,10 @@ implementation { print all global variables } //current_asmdata.AsmSymbolDict + // for every unit __stack_top is a weak symbol + // __stack_top is strong only for libraries or programs. + if current_module.is_unit then + writer.AsmWriteLn(#9';;.weak'); writer.AsmWrite(#9'(global $__stack_top (mut i32) (i32.const '); writer.AsmWrite(tostr(globals.stacksize)); writer.AsmWriteLn('))'); @@ -1070,7 +1080,7 @@ implementation ( id : as_wasm_wabt; idtxt : 'Wabt'; - asmbin : 'wat2wasm'; + asmbin : 'wasa'; asmcmd : '-r --no-canonicalize-leb128s -o $OBJ $EXTRAOPT $ASM'; supported_targets : [system_wasm_wasm32]; flags : [];