|
@@ -1,47 +1,68 @@
|
|
#include "Optimizer.h"
|
|
#include "Optimizer.h"
|
|
#include "Parser.h"
|
|
#include "Parser.h"
|
|
#include <iostream>
|
|
#include <iostream>
|
|
|
|
+#include <vector>
|
|
|
|
|
|
using namespace zp;
|
|
using namespace zp;
|
|
|
|
+using namespace std;
|
|
|
|
|
|
-std::unique_ptr<BlockInstruction> AstVisitor::visit(Block& block)
|
|
|
|
|
|
+unique_ptr<BlockInstruction> AstVisitor::visit(Block& block)
|
|
{
|
|
{
|
|
return block.accept(*this);
|
|
return block.accept(*this);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
-std::unique_ptr<BlockInstruction> Optimizer::visitInstructionBlock(InstructionBlock& ib)
|
|
|
|
|
|
+unique_ptr<BlockInstruction> Optimizer::visitInstructionBlock(InstructionBlock& ib)
|
|
{
|
|
{
|
|
std::cout << "InstructionBlock" << std::endl;
|
|
std::cout << "InstructionBlock" << std::endl;
|
|
- bool isSimple = true;
|
|
|
|
|
|
+ unique_ptr<SimpleBlockInstruction> sbi = make_unique<SimpleBlockInstruction>();
|
|
for (auto instr : ib.instructions) {
|
|
for (auto instr : ib.instructions) {
|
|
switch(instr) {
|
|
switch(instr) {
|
|
- case Instruction::COMMA:
|
|
|
|
- case Instruction::DOT:
|
|
|
|
-
|
|
|
|
|
|
+ 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 std::make_unique<SimpleBlockInstruction>();
|
|
|
|
|
|
+ return sbi;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
-std::unique_ptr<BlockInstruction> Optimizer::visitUnionBlock(UnionBlock& ub)
|
|
|
|
|
|
+unique_ptr<BlockInstruction> Optimizer::visitIOBlock(IOBlock& io)
|
|
{
|
|
{
|
|
- std::cout << "UnionBlock" << std::endl;
|
|
|
|
|
|
+ cout << "IOBlock" << std::endl;
|
|
|
|
+ return make_unique<SimpleBlockInstruction>();
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+unique_ptr<BlockInstruction> Optimizer::visitUnionBlock(UnionBlock& ub)
|
|
|
|
+{
|
|
|
|
+ cout << "UnionBlock" << std::endl;
|
|
|
|
+
|
|
for (auto& block : ub.instructions) {
|
|
for (auto& block : ub.instructions) {
|
|
visit(*block.get());
|
|
visit(*block.get());
|
|
}
|
|
}
|
|
- return std::make_unique<SimpleBlockInstruction>();
|
|
|
|
|
|
+ return make_unique<SimpleBlockInstruction>();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
-std::unique_ptr<BlockInstruction> Optimizer::visitLoop(Loop& loop)
|
|
|
|
|
|
+unique_ptr<BlockInstruction> Optimizer::visitLoop(Loop& loop)
|
|
{
|
|
{
|
|
- std::cout << "Loop" << std::endl;
|
|
|
|
|
|
+ cout << "Loop" << std::endl;
|
|
for (auto& block : loop.instructions) {
|
|
for (auto& block : loop.instructions) {
|
|
visit(*block.get());
|
|
visit(*block.get());
|
|
}
|
|
}
|
|
- return std::make_unique<SimpleBlockInstruction>();
|
|
|
|
|
|
+ return make_unique<SimpleBlockInstruction>();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|