Bug 148934 - Implement control flow statements in WebAssembly
Summary: Implement control flow statements in WebAssembly
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks: 146064
  Show dependency treegraph
 
Reported: 2015-09-07 10:53 PDT by Sukolsak Sakshuwong
Modified: 2015-09-08 16:05 PDT (History)
6 users (show)

See Also:


Attachments
Patch (19.61 KB, patch)
2015-09-07 10:58 PDT, Sukolsak Sakshuwong
no flags Details | Formatted Diff | Diff
Patch (19.63 KB, patch)
2015-09-07 11:10 PDT, Sukolsak Sakshuwong
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Sukolsak Sakshuwong 2015-09-07 10:53:27 PDT
This patch implements if, while, do, label, break, and continue statements in WebAssembly. Switches will be implemented in a subsequent patch.
Comment 1 Sukolsak Sakshuwong 2015-09-07 10:58:52 PDT
Created attachment 260741 [details]
Patch
Comment 2 Sukolsak Sakshuwong 2015-09-07 11:10:12 PDT
Created attachment 260742 [details]
Patch
Comment 3 Sukolsak Sakshuwong 2015-09-08 07:27:02 PDT
When we implement an LLVM IR generator for WebAssembly, JumpTarget will be just an LLVM Basic Block. The code will look like this:

typedef LBasicBlock JumpTarget;

LBasicBlock newTarget()
{
    return m_out.newBlock();
}

void linkTarget(LBasicBlock target)
{
    m_out.jump(target);
    m_out.appendTo(target);
}
    
void jumpToTarget(LBasicBlock target)
{
    m_out.jump(target);
}
    
void jumpToTargetIf(JumpCondition condition, LValue expression, LBasicBlock target)
{
    LBasicBlock notTaken = m_out.newBlock();
    m_out.branch((condition == JumpCondition::Zero) ? m_out.isZero32(expression) : m_out.notZero32(expression), FTL::unsure(target), FTL::unsure(notTaken));
    m_out.appendTo(notTaken);
}
Comment 4 Geoffrey Garen 2015-09-08 11:13:19 PDT
Comment on attachment 260742 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=260742&action=review

r=me

> Source/JavaScriptCore/wasm/WASMFunctionCompiler.h:407
> +    void endLabel()
> +    {
> +        linkTarget(m_breakLabelTargets.last());
> +
> +        m_breakLabelTargets.removeLast();
> +        m_continueLabelTargets.removeLast();
> +    }

Is it guaranteed that WASM can't have arbitrary gotos? (An arbitrary goto would make the push/pop model of labels invalid.)
Comment 5 Sukolsak Sakshuwong 2015-09-08 11:36:15 PDT
Thanks!

(In reply to comment #4)
> Comment on attachment 260742 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=260742&action=review
> 
> r=me
> 
> > Source/JavaScriptCore/wasm/WASMFunctionCompiler.h:407
> > +    void endLabel()
> > +    {
> > +        linkTarget(m_breakLabelTargets.last());
> > +
> > +        m_breakLabelTargets.removeLast();
> > +        m_continueLabelTargets.removeLast();
> > +    }
> 
> Is it guaranteed that WASM can't have arbitrary gotos? (An arbitrary goto
> would make the push/pop model of labels invalid.)

goto is not part of the MVP, but it is under consideration for a future version. <https://github.com/WebAssembly/design/blob/master/FutureFeatures.md#more-expressive-control-flow> The WASM format that we are using doesn't have goto.
Comment 6 WebKit Commit Bot 2015-09-08 16:05:08 PDT
Comment on attachment 260742 [details]
Patch

Clearing flags on attachment: 260742

Committed r189514: <http://trac.webkit.org/changeset/189514>
Comment 7 WebKit Commit Bot 2015-09-08 16:05:12 PDT
All reviewed patches have been landed.  Closing bug.