1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- #include "Optimizer.h"
- #include "Parser.h"
- #include <iostream>
- #include <vector>
- using namespace zp;
- using namespace std;
- unique_ptr<BlockInstruction> AstVisitor::visit(Block& block)
- {
- return block.accept(*this);
- }
- unique_ptr<BlockInstruction> Optimizer::visitInstructionBlock(InstructionBlock& ib)
- {
- std::cout << "InstructionBlock" << std::endl;
- unique_ptr<SimpleBlockInstruction> sbi = make_unique<SimpleBlockInstruction>();
- for (auto instr : ib.instructions) {
- switch(instr) {
- case Instruction::LEFT:
- sbi->pointerMoved--;
- break;
- case Instruction::RIGHT:
- sbi->pointerMoved++;
- break;
- case Instruction::PLUS:
- sbi->added[sbi->pointerMoved]++;
- break;
- case Instruction::MINUS:
- sbi->added[sbi->pointerMoved]--;
- break;
- default:
- break;
- }
- }
- return sbi;
- }
- unique_ptr<BlockInstruction> Optimizer::visitIOBlock(IOBlock& io)
- {
- cout << "IOBlock" << std::endl;
- return make_unique<SimpleBlockInstruction>();
- }
- unique_ptr<BlockInstruction> Optimizer::visitUnionBlock(UnionBlock& ub)
- {
- cout << "UnionBlock" << std::endl;
-
- for (auto& block : ub.instructions) {
- visit(*block.get());
- }
- return make_unique<SimpleBlockInstruction>();
- }
- unique_ptr<BlockInstruction> Optimizer::visitLoop(Loop& loop)
- {
- cout << "Loop" << std::endl;
- for (auto& block : loop.instructions) {
- visit(*block.get());
- }
- return make_unique<SimpleBlockInstruction>();
- }
|