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:
@@ -143,20 +143,8 @@ static unsigned SkipFragment (FILE* F)
|
||||
/* Handle the different fragment types */
|
||||
switch (Type) {
|
||||
|
||||
case FRAG_LITERAL8:
|
||||
Size = Read8 (F);
|
||||
break;
|
||||
|
||||
case FRAG_LITERAL16:
|
||||
Size = Read16 (F);
|
||||
break;
|
||||
|
||||
case FRAG_LITERAL24:
|
||||
Size = Read24 (F);
|
||||
break;
|
||||
|
||||
case FRAG_LITERAL32:
|
||||
Size = Read32 (F);
|
||||
case FRAG_LITERAL:
|
||||
Size = ReadVar (F);
|
||||
break;
|
||||
|
||||
case FRAG_EXPR8:
|
||||
@@ -171,7 +159,7 @@ static unsigned SkipFragment (FILE* F)
|
||||
break;
|
||||
|
||||
case FRAG_FILL:
|
||||
Size = Read16 (F);
|
||||
Size = ReadVar (F);
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -277,7 +265,7 @@ void DumpObjOptions (FILE* F, unsigned long Offset)
|
||||
printf (" Options:\n");
|
||||
|
||||
/* Read the number of options and print it */
|
||||
Count = Read16 (F);
|
||||
Count = ReadVar (F);
|
||||
printf (" Count:%27u\n", Count);
|
||||
|
||||
/* Read and print all options */
|
||||
@@ -313,7 +301,7 @@ void DumpObjOptions (FILE* F, unsigned long Offset)
|
||||
switch (ArgType) {
|
||||
|
||||
case OPT_ARGSTR:
|
||||
ArgStr = ReadMallocedStr (F);
|
||||
ArgStr = ReadStr (F);
|
||||
ArgLen = strlen (ArgStr);
|
||||
printf (" Data:%*s\"%s\"\n", 24-ArgLen, "", ArgStr);
|
||||
xfree (ArgStr);
|
||||
@@ -361,7 +349,7 @@ void DumpObjFiles (FILE* F, unsigned long Offset)
|
||||
printf (" Files:\n");
|
||||
|
||||
/* Read the number of files and print it */
|
||||
Count = Read16 (F);
|
||||
Count = ReadVar (F);
|
||||
printf (" Count:%27u\n", Count);
|
||||
|
||||
/* Read and print all files */
|
||||
@@ -370,7 +358,7 @@ void DumpObjFiles (FILE* F, unsigned long Offset)
|
||||
/* Read the data for one file */
|
||||
unsigned long MTime = Read32 (F);
|
||||
unsigned long Size = Read32 (F);
|
||||
char* Name = ReadMallocedStr (F);
|
||||
char* Name = ReadStr (F);
|
||||
unsigned Len = strlen (Name);
|
||||
|
||||
/* Print the header */
|
||||
@@ -409,14 +397,14 @@ void DumpObjSegments (FILE* F, unsigned long Offset)
|
||||
printf (" Segments:\n");
|
||||
|
||||
/* Read the number of segments and print it */
|
||||
Count = Read8 (F);
|
||||
Count = ReadVar (F);
|
||||
printf (" Count:%27u\n", Count);
|
||||
|
||||
/* Read and print all segments */
|
||||
for (I = 0; I < Count; ++I) {
|
||||
|
||||
/* Read the data for one segments */
|
||||
char* Name = ReadMallocedStr (F);
|
||||
char* Name = ReadStr (F);
|
||||
unsigned Len = strlen (Name);
|
||||
unsigned long Size = Read32 (F);
|
||||
unsigned Align = (1U << Read8 (F));
|
||||
@@ -484,7 +472,7 @@ void DumpObjImports (FILE* F, unsigned long Offset)
|
||||
printf (" Imports:\n");
|
||||
|
||||
/* Read the number of imports and print it */
|
||||
Count = Read16 (F);
|
||||
Count = ReadVar (F);
|
||||
printf (" Count:%27u\n", Count);
|
||||
|
||||
/* Read and print all imports */
|
||||
@@ -494,7 +482,7 @@ void DumpObjImports (FILE* F, unsigned long Offset)
|
||||
|
||||
/* Read the data for one import */
|
||||
unsigned char Type = Read8 (F);
|
||||
char* Name = ReadMallocedStr (F);
|
||||
char* Name = ReadStr (F);
|
||||
unsigned Len = strlen (Name);
|
||||
ReadFilePos (F, &Pos);
|
||||
|
||||
@@ -540,7 +528,7 @@ void DumpObjExports (FILE* F, unsigned long Offset)
|
||||
printf (" Exports:\n");
|
||||
|
||||
/* Read the number of exports and print it */
|
||||
Count = Read16 (F);
|
||||
Count = ReadVar (F);
|
||||
printf (" Count:%27u\n", Count);
|
||||
|
||||
/* Read and print all exports */
|
||||
@@ -552,7 +540,7 @@ void DumpObjExports (FILE* F, unsigned long Offset)
|
||||
|
||||
/* Read the data for one export */
|
||||
unsigned char Type = Read8 (F);
|
||||
char* Name = ReadMallocedStr (F);
|
||||
char* Name = ReadStr (F);
|
||||
unsigned Len = strlen (Name);
|
||||
if (Type & EXP_EXPR) {
|
||||
SkipExpr (F);
|
||||
@@ -617,19 +605,19 @@ void DumpObjDbgSyms (FILE* F, unsigned long Offset)
|
||||
}
|
||||
|
||||
/* Read the number of exports and print it */
|
||||
Count = Read16 (F);
|
||||
Count = ReadVar (F);
|
||||
printf (" Count:%27u\n", Count);
|
||||
|
||||
/* Read and print all debug symbols */
|
||||
for (I = 0; I < Count; ++I) {
|
||||
|
||||
unsigned long Value = 0;
|
||||
int HaveValue;
|
||||
int HaveValue;
|
||||
const char* TypeDesc;
|
||||
|
||||
/* Read the data for one symbol */
|
||||
unsigned char Type = Read8 (F);
|
||||
char* Name = ReadMallocedStr (F);
|
||||
char* Name = ReadStr (F);
|
||||
unsigned Len = strlen (Name);
|
||||
if (Type & EXP_EXPR) {
|
||||
SkipExpr (F);
|
||||
@@ -666,3 +654,4 @@ void DumpObjDbgSyms (FILE* F, unsigned long Offset)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ unsigned Read8 (FILE* F)
|
||||
int C = getc (F);
|
||||
if (C == EOF) {
|
||||
Error ("Read error (file corrupt?)");
|
||||
}
|
||||
}
|
||||
return C;
|
||||
}
|
||||
|
||||
@@ -121,27 +121,35 @@ long Read32Signed (FILE* F)
|
||||
|
||||
|
||||
|
||||
char* ReadStr (FILE* F, char* Str)
|
||||
/* Read a string from the file. Str must hold 256 chars at max */
|
||||
unsigned long ReadVar (FILE* F)
|
||||
/* Read a variable size value from the file */
|
||||
{
|
||||
/* Read the length byte */
|
||||
unsigned Len = Read8 (F);
|
||||
/* 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);
|
||||
|
||||
/* Read the string itself */
|
||||
ReadData (F, Str, Len);
|
||||
|
||||
/* Terminate the string and return it */
|
||||
Str [Len] = '\0';
|
||||
return Str;
|
||||
/* Return the value read */
|
||||
return V;
|
||||
}
|
||||
|
||||
|
||||
|
||||
char* ReadMallocedStr (FILE* F)
|
||||
char* ReadStr (FILE* F)
|
||||
/* Read a string from the file into a malloced area */
|
||||
{
|
||||
/* Read the length byte */
|
||||
unsigned Len = Read8 (F);
|
||||
/* Read the length */
|
||||
unsigned Len = ReadVar (F);
|
||||
|
||||
/* Allocate memory */
|
||||
char* Str = xmalloc (Len + 1);
|
||||
@@ -159,10 +167,10 @@ char* ReadMallocedStr (FILE* F)
|
||||
FilePos* ReadFilePos (FILE* F, FilePos* Pos)
|
||||
/* Read a file position from the file */
|
||||
{
|
||||
/* The line number is encoded as 24 bit value to save some space */
|
||||
Pos->Line = Read24 (F);
|
||||
Pos->Col = Read8 (F);
|
||||
Pos->Name = Read8 (F);
|
||||
/* Read the data fields */
|
||||
Pos->Line = ReadVar (F);
|
||||
Pos->Col = ReadVar (F);
|
||||
Pos->Name = ReadVar (F);
|
||||
return Pos;
|
||||
}
|
||||
|
||||
|
||||
@@ -70,10 +70,10 @@ unsigned long Read32 (FILE* F);
|
||||
long Read32Signed (FILE* F);
|
||||
/* Read a 32 bit value from the file. Sign extend the value. */
|
||||
|
||||
char* ReadStr (FILE* F, char* Str);
|
||||
/* Read a string from the file. Str must hold 256 chars at max */
|
||||
unsigned long ReadVar (FILE* F);
|
||||
/* Read a variable size value from the file */
|
||||
|
||||
char* ReadMallocedStr (FILE* F);
|
||||
char* ReadStr (FILE* F);
|
||||
/* Read a string from the file into a malloced area */
|
||||
|
||||
FilePos* ReadFilePos (FILE* F, FilePos* Pos);
|
||||
|
||||
Reference in New Issue
Block a user