Skip to content

Commit

Permalink
Implement base for Walrus WASI
Browse files Browse the repository at this point in the history
Implement basic structure of wasi functions and also update test runner
to run wasi tests with the 'wasi' argument.

Signed-off-by: Adam Laszlo Kulcsar <[email protected]>
  • Loading branch information
kulcsaradam committed Aug 21, 2023
1 parent ca928c3 commit 7144b48
Show file tree
Hide file tree
Showing 7 changed files with 333 additions and 127 deletions.
132 changes: 132 additions & 0 deletions src/runtime/SpecTest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/*
* Copyright (c) 2023-present Samsung Electronics Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "Walrus.h"

namespace Walrus {

class SpecTestFunctionTypes {
MAKE_STACK_ALLOCATED();

public:
enum Index : uint8_t {
// The R is meant to represent the results, after R are the result types.
NONE = 0,
I32R,
RI32,
I64R,
F32R,
F64R,
I32F32R,
F64F64R,
INVALID,
INDEX_NUM,
};

SpecTestFunctionTypes()
{
m_vector.reserve(INDEX_NUM);
size_t index = 0;

ValueTypeVector* param;
ValueTypeVector* result;

{
// NONE
param = new ValueTypeVector();
result = new ValueTypeVector();
m_vector[index++] = new FunctionType(param, result);
}
{
// I32R
param = new ValueTypeVector();
result = new ValueTypeVector();
param->push_back(Value::Type::I32);
m_vector[index++] = new FunctionType(param, result);
}
{
// RI32
param = new ValueTypeVector();
result = new ValueTypeVector();
result->push_back(Value::Type::I32);
m_vector[index++] = new FunctionType(param, result);
}
{
// I64
param = new ValueTypeVector();
result = new ValueTypeVector();
param->push_back(Value::Type::I64);
m_vector[index++] = new FunctionType(param, result);
}
{
// F32
param = new ValueTypeVector();
result = new ValueTypeVector();
param->push_back(Value::Type::F32);
m_vector[index++] = new FunctionType(param, result);
}
{
// F64
param = new ValueTypeVector();
result = new ValueTypeVector();
param->push_back(Value::Type::F64);
m_vector[index++] = new FunctionType(param, result);
}
{
// I32F32
param = new ValueTypeVector();
result = new ValueTypeVector();
param->push_back(Value::Type::I32);
param->push_back(Value::Type::F32);
m_vector[index++] = new FunctionType(param, result);
}
{
// F64F64
param = new ValueTypeVector();
result = new ValueTypeVector();
param->push_back(Value::Type::F64);
param->push_back(Value::Type::F64);
m_vector[index++] = new FunctionType(param, result);
}
{
// INVALID
param = new ValueTypeVector();
result = new ValueTypeVector();
param->push_back(Value::Type::Void);
m_vector[index++] = new FunctionType(param, result);
}

ASSERT(index == INDEX_NUM);
}

~SpecTestFunctionTypes()
{
for (size_t i = 0; i < m_vector.size(); i++) {
delete m_vector[i];
}
}

FunctionType* operator[](const size_t idx)
{
ASSERT(idx < m_vector.size());
return m_vector[idx];
}

private:
FunctionTypeVector m_vector;
};

} // namespace Walrus
Loading

0 comments on commit 7144b48

Please sign in to comment.