Refactor temp handling in inter code
This commit is contained in:
parent
330e022a43
commit
15743d3115
|
@ -30,6 +30,12 @@ if %errorlevel% neq 0 goto :error
|
||||||
..\release\oscar64 -e -n strcmptest.c
|
..\release\oscar64 -e -n strcmptest.c
|
||||||
if %errorlevel% neq 0 goto :error
|
if %errorlevel% neq 0 goto :error
|
||||||
|
|
||||||
|
..\release\oscar64 -e strcmptest2.c
|
||||||
|
if %errorlevel% neq 0 goto :error
|
||||||
|
|
||||||
|
..\release\oscar64 -e -n strcmptest2.c
|
||||||
|
if %errorlevel% neq 0 goto :error
|
||||||
|
|
||||||
..\release\oscar64 -e arraytest.c
|
..\release\oscar64 -e arraytest.c
|
||||||
if %errorlevel% neq 0 goto :error
|
if %errorlevel% neq 0 goto :error
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
#include <string.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
char aa[2000], ba[2000];
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
assert(strcmp("abcdefgh", "abcdefgh") == 0);
|
||||||
|
assert(strcmp("abcdefgh", "abcdemgh") < 0);
|
||||||
|
assert(strcmp("abcdefgh", "abcdefghi") < 0);
|
||||||
|
assert(strcmp("abcdefghi", "abcdefgh") > 0);
|
||||||
|
assert(strcmp("abcdemgh", "abcdefgh") > 0);
|
||||||
|
|
||||||
|
for(int i=0; i<1900; i++)
|
||||||
|
{
|
||||||
|
aa[i] = 'a' + (i & 7);
|
||||||
|
}
|
||||||
|
aa[1900] = 0;
|
||||||
|
|
||||||
|
strcpy(ba, aa);
|
||||||
|
|
||||||
|
assert(strcmp(aa, ba) == 0);
|
||||||
|
ba[1000] = 'z';
|
||||||
|
assert(strcmp(aa, ba) < 0);
|
||||||
|
assert(strcmp(ba, aa) > 0);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -45,6 +45,53 @@ char * strcpy(char * dst, const char * src)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if 1
|
||||||
|
int strcmp(const char * ptr1, const char * ptr2)
|
||||||
|
{
|
||||||
|
__asm
|
||||||
|
{
|
||||||
|
ldy #ptr1
|
||||||
|
lda (fp), y
|
||||||
|
sta $1f
|
||||||
|
iny
|
||||||
|
lda (fp), y
|
||||||
|
sta $20
|
||||||
|
|
||||||
|
ldy #ptr2
|
||||||
|
lda (fp), y
|
||||||
|
sta $1b
|
||||||
|
iny
|
||||||
|
lda (fp), y
|
||||||
|
sta $1c
|
||||||
|
|
||||||
|
ldy #0
|
||||||
|
L1: lda ($1f), y
|
||||||
|
beq W1
|
||||||
|
cmp ($1b), y
|
||||||
|
bne W2
|
||||||
|
iny
|
||||||
|
bne L1
|
||||||
|
inc $1c
|
||||||
|
inc $20
|
||||||
|
bne L1
|
||||||
|
W2: bcs gt
|
||||||
|
lda #$ff
|
||||||
|
sta accu
|
||||||
|
sta accu + 1
|
||||||
|
rts
|
||||||
|
gt: lda #$01
|
||||||
|
sta accu
|
||||||
|
lda #$00
|
||||||
|
sta accu + 1
|
||||||
|
rts
|
||||||
|
W1: cmp ($1b), y
|
||||||
|
bne W2
|
||||||
|
lda #$00
|
||||||
|
sta accu
|
||||||
|
sta accu + 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
int strcmp(const char * ptr1, const char * ptr2)
|
int strcmp(const char * ptr1, const char * ptr2)
|
||||||
{
|
{
|
||||||
const char * p = ptr1, * q = ptr2;
|
const char * p = ptr1, * q = ptr2;
|
||||||
|
@ -59,6 +106,8 @@ int strcmp(const char * ptr1, const char * ptr2)
|
||||||
else
|
else
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
int strlen(const char * str)
|
int strlen(const char * str)
|
||||||
{
|
{
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -285,16 +285,26 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class InterOperand
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
int mTemp;
|
||||||
|
InterType mType;
|
||||||
|
bool mFinal;
|
||||||
|
int64 mIntConst;
|
||||||
|
double mFloatConst;
|
||||||
|
|
||||||
|
InterOperand(void)
|
||||||
|
: mTemp(INVALID_TEMPORARY), mType(IT_NONE), mFinal(false), mIntConst(0), mFloatConst(0)
|
||||||
|
{}
|
||||||
|
};
|
||||||
|
|
||||||
class InterInstruction
|
class InterInstruction
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
InterCode mCode;
|
InterCode mCode;
|
||||||
InterType mTType, mSType[3];
|
InterOperand mSrc[3];
|
||||||
int mTTemp, mSTemp[3];
|
InterOperand mDst;
|
||||||
bool mSFinal[3];
|
|
||||||
int64 mSIntConst[3];
|
|
||||||
double mSFloatConst[3];
|
|
||||||
InterMemory mMemory;
|
InterMemory mMemory;
|
||||||
InterOperator mOperator;
|
InterOperator mOperator;
|
||||||
int mOperandSize;
|
int mOperandSize;
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue