Rename wasm::Break(If) to wasm::Branch(If) for clarity

This commit is contained in:
Alex Beregszaszi 2020-05-20 23:59:03 +01:00
parent 32bec6b374
commit cfdfa36065
6 changed files with 22 additions and 22 deletions

View File

@ -382,15 +382,15 @@ bytes BinaryTransform::operator()(Loop const& _loop)
return result; return result;
} }
bytes BinaryTransform::operator()(Break const& _break) bytes BinaryTransform::operator()(Branch const& _branch)
{ {
return toBytes(Opcode::Br) + encodeLabelIdx(_break.label.name); return toBytes(Opcode::Br) + encodeLabelIdx(_branch.label.name);
} }
bytes BinaryTransform::operator()(BreakIf const& _breakIf) bytes BinaryTransform::operator()(BranchIf const& _branchIf)
{ {
bytes result = std::visit(*this, *_breakIf.condition); bytes result = std::visit(*this, *_branchIf.condition);
result += toBytes(Opcode::BrIf) + encodeLabelIdx(_breakIf.label.name); result += toBytes(Opcode::BrIf) + encodeLabelIdx(_branchIf.label.name);
return result; return result;
} }

View File

@ -48,8 +48,8 @@ public:
bytes operator()(wasm::GlobalAssignment const& _assignment); bytes operator()(wasm::GlobalAssignment const& _assignment);
bytes operator()(wasm::If const& _if); bytes operator()(wasm::If const& _if);
bytes operator()(wasm::Loop const& _loop); bytes operator()(wasm::Loop const& _loop);
bytes operator()(wasm::Break const& _break); bytes operator()(wasm::Branch const& _branch);
bytes operator()(wasm::BreakIf const& _break); bytes operator()(wasm::BranchIf const& _branchIf);
bytes operator()(wasm::Return const& _return); bytes operator()(wasm::Return const& _return);
bytes operator()(wasm::Block const& _block); bytes operator()(wasm::Block const& _block);
bytes operator()(wasm::FunctionDefinition const& _function); bytes operator()(wasm::FunctionDefinition const& _function);

View File

@ -121,14 +121,14 @@ string TextTransform::operator()(wasm::Loop const& _loop)
return "(loop" + move(label) + "\n" + indented(joinTransformed(_loop.statements, '\n')) + ")\n"; return "(loop" + move(label) + "\n" + indented(joinTransformed(_loop.statements, '\n')) + ")\n";
} }
string TextTransform::operator()(wasm::Break const& _break) string TextTransform::operator()(wasm::Branch const& _branch)
{ {
return "(br $" + _break.label.name + ")\n"; return "(br $" + _branch.label.name + ")\n";
} }
string TextTransform::operator()(wasm::BreakIf const& _break) string TextTransform::operator()(wasm::BranchIf const& _branchIf)
{ {
return "(br_if $" + _break.label.name + " " + visit(*_break.condition) + ")\n"; return "(br_if $" + _branchIf.label.name + " " + visit(*_branchIf.condition) + ")\n";
} }
string TextTransform::operator()(wasm::Return const&) string TextTransform::operator()(wasm::Return const&)

View File

@ -48,9 +48,9 @@ public:
std::string operator()(wasm::GlobalAssignment const& _assignment); std::string operator()(wasm::GlobalAssignment const& _assignment);
std::string operator()(wasm::If const& _if); std::string operator()(wasm::If const& _if);
std::string operator()(wasm::Loop const& _loop); std::string operator()(wasm::Loop const& _loop);
std::string operator()(wasm::Break const& _break); std::string operator()(wasm::Branch const& _branch);
std::string operator()(wasm::BranchIf const& _branchIf);
std::string operator()(wasm::Return const& _return); std::string operator()(wasm::Return const& _return);
std::string operator()(wasm::BreakIf const& _break);
std::string operator()(wasm::Block const& _block); std::string operator()(wasm::Block const& _block);
private: private:

View File

@ -41,13 +41,13 @@ struct GlobalAssignment;
struct Block; struct Block;
struct If; struct If;
struct Loop; struct Loop;
struct Break; struct Branch;
struct BreakIf; struct BranchIf;
struct Return; struct Return;
using Expression = std::variant< using Expression = std::variant<
Literal, StringLiteral, LocalVariable, GlobalVariable, Literal, StringLiteral, LocalVariable, GlobalVariable,
FunctionCall, BuiltinCall, LocalAssignment, GlobalAssignment, FunctionCall, BuiltinCall, LocalAssignment, GlobalAssignment,
Block, If, Loop, Break, BreakIf, Return Block, If, Loop, Branch, BranchIf, Return
>; >;
struct Literal { uint64_t value; }; struct Literal { uint64_t value; };
@ -66,9 +66,9 @@ struct If {
std::unique_ptr<std::vector<Expression>> elseStatements; std::unique_ptr<std::vector<Expression>> elseStatements;
}; };
struct Loop { std::string labelName; std::vector<Expression> statements; }; struct Loop { std::string labelName; std::vector<Expression> statements; };
struct Break { Label label; }; struct Branch { Label label; };
struct Return {}; struct Return {};
struct BreakIf { Label label; std::unique_ptr<Expression> condition; }; struct BranchIf { Label label; std::unique_ptr<Expression> condition; };
struct VariableDeclaration { std::string variableName; }; struct VariableDeclaration { std::string variableName; };
struct GlobalVariableDeclaration { std::string variableName; }; struct GlobalVariableDeclaration { std::string variableName; };

View File

@ -256,26 +256,26 @@ wasm::Expression WasmCodeTransform::operator()(ForLoop const& _for)
wasm::Loop loop; wasm::Loop loop;
loop.labelName = newLabel(); loop.labelName = newLabel();
loop.statements = visit(_for.pre.statements); loop.statements = visit(_for.pre.statements);
loop.statements.emplace_back(wasm::BreakIf{wasm::Label{breakLabel}, make_unique<wasm::Expression>( loop.statements.emplace_back(wasm::BranchIf{wasm::Label{breakLabel}, make_unique<wasm::Expression>(
wasm::BuiltinCall{"i64.eqz", make_vector<wasm::Expression>( wasm::BuiltinCall{"i64.eqz", make_vector<wasm::Expression>(
visitReturnByValue(*_for.condition) visitReturnByValue(*_for.condition)
)} )}
)}); )});
loop.statements.emplace_back(wasm::Block{continueLabel, visit(_for.body.statements)}); loop.statements.emplace_back(wasm::Block{continueLabel, visit(_for.body.statements)});
loop.statements += visit(_for.post.statements); loop.statements += visit(_for.post.statements);
loop.statements.emplace_back(wasm::Break{wasm::Label{loop.labelName}}); loop.statements.emplace_back(wasm::Branch{wasm::Label{loop.labelName}});
return { wasm::Block{breakLabel, make_vector<wasm::Expression>(move(loop))} }; return { wasm::Block{breakLabel, make_vector<wasm::Expression>(move(loop))} };
} }
wasm::Expression WasmCodeTransform::operator()(Break const&) wasm::Expression WasmCodeTransform::operator()(Break const&)
{ {
return wasm::Break{wasm::Label{m_breakContinueLabelNames.top().first}}; return wasm::Branch{wasm::Label{m_breakContinueLabelNames.top().first}};
} }
wasm::Expression WasmCodeTransform::operator()(Continue const&) wasm::Expression WasmCodeTransform::operator()(Continue const&)
{ {
return wasm::Break{wasm::Label{m_breakContinueLabelNames.top().second}}; return wasm::Branch{wasm::Label{m_breakContinueLabelNames.top().second}};
} }
wasm::Expression WasmCodeTransform::operator()(Leave const&) wasm::Expression WasmCodeTransform::operator()(Leave const&)