forked from chakra-core/ChakraCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWasmCustomReader.cpp
More file actions
55 lines (44 loc) · 1.33 KB
/
WasmCustomReader.cpp
File metadata and controls
55 lines (44 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft Corporation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
#include "WasmReaderPch.h"
#ifdef ENABLE_WASM
namespace Wasm
{
WasmCustomReader::WasmCustomReader(ArenaAllocator* alloc) : m_nodes(alloc)
{
}
void WasmCustomReader::SeekToFunctionBody(class WasmFunctionInfo* funcInfo)
{
Assert(funcInfo->GetCustomReader() == this);
m_state = 0;
}
bool WasmCustomReader::IsCurrentFunctionCompleted() const
{
return m_state >= (uint32)m_nodes.Count();
}
WasmOp WasmCustomReader::ReadExpr()
{
if (m_state < (uint32)m_nodes.Count())
{
m_currentNode = m_nodes.Item(m_state++);
return m_currentNode.op;
}
return wbEnd;
}
void WasmCustomReader::FunctionEnd()
{
}
void WasmCustomReader::AddNode(WasmNode node)
{
m_nodes.Add(node);
}
uint32 WasmCustomReader::EstimateCurrentFunctionBytecodeSize() const
{
uint32 count = min((uint32)m_nodes.Count(), (uint32)AutoSystemInfo::PageSize);
// On average each node takes between 3 - 7 bytes to encode
return count * 5;
}
};
#endif