diff --git a/compiler/ogwasm.pas b/compiler/ogwasm.pas new file mode 100644 index 0000000000..4127ad1f47 --- /dev/null +++ b/compiler/ogwasm.pas @@ -0,0 +1,130 @@ +{ + Copyright (c) 2021 by Nikolay Nikolov + + Contains the WebAssembly binary module format reader and writer + + 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 ogwasm; + +{$i fpcdefs.inc} + +interface + + uses + { common } + globtype, + { target } + systems, + { assembler } + aasmbase,assemble, + { output } + ogbase, + owbase; + + type + + { TWasmObjData } + + TWasmObjData = class(TObjData) + public + function sectionname(atype:TAsmSectiontype;const aname:string;aorder:TAsmSectionOrder):string;override; + procedure writeReloc(Data:TRelocDataInt;len:aword;p:TObjSymbol;Reloctype:TObjRelocationType);override; + end; + + { TWasmObjOutput } + + TWasmObjOutput = class(tObjOutput) + protected + function writeData(Data:TObjData):boolean;override; + public + constructor create(AWriter:TObjectWriter);override; + end; + + { TWasmAssembler } + + TWasmAssembler = class(tinternalassembler) + constructor create(info: pasminfo; smart:boolean);override; + end; + +implementation + +{**************************************************************************** + TWasmObjData +****************************************************************************} + + function TWasmObjData.sectionname(atype: TAsmSectiontype; + const aname: string; aorder: TAsmSectionOrder): string; + begin + result:='todosectionname'; + end; + + procedure TWasmObjData.writeReloc(Data: TRelocDataInt; len: aword; + p: TObjSymbol; Reloctype: TObjRelocationType); + begin + end; + +{**************************************************************************** + TWasmObjOutput +****************************************************************************} + + function TWasmObjOutput.writeData(Data:TObjData):boolean; + begin + result:=false; + end; + + constructor TWasmObjOutput.create(AWriter: TObjectWriter); + begin + inherited; + cobjdata:=TWasmObjData; + end; + +{**************************************************************************** + TWasmAssembler +****************************************************************************} + + constructor TWasmAssembler.Create(info: pasminfo; smart:boolean); + begin + inherited; + CObjOutput:=TWasmObjOutput; + end; + +{***************************************************************************** + Initialize +*****************************************************************************} +{$ifdef wasm32} + const + as_wasm32_wasm_info : tasminfo = + ( + id : as_wasm32_wasm; + idtxt : 'OMF'; + asmbin : ''; + asmcmd : ''; + supported_targets : [system_wasm32_embedded,system_wasm32_wasi]; + flags : [af_outputbinary,af_smartlink_sections]; + labelprefix : '..@'; + labelmaxlen : -1; + comment : '; '; + dollarsign: '$'; + ); +{$endif wasm32} + +initialization +{$ifdef wasm32} + RegisterAssembler(as_wasm32_wasm_info,TWasmAssembler); +{$endif wasm32} +end. diff --git a/compiler/systems.inc b/compiler/systems.inc index 426275b6e7..c38320e1f6 100644 --- a/compiler/systems.inc +++ b/compiler/systems.inc @@ -268,6 +268,7 @@ ,as_wasm32_wabt ,as_wasm32_llvm_mc { WebAssembly code assembled by llvm-mc (llvm machine code playground) } ,as_arm_vasm + ,as_wasm32_wasm ); tlink = (ld_none, diff --git a/compiler/systems/i_embed.pas b/compiler/systems/i_embed.pas index 81af1f9633..864b45955c 100644 --- a/compiler/systems/i_embed.pas +++ b/compiler/systems/i_embed.pas @@ -821,7 +821,11 @@ unit i_embed; Cprefix : ''; newline : #10; dirsep : '/'; +{$ifdef WASM32_INTERNALASM} + assem : as_wasm32_wasm; +{$else WASM32_INTERNALASM} assem : as_wasm32_llvm_mc; +{$endif WASM32_INTERNALASM} assemextern : as_wasm32_llvm_mc; link : ld_none; linkextern : ld_embedded; diff --git a/compiler/systems/i_wasi.pas b/compiler/systems/i_wasi.pas index 47a1477f5f..c33dd43fac 100644 --- a/compiler/systems/i_wasi.pas +++ b/compiler/systems/i_wasi.pas @@ -77,7 +77,11 @@ unit i_wasi; Cprefix : ''; newline : #10; dirsep : '/'; +{$ifdef WASM32_INTERNALASM} + assem : as_wasm32_wasm; +{$else WASM32_INTERNALASM} assem : as_wasm32_llvm_mc; +{$endif WASM32_INTERNALASM} assemextern : as_wasm32_llvm_mc; link : ld_none; linkextern : ld_wasi; // there's no linker, only object files for WASM diff --git a/compiler/wasm32/cputarg.pas b/compiler/wasm32/cputarg.pas index c6679b619b..8692268a13 100644 --- a/compiler/wasm32/cputarg.pas +++ b/compiler/wasm32/cputarg.pas @@ -48,6 +48,7 @@ implementation ,agwat ,agbinaryen ,agllvmmc + ,ogwasm {************************************** Assembler Readers