New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
wasm: implement inline assembly #19686
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…wasm-inline-asm
Great work! |
sibkod
pushed a commit
to sibkod/v
that referenced
this pull request
Oct 30, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR implements support for inline assembly inside the
wasm
backend. This also allows removal of all__builtins
present in the standard library, replacing them withvwasm_*
functions instead, implemented with inline assembly. Compile time conditional compilation is also implemented, as well as somev fmt
changes.This PR touches the following modules:
import wasm
- Minor fixes.import v.gen.wasm
- Implementation.import v.pref
-wasm
arch changes.import v.parser
- Parsing wasm inasm
blocks.import v.fmt
- Proper formatting for arch string.import builtin
- Removewasm
builtins, and replace with inline assembly.🤖 Generated by Copilot at eb1eb54
This pull request adds support for compiling V code to WebAssembly (wasm) as a target operating system. It refactors the wasm memory management functions, improves the wasm code generation and error handling, adds support for inline assembly and comptime evaluation for wasm, and adds tests for the wasm features. It modifies the files
vlib/builtin/wasm/builtin.v
,vlib/v/gen/wasm/gen.v
,vlib/v/parser/parser.v
,vlib/v/pref/pref.v
,vlib/wasm/instructions.v
, andvlib/v/ast/ast.v
, and adds the filesvlib/builtin/wasm/alloc.v
,vlib/v/gen/wasm/mem.v
,vlib/v/fmt/asm.v
,vlib/v/gen/wasm/comptime.v
, andvlib/v/gen/wasm/tests/*.vv*
.🤖 Generated by Copilot at eb1eb54
builtin.v
intobuiltin.v
andalloc.v
and implement memory allocation and manipulation functions for wasm using inline assembly (link, link, link, link, link, link)wasm32
case togen_asm
method and format assembly statements withwasm
literal for wasm architecture (link, link)comptime.v
file and define functions for comptime evaluation of conditional expressions for wasm using$if
directives (link)v_error
method to exit with code 1 instead of returning and remove unused code for output modes for wasm (link, link)__heap_base
global withhp
method that returns heap base global index usingwasm
module and create global if needed (link, link)comptime_if_expr
method for wasm (link)ast.AsmStmt
and callasm_stmt
method for wasm ingen_stmt
method (link)ast.mktyp
innew_global
method to ensure valid type (link)tee
method to copy value from stack to variable for inline assembly (link)asm.vv
file andasm.vv.out
file to test inline assembly feature for wasm with various arithmetic, memory, and conversion operations (link, link)builtin.vv
file andbuiltin.vv.out
file (link, link)comptime.vv
file andcomptime.vv.out
file to test comptime evaluation of conditional expressions for wasm (link, link)wasm32
and addwasm
as valid option in error message inparse_asm_stmt
method (link, link)select
andreturn
as v keywords that are also wasm instructions and append them to instruction name inparse_asm_stmt
method (link)const
and append it to name inparse_asm_stmt
method (link)parse_asm_stmt
method (link)wasm32
architecture inparse_asm_stmt
method (link)wasm
andwasm32
inparse_target_os
andos_from_str
methods and setcompile_defines
andarch
fields accordingly (link, link)sign_extend32_i64
method tosign_extend32
to match wasm instruction name and addis_signed
parameter tocast_trapping
method and use different instructions depending on parameter (link, link)