mirror of
https://github.com/cc65/cc65.git
synced 2025-01-05 15:30:44 +00:00
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:
parent
e7fe36399b
commit
6e32190cae
@ -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
|
||||
* a complex expression. If E is a constant, return true and place its value
|
||||
* into Val, provided that Val is not NULL.
|
||||
|
@ -6,10 +6,10 @@
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* (C) 1998-2006 Ullrich von Bassewitz */
|
||||
/* Römerstraße 52 */
|
||||
/* D-70794 Filderstadt */
|
||||
/* EMail: uz@cc65.org */
|
||||
/* (C) 1998-2011, Ullrich von Bassewitz */
|
||||
/* Roemerstrasse 52 */
|
||||
/* D-70794 Filderstadt */
|
||||
/* EMail: uz@cc65.org */
|
||||
/* */
|
||||
/* */
|
||||
/* This software is provided 'as-is', without any expressed or implied */
|
||||
@ -129,6 +129,12 @@ int IsWordRange (long Val);
|
||||
int IsFarRange (long Val);
|
||||
/* 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);
|
||||
/* Clone the given expression tree. The function will simply clone symbol
|
||||
* nodes, it will not resolve them.
|
||||
|
@ -61,8 +61,8 @@ struct Fragment {
|
||||
unsigned short Len; /* Length for this fragment */
|
||||
unsigned char Type; /* Fragment type */
|
||||
union {
|
||||
unsigned char Data[4]; /* Literal values */
|
||||
ExprNode* Expr; /* Expression */
|
||||
unsigned char Data[sizeof (ExprNode*)]; /* Literal values */
|
||||
ExprNode* Expr; /* Expression */
|
||||
} V;
|
||||
};
|
||||
|
||||
|
@ -15,7 +15,7 @@ CA65_INC = \"/usr/lib/cc65/asminc/\"
|
||||
|
||||
#
|
||||
CC = gcc
|
||||
CFLAGS = -g -O2 -Wall -W -std=c89
|
||||
CFLAGS = -g -Wall -W -std=c89
|
||||
override CFLAGS += -I$(COMMON)
|
||||
override CFLAGS += -DCA65_INC=$(CA65_INC)
|
||||
EBIND = emxbind
|
||||
|
@ -6,10 +6,10 @@
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* (C) 1998-2008 Ullrich von Bassewitz */
|
||||
/* Roemerstrasse 52 */
|
||||
/* D-70794 Filderstadt */
|
||||
/* EMail: uz@cc65.org */
|
||||
/* (C) 1998-2011, Ullrich von Bassewitz */
|
||||
/* Roemerstrasse 52 */
|
||||
/* D-70794 Filderstadt */
|
||||
/* EMail: uz@cc65.org */
|
||||
/* */
|
||||
/* */
|
||||
/* 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 */
|
||||
{
|
||||
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)
|
||||
/* Emit an instruction with an one byte argument */
|
||||
{
|
||||
Emit0 (OPC);
|
||||
EmitByte (Value);
|
||||
long V;
|
||||
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)
|
||||
/* Emit an instruction with a two byte argument */
|
||||
{
|
||||
Emit0 (OPC);
|
||||
EmitWord (Value);
|
||||
long V;
|
||||
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)
|
||||
/* Emit one byte */
|
||||
{
|
||||
/* Create a new fragment */
|
||||
Fragment* F = GenFragment (FRAG_EXPR, 1);
|
||||
long V;
|
||||
Fragment* F;
|
||||
|
||||
/* Set the data */
|
||||
F->V.Expr = Expr;
|
||||
if (IsEasyConst (Expr, &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, 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)
|
||||
/* Emit one word */
|
||||
{
|
||||
/* Create a new fragment */
|
||||
Fragment* F = GenFragment (FRAG_EXPR, 2);
|
||||
long V;
|
||||
Fragment* F;
|
||||
|
||||
/* Set the data */
|
||||
F->V.Expr = Expr;
|
||||
if (IsEasyConst (Expr, &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, 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user