From: uz Date: Sun, 14 Aug 2011 20:06:14 +0000 (+0000) Subject: A few measures to create slightly smaller object files. X-Git-Tag: V2.13.3~297 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=6e32190cae15affd0d2c0faef8795bf871a2ce3b;p=cc65 A few measures to create slightly smaller object files. git-svn-id: svn://svn.cc65.org/cc65/trunk@5165 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- diff --git a/src/ca65/expr.c b/src/ca65/expr.c index 123e9ad65..25129decc 100644 --- a/src/ca65/expr.c +++ b/src/ca65/expr.c @@ -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. diff --git a/src/ca65/expr.h b/src/ca65/expr.h index 8d492a3db..694a3b1a6 100644 --- a/src/ca65/expr.h +++ b/src/ca65/expr.h @@ -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. diff --git a/src/ca65/fragment.h b/src/ca65/fragment.h index 2db86f48a..6cd9a8fbb 100644 --- a/src/ca65/fragment.h +++ b/src/ca65/fragment.h @@ -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; }; diff --git a/src/ca65/make/gcc.mak b/src/ca65/make/gcc.mak index 46d432bbd..176e246e2 100644 --- a/src/ca65/make/gcc.mak +++ b/src/ca65/make/gcc.mak @@ -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 diff --git a/src/ca65/objcode.c b/src/ca65/objcode.c index f9032a076..f80eec203 100644 --- a/src/ca65/objcode.c +++ b/src/ca65/objcode.c @@ -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); - - /* Set the data */ - F->V.Expr = Expr; + long V; + Fragment* F; + + 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); - - /* Set the data */ - F->V.Expr = Expr; + long V; + Fragment* F; + + 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; + } }