-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
stage2: add a wasm backend #6056
Conversation
This function should be modified to accept an (optional?) ObjectFormat parameter, and it should also be improved to take into account architecture. Wait, is that how it works though? Wasm uses the same extension for both objects and executables? I thought wasm objects were still Lines 1047 to 1049 in c12a262
Called here: Line 79 in c12a262
This C logic should be removed in favor of making Lines 474 to 477 in c12a262
|
src-self-hosted/link/Wasm.zig
Outdated
// TODO: updateDeclExports() may currently be called before updateDecl, | ||
// presumably due to a bug. For now just rely on the following call | ||
// being made in updateDecl(). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll look into this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is the only change that needs to happen regarding this:
diff --git a/src-self-hosted/link.zig b/src-self-hosted/link.zig
index a835cc6b7..e89210763 100644
--- a/src-self-hosted/link.zig
+++ b/src-self-hosted/link.zig
@@ -186,7 +186,8 @@ pub const File = struct {
};
}
- /// Must be called only after a successful call to `updateDecl`.
+ /// Can be called any time before or after the call to `updateDecl`. Same
+ /// with `allocateDeclIndexes`.
pub fn updateDeclExports(
base: *File,
module: *Module,
Happy to discuss other possible ways of doing things
Discovered a design flaw with regards to incremental compilation. On "freeing" a function decl we immediately mark both the function itself and the corresponding type in the types section as "dead." This breaks down however if the type is overwritten and reused before the function is erased from the binary as this may cause a type mismatch. One way to solve this would be to keep the type corresponding to each function "alive" until the function is overwritten. |
b36c75d
to
f419ae1
Compare
Thus far, we only generate the type, function, export, and code sections. These are sufficient to generate and export simple functions. Codegen is currently hardcoded to `i32.const 42`, the main goal of this commit is to create infrastructure for the container format which will work with incremental compilation.
We now generate code for returning constants of any of the basic types.
Exports now have a dirty flag and are rewritten on flush if this flag has been set. A couple other minor changes have been made based on Andrew's review.
Functions which are free'd are not immediately removed from the binary as this would cause a shifting of function indexes. Instead, they hang around until they can be overwritten by a new function. This means that the types associated with these dead functions must also remain until the function is overwritten to avoid a type mismatch.
I think this is ready to merge. The last remaining checkbox is orthogonal to these additions and could easily be done in another PR |
, | ||
// This is what you get when you take the bits of the IEE-754 | ||
// representation of 42.0 and reinterpret them as an unsigned | ||
// integer. Guess that's a bug in wasmtime. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if it's a bug: at least in wasi the main/start function always returns int
@@ -150,6 +150,7 @@ const usage_build_generic = | |||
\\ -ofmt=[mode] Override target object format | |||
\\ elf Executable and Linking Format | |||
\\ c Compile to C source code | |||
\\ wasm WebAssembly |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe (planned) / (alpha) would be appropriate here
Thus far, we only generate the type, function, export, and code
sections. These are sufficient to generate and export simple functions.
TODO:
.o
extension even with-ofmt=wasm