support reset
This commit is contained in:
parent
1009e09f6d
commit
458a6e06bd
2 changed files with 53 additions and 0 deletions
|
@ -94,6 +94,37 @@ public:
|
|||
int (*get() const)(const char *) { return (int (*)(const char *))(const void*)getCode(); }
|
||||
};
|
||||
|
||||
struct Reset : public Xbyak::CodeGenerator {
|
||||
void init(int n)
|
||||
{
|
||||
xor(eax, eax);
|
||||
mov(ecx, n);
|
||||
test(ecx, ecx);
|
||||
jnz("@f");
|
||||
ret();
|
||||
L("@@");
|
||||
for (int i = 0; i < 10 - n; i++) {
|
||||
add(eax, ecx);
|
||||
}
|
||||
sub(ecx, 1);
|
||||
jnz("@b");
|
||||
ret();
|
||||
}
|
||||
};
|
||||
|
||||
void testReset()
|
||||
{
|
||||
puts("tsetReset");
|
||||
Reset code;
|
||||
int (*f)(int) = (int (*)(int))code.getCode();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
code.init(i);
|
||||
int v = f(i);
|
||||
printf("%d %d\n", i, v);
|
||||
code.reset();
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
try {
|
||||
|
@ -137,6 +168,7 @@ int main()
|
|||
CodeArray::protect(p, codeSize, false);
|
||||
}
|
||||
puts("OK");
|
||||
testReset();
|
||||
} catch (Xbyak::Error err) {
|
||||
printf("ERR:%s(%d)\n", Xbyak::ConvertErrorToString(err), err);
|
||||
} catch (...) {
|
||||
|
|
|
@ -542,6 +542,11 @@ public:
|
|||
if (type_ != FIXED_BUF) throw ERR_CODE_ISNOT_COPYABLE;
|
||||
for (size_t i = 0; i < size_; i++) top_[i] = rhs.top_[i];
|
||||
}
|
||||
void resetSize()
|
||||
{
|
||||
size_ = 0;
|
||||
addrInfoList_.clear();
|
||||
}
|
||||
void db(int code)
|
||||
{
|
||||
if (size_ >= maxSize_) {
|
||||
|
@ -795,6 +800,16 @@ public:
|
|||
, localCount_(0)
|
||||
{
|
||||
}
|
||||
void reset()
|
||||
{
|
||||
base_ = 0;
|
||||
anonymousCount_ = 0;
|
||||
stackPos_ = 1;
|
||||
usedCount_ = 0;
|
||||
localCount_ = 0;
|
||||
definedList_.clear();
|
||||
undefinedList_.clear();
|
||||
}
|
||||
void enterLocal()
|
||||
{
|
||||
if (stackPos_ == maxStack) throw ERR_OVER_LOCAL_LABEL;
|
||||
|
@ -1603,6 +1618,12 @@ public:
|
|||
{
|
||||
label_.set(this);
|
||||
}
|
||||
void reset()
|
||||
{
|
||||
resetSize();
|
||||
label_.reset();
|
||||
label_.set(this);
|
||||
}
|
||||
bool hasUndefinedLabel() const { return label_.hasUndefinedLabel(); }
|
||||
/*
|
||||
call ready() to complete generating code on AutoGrow
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue