mirror of
https://github.com/cc65/cc65.git
synced 2024-09-30 08:57:49 +00:00
Reenable compile time evaluation of strlen for string literals.
git-svn-id: svn://svn.cc65.org/cc65/trunk@4631 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
15f95d7623
commit
1a4e2edede
@ -578,7 +578,6 @@ static void Primary (ExprDesc* E)
|
|||||||
/* This is the lowest level of the expression parser. */
|
/* This is the lowest level of the expression parser. */
|
||||||
{
|
{
|
||||||
SymEntry* Sym;
|
SymEntry* Sym;
|
||||||
Literal* L;
|
|
||||||
|
|
||||||
/* Initialize fields in the expression stucture */
|
/* Initialize fields in the expression stucture */
|
||||||
ED_Init (E);
|
ED_Init (E);
|
||||||
@ -749,7 +748,7 @@ static void Primary (ExprDesc* E)
|
|||||||
case TOK_SCONST:
|
case TOK_SCONST:
|
||||||
case TOK_WCSCONST:
|
case TOK_WCSCONST:
|
||||||
/* String literal */
|
/* String literal */
|
||||||
L = UseLiteral (CurTok.SVal);
|
E->LVal = UseLiteral (CurTok.SVal);
|
||||||
E->Type = GetCharArrayType (GetLiteralSize (CurTok.SVal));
|
E->Type = GetCharArrayType (GetLiteralSize (CurTok.SVal));
|
||||||
E->Flags = E_LOC_LITERAL | E_RTYPE_RVAL;
|
E->Flags = E_LOC_LITERAL | E_RTYPE_RVAL;
|
||||||
E->IVal = 0;
|
E->IVal = 0;
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* (C) 2002-2009, Ullrich von Bassewitz */
|
/* (C) 2002-2010, Ullrich von Bassewitz */
|
||||||
/* Roemerstrasse 52 */
|
/* Roemerstrasse 52 */
|
||||||
/* D-70794 Filderstadt */
|
/* D-70794 Filderstadt */
|
||||||
/* EMail: uz@cc65.org */
|
/* EMail: uz@cc65.org */
|
||||||
@ -63,6 +63,7 @@ ExprDesc* ED_Init (ExprDesc* Expr)
|
|||||||
Expr->Name = 0;
|
Expr->Name = 0;
|
||||||
Expr->IVal = 0;
|
Expr->IVal = 0;
|
||||||
Expr->FVal = FP_D_Make (0.0);
|
Expr->FVal = FP_D_Make (0.0);
|
||||||
|
Expr->LVal = 0;
|
||||||
Expr->BitOffs = 0;
|
Expr->BitOffs = 0;
|
||||||
Expr->BitWidth = 0;
|
Expr->BitWidth = 0;
|
||||||
return Expr;
|
return Expr;
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* (C) 2002-2009, Ullrich von Bassewitz */
|
/* (C) 2002-2010, Ullrich von Bassewitz */
|
||||||
/* Roemerstrasse 52 */
|
/* Roemerstrasse 52 */
|
||||||
/* D-70794 Filderstadt */
|
/* D-70794 Filderstadt */
|
||||||
/* EMail: uz@cc65.org */
|
/* EMail: uz@cc65.org */
|
||||||
@ -89,6 +89,9 @@ enum {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Forward */
|
||||||
|
struct Literal;
|
||||||
|
|
||||||
/* Describe the result of an expression */
|
/* Describe the result of an expression */
|
||||||
typedef struct ExprDesc ExprDesc;
|
typedef struct ExprDesc ExprDesc;
|
||||||
struct ExprDesc {
|
struct ExprDesc {
|
||||||
@ -98,6 +101,7 @@ struct ExprDesc {
|
|||||||
unsigned long Name; /* Name or label number */
|
unsigned long Name; /* Name or label number */
|
||||||
long IVal; /* Integer value if expression constant */
|
long IVal; /* Integer value if expression constant */
|
||||||
Double FVal; /* Floating point value */
|
Double FVal; /* Floating point value */
|
||||||
|
struct Literal* LVal; /* Literal value */
|
||||||
|
|
||||||
/* Bit field stuff */
|
/* Bit field stuff */
|
||||||
unsigned BitOffs; /* Bit offset for bit fields */
|
unsigned BitOffs; /* Bit offset for bit fields */
|
||||||
|
@ -934,7 +934,6 @@ static void StdFunc_strlen (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
|
|||||||
/* Do type conversion */
|
/* Do type conversion */
|
||||||
TypeConversion (&Arg, ArgType);
|
TypeConversion (&Arg, ArgType);
|
||||||
|
|
||||||
#if 0
|
|
||||||
/* If the expression is a literal, and if string literals are read
|
/* If the expression is a literal, and if string literals are read
|
||||||
* only, we can calculate the length of the string and remove it
|
* only, we can calculate the length of the string and remove it
|
||||||
* from the literal pool. Otherwise we have to calculate the length
|
* from the literal pool. Otherwise we have to calculate the length
|
||||||
@ -943,15 +942,16 @@ static void StdFunc_strlen (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
|
|||||||
if (ED_IsLocLiteral (&Arg) && IS_Get (&WritableStrings) == 0) {
|
if (ED_IsLocLiteral (&Arg) && IS_Get (&WritableStrings) == 0) {
|
||||||
|
|
||||||
/* Constant string literal */
|
/* Constant string literal */
|
||||||
ED_MakeConstAbs (Expr, GetLiteralSize (GetLiteral (Arg.IVal)), type_size_t);
|
ED_MakeConstAbs (Expr, GetLiteralSize (Arg.LVal) - 1, type_size_t);
|
||||||
|
|
||||||
|
/* We don't need the literal any longer */
|
||||||
|
ReleaseLiteral (Arg.LVal);
|
||||||
|
|
||||||
/* We will inline strlen for arrays with constant addresses, if either the
|
/* We will inline strlen for arrays with constant addresses, if either the
|
||||||
* inlining was forced on the command line, or the array is smaller than
|
* inlining was forced on the command line, or the array is smaller than
|
||||||
* 256, so the inlining is considered safe.
|
* 256, so the inlining is considered safe.
|
||||||
*/
|
*/
|
||||||
} else
|
} else if (ED_IsLocConst (&Arg) && IsArray &&
|
||||||
#endif
|
|
||||||
if (ED_IsLocConst (&Arg) && IsArray &&
|
|
||||||
(IS_Get (&InlineStdFuncs) || IsByteIndex)) {
|
(IS_Get (&InlineStdFuncs) || IsByteIndex)) {
|
||||||
|
|
||||||
/* Generate the strlen code */
|
/* Generate the strlen code */
|
||||||
|
Loading…
Reference in New Issue
Block a user