Skip to content

WIP: Remove binaryen for codegen #20

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

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ GPUCompiler = "61eb1bfa-7361-4325-ad38-22787b887f55"
NodeCall = "84d67a5e-1aa2-4817-a501-81e0ebf70bff"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
Unrolled = "9602ed7d-8fef-5bc8-8597-8f21381861e8"
WasmCompiler = "d6c8c267-1a52-47cb-afc2-bc072b58c422"
libjlnode_jll = "e3ef64f0-f261-50ad-b884-29c8a26457f8"
libnode_jll = "76d26698-d9ba-5ca1-ae24-4ac9393d02a0"

Expand All @@ -22,7 +23,7 @@ CodeInfoTools = "0.3"
CompTime = "0.1"
Dictionaries = "0.3"
GPUCompiler = "0.24"
NodeCall = "1.1"
NodeCall = "1.1"
Reexport = "1.2"
Unrolled = "0.1"
julia = "1.7"
Expand Down
1 change: 1 addition & 0 deletions src/WebAssemblyCompiler.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module WebAssemblyCompiler

using Binaryen_jll
using WasmCompiler

include("../lib/LibBinaryen.jl")
using .LibBinaryen
Expand Down
28 changes: 12 additions & 16 deletions src/_compile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,26 @@ function _compile(ctx::CompilerContext, x::Core.Argument; kw...)
end
# If at the top level or if it's not a callable struct,
# we don't include the fun as the first argument.
BinaryenLocalGet(ctx.mod, argmap(ctx, x.n) - 1,
gettype(ctx, type))
WasmCompiler.InstOperands(WasmCompiler.local_get(argmap(ctx, x.n)), [])
end
function _compile(ctx::CompilerContext, x::Core.SSAValue; kw...) # These come after the function arguments.
bt = basetype(ctx, x)
if Base.issingletontype(bt)
getglobal(ctx, _compile(ctx, nothing))
else
BinaryenLocalGet(ctx.mod, ctx.varmap[x.id],
gettype(ctx, ssatype(ctx, x.id)))
InstOperands(WC.local_get(ctx.varmap[x.id]), [])
end
# localid = ctx.varmap[x.id]
# BinaryenLocalGet(ctx.mod, localid, ctx.locals[localid])
end
_compile(ctx::CompilerContext, x::Float64; kw...) = BinaryenConst(ctx.mod, BinaryenLiteralFloat64(x))
_compile(ctx::CompilerContext, x::Float32; kw...) = BinaryenConst(ctx.mod, BinaryenLiteralFloat32(x))
_compile(ctx::CompilerContext, x::Int64; kw...) = BinaryenConst(ctx.mod, BinaryenLiteralInt64(x))
_compile(ctx::CompilerContext, x::Int32; kw...) = BinaryenConst(ctx.mod, BinaryenLiteralInt32(x))
_compile(ctx::CompilerContext, x::UInt8; kw...) = BinaryenConst(ctx.mod, BinaryenLiteralInt32(x))
_compile(ctx::CompilerContext, x::Int8; kw...) = BinaryenConst(ctx.mod, BinaryenLiteralInt32(x))
_compile(ctx::CompilerContext, x::UInt64; kw...) = BinaryenConst(ctx.mod, BinaryenLiteralInt64(reinterpret(Int64, x)))
_compile(ctx::CompilerContext, x::UInt32; kw...) = BinaryenConst(ctx.mod, BinaryenLiteralInt32(reinterpret(Int32, x)))
_compile(ctx::CompilerContext, x::Bool; kw...) = BinaryenConst(ctx.mod, BinaryenLiteralInt32(x))
_compile(ctx::CompilerContext, x::Ptr{BinaryenExpression}; kw...) = x
_compile(ctx::CompilerContext, x::Float64; kw...) = InstOperands(WC.f64_const(x), [])
_compile(ctx::CompilerContext, x::Float32; kw...) = InstOperands(WC.f32_const(x), [])
_compile(ctx::CompilerContext, x::Int64; kw...) = InstOperands(WC.i64_const(x), [])
_compile(ctx::CompilerContext, x::Int32; kw...) = InstOperands(WC.i32_const(x), [])
_compile(ctx::CompilerContext, x::UInt8; kw...) = InstOperands(WC.i32_const(x), [])
_compile(ctx::CompilerContext, x::Int8; kw...) = InstOperands(WC.i32_const(x), [])
_compile(ctx::CompilerContext, x::UInt64; kw...) = InstOperands(WC.i64_const(reinterpret(Int64, x)), [])
_compile(ctx::CompilerContext, x::UInt32; kw...) = InstOperands(WC.i32_const(reinterpret(Int32, x)), [])
_compile(ctx::CompilerContext, x::Bool; kw...) = InstOperands(WC.i32_const(x), [])
# _compile(ctx::CompilerContext, x::Ptr{BinaryenExpression}; kw...) = x
_compile(ctx::CompilerContext, x::GlobalRef; kw...) = getglobal(ctx, x.mod, x.name)
_compile(ctx::CompilerContext, x::QuoteNode; kw...) = _compile(ctx, x.value)
# _compile(ctx::CompilerContext, x::String; globals = false, kw...) = globals ?
Expand Down
Loading
Loading