Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
321 changes: 321 additions & 0 deletions src/parser/WASMComponentParser.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,321 @@
/*
* Copyright (c) 2022-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"

#include "parser/WASMComponentParser.h"
#include "runtime/Store.h"
#include "runtime/TypeStore.h"

#include "wabt/binary-reader.h"
#include "wabt/walrus/binary-reader-walrus.h"

namespace wabt {

class WASMComponentBinaryReader : public wabt::WASMComponentBinaryReaderDelegate {
private:
Walrus::TypeStore& m_typeStore;

public:
WASMComponentBinaryReader(Walrus::TypeStore& typeStore)
: m_typeStore(typeStore)
{
}

void OnCoreModule(const void* data,
size_t size,
const ReadBinaryOptions& options)
{
}

void BeginComponent(uint32_t version, size_t depth)
{
}

void EndComponent()
{
}

void BeginCoreInstance(Index module_index,
uint32_t argument_count)
{
}

void OnCoreInstanceArg(const ComponentStringLoc& name,
ComponentSort sort,
Index index)
{
}

void EndCoreInstance()
{
}

void BeginInlineCoreInstance(uint32_t argument_count)
{
}

void OnInlineCoreInstanceArg(const ComponentStringLoc& name,
ComponentSort sort,
Index index)
{
}

void EndInlineCoreInstance()
{
}

void BeginInstance(Index component_index,
uint32_t argument_count)
{
}

void OnInstanceArg(const ComponentStringLoc& name,
ComponentSort sort,
Index index)
{
}

void EndInstance()
{
}

void BeginInlineInstance(uint32_t argument_count)
{
}

void OnInlineInstanceArg(const ComponentStringLoc& name,
nonstd::string_view* version_suffix,
ComponentSort sort,
Index index)
{
}

void EndInlineInstance()
{
}

void OnAliasExport(ComponentSort sort,
Index instance_index,
const ComponentStringLoc& name)
{
}

void OnAliasCoreExport(ComponentSort sort,
Index core_instance_index,
const ComponentStringLoc& name)
{
}

void OnAliasOuter(ComponentSort sort,
uint32_t counter,
uint32_t index)
{
}

void OnPrimitiveType(const ComponentType& type)
{
}

void BeginRecordType(uint32_t field_count)
{
}

void OnRecordField(const ComponentStringLoc& field_name,
const ComponentType& field_type)
{
}

void EndRecordType()
{
}

void BeginVariantType(uint32_t case_count)
{
}

void OnVariantCase(const ComponentStringLoc& case_name,
const ComponentType& case_type)
{
}

void EndVariantType()
{
}

void OnListType(const ComponentType& type)
{
}

void OnListFixedType(const ComponentType& type,
uint32_t size)
{
}

void BeginTupleType(uint32_t item_count)
{
}

void OnTupleItem(const ComponentType& item)
{
}

void EndTupleType()
{
}

void BeginFlagsType(uint32_t label_count)
{
}

void OnFlagsLabel(const ComponentStringLoc& label)
{
}

void EndFlagsType()
{
}

void BeginEnumType(uint32_t label_count)
{
}

void OnEnumLabel(const ComponentStringLoc& label)
{
}

void EndEnumType()
{
}

void OnOptionType(const ComponentType& type)
{
}

void OnResultType(const ComponentType& result_type,
const ComponentType& error_type)
{
}

void OnOwnType(Index index)
{
}

void OnBorrowType(Index index)
{
}

void OnStreamType(const ComponentType& type)
{
}

void OnFutureType(const ComponentType& type)
{
}

void BeginFuncType(ComponentTypeDef type,
uint32_t param_count)
{
}

void OnFuncParam(ComponentStringLoc name,
const ComponentType& type)
{
}

void OnFuncResult(const ComponentType& type)
{
}

void EndFuncType()
{
}

void OnResourceType(ComponentResourceRep rep,
Index dtor)
{
}

void OnResourceAsyncType(ComponentResourceRep rep,
Index dtor,
Index callback)
{
}

void BeginInstanceType(uint32_t count)
{
}

void EndInstanceType()
{
}

void BeginComponentType(uint32_t count)
{
}

void EndComponentType()
{
}

void OnCanonLift(Index core_func_index,
uint32_t option_count,
ComponentCanonOption* options,
Index type_index)
{
}

void OnCanonLower(Index func_index,
uint32_t option_count,
ComponentCanonOption* options)
{
}

void OnCanonType(ComponentCanon canon,
Index type_index)
{
}

void OnImport(const ComponentStringLoc& name,
nonstd::string_view* version_suffix,
const ComponentExternalInfo& external_info)
{
}

void OnExport(const ComponentStringLoc& name,
nonstd::string_view* version_suffix,
ComponentExternalInfo* external_info,
ComponentExportInfo* export_info)
{
}
};

} // namespace wabt

namespace Walrus {

std::pair<Optional<Component*>, std::string> WASMComponentParser::parseBinary(Store* store, const std::string& filename, const uint8_t* data, size_t len, const uint32_t JITFlags, const uint32_t featureFlags)
{
wabt::WASMComponentBinaryReader delegate(store->getTypeStore());

std::string error = ReadWasmComponentBinary(filename, data, len, &delegate, featureFlags);
if (error.length()) {
return std::make_pair(nullptr, error);
}

return std::make_pair(nullptr, std::string());
}

} // namespace Walrus
32 changes: 32 additions & 0 deletions src/parser/WASMComponentParser.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2022-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.
*/

#ifndef __WalrusWASMComponentParser__
#define __WalrusWASMComponentParser__

#include "runtime/Component.h"

namespace Walrus {

class WASMComponentParser {
public:
// returns <result, error>
static std::pair<Optional<Component*>, std::string> parseBinary(Store* store, const std::string& filename, const uint8_t* data, size_t len, const uint32_t JITFlags = 0, const uint32_t featureFlags = 0);
};

} // namespace Walrus

#endif // __WalrusParser__
6 changes: 3 additions & 3 deletions src/parser/WASMParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ class WASMBinaryReader : public wabt::WASMBinaryReaderDelegate {
size_t* m_readerOffsetPointer;
const uint8_t* m_readerDataPointer;
size_t m_codeEndOffset;
Walrus::TypeStore& typeStore;
Walrus::TypeStore& m_typeStore;

struct PreprocessData {
struct LocalVariableInfo {
Expand Down Expand Up @@ -864,7 +864,7 @@ class WASMBinaryReader : public wabt::WASMBinaryReaderDelegate {
: m_readerOffsetPointer(nullptr)
, m_readerDataPointer(nullptr)
, m_codeEndOffset(0)
, typeStore(typeStore)
, m_typeStore(typeStore)
, m_inInitExpr(false)
, m_currentFunction(nullptr)
, m_currentFunctionType(nullptr)
Expand Down Expand Up @@ -1013,7 +1013,7 @@ class WASMBinaryReader : public wabt::WASMBinaryReaderDelegate {
virtual void EndTypeSection() override
{
m_result.m_typesAddedToStore = true;
typeStore.updateTypes(m_result.m_compositeTypes);
m_typeStore.updateTypes(m_result.m_compositeTypes);
}

virtual void OnImportCount(Index count) override
Expand Down
2 changes: 1 addition & 1 deletion src/parser/WASMParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@ class WASMParser {

} // namespace Walrus

#endif // __WalrusParser__
#endif // __WalrusWASMParser__
Loading
Loading