Skip to content

Commit 63293cf

Browse files
zherczegksh8281
authored andcommitted
Create a separate type vector
The new type vector uses bytes for generic types. Signed-off-by: Zoltan Herczeg [email protected]
1 parent 41278ce commit 63293cf

20 files changed

+476
-264
lines changed

src/api/wasm.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ static void FromWalrusValueTypes(const TypeVector& types, wasm_valtype_vec_t* ou
505505
{
506506
wasm_valtype_vec_new_uninitialized(out, types.size());
507507
for (size_t i = 0; i < types.size(); i++) {
508-
out->data[i] = wasm_valtype_new(FromWalrusValueType(types[i]));
508+
out->data[i] = wasm_valtype_new(FromWalrusValueType(types.types()[i]));
509509
}
510510
}
511511

@@ -903,16 +903,14 @@ own wasm_module_t* wasm_module_deserialize(wasm_store_t*, const wasm_byte_vec_t*
903903
// Function Instances
904904
static FunctionType* ToWalrusFunctionType(const wasm_functype_t* ft)
905905
{
906-
TypeVector* params = new TypeVector();
907-
TypeVector* results = new TypeVector();
908-
params->reserve(ft->params.size);
909-
results->reserve(ft->results.size);
906+
TypeVector* params = new TypeVector(ft->params.size, 0);
907+
TypeVector* results = new TypeVector(ft->results.size, 0);
910908

911909
for (uint32_t i = 0; i < ft->params.size; i++) {
912-
params->push_back(ft->params.data[i]->type);
910+
params->setType(i, ft->params.data[i]->type);
913911
}
914912
for (uint32_t i = 0; i < ft->results.size; i++) {
915-
results->push_back(ft->results.data[i]->type);
913+
results->setType(i, ft->results.data[i]->type);
916914
}
917915

918916
return new FunctionType(params, results);

src/interpreter/Interpreter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2223,7 +2223,7 @@ ByteCodeStackOffset* Interpreter::interpret(ExecutionState& state,
22232223
userExceptionData.resizeWithUninitializedValues(sz);
22242224

22252225
uint8_t* ptr = userExceptionData.data();
2226-
auto& param = tag->functionType()->param();
2226+
auto& param = tag->functionType()->param().types();
22272227
for (size_t i = 0; i < param.size(); i++) {
22282228
auto sz = valueStackAllocatedSize(param[i]);
22292229
memcpy(ptr, bp + code->dataOffsets()[i], sz);

src/jit/Analysis.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ void DependencyGenContext::update(size_t dependencyStart, size_t id, size_t excl
9797
&& (dependencyStart % size) == 0
9898
&& maxDistance[dependencyStart / size] <= id);
9999

100-
for (auto it : param) {
100+
for (auto it : param.types()) {
101101
if (variableList != nullptr) {
102102
// Construct new variables.
103103
VariableRef ref = variableList->variables.size();
@@ -520,7 +520,7 @@ void JITCompiler::buildVariables(uint32_t requiredStackSize)
520520

521521
size_t id = instr->id();
522522

523-
for (auto it : functionType->result()) {
523+
for (auto it : functionType->result().types()) {
524524
VariableRef ref = VARIABLE_SET(m_variableList->variables.size(), DependencyGenContext::Variable);
525525
uint32_t typeInfo = Instruction::valueTypeToOperandType(it);
526526

@@ -700,7 +700,7 @@ void JITCompiler::buildVariables(uint32_t requiredStackSize)
700700
} else {
701701
switch (instr->opcode()) {
702702
case ByteCode::StructNewOpcode: {
703-
for (auto it : reinterpret_cast<StructNew*>(instr->byteCode())->typeInfo()->fields()) {
703+
for (auto it : reinterpret_cast<StructNew*>(instr->byteCode())->typeInfo()->fields().types()) {
704704
VariableList::Variable& variable = m_variableList->variables[*param++];
705705
variable.info |= Instruction::valueTypeToOperandType(Value::unpackType(it.type()));
706706
}
@@ -790,7 +790,7 @@ void JITCompiler::buildVariables(uint32_t requiredStackSize)
790790
}
791791
}
792792

793-
for (auto it : *types) {
793+
for (auto it : types->types()) {
794794
VariableList::Variable& variable = m_variableList->variables[*param++];
795795
variable.info |= Instruction::valueTypeToOperandType(it);
796796
}

src/jit/Backend.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ static void emitImmediate(sljit_compiler* compiler, Instruction* instr)
703703

704704
static ByteCodeStackOffset* emitStoreOntoStack(sljit_compiler* compiler, Operand* param, ByteCodeStackOffset* stackOffset, const TypeVector& types, bool isWordOffsets)
705705
{
706-
for (auto it : types) {
706+
for (auto it : types.types()) {
707707
Operand dst = VARIABLE_SET(STACK_OFFSET(*stackOffset), Instruction::Offset);
708708

709709
switch (VARIABLE_TYPE(*param)) {

src/jit/ByteCodeParser.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ static void buildCatchInfo(JITCompiler* compiler, ModuleFunction* function, std:
9393

9494
static bool isFloatGlobal(uint32_t globalIndex, Module* module)
9595
{
96-
Value::Type type = module->globalType(globalIndex)->type();
96+
Value::Type type = module->globalType(globalIndex)->type().type();
9797

9898
return type == Value::F32 || type == Value::F64;
9999
}
@@ -1146,7 +1146,7 @@ static void compileFunction(JITCompiler* compiler)
11461146
Operand* operand = instr->operands();
11471147
instr->addInfo(Instruction::kIsCallback | Instruction::kFreeUnusedEarly);
11481148

1149-
for (auto it : functionType->param()) {
1149+
for (auto it : functionType->param().types()) {
11501150
*operand++ = STACK_OFFSET(*stackOffset);
11511151
stackOffset += (valueSize(it) + (sizeof(size_t) - 1)) / sizeof(size_t);
11521152
}
@@ -1157,7 +1157,7 @@ static void compileFunction(JITCompiler* compiler)
11571157
*operand++ = STACK_OFFSET(reinterpret_cast<CallRef*>(byteCode)->calleeOffset());
11581158
}
11591159

1160-
for (auto it : functionType->result()) {
1160+
for (auto it : functionType->result().types()) {
11611161
*operand++ = STACK_OFFSET(*stackOffset);
11621162
stackOffset += (valueSize(it) + (sizeof(size_t) - 1)) / sizeof(size_t);
11631163
}
@@ -2066,7 +2066,7 @@ static void compileFunction(JITCompiler* compiler)
20662066
Operand* param = instr->params();
20672067
ByteCodeStackOffset* offsets = reinterpret_cast<End*>(byteCode)->resultOffsets();
20682068

2069-
for (auto it : result) {
2069+
for (auto it : result.types()) {
20702070
*param++ = STACK_OFFSET(*offsets);
20712071
offsets += (valueSize(it) + (sizeof(size_t) - 1)) / sizeof(size_t);
20722072
}

src/jit/CallInl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ static void emitCall(sljit_compiler* compiler, Instruction* instr)
182182

183183
sljit_jump* jump = sljit_emit_cmp(compiler, SLJIT_NOT_EQUAL, SLJIT_R0, 0, SLJIT_IMM, ExecutionContext::NoError);
184184

185-
for (auto it : functionType->result()) {
185+
for (auto it : functionType->result().types()) {
186186
ASSERT(VARIABLE_TYPE(*operand) != Instruction::ConstPtr);
187187

188188
if (VARIABLE_TYPE(*operand) == Instruction::Register) {

src/jit/GarbageCollectorInl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,7 @@ static void emitGCStructNew(sljit_compiler* compiler, Instruction* instr)
10221022
ByteCodeStackOffset* stackOffset = structNew->dataOffsets();
10231023
Operand* param = instr->params();
10241024

1025-
for (auto it : structNew->typeInfo()->fields()) {
1025+
for (auto it : structNew->typeInfo()->fields().types()) {
10261026
emitGCStore(compiler, *stackOffset++, param++, it.type());
10271027
}
10281028

src/jit/TryCatchInl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ static void throwWithArgs(Throw* throwTag, uint8_t* bp, ExecutionContext* contex
232232
userExceptionData.resizeWithUninitializedValues(sz);
233233

234234
uint8_t* ptr = userExceptionData.data();
235-
auto& param = tag->functionType()->param();
235+
auto& param = tag->functionType()->param().types();
236236
for (size_t i = 0; i < param.size(); i++) {
237237
auto sz = valueStackAllocatedSize(param[i]);
238238
memcpy(ptr, bp + throwTag->dataOffsets()[i], sz);

0 commit comments

Comments
 (0)