Commit Graph

174 Commits

Author SHA1 Message Date
Nikolay Nikolov
8cd6606970 + support nil comparison of WebAssembly reference types (externref and funcref) 2023-06-11 07:17:04 +03:00
Nikolay Nikolov
9daabb2123 + support using nil constants for setting values of WebAssembly reference types (funcref and externref) 2023-06-11 06:23:02 +03:00
Nikolay Nikolov
11712658b0 + implemented WebAssembly code generator support for funcref and externref data
types, using new register types R_FUNCREFREGISTER and R_EXTERNREFREGISTER
2023-06-07 05:25:57 +03:00
Nikolay Nikolov
f32ef29253 * WebAssembly high level code generator: use the global.get and global.set
instructions to access references to symbols of type AT_WASM_GLOBAL
2022-07-26 02:13:09 +03:00
Nikolay Nikolov
4db653998b + generate proper WebAssembly threadvar access when multithreading is turned on 2022-07-14 02:39:07 +03:00
Nikolay Nikolov
9b16fafc52 + generate exception checks after calls to fpc_overflow class in WebAssembly
branchful exceptions mode, because fpc_overflow can raise an exception in case
  unit SysUtils is included.
2022-06-22 03:21:21 +03:00
Nikolay Nikolov
b11434a6f8 + WebAssembly: use the 64-bit div instruction, instead of an RTL helper for 64-bit division 2022-06-22 01:10:02 +03:00
Nikolay Nikolov
e74797d411 * replaced several internal errors, related to the WebAssembly labels
resolution with more meaningful error messages, in order to ease the
  debugging of the compiler. Based on patch by Pierre.
2022-05-24 11:44:15 +03:00
Nikolay Nikolov
6e4e3b8580 * fixed WebAssembly code generation in thlcgwasm.g_overflowCheck_loc (patch by Pierre) 2022-05-24 11:06:59 +03:00
Nikolay Nikolov
8bea5dd41e * WebAssembly code generation fix in thlcgwasm.a_op_reg_reg_reg_checkoverflow, based on patch by Pierre (but simplified, to use a single block) 2022-05-24 11:00:10 +03:00
Pierre Muller
be969205ad Do not alloc/dealloc NR_DEFAULTFLAGS for wasm32, as it is NR_NO 2022-05-17 22:47:13 +02:00
Nikolay Nikolov
c4f9ec91c9 + fix support for 8-byte records, held in a register pair on the WebAssembly target. This fixes #39524 2022-01-25 13:03:35 +02:00
J. Gareth "Curious Kit" Moreton
2dc0995067 - Bug fix to new ADD/SUB optimisation where conditions are concerned
- Register allocation fixes for overflow checks
2021-11-17 20:18:57 +00:00
Nikolay Nikolov
12a2c56461 - removed thlcgwasm.incblock, .decblock and br_blocks, as branching is now done
entirely with labels
2021-10-22 17:42:29 +03:00
Nikolay Nikolov
3094f75690 * WebAssembly code generation for 'case' nodes changed to use labels 2021-10-22 17:31:04 +03:00
Nikolay Nikolov
6fe647ee3d * moved the default procedure CurrRaiseLabel to the end of the procedure, not
at the exit label. This fixes problems when using units with finalization
  code that contain classes with class destructors in branchful WebAssembly
  exceptions mode.
2021-10-22 13:54:55 +03:00
Nikolay Nikolov
5a0956d805 * use WebAssembly asm labels for the raise branch instruction in branchful
exceptions mode
2021-10-22 13:54:55 +03:00
Nikolay Nikolov
c96e203780 * moved the 'end_block' WebAssembly instruction before the 'exit' label right
before the procedure finalization code. This fixes compilation errors in
  procedures with implicit finalization code (e.g. for ansistring local vars,
  etc).
2021-10-20 14:35:52 +03:00
Nikolay Nikolov
1ce2fb8a4a * use WebAssembly asm labels for generating code for the 'exit' statement 2021-10-20 14:35:51 +03:00
Nikolay Nikolov
0662a0bd44 + use WebAssembly asm labels for the code generation of 'break' statements as well 2021-10-20 09:59:54 +03:00
Nikolay Nikolov
01dc62b127 + introduced the use of asm labels for WebAssembly. Resolve them in
tcpuprocinfo.postprocess_code. Use them when generating code for the
  'continue' label jumps.
2021-10-20 09:39:44 +03:00
Nikolay Nikolov
b91fc3a0d3 * fixed passing of singleton record parameters, containing a float in WebAssembly 2021-10-14 10:53:55 +03:00
Nikolay Nikolov
3c58f26e83 * thlcgwasm.g_checkexceptions renamed .g_maybe_checkforexceptions, added also as
an empty virtual method in thlcgobj and modified the WebAssembly
  implementation, so that it can be called from any exceptions mode (so it
  emits no code in exception modes that don't require it, instead of generating
  an internal error). This will allow .g_maybe_checkforexceptions to be called
  from the generic parts of the code generator, after calls to systemprocs that
  could raise an exceptions.
2021-10-05 17:54:35 +03:00
Nikolay Nikolov
7110d1e48e * use 'br_if' instead of 'if br end_if' sequence in the code, generated by
thlcgwasm.g_checkexceptions
2021-10-05 05:29:10 +03:00
Nikolay Nikolov
7afb665c92 + insert exception flag check and branch after each function call, when
compiling in WebAssembly branchful exceptions mode
2021-10-05 02:26:13 +03:00
Nikolay Nikolov
5be1bfeeca + added comment that states that raiseBr is only used in branchful exceptions mode 2021-10-05 01:11:31 +03:00
Nikolay Nikolov
d02921d66b + introduced raiseBr, similar to exitBr, but will point to the current
innermost exception handler, if there is such a handler in the current
  procedure, otherwise it will be the same as exitBr.
2021-10-05 01:07:37 +03:00
Nikolay Nikolov
5adec3ca98 + workaround for WebAssembly treating the stack parameter of the store and load
instructions as unsigned. This caused an 'out of bounds memory access' trap
  when accessing arrays with negative offset index, e.g. in test/cg/tvec.pp
2021-10-03 03:16:34 +03:00
Nikolay Nikolov
0a383d8c0f * fixed WebAssembly method pointer assignment 2021-10-03 02:27:19 +03:00
Nikolay Nikolov
cc2fa67dfa * fixed OS_S8 to OS_16 conversion for WebAssembly. This fixes test/cg/tcnvint6 2021-10-02 22:10:34 +03:00
Nikolay Nikolov
d2726c2406 * fixed WebAssembly code generation for not(cbool64) 2021-10-01 05:17:12 +03:00
Nikolay Nikolov
4fc763ac50 * fixed WebAssembly cbool support for OP_NOT 2021-10-01 04:54:17 +03:00
Nikolay Nikolov
188a21bbfd * fixed 'not(boolean64)' for WebAssembly 2021-10-01 03:01:55 +03:00
Nikolay Nikolov
812732cb6a + introduced the AT_WASM_GLOBAL asm symbol type 2021-09-27 02:52:29 +03:00
Nikolay Nikolov
d3ec8f0d29 * generate an internalerror if there are values remaining on top of stack
at the end of a procedure. If the compiler is compiled with
  DEBUG_WASMSTACK, the previous asm comment message is emitted instead of
  internal error.
2021-09-18 18:10:57 +03:00
Nikolay Nikolov
f7cc2d560c + initialize br_blocks in the thlcgwasm constructor 2021-09-18 16:29:19 +03:00
Nikolay Nikolov
a3610bfea1 + also added stack underflow check in thlcgwasm.incstack (in case stack
height was already negative in the beginning, due to previous underflow)
2021-09-18 16:28:14 +03:00
Nikolay Nikolov
d4bd1f1e9b * don't halt with an internal error, but add an asm comment instead, when a
stack underflow is detected in thlcgwasm.decstack and when the compiler is
  compiled with the DEBUG_WASMSTACK define
2021-09-18 16:28:14 +03:00
Nikolay Nikolov
58e4692795 * fixed thlcgwasm.g_adjust_stack_after_call after the removal of discardresult 2021-09-18 16:28:14 +03:00
Nikolay Nikolov
9526b939a2 + implemented thlcgwasm.g_unreachable, emits the 'unreachable' WebAssembly instruction 2021-09-17 03:41:45 +03:00
Nikolay Nikolov
3bf5b0c395 - avoid useless typecasts for accessing members in self in thlcgwasm.a_load_subsetref_regs_index 2021-09-16 15:15:39 +03:00
Nikolay Nikolov
4120825f50 + implemented thlcgwasm.a_load_regconst_subsetref_intern 2021-09-16 15:14:51 +03:00
Nikolay Nikolov
7af6e628c8 + implemented thlcgwasm.a_load_subsetref_regs_index 2021-09-16 14:30:29 +03:00
Nikolay Nikolov
c41516399b + implemented thlcgwasm.a_load_subsetref_stack 2021-09-16 12:10:43 +03:00
Nikolay Nikolov
ba9a8ab069 + added thlcgwasm.a_load_subsetref_stack, not implemented yet 2021-09-09 14:11:20 +03:00
nickysn
74bac86711 + support loading a function result (on the evaluation stack) to a register in
thlcgwasm.gen_load_cgpara_loc

git-svn-id: trunk@49449 -
2021-06-01 21:52:51 +00:00
nickysn
9fa61a6c9f - removed the discardresult proc directive
git-svn-id: trunk@49017 -
2021-03-20 01:22:43 +00:00
nickysn
ecad5e9a6c + WebAssembly implementation of g_rangecheck that uses if/endif instead of
jumps to labels (which causes internal compiler error, because they're not
  supported in WebAssembly)

git-svn-id: trunk@49000 -
2021-03-18 16:45:40 +00:00
nickysn
f0aed5d355 * fixed another WebAssembly compilation error with -CR
git-svn-id: trunk@48966 -
2021-03-14 15:06:13 +00:00
nickysn
74854eee58 * fixed WebAssembly compilation error with -CR
git-svn-id: trunk@48964 -
2021-03-14 15:03:58 +00:00