A few measures to create slightly smaller object files.

git-svn-id: svn://svn.cc65.org/cc65/trunk@5165 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
uz
2011-08-14 20:06:14 +00:00
parent e7fe36399b
commit 6e32190cae
5 changed files with 105 additions and 25 deletions

View File

@@ -169,7 +169,7 @@ int IsFarRange (long Val)
static int IsEasyConst (const ExprNode* E, long* Val) int IsEasyConst (const ExprNode* E, long* Val)
/* Do some light checking if the given node is a constant. Don't care if E is /* Do some light checking if the given node is a constant. Don't care if E is
* a complex expression. If E is a constant, return true and place its value * a complex expression. If E is a constant, return true and place its value
* into Val, provided that Val is not NULL. * into Val, provided that Val is not NULL.

View File

@@ -6,10 +6,10 @@
/* */ /* */
/* */ /* */
/* */ /* */
/* (C) 1998-2006 Ullrich von Bassewitz */ /* (C) 1998-2011, Ullrich von Bassewitz */
/* R<EFBFBD>merstra<EFBFBD>e 52 */ /* Roemerstrasse 52 */
/* D-70794 Filderstadt */ /* D-70794 Filderstadt */
/* EMail: uz@cc65.org */ /* EMail: uz@cc65.org */
/* */ /* */
/* */ /* */
/* This software is provided 'as-is', without any expressed or implied */ /* This software is provided 'as-is', without any expressed or implied */
@@ -129,6 +129,12 @@ int IsWordRange (long Val);
int IsFarRange (long Val); int IsFarRange (long Val);
/* Return true if this is a far (24 bit) value */ /* Return true if this is a far (24 bit) value */
int IsEasyConst (const ExprNode* E, long* Val);
/* Do some light checking if the given node is a constant. Don't care if E is
* a complex expression. If E is a constant, return true and place its value
* into Val, provided that Val is not NULL.
*/
ExprNode* CloneExpr (ExprNode* Expr); ExprNode* CloneExpr (ExprNode* Expr);
/* Clone the given expression tree. The function will simply clone symbol /* Clone the given expression tree. The function will simply clone symbol
* nodes, it will not resolve them. * nodes, it will not resolve them.

View File

@@ -61,8 +61,8 @@ struct Fragment {
unsigned short Len; /* Length for this fragment */ unsigned short Len; /* Length for this fragment */
unsigned char Type; /* Fragment type */ unsigned char Type; /* Fragment type */
union { union {
unsigned char Data[4]; /* Literal values */ unsigned char Data[sizeof (ExprNode*)]; /* Literal values */
ExprNode* Expr; /* Expression */ ExprNode* Expr; /* Expression */
} V; } V;
}; };

View File

@@ -15,7 +15,7 @@ CA65_INC = \"/usr/lib/cc65/asminc/\"
# #
CC = gcc CC = gcc
CFLAGS = -g -O2 -Wall -W -std=c89 CFLAGS = -g -Wall -W -std=c89
override CFLAGS += -I$(COMMON) override CFLAGS += -I$(COMMON)
override CFLAGS += -DCA65_INC=$(CA65_INC) override CFLAGS += -DCA65_INC=$(CA65_INC)
EBIND = emxbind EBIND = emxbind

View File

@@ -6,10 +6,10 @@
/* */ /* */
/* */ /* */
/* */ /* */
/* (C) 1998-2008 Ullrich von Bassewitz */ /* (C) 1998-2011, Ullrich von Bassewitz */
/* Roemerstrasse 52 */ /* Roemerstrasse 52 */
/* D-70794 Filderstadt */ /* D-70794 Filderstadt */
/* EMail: uz@cc65.org */ /* EMail: uz@cc65.org */
/* */ /* */
/* */ /* */
/* This software is provided 'as-is', without any expressed or implied */ /* This software is provided 'as-is', without any expressed or implied */
@@ -54,7 +54,7 @@ void Emit0 (unsigned char OPC)
/* Emit an instruction with a zero sized operand */ /* Emit an instruction with a zero sized operand */
{ {
Fragment* F = GenFragment (FRAG_LITERAL, 1); Fragment* F = GenFragment (FRAG_LITERAL, 1);
F->V.Data [0] = OPC; F->V.Data[0] = OPC;
} }
@@ -62,8 +62,31 @@ void Emit0 (unsigned char OPC)
void Emit1 (unsigned char OPC, ExprNode* Value) void Emit1 (unsigned char OPC, ExprNode* Value)
/* Emit an instruction with an one byte argument */ /* Emit an instruction with an one byte argument */
{ {
Emit0 (OPC); long V;
EmitByte (Value); Fragment* F;
if (IsEasyConst (Value, &V)) {
/* Must be in byte range */
if (!IsByteRange (V)) {
Error ("Range error (%ld not in [0..255])", V);
}
/* Create a literal fragment */
F = GenFragment (FRAG_LITERAL, 2);
F->V.Data[0] = OPC;
F->V.Data[1] = (unsigned char) V;
FreeExpr (Value);
} else {
/* Emit the opcode */
Emit0 (OPC);
/* Emit the argument as an expression */
F = GenFragment (FRAG_EXPR, 1);
F->V.Expr = Value;
}
} }
@@ -71,8 +94,32 @@ void Emit1 (unsigned char OPC, ExprNode* Value)
void Emit2 (unsigned char OPC, ExprNode* Value) void Emit2 (unsigned char OPC, ExprNode* Value)
/* Emit an instruction with a two byte argument */ /* Emit an instruction with a two byte argument */
{ {
Emit0 (OPC); long V;
EmitWord (Value); Fragment* F;
if (IsEasyConst (Value, &V)) {
/* Must be in byte range */
if (!IsWordRange (V)) {
Error ("Range error (%ld not in [0..65535])", V);
}
/* Create a literal fragment */
F = GenFragment (FRAG_LITERAL, 3);
F->V.Data[0] = OPC;
F->V.Data[1] = (unsigned char) V;
F->V.Data[2] = (unsigned char) (V >> 8);
FreeExpr (Value);
} else {
/* Emit the opcode */
Emit0 (OPC);
/* Emit the argument as an expression */
F = GenFragment (FRAG_EXPR, 2);
F->V.Expr = Value;
}
} }
@@ -147,11 +194,24 @@ void EmitStrBuf (const StrBuf* Data)
void EmitByte (ExprNode* Expr) void EmitByte (ExprNode* Expr)
/* Emit one byte */ /* Emit one byte */
{ {
/* Create a new fragment */ long V;
Fragment* F = GenFragment (FRAG_EXPR, 1); Fragment* F;
/* Set the data */ if (IsEasyConst (Expr, &V)) {
F->V.Expr = Expr; /* Must be in byte range */
if (!IsByteRange (V)) {
Error ("Range error (%ld not in [0..255])", V);
}
/* Create a literal fragment */
F = GenFragment (FRAG_LITERAL, 1);
F->V.Data[0] = (unsigned char) V;
FreeExpr (Expr);
} else {
/* Emit the argument as an expression */
F = GenFragment (FRAG_EXPR, 1);
F->V.Expr = Expr;
}
} }
@@ -159,11 +219,25 @@ void EmitByte (ExprNode* Expr)
void EmitWord (ExprNode* Expr) void EmitWord (ExprNode* Expr)
/* Emit one word */ /* Emit one word */
{ {
/* Create a new fragment */ long V;
Fragment* F = GenFragment (FRAG_EXPR, 2); Fragment* F;
/* Set the data */ if (IsEasyConst (Expr, &V)) {
F->V.Expr = Expr; /* Must be in byte range */
if (!IsWordRange (V)) {
Error ("Range error (%ld not in [0..65535])", V);
}
/* Create a literal fragment */
F = GenFragment (FRAG_LITERAL, 2);
F->V.Data[0] = (unsigned char) V;
F->V.Data[1] = (unsigned char) (V >> 8);
FreeExpr (Expr);
} else {
/* Emit the argument as an expression */
Fragment* F = GenFragment (FRAG_EXPR, 2);
F->V.Expr = Expr;
}
} }