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:
@@ -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 */
|
||||
@@ -35,9 +35,11 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "../common/hashstr.h"
|
||||
#include "../common/xmalloc.h"
|
||||
|
||||
/* common */
|
||||
#include "hashstr.h"
|
||||
#include "xmalloc.h"
|
||||
|
||||
/* ar65 */
|
||||
#include "error.h"
|
||||
#include "objdata.h"
|
||||
#include "exports.h"
|
||||
@@ -112,7 +114,7 @@ void ExpInsert (const char* Name, unsigned Module)
|
||||
/* Duplicate entry */
|
||||
Warning ("External symbol `%s' in module `%s' is duplicated in "
|
||||
"module `%s'",
|
||||
Name, GetObjName (L->Module), GetObjName (Module));
|
||||
Name, GetObjName (L->Module), GetObjName (Module));
|
||||
}
|
||||
if (L->Next == 0) {
|
||||
break;
|
||||
@@ -147,4 +149,4 @@ int ExpFind (const char* Name)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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 */
|
||||
@@ -35,8 +35,10 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "../common/xmalloc.h"
|
||||
/* common */
|
||||
#include "xmalloc.h"
|
||||
|
||||
/* ar65 */
|
||||
#include "error.h"
|
||||
#include "fileio.h"
|
||||
|
||||
@@ -78,14 +80,31 @@ void Write32 (FILE* F, unsigned long Val)
|
||||
|
||||
|
||||
|
||||
void WriteVar (FILE* F, 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;
|
||||
}
|
||||
Write8 (F, C);
|
||||
} while (V != 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void WriteStr (FILE* F, const char* S)
|
||||
/* Write a string to the file */
|
||||
{
|
||||
unsigned Len = strlen (S);
|
||||
if (Len > 255) {
|
||||
Internal ("String too long");
|
||||
}
|
||||
Write8 (F, (unsigned char) Len);
|
||||
WriteVar (F, Len);
|
||||
WriteData (F, S, Len);
|
||||
}
|
||||
|
||||
@@ -133,11 +152,35 @@ unsigned long Read32 (FILE* F)
|
||||
|
||||
|
||||
|
||||
unsigned long ReadVar (FILE* F)
|
||||
/* Read a variable size value from the file */
|
||||
{
|
||||
/* The value was written to the file in 7 bit chunks LSB first. If there
|
||||
* are more bytes, bit 8 is set, otherwise it is clear.
|
||||
*/
|
||||
unsigned char C;
|
||||
unsigned long V = 0;
|
||||
unsigned Shift = 0;
|
||||
do {
|
||||
/* Read one byte */
|
||||
C = Read8 (F);
|
||||
/* Encode it into the target value */
|
||||
V |= ((unsigned long)(C & 0x7F)) << Shift;
|
||||
/* Next value */
|
||||
Shift += 7;
|
||||
} while (C & 0x80);
|
||||
|
||||
/* Return the value read */
|
||||
return V;
|
||||
}
|
||||
|
||||
|
||||
|
||||
char* ReadStr (FILE* F)
|
||||
/* Read a string from the file (the memory will be malloc'ed) */
|
||||
{
|
||||
/* Read the length byte */
|
||||
unsigned Len = Read8 (F);
|
||||
/* Read the length */
|
||||
unsigned Len = ReadVar (F);
|
||||
|
||||
/* Allocate memory and read the string itself */
|
||||
char* S = xmalloc (Len + 1);
|
||||
|
||||
@@ -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 */
|
||||
@@ -57,6 +57,9 @@ void Write16 (FILE* F, unsigned Val);
|
||||
void Write32 (FILE* F, unsigned long Val);
|
||||
/* Write a 32 bit value to the file */
|
||||
|
||||
void WriteVar (FILE* F, unsigned long V);
|
||||
/* Write a variable sized value to the file in special encoding */
|
||||
|
||||
void WriteStr (FILE* F, const char* S);
|
||||
/* Write a string to the file */
|
||||
|
||||
@@ -72,6 +75,9 @@ unsigned Read16 (FILE* F);
|
||||
unsigned long Read32 (FILE* F);
|
||||
/* Read a 32 bit value from the file */
|
||||
|
||||
unsigned long ReadVar (FILE* F);
|
||||
/* Read a variable size value from the file */
|
||||
|
||||
char* ReadStr (FILE* F);
|
||||
/* Read a string from the file (the memory will be malloc'ed) */
|
||||
|
||||
|
||||
@@ -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 */
|
||||
@@ -37,13 +37,15 @@
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "../common/bitops.h"
|
||||
#include "../common/exprdefs.h"
|
||||
#include "../common/filepos.h"
|
||||
#include "../common/libdefs.h"
|
||||
#include "../common/symdefs.h"
|
||||
#include "../common/xmalloc.h"
|
||||
/* common */
|
||||
#include "bitops.h"
|
||||
#include "exprdefs.h"
|
||||
#include "filepos.h"
|
||||
#include "libdefs.h"
|
||||
#include "symdefs.h"
|
||||
#include "xmalloc.h"
|
||||
|
||||
/* ar65 */
|
||||
#include "error.h"
|
||||
#include "global.h"
|
||||
#include "fileio.h"
|
||||
@@ -303,6 +305,28 @@ void LibCopyFrom (unsigned long Pos, unsigned long Bytes, FILE* F)
|
||||
|
||||
|
||||
|
||||
static unsigned long GetVar (unsigned char** Buf)
|
||||
/* Get a variable sized value from Buf */
|
||||
{
|
||||
unsigned char C;
|
||||
unsigned long V = 0;
|
||||
unsigned Shift = 0;
|
||||
do {
|
||||
/* Read one byte */
|
||||
C = **Buf;
|
||||
++(*Buf);
|
||||
/* Add this char to the value */
|
||||
V |= ((unsigned long)(C & 0x7F)) << Shift;
|
||||
/* Next value */
|
||||
Shift += 7;
|
||||
} while (C & 0x80);
|
||||
|
||||
/* Return the result */
|
||||
return V;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void SkipExpr (unsigned char** Buf)
|
||||
/* Skip an expression in Buf */
|
||||
{
|
||||
@@ -339,20 +363,26 @@ static void SkipExpr (unsigned char** Buf)
|
||||
|
||||
|
||||
|
||||
static void SkipFilePos (unsigned char** Buf)
|
||||
/* Skip a file position in Buf */
|
||||
{
|
||||
(void) GetVar (Buf); /* Line */
|
||||
(void) GetVar (Buf); /* Col */
|
||||
(void) GetVar (Buf); /* Name */
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void LibCheckExports (ObjData* O)
|
||||
/* Insert all exports from the given object file into the global list
|
||||
* checking for duplicates.
|
||||
*/
|
||||
{
|
||||
char Name [256];
|
||||
|
||||
/* Get a pointer to the buffer */
|
||||
unsigned char* Exports = O->Exports;
|
||||
|
||||
/* First two bytes are export count */
|
||||
unsigned Lo = *Exports++;
|
||||
unsigned Hi = *Exports++;
|
||||
unsigned Count = (Hi << 8) + Lo;
|
||||
/* Get the export count */
|
||||
unsigned Count = GetVar (&Exports);
|
||||
|
||||
/* Read the exports */
|
||||
if (Verbose > 1) {
|
||||
@@ -360,13 +390,12 @@ static void LibCheckExports (ObjData* O)
|
||||
}
|
||||
while (Count--) {
|
||||
|
||||
unsigned char Len;
|
||||
|
||||
/* Get the export tag */
|
||||
unsigned char Tag = *Exports++;
|
||||
|
||||
/* Next thing is name of symbol */
|
||||
Len = *Exports++;
|
||||
unsigned Len = GetVar (&Exports);
|
||||
char* Name = xmalloc (Len + 1);
|
||||
memcpy (Name, Exports, Len);
|
||||
Name [Len] = '\0';
|
||||
Exports += Len;
|
||||
@@ -381,13 +410,16 @@ static void LibCheckExports (ObjData* O)
|
||||
}
|
||||
|
||||
/* Skip the position */
|
||||
Exports += POS_SIZE;
|
||||
SkipFilePos (&Exports);
|
||||
|
||||
/* Insert the name into the hash table */
|
||||
if (Verbose > 1) {
|
||||
printf (" %s\n", Name);
|
||||
}
|
||||
ExpInsert (Name, O->Index);
|
||||
|
||||
/* Free the name */
|
||||
xfree (Name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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,7 @@
|
||||
/* common */
|
||||
#include "check.h"
|
||||
#include "xmalloc.h"
|
||||
|
||||
|
||||
/* ar65 */
|
||||
#include "error.h"
|
||||
#include "objdata.h"
|
||||
@@ -189,7 +189,7 @@ void MakeObjPool (void)
|
||||
|
||||
/* Set the pool pointer */
|
||||
ObjPool [Index] = O;
|
||||
|
||||
|
||||
/* Next object */
|
||||
++Index;
|
||||
O = O->Next;
|
||||
|
||||
Reference in New Issue
Block a user