diff options
Diffstat (limited to 'src/ir.cc')
-rw-r--r-- | src/ir.cc | 289 |
1 files changed, 7 insertions, 282 deletions
@@ -323,296 +323,21 @@ Catch::~Catch() { delete first; } -void destroy_catches(CatchVector* catches) { - for (Catch* catch_ : *catches) - delete catch_; - delete catches; +IfExpr::~IfExpr() { + delete true_; + DestroyExprList(false_); } - -Expr::Expr() : type(ExprType::Binary), next(nullptr) { - WABT_ZERO_MEMORY(loc); - binary.opcode = Opcode::Nop; +TryExpr::~TryExpr() { + delete block; + for (Catch* catch_ : catches) + delete catch_; } Expr::Expr(ExprType type) : type(type), next(nullptr) { WABT_ZERO_MEMORY(loc); } -Expr::~Expr() { - switch (type) { - case ExprType::Block: - delete block; - break; - case ExprType::Br: - br.var.~Var(); - break; - case ExprType::BrIf: - br_if.var.~Var(); - break; - case ExprType::BrTable: - delete br_table.targets; - br_table.default_target.~Var(); - break; - case ExprType::Call: - call.var.~Var(); - break; - case ExprType::CallIndirect: - call_indirect.var.~Var(); - break; - case ExprType::GetGlobal: - get_global.var.~Var(); - break; - case ExprType::GetLocal: - get_local.var.~Var(); - break; - case ExprType::If: - delete if_.true_; - DestroyExprList(if_.false_); - break; - case ExprType::Loop: - delete loop; - break; - case ExprType::Rethrow: - rethrow_.var.~Var(); - break; - case ExprType::SetGlobal: - set_global.var.~Var(); - break; - case ExprType::SetLocal: - set_local.var.~Var(); - break; - case ExprType::TeeLocal: - tee_local.var.~Var(); - break; - case ExprType::Throw: - throw_.var.~Var(); - break; - case ExprType::TryBlock: - delete try_block.block; - destroy_catches(try_block.catches); - break; - case ExprType::Binary: - case ExprType::Compare: - case ExprType::Const: - case ExprType::Convert: - case ExprType::Drop: - case ExprType::CurrentMemory: - case ExprType::GrowMemory: - case ExprType::Load: - case ExprType::Nop: - case ExprType::Return: - case ExprType::Select: - case ExprType::Store: - case ExprType::Unary: - case ExprType::Unreachable: - break; - } -} - -// static -Expr* Expr::CreateBinary(Opcode opcode) { - Expr* expr = new Expr(ExprType::Binary); - expr->binary.opcode = opcode; - return expr; -} - -// static -Expr* Expr::CreateBlock(Block* block) { - Expr* expr = new Expr(ExprType::Block); - expr->block = block; - return expr; -} - -// static -Expr* Expr::CreateBr(Var var) { - Expr* expr = new Expr(ExprType::Br); - expr->br.var = var; - return expr; -} - -// static -Expr* Expr::CreateBrIf(Var var) { - Expr* expr = new Expr(ExprType::BrIf); - expr->br_if.var = var; - return expr; -} - -// static -Expr* Expr::CreateBrTable(VarVector* targets, Var default_target) { - Expr* expr = new Expr(ExprType::BrTable); - expr->br_table.targets = targets; - expr->br_table.default_target = default_target; - return expr; -} - -// static -Expr* Expr::CreateCall(Var var) { - Expr* expr = new Expr(ExprType::Call); - expr->call.var = var; - return expr; -} - -// static -Expr* Expr::CreateCallIndirect(Var var) { - Expr* expr = new Expr(ExprType::CallIndirect); - expr->call_indirect.var = var; - return expr; -} - -// static -Expr* Expr::CreateCompare(Opcode opcode) { - Expr* expr = new Expr(ExprType::Compare); - expr->compare.opcode = opcode; - return expr; -} - -// static -Expr* Expr::CreateConst(const Const& const_) { - Expr* expr = new Expr(ExprType::Const); - expr->const_ = const_; - return expr; -} - -// static -Expr* Expr::CreateConvert(Opcode opcode) { - Expr* expr = new Expr(ExprType::Convert); - expr->convert.opcode = opcode; - return expr; -} - -// static -Expr* Expr::CreateCurrentMemory() { - return new Expr(ExprType::CurrentMemory); -} - -// static -Expr* Expr::CreateDrop() { - return new Expr(ExprType::Drop); -} - -// static -Expr* Expr::CreateGetGlobal(Var var) { - Expr* expr = new Expr(ExprType::GetGlobal); - expr->get_global.var = var; - return expr; -} - -// static -Expr* Expr::CreateGetLocal(Var var) { - Expr* expr = new Expr(ExprType::GetLocal); - expr->get_local.var = var; - return expr; -} - -// static -Expr* Expr::CreateGrowMemory() { - return new Expr(ExprType::GrowMemory); -} - -// static -Expr* Expr::CreateIf(Block* true_, Expr* false_) { - Expr* expr = new Expr(ExprType::If); - expr->if_.true_ = true_; - expr->if_.false_ = false_; - return expr; -} - -// static -Expr* Expr::CreateLoad(Opcode opcode, Address align, uint32_t offset) { - Expr* expr = new Expr(ExprType::Load); - expr->load.opcode = opcode; - expr->load.align = align; - expr->load.offset = offset; - return expr; -} - -// static -Expr* Expr::CreateLoop(Block* block) { - Expr* expr = new Expr(ExprType::Loop); - expr->loop = block; - return expr; -} - -// static -Expr* Expr::CreateNop() { - return new Expr(ExprType::Nop); -} - -// static -Expr* Expr::CreateRethrow(Var var) { - Expr* expr = new Expr(ExprType::Rethrow); - expr->rethrow_.var = var; - return expr; -} - -// static -Expr* Expr::CreateReturn() { - return new Expr(ExprType::Return); -} - -// static -Expr* Expr::CreateSelect() { - return new Expr(ExprType::Select); -} - -// static -Expr* Expr::CreateSetGlobal(Var var) { - Expr* expr = new Expr(ExprType::SetGlobal); - expr->set_global.var = var; - return expr; -} - -// static -Expr* Expr::CreateSetLocal(Var var) { - Expr* expr = new Expr(ExprType::SetLocal); - expr->set_local.var = var; - return expr; -} - -// static -Expr* Expr::CreateStore(Opcode opcode, Address align, uint32_t offset) { - Expr* expr = new Expr(ExprType::Store); - expr->store.opcode = opcode; - expr->store.align = align; - expr->store.offset = offset; - return expr; -} - -// static -Expr* Expr::CreateTeeLocal(Var var) { - Expr* expr = new Expr(ExprType::TeeLocal); - expr->tee_local.var = var; - return expr; -} - -// static -Expr* Expr::CreateThrow(Var var) { - Expr* expr = new Expr(ExprType::Throw); - expr->throw_.var = var; - return expr; -} - -// static -Expr* Expr::CreateTry() { - Expr* expr = new Expr(ExprType::TryBlock); - expr->try_block.block = nullptr; - expr->try_block.catches = new CatchVector(); - return expr; -} - -// static -Expr* Expr::CreateUnary(Opcode opcode) { - Expr* expr = new Expr(ExprType::Unary); - expr->unary.opcode = opcode; - return expr; -} - -// static -Expr* Expr::CreateUnreachable() { - return new Expr(ExprType::Unreachable); -} - FuncType::FuncType() { WABT_ZERO_MEMORY(name); } |