pass small test of new Label

This commit is contained in:
MITSUNARI Shigeo 2014-03-15 08:09:54 +09:00
parent 95d3b5c8d0
commit 7036a37e6a
2 changed files with 65 additions and 34 deletions

View File

@ -634,18 +634,49 @@ void testNewLabel()
: Xbyak::CodeGenerator(grow ? 128 : 4096, grow ? Xbyak::AutoGrow : 0)
{
xor_(eax, eax);
Label label;
inLocalLabel();
jmp(".start0");
L(label);
inc(eax);
jmp(".exit");
L(".start0");
inc(eax);
jmp(label);
L(".exit");
{
Label label1;
Label label2;
Label label3;
Label label4;
Label exit;
jmp(label1);
L(label2);
inc(eax); // 2
jmp(label3);
L(label4);
inc(eax); // 4
jmp(exit);
L(label3);
inc(eax); // 3
jmp(label4);
L(label1);
inc(eax); // 1
jmp(label2);
L(exit);
}
{
Label label1;
Label label2;
Label label3;
Label label4;
Label exit;
jmp(label1);
L(label2);
inc(eax); // 6
jmp(label3);
L(label4);
inc(eax); // 8
jmp(exit);
L(label3);
inc(eax); // 7
jmp(label4);
L(label1);
inc(eax); // 5
jmp(label2);
L(exit);
}
ret();
outLocalLabel();
}
};
const bool grow = false;
@ -653,30 +684,30 @@ void testNewLabel()
Code code(grow);
int (*f)() = code.getCode<int (*)()>();
int r = f();
if (r != 2) {
if (r != 8) {
printf("err %d\n", r);
}
}
int main()
{
try {
test1();
test2();
try {
#if 0
test1();
test2();
#ifdef ONLY_32BIT
test3();
test3();
#endif
test4();
test5();
test6();
testJmpCx();
testMovLabel(false);
testMovLabel(true);
testMovLabel2();
testNewLabel();
} catch (std::exception& e) {
printf("ERR:%s\n", e.what());
} catch (...) {
printf("unknown error\n");
}
test4();
test5();
test6();
testJmpCx();
testMovLabel(false);
testMovLabel(true);
testMovLabel2();
#endif
testNewLabel();
} catch (std::exception& e) {
printf("ERR:%s\n", e.what());
} catch (...) {
printf("unknown error\n");
}

View File

@ -881,11 +881,12 @@ struct JmpLabel {
// QQQ
class Label {
int id; // 0 : not set, > 0 : id
int id;
friend class LabelManager;
public:
Label() : id(0) {}
bool isSet() const { return id > 0; }
// backward compatibility
static std::string toStr(int num)
{
char buf[16];
@ -1047,8 +1048,7 @@ public:
}
void define2(Label& label)
{
if (label.isSet()) throw Error(ERR_LABEL_IS_ALREADY_SET);
label.id = labelId_++;
if (label.id == 0) label.id = labelId_++;
// add label
const size_t addrOffset = base_->getSize();
DefinedList2::value_type item(label.id, addrOffset);