Exemplo n.º 1
0
Symbol parseStatement(CharacterSource* source)
{
    Symbol s = parseExpressionStatement(source);
    if (s.valid())
        return s;
    s = parseFunctionDefinitionStatement(source);
    if (s.valid())
        return s;
    s = parseVariableDefinitionStatement(source);
    if (s.valid())
        return s;
    s = parseAssignmentStatement(source);
    if (s.valid())
        return s;
    s = parseCompoundStatement(source);
    if (s.valid())
        return s;
    s = parseTypeConstructorDefinitionStatement(source);
    if (s.valid())
        return s;
    s = parseNothingStatement(source);
    if (s.valid())
        return s;
    s = parseIncrementDecrementStatement(source);
    if (s.valid())
        return s;
    s = parseConditionalStatement(source);
    if (s.valid())
        return s;
    s = parseSwitchStatement(source);
    if (s.valid())
        return s;
    s = parseReturnStatement(source);
    if (s.valid())
        return s;
    s = parseIncludeStatement(source);
    if (s.valid())
        return s;
    s = parseBreakOrContinueStatement(source);
    if (s.valid())
        return s;
    s = parseForeverStatement(source);
    if (s.valid())
        return s;
    s = parseWhileStatement(source);
    if (s.valid())
        return s;
    s = parseForStatement(source);
    if (s.valid())
        return s;
    s = parseEmitStatement(source);
    if (s.valid())
        return s;
    s = parseLabelStatement(source);
    if (s.valid())
        return s;
    s = parseGotoStatement(source);
    if (s.valid())
        return s;
    return Symbol();
}
Exemplo n.º 2
0
ContextStatement WASMFunctionParser::parseStatement(Context& context)
{
    bool hasImmediate;
    WASMOpStatement op;
    WASMOpStatementWithImmediate opWithImmediate;
    uint8_t immediate;
    READ_OP_STATEMENT_OR_FAIL(hasImmediate, op, opWithImmediate, immediate, "Cannot read the statement opcode.");
    if (!hasImmediate) {
        switch (op) {
        case WASMOpStatement::SetLocal:
            parseSetLocalStatement(context);
            break;
        case WASMOpStatement::Return:
            parseReturnStatement(context);
            break;
        case WASMOpStatement::Block:
            parseBlockStatement(context);
            break;
        case WASMOpStatement::If:
            parseIfStatement(context);
            break;
        case WASMOpStatement::IfElse:
            parseIfElseStatement(context);
            break;
        case WASMOpStatement::While:
            parseWhileStatement(context);
            break;
        case WASMOpStatement::Do:
            parseDoStatement(context);
            break;
        case WASMOpStatement::Label:
            parseLabelStatement(context);
            break;
        case WASMOpStatement::Break:
            parseBreakStatement(context);
            break;
        case WASMOpStatement::BreakLabel:
            parseBreakLabelStatement(context);
            break;
        case WASMOpStatement::Continue:
            parseContinueStatement(context);
            break;
        case WASMOpStatement::ContinueLabel:
            parseContinueLabelStatement(context);
            break;
        case WASMOpStatement::Switch:
            parseSwitchStatement(context);
            break;
        case WASMOpStatement::SetGlobal:
        case WASMOpStatement::I32Store8:
        case WASMOpStatement::I32StoreWithOffset8:
        case WASMOpStatement::I32Store16:
        case WASMOpStatement::I32StoreWithOffset16:
        case WASMOpStatement::I32Store32:
        case WASMOpStatement::I32StoreWithOffset32:
        case WASMOpStatement::F32Store:
        case WASMOpStatement::F32StoreWithOffset:
        case WASMOpStatement::F64Store:
        case WASMOpStatement::F64StoreWithOffset:
        case WASMOpStatement::CallInternal:
        case WASMOpStatement::CallIndirect:
        case WASMOpStatement::CallImport:
            // FIXME: Implement these instructions.
            FAIL_WITH_MESSAGE("Unsupported instruction.");
        default:
            ASSERT_NOT_REACHED();
        }
    } else {
        switch (opWithImmediate) {
        case WASMOpStatementWithImmediate::SetLocal:
            parseSetLocalStatement(context, immediate);
            break;
        case WASMOpStatementWithImmediate::SetGlobal:
            // FIXME: Implement this instruction.
            FAIL_WITH_MESSAGE("Unsupported instruction.");
        default:
            ASSERT_NOT_REACHED();
        }
    }
    return UNUSED;
}