This patch adds complete support for the `sub` and `add` WebAssembly instructions for x64, and complete support for the `add` WebAssembly instruction for aarch64. This patch also refactors how the binary operations get constructed within the `VisitOperator` trait implementation. The refactor adds methods in the `CodeGenContext` to abstract all the common steps to emit binary operations, making this process less repetitive and less brittle (e.g. omitting to push the resulting value to the stack, or omitting to free registers after used). This patch also improves test coverage and refactors the filetests directory to make it easier to add tests for other instructions.
16 lines
371 B
Plaintext
16 lines
371 B
Plaintext
;;! target = "x86_64"
|
|
|
|
(module
|
|
(func (result i32)
|
|
(i32.const -1)
|
|
(i32.const -1)
|
|
(i32.sub)
|
|
)
|
|
)
|
|
;; 0: 55 push rbp
|
|
;; 1: 4889e5 mov rbp, rsp
|
|
;; 4: b8ffffffff mov eax, 0xffffffff
|
|
;; 9: 83e8ff sub eax, -1
|
|
;; c: 5d pop rbp
|
|
;; d: c3 ret
|