bf uses Label class

This commit is contained in:
MITSUNARI Shigeo 2018-09-04 11:41:11 +09:00
parent 613922bda3
commit 1de435ed04

View file

@ -10,12 +10,6 @@
#endif
class Brainfuck : public Xbyak::CodeGenerator {
private:
enum Direction { B, F };
std::string toStr(int labelNo, Direction dir)
{
return Xbyak::Label::toStr(labelNo) + (dir == B ? 'B' : 'F');
}
public:
int getContinuousChar(std::istream& is, char c)
{
@ -67,8 +61,7 @@ public:
mov(pGetchar, rsi); // getchar
mov(stack, rdx); // stack
#endif
int labelNo = 0;
std::stack<int> keepLabelNo;
std::stack<Label> labelF, labelB;
char c;
while (is >> c) {
switch (c) {
@ -116,17 +109,22 @@ public:
mov(cur, eax);
break;
case '[':
L(toStr(labelNo, B));
mov(eax, cur);
test(eax, eax);
jz(toStr(labelNo, F), T_NEAR);
keepLabelNo.push(labelNo++);
{
Label B = L();
labelB.push(B);
mov(eax, cur);
test(eax, eax);
Label F;
jz(F, T_NEAR);
labelF.push(F);
}
break;
case ']':
{
int no = keepLabelNo.top(); keepLabelNo.pop();
jmp(toStr(no, B));
L(toStr(no, F));
Label B = labelB.top(); labelB.pop();
jmp(B);
Label F = labelF.top(); labelF.pop();
L(F);
}
break;
default: