Enable charmap inside a series of string literals
This commit is contained in:
parent
9dd493d20b
commit
742866c8c2
|
@ -342,3 +342,4 @@ ASALocalRun/
|
|||
make/oscar64
|
||||
*.int
|
||||
*.bcs
|
||||
*.crt
|
||||
|
|
|
@ -8,6 +8,7 @@ static const uint64 COPT_OPTIMIZE_INLINE = 0x00000002;
|
|||
static const uint64 COPT_OPTIMIZE_AUTO_INLINE = 0x00000010;
|
||||
static const uint64 COPT_OPTIMIZE_AUTO_INLINE_ALL = 0x00000020;
|
||||
static const uint64 COPT_OPTIMIZE_AUTO_UNROLL = 0x00000040;
|
||||
static const uint64 COPT_OPTIMIZE_CONST_EXPRESSIONS = 0x00000080;
|
||||
|
||||
static const uint64 COPT_TARGET_PRG = 0x100000000ULL;
|
||||
static const uint64 COPT_TARGET_CRT16 = 0x200000000ULL;
|
||||
|
@ -19,15 +20,15 @@ static const uint64 COPT_VERBOSE = 0x1000000000ULL;
|
|||
|
||||
static const uint64 COPT_NATIVE = 0x01000000;
|
||||
|
||||
static const uint64 COPT_DEFAULT = COPT_OPTIMIZE_BASIC | COPT_OPTIMIZE_INLINE;
|
||||
static const uint64 COPT_DEFAULT = COPT_OPTIMIZE_BASIC | COPT_OPTIMIZE_INLINE | COPT_OPTIMIZE_CONST_EXPRESSIONS;
|
||||
|
||||
static const uint64 COPT_OPTIMIZE_DEFAULT = COPT_OPTIMIZE_BASIC | COPT_OPTIMIZE_INLINE;
|
||||
static const uint64 COPT_OPTIMIZE_DEFAULT = COPT_OPTIMIZE_BASIC | COPT_OPTIMIZE_INLINE | COPT_OPTIMIZE_CONST_EXPRESSIONS;
|
||||
|
||||
static const uint64 COPT_OPTIMIZE_SIZE = COPT_OPTIMIZE_BASIC | COPT_OPTIMIZE_INLINE;
|
||||
static const uint64 COPT_OPTIMIZE_SIZE = COPT_OPTIMIZE_BASIC | COPT_OPTIMIZE_INLINE | COPT_OPTIMIZE_CONST_EXPRESSIONS;
|
||||
|
||||
static const uint64 COPT_OPTIMIZE_SPEED = COPT_OPTIMIZE_BASIC | COPT_OPTIMIZE_INLINE | COPT_OPTIMIZE_AUTO_INLINE | COPT_OPTIMIZE_AUTO_UNROLL;
|
||||
static const uint64 COPT_OPTIMIZE_SPEED = COPT_OPTIMIZE_BASIC | COPT_OPTIMIZE_INLINE | COPT_OPTIMIZE_AUTO_INLINE | COPT_OPTIMIZE_AUTO_UNROLL | COPT_OPTIMIZE_CONST_EXPRESSIONS;
|
||||
|
||||
static const uint64 COPT_OPTIMIZE_ALL = COPT_OPTIMIZE_BASIC | COPT_OPTIMIZE_INLINE | COPT_OPTIMIZE_AUTO_INLINE | COPT_OPTIMIZE_AUTO_INLINE_ALL | COPT_OPTIMIZE_AUTO_UNROLL;
|
||||
static const uint64 COPT_OPTIMIZE_ALL = COPT_OPTIMIZE_BASIC | COPT_OPTIMIZE_INLINE | COPT_OPTIMIZE_AUTO_INLINE | COPT_OPTIMIZE_AUTO_INLINE_ALL | COPT_OPTIMIZE_AUTO_UNROLL | COPT_OPTIMIZE_CONST_EXPRESSIONS;
|
||||
|
||||
struct CompilerSettings
|
||||
{
|
||||
|
|
|
@ -163,7 +163,8 @@ void GlobalAnalyzer::AnalyzeProcedure(Expression* exp, Declaration* dec)
|
|||
dec->mFlags |= DTF_FUNC_CONSTEXPR;
|
||||
else if (dec->mFlags & DTF_DEFINED)
|
||||
{
|
||||
dec->mFlags |= DTF_FUNC_CONSTEXPR;
|
||||
if (mCompilerOptions & COPT_OPTIMIZE_CONST_EXPRESSIONS)
|
||||
dec->mFlags |= DTF_FUNC_CONSTEXPR;
|
||||
Analyze(exp, dec);
|
||||
}
|
||||
else
|
||||
|
@ -305,7 +306,10 @@ Declaration * GlobalAnalyzer::Analyze(Expression* exp, Declaration* procDec)
|
|||
ldec->mFlags |= DTF_VAR_ALIASING;
|
||||
}
|
||||
else if (exp->mToken == TK_MUL)
|
||||
{
|
||||
procDec->mFlags &= ~DTF_FUNC_CONSTEXPR;
|
||||
return exp->mDecType;
|
||||
}
|
||||
break;
|
||||
case EX_POSTFIX:
|
||||
break;
|
||||
|
|
|
@ -8829,6 +8829,7 @@ void InterCodeProcedure::Disassemble(FILE* file)
|
|||
|
||||
void InterCodeProcedure::Disassemble(const char* name, bool dumpSets)
|
||||
{
|
||||
#if 0
|
||||
#ifdef _WIN32
|
||||
FILE* file;
|
||||
static bool initial = true;
|
||||
|
@ -8864,6 +8865,7 @@ void InterCodeProcedure::Disassemble(const char* name, bool dumpSets)
|
|||
fclose(file);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
InterCodeModule::InterCodeModule(void)
|
||||
|
|
|
@ -615,6 +615,62 @@ Declaration * Parser::CopyConstantInitializer(int offset, Declaration* dtype, Ex
|
|||
return dec;
|
||||
}
|
||||
|
||||
uint8* Parser::ParseStringLiteral(int msize)
|
||||
{
|
||||
int size = strlen(mScanner->mTokenString);
|
||||
if (size + 1 > msize)
|
||||
msize = size + 1;
|
||||
uint8* d = new uint8[msize];
|
||||
|
||||
int i = 0;
|
||||
while (mScanner->mTokenString[i])
|
||||
{
|
||||
d[i] = mCharMap[mScanner->mTokenString[i]];
|
||||
i++;
|
||||
}
|
||||
|
||||
mScanner->NextToken();
|
||||
|
||||
while (mScanner->mToken == TK_PREP_PRAGMA)
|
||||
{
|
||||
mScanner->NextToken();
|
||||
ParsePragma();
|
||||
}
|
||||
|
||||
// automatic string concatenation
|
||||
while (mScanner->mToken == TK_STRING)
|
||||
{
|
||||
int s = strlen(mScanner->mTokenString);
|
||||
|
||||
if (size + s + 1 > msize)
|
||||
msize = size + s + 1;
|
||||
|
||||
uint8* nd = new uint8[msize];
|
||||
memcpy(nd, d, size);
|
||||
int i = 0;
|
||||
while (mScanner->mTokenString[i])
|
||||
{
|
||||
nd[i + size] = mCharMap[mScanner->mTokenString[i]];
|
||||
i++;
|
||||
}
|
||||
size += s;
|
||||
delete[] d;
|
||||
d = nd;
|
||||
mScanner->NextToken();
|
||||
|
||||
while (mScanner->mToken == TK_PREP_PRAGMA)
|
||||
{
|
||||
mScanner->NextToken();
|
||||
ParsePragma();
|
||||
}
|
||||
}
|
||||
|
||||
while (size < msize)
|
||||
d[size++] = 0;
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
Expression* Parser::ParseInitExpression(Declaration* dtype)
|
||||
{
|
||||
Expression* exp = nullptr;
|
||||
|
@ -713,10 +769,13 @@ Expression* Parser::ParseInitExpression(Declaration* dtype)
|
|||
}
|
||||
else if (mScanner->mToken == TK_STRING && dtype->mType == DT_TYPE_ARRAY && dtype->mBase->mType == DT_TYPE_INTEGER && dtype->mBase->mSize == 1)
|
||||
{
|
||||
uint8* d = ParseStringLiteral(dtype->mSize);
|
||||
int ds = strlen((char *)d);
|
||||
|
||||
if (!(dtype->mFlags & DTF_DEFINED))
|
||||
{
|
||||
dtype->mFlags |= DTF_DEFINED;
|
||||
dtype->mSize = strlen(mScanner->mTokenString) + 1;
|
||||
dtype->mSize = ds + 1;
|
||||
}
|
||||
|
||||
dec = new Declaration(mScanner->mLocation, DT_CONST_DATA);
|
||||
|
@ -724,24 +783,10 @@ Expression* Parser::ParseInitExpression(Declaration* dtype)
|
|||
dec->mSize = dtype->mSize;
|
||||
dec->mSection = mDataSection;
|
||||
|
||||
uint8* d = new uint8[dtype->mSize];
|
||||
dec->mData = d;
|
||||
|
||||
if (strlen(mScanner->mTokenString) < dtype->mSize)
|
||||
{
|
||||
int i = 0;
|
||||
while (i < dec->mSize && mScanner->mTokenString[i])
|
||||
{
|
||||
d[i] = mCharMap[mScanner->mTokenString[i]];
|
||||
i++;
|
||||
}
|
||||
if (i < dec->mSize)
|
||||
d[i] = 0;
|
||||
}
|
||||
else
|
||||
if (ds > dtype->mSize)
|
||||
mErrors->Error(mScanner->mLocation, EERR_CONSTANT_INITIALIZER, "String constant is too large for char array");
|
||||
|
||||
mScanner->NextToken();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -23,6 +23,7 @@ protected:
|
|||
|
||||
char mCharMap[256];
|
||||
|
||||
uint8* ParseStringLiteral(int msize);
|
||||
|
||||
void ParsePragma(void);
|
||||
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue