Coverage Report

Created: 2026-02-14 08:01

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/serenity/Userland/Libraries/LibWasm/AbstractMachine/Configuration.h
Line
Count
Source
1
/*
2
 * Copyright (c) 2021, Ali Mohammad Pur <mpfard@serenityos.org>
3
 *
4
 * SPDX-License-Identifier: BSD-2-Clause
5
 */
6
7
#pragma once
8
9
#include <LibWasm/AbstractMachine/AbstractMachine.h>
10
11
namespace Wasm {
12
13
class Configuration {
14
public:
15
    explicit Configuration(Store& store)
16
0
        : m_store(store)
17
0
    {
18
0
    }
19
20
    void set_frame(Frame frame)
21
0
    {
22
0
        Label label(frame.arity(), frame.expression().instructions().size(), m_value_stack.size());
23
0
        frame.label_index() = m_label_stack.size();
24
0
        m_frame_stack.append(move(frame));
25
0
        m_label_stack.append(label);
26
0
    }
27
0
    ALWAYS_INLINE auto& frame() const { return m_frame_stack.last(); }
28
0
    ALWAYS_INLINE auto& frame() { return m_frame_stack.last(); }
29
0
    ALWAYS_INLINE auto& ip() const { return m_ip; }
30
0
    ALWAYS_INLINE auto& ip() { return m_ip; }
31
0
    ALWAYS_INLINE auto& depth() const { return m_depth; }
32
0
    ALWAYS_INLINE auto& depth() { return m_depth; }
33
0
    ALWAYS_INLINE auto& value_stack() const { return m_value_stack; }
34
0
    ALWAYS_INLINE auto& value_stack() { return m_value_stack; }
35
0
    ALWAYS_INLINE auto& label_stack() const { return m_label_stack; }
36
0
    ALWAYS_INLINE auto& label_stack() { return m_label_stack; }
37
0
    ALWAYS_INLINE auto& store() const { return m_store; }
38
0
    ALWAYS_INLINE auto& store() { return m_store; }
39
40
    struct CallFrameHandle {
41
        explicit CallFrameHandle(Configuration& configuration)
42
0
            : ip(configuration.ip())
43
0
            , configuration(configuration)
44
0
        {
45
0
            configuration.depth()++;
46
0
        }
47
48
        ~CallFrameHandle()
49
0
        {
50
0
            configuration.unwind({}, *this);
51
0
        }
52
53
        InstructionPointer ip { 0 };
54
        Configuration& configuration;
55
    };
56
57
    void unwind(Badge<CallFrameHandle>, CallFrameHandle const&);
58
    Result call(Interpreter&, FunctionAddress, Vector<Value> arguments);
59
    Result execute(Interpreter&);
60
61
0
    void enable_instruction_count_limit() { m_should_limit_instruction_count = true; }
62
0
    bool should_limit_instruction_count() const { return m_should_limit_instruction_count; }
63
64
    void dump_stack();
65
66
private:
67
    Store& m_store;
68
    Vector<Value> m_value_stack;
69
    Vector<Label> m_label_stack;
70
    Vector<Frame> m_frame_stack;
71
    size_t m_depth { 0 };
72
    InstructionPointer m_ip;
73
    bool m_should_limit_instruction_count { false };
74
};
75
76
}