Added a method to write variable sized unsigned values. Use this method for

all sorts of things in the object files. This does not only make the object
files smaller, but does also remove several limits (strings may be longer
than 255 bytes, several counters no longer have 8 or 16 bit limits).


git-svn-id: svn://svn.cc65.org/cc65/trunk@260 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz
2000-08-02 13:23:06 +00:00
parent 85d8b3badf
commit 097a01094e
29 changed files with 423 additions and 295 deletions

View File

@@ -81,3 +81,19 @@ void DbgInfoFile (void)
void DbgInfoLine (void)
/* Parse and handle LINE subcommand of the .dbg pseudo instruction */
{
ErrorSkip (ERR_NOT_IMPLEMENTED);
}
void DbgInfoSym (void)
/* Parse and handle SYM subcommand of the .dbg pseudo instruction */
{
ErrorSkip (ERR_NOT_IMPLEMENTED);
}

View File

@@ -45,7 +45,13 @@
void DbgInfoFile (void);
/* Parse and handle the .REPEAT statement */
/* Parse and handle FILE subcommand of the .dbg pseudo instruction */
void DbgInfoLine (void);
/* Parse and handle LINE subcommand of the .dbg pseudo instruction */
void DbgInfoSym (void);
/* Parse and handle SYM subcommand of the .dbg pseudo instruction */
@@ -56,4 +62,4 @@ void DbgInfoFile (void);

View File

@@ -119,7 +119,7 @@ void WriteFiles (void)
ObjStartFiles ();
/* Write the file count */
ObjWrite16 (FileCount);
ObjWriteVar (FileCount);
/* Write the file data */
for (I = 0; I < FileCount; ++I) {

View File

@@ -486,19 +486,8 @@ static void WriteOneSeg (Segment* Seg)
Size += F->Len;
F = F->Next;
}
if (Size < 0x100) {
ObjWrite8 (FRAG_LITERAL8);
ObjWrite8 (Size);
} else if (Size < 0x10000) {
ObjWrite8 (FRAG_LITERAL16);
ObjWrite16 (Size);
} else if (Size < 0x1000000) {
ObjWrite8 (FRAG_LITERAL24);
ObjWrite24 (Size);
} else {
ObjWrite8 (FRAG_LITERAL32);
ObjWrite32 (Size);
}
ObjWrite8 (FRAG_LITERAL);
ObjWriteVar (Size);
/* Now write the literal data */
F = Frag;
@@ -533,7 +522,7 @@ static void WriteOneSeg (Segment* Seg)
case FRAG_FILL:
ObjWrite8 (FRAG_FILL);
ObjWrite16 (Frag->Len);
ObjWriteVar (Frag->Len);
break;
default:
@@ -560,7 +549,7 @@ void WriteSegments (void)
ObjStartSegments ();
/* First thing is segment count */
ObjWrite8 (SegmentCount);
ObjWriteVar (SegmentCount);
/* Now walk through all segments and write them to the object file */
Seg = SegmentList;
@@ -578,7 +567,7 @@ void WriteSegments (void)
/*****************************************************************************/
/* Code */
/* Code */
/*****************************************************************************/

View File

@@ -6,10 +6,10 @@
/* */
/* */
/* */
/* (C) 1998 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
/* (C) 1998-2000 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
@@ -41,7 +41,7 @@
/* common */
#include "fname.h"
#include "objdefs.h"
/* ca65 */
#include "global.h"
#include "error.h"
@@ -210,19 +210,36 @@ void ObjWrite32 (unsigned long V)
void ObjWriteVar (unsigned long V)
/* Write a variable sized value to the file in special encoding */
{
/* We will write the value to the file in 7 bit chunks. If the 8th bit
* is clear, we're done, if it is set, another chunk follows. This will
* allow us to encode smaller values with less bytes, at the expense of
* needing 5 bytes if a 32 bit value is written to file.
*/
do {
unsigned char C = (V & 0x7F);
V >>= 7;
if (V) {
C |= 0x80;
}
ObjWrite8 (C);
} while (V != 0);
}
void ObjWriteStr (const char* S)
/* Write a string to the object file */
{
unsigned Len = strlen (S);
if (Len > 255) {
Internal ("String too long in ObjWriteStr");
}
/* Write the string with a length byte preceeded (this is easier for
/* Write the string with the length preceeded (this is easier for
* the reading routine than the C format since the length is known in
* advance).
*/
ObjWrite8 ((unsigned char) Len);
ObjWriteVar (Len);
ObjWriteData (S, Len);
}
@@ -241,15 +258,15 @@ void ObjWriteData (const void* Data, unsigned Size)
void ObjWritePos (const FilePos* Pos)
/* Write a file position to the object file */
{
/* Write the line number as 24 bit value to save one byte */
ObjWrite24 (Pos->Line);
ObjWrite8 (Pos->Col);
/* Write the data entries */
ObjWriteVar (Pos->Line);
ObjWriteVar (Pos->Col);
if (Pos->Name == 0) {
/* Position is outside file scope, use the main file instead */
ObjWrite8 (0);
/* Position is outside file scope, use the main file instead */
ObjWriteVar (0);
} else {
ObjWrite8 (Pos->Name - 1);
}
ObjWriteVar (Pos->Name - 1);
}
}

View File

@@ -6,10 +6,10 @@
/* */
/* */
/* */
/* (C) 1998 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
/* (C) 1998-2000 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
@@ -38,7 +38,8 @@
#include "../common/filepos.h"
/* common */
#include "filepos.h"
@@ -65,6 +66,9 @@ void ObjWrite24 (unsigned long V);
void ObjWrite32 (unsigned long V);
/* Write a 32 bit value to the file */
void ObjWriteVar (unsigned long V);
/* Write a variable sized value to the file in special encoding */
void ObjWriteStr (const char* S);
/* Write a string to the object file */

View File

@@ -6,10 +6,10 @@
/* */
/* */
/* */
/* (C) 1998 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
/* (C) 1998-2000 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
@@ -33,9 +33,11 @@
#include "../common/optdefs.h"
#include "../common/xmalloc.h"
/* common */
#include "optdefs.h"
#include "xmalloc.h"
/* ca65 */
#include "error.h"
#include "objfile.h"
#include "options.h"
@@ -164,7 +166,7 @@ void WriteOptions (void)
ObjStartOptions ();
/* Write the option count */
ObjWrite16 (OptCount);
ObjWriteVar (OptCount);
/* Walk through the list and write the options */
O = OptRoot;

View File

@@ -370,14 +370,15 @@ static void DoDbg (void)
/* Skip the subkey */
NextTok ();
/* Parameters are separated by a comma */
ConsumeComma ();
/* Check the key and dispatch to a handler */
switch (Key) {
case 0: DbgInfoFile (); break;
case 1:
case 1: DbgInfoLine (); break;
case 2: DbgInfoSym (); break;
default: ErrorSkip (ERR_SYNTAX); break;
}
}

View File

@@ -6,10 +6,10 @@
/* */
/* */
/* */
/* (C) 1998 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
/* (C) 1998-2000 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
@@ -978,12 +978,12 @@ void WriteImports (void)
/* Write the imports list to the object file */
{
SymEntry* S;
/* Tell the object file module that we're about to start the imports */
ObjStartImports ();
/* Write the import count to the list */
ObjWrite16 (ImportCount);
ObjWriteVar (ImportCount);
/* Walk throught list and write all imports to the file */
S = SymList;
@@ -1015,7 +1015,7 @@ void WriteExports (void)
ObjStartExports ();
/* Write the export count to the list */
ObjWrite16 (ExportCount);
ObjWriteVar (ExportCount);
/* Walk throught list and write all exports to the file */
S = SymList;
@@ -1076,13 +1076,8 @@ void WriteDbgSyms (void)
S = S->List;
}
/* Safety check */
if (Count > 0xFFFF) {
Fatal (FAT_TOO_MANY_SYMBOLS);
}
/* Write the symbol count to the list */
ObjWrite16 (Count);
ObjWriteVar (Count);
/* Walk through list and write all symbols to the file */
S = SymList;
@@ -1118,7 +1113,7 @@ void WriteDbgSyms (void)
} else {
/* No debug symbols */
ObjWrite16 (0);
ObjWriteVar (0);
}