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
34 changes: 29 additions & 5 deletions src/parser/WASMComponentParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,6 @@ class WASMComponentBinaryReader : public wabt::WASMComponentBinaryReaderDelegate
ComponentTypeInfo* info = m_currentInfo;
m_current = m_currentInfo->parentComponentType;
m_currentComponent = m_currentInfo->parentComponent;
ASSERT(m_currentComponent == nullptr || m_currentComponent->type() == m_current);
m_currentInfo = m_currentInfo->parent;
delete info;
}
Expand All @@ -764,7 +763,6 @@ class WASMComponentBinaryReader : public wabt::WASMComponentBinaryReaderDelegate
ComponentTypeInfo* info = m_currentInfo;
m_current = m_currentInfo->parentComponentType;
m_currentComponent = m_currentInfo->parentComponent;
ASSERT(m_currentComponent == nullptr || m_currentComponent->type() == m_current);
m_currentInfo = m_currentInfo->parent;
delete info;
}
Expand Down Expand Up @@ -806,7 +804,7 @@ class WASMComponentBinaryReader : public wabt::WASMComponentBinaryReaderDelegate
nonstd::string_view* versionSuffix,
const ComponentExternalInfo& externalInfo)
{
if (m_currentComponent != nullptr) {
if (m_currentComponent->type() == m_current) {
m_currentComponent->pushDeclaration(new Walrus::ComponentImport(static_cast<uint32_t>(m_current->imports().size())));
}
m_current->imports().push_back(Walrus::ComponentType::External{ name.str.to_string(), pushExternalType(externalInfo), getSort(externalInfo.sort), kInvalidIndex });
Expand All @@ -823,8 +821,34 @@ class WASMComponentBinaryReader : public wabt::WASMComponentBinaryReaderDelegate
return;
}

ComponentExternalInfo info{ exportInfo->sort, ComponentExternalDesc::Unused, exportInfo->index };
m_current->exports().push_back(Walrus::ComponentType::External{ name.str.to_string(), pushExternalType(info), getSort(exportInfo->sort), exportInfo->index.index });
ASSERT(m_currentComponent->type() == m_current);
Walrus::ComponentRefCounted* type;

switch (exportInfo->sort) {
case ComponentSort::Func:
type = m_currentInfo->funcTypes[exportInfo->index.index];
m_currentInfo->funcTypes.push_back(type->asTypeFunc());
break;
case ComponentSort::Type:
type = m_current->getType(exportInfo->index.index);
type->addRef();
m_current->pushType(type);
break;
case ComponentSort::Component:
type = m_currentInfo->componentTypes[exportInfo->index.index];
m_currentInfo->componentTypes.push_back(type->asComponentType());
break;
case ComponentSort::Instance:
type = m_currentInfo->instanceTypes[exportInfo->index.index];
m_currentInfo->instanceTypes.push_back(type->asComponentType());
break;
default:
RELEASE_ASSERT_NOT_REACHED();
return;
}

type->addRef();
m_current->exports().push_back(Walrus::ComponentType::External{ name.str.to_string(), type, getSort(exportInfo->sort), exportInfo->index.index });
}

Walrus::Component* parsingResult()
Expand Down
37 changes: 37 additions & 0 deletions src/runtime/Store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,20 @@ FunctionType* Store::createDefinedFunctionType(DefinedFunctionType type)
param->setType(0, Value::Type::I32);
param->setType(1, Value::Type::I32);
break;
case I32I32I32R:
functionType = new FunctionType(3, 0, 0, 0, true, noIndex);
param = functionType->initParam();
param->setType(0, Value::Type::I32);
param->setType(1, Value::Type::I32);
param->setType(2, Value::Type::I32);
break;
case I32I64I32R:
functionType = new FunctionType(3, 0, 0, 0, true, noIndex);
param = functionType->initParam();
param->setType(0, Value::Type::I32);
param->setType(1, Value::Type::I64);
param->setType(2, Value::Type::I32);
break;
case I32I32I32I32R:
functionType = new FunctionType(4, 0, 0, 0, true, noIndex);
param = functionType->initParam();
Expand Down Expand Up @@ -260,6 +274,17 @@ FunctionType* Store::createDefinedFunctionType(DefinedFunctionType type)
param->setType(5, Value::Type::I32);
result->setType(0, Value::Type::I32);
break;
case I32I32I32I32I32I32I32R:
functionType = new FunctionType(7, 0, 0, 0, true, noIndex);
param = functionType->initParam();
param->setType(0, Value::Type::I32);
param->setType(1, Value::Type::I32);
param->setType(2, Value::Type::I32);
param->setType(3, Value::Type::I32);
param->setType(4, Value::Type::I32);
param->setType(5, Value::Type::I32);
param->setType(6, Value::Type::I32);
break;
case I32I32I32I32I64I64I32_RI32:
functionType = new FunctionType(7, 0, 1, 0, true, noIndex);
param = functionType->initParam();
Expand Down Expand Up @@ -298,6 +323,18 @@ FunctionType* Store::createDefinedFunctionType(DefinedFunctionType type)
param = functionType->initParam();
param->setType(0, Value::Type::I64);
break;
case I64_RI32:
functionType = new FunctionType(1, 0, 1, 0, true, noIndex);
param = functionType->initParam();
param->setType(0, Value::Type::I64);
result = functionType->initResult();
result->setType(0, Value::Type::I32);
break;
case RI64:
functionType = new FunctionType(0, 0, 1, 0, true, noIndex);
result = functionType->initResult();
result->setType(0, Value::Type::I64);
break;
case F32R:
functionType = new FunctionType(1, 0, 0, 0, true, noIndex);
param = functionType->initParam();
Expand Down
5 changes: 5 additions & 0 deletions src/runtime/Store.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class Store {
NONE = 0,
I32R,
I32I32R,
I32I32I32R,
I32I64I32R,
I32I32I32I32R,
I32_RI32,
I32I32_RI32,
Expand All @@ -72,10 +74,13 @@ class Store {
I32I32I32I32I32_RI32,
I32I32I32I64I32_RI32,
I32I32I32I32I32I32_RI32,
I32I32I32I32I32I32I32R,
I32I32I32I32I64I64I32_RI32,
I32I32I32I32I32I64I64I32I32_RI32,
RI32,
I64R,
I64_RI32,
RI64,
F32R,
F64R,
I32F32R,
Expand Down
9 changes: 3 additions & 6 deletions src/runtime/TypeStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,12 +379,9 @@ void TypeStore::updateTypes(Vector<CompositeType*>& types)
}
}

void TypeStore::releaseRecursiveType(RecursiveType* recType)
void TypeStore::destroyRecursiveType(RecursiveType* recType)
{
recType->m_refCount--;
if (recType->m_refCount != 0) {
return;
}
ASSERT(recType->m_refCount == 0);

if (recType->m_prev == nullptr) {
m_first = recType->m_next;
Expand Down Expand Up @@ -434,7 +431,7 @@ void TypeStore::ReleaseRef(const CompositeType** typeInfo)
ASSERT(index > 0);
RecursiveType* recType = typeInfo[index]->getRecursiveType();
if (--recType->m_refCount == 0) {
recType->m_typeStore->releaseRecursiveType(recType);
recType->m_typeStore->destroyRecursiveType(recType);
}
}

Expand Down
9 changes: 8 additions & 1 deletion src/runtime/TypeStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,14 @@ class TypeStore {
#endif

static const CompositeType** updateRefs(CompositeType* type, const Vector<CompositeType*>& types, const CompositeType** nextSubType);
void releaseRecursiveType(RecursiveType* recType);
void destroyRecursiveType(RecursiveType* recType);

void releaseRecursiveType(RecursiveType* recType)
{
if (--recType->m_refCount == 0) {
destroyRecursiveType(recType);
}
}

#ifdef ENABLE_GC
void insertRootRef(GCBase* object);
Expand Down
2 changes: 1 addition & 1 deletion src/shell/Shell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ static Trap::TrapResult executeWASMComponent(Store* store, const std::string& fi
RunData* data = reinterpret_cast<RunData*>(d);
ComponentInstance* instance = ComponentInstance::instantiate(state, data->store, data->component);
for (auto& it : instance->type()->exports()) {
if (it.sort == ComponentSort::Instance && it.name == "wasi:cli/run@0.2.6") {
if (it.sort == ComponentSort::Instance && it.name.length() >= 17 && memcmp(it.name.data(), "wasi:cli/run@0.2.", 17) == 0) {
instance = instance->getInstance(it.exportIndex);
break;
}
Expand Down
Loading
Loading