Browse Source

Complete pucrunch support: fix sizes and checksum, actually call the compression function.

git-svn-id: file:///var/svn/tigccpp/trunk@1148 9552661e-59e3-4036-b4f2-dbe53926924f
kevinkofler 17 years ago
parent
commit
a091273289

+ 4 - 1
tigcc/ld-tigcc/export/exp_tios.c

@@ -173,6 +173,8 @@ BOOLEAN ExportTIOSFile (const PROGRAM *Program, EXP_FILE *File, SIZE FileSize, P
 }
 
 #ifdef PUCRUNCH_SUPPORT
+#include "pucrunch.h"
+
 // Export the internal data structures into a packed TIOS file.
 BOOLEAN ExportPackedTIOSFile (const PROGRAM *Program, EXP_FILE *File, SIZE FileSize, ProgramCalcs DestCalc)
 {
@@ -280,7 +282,8 @@ BOOLEAN ExportPackedTIOSFile (const PROGRAM *Program, EXP_FILE *File, SIZE FileS
 	if (Program->OptimizeInfo->NativeRelocCount < EmittedRelocCount)
 		Program->OptimizeInfo->NativeRelocCount = EmittedRelocCount;
 	
-	return TRUE;
+	// Now compress the buffer and write it out to the file.
+	return !TTPack(0, VarFileSize, Buffer, File);
 	
 #undef FailWithError
 }

+ 8 - 2
tigcc/ld-tigcc/export/export.c

@@ -320,8 +320,11 @@ BOOLEAN GetOutputFile (INT_EXP_FILE *File, SIZE FileSize, unsigned int DestCalc,
 				SIZE VarFileSize = 2 + FileSize + 1;
 				
 				// If the file has an extension, add the size needed for it.
-				if (Extension)
-					VarFileSize += 1 + strlen (Extension) + 1;
+#ifdef PUCRUNCH_SUPPORT
+				if (!Pack || FileRole != FR_MAIN)
+#endif /* !PUCRUNCH_SUPPORT */
+					if (Extension)
+						VarFileSize += 1 + strlen (Extension) + 1;
 				
 				// The variable size is what the user will see.
 				*EffectiveSize = VarFileSize;
@@ -486,6 +489,9 @@ BOOLEAN GetOutputFile (INT_EXP_FILE *File, SIZE FileSize, unsigned int DestCalc,
 					}
 					
 					// Write the on-calc file header.
+#ifdef PUCRUNCH_SUPPORT
+					if (!Pack || FileRole != FR_MAIN)
+#endif /* !PUCRUNCH_SUPPORT */
 					{
 						TI2 EncVarFileSize;
 						

+ 27 - 5
tigcc/ld-tigcc/export/pucrunch.c

@@ -26,7 +26,8 @@
 #include <time.h>
 
 #include "../generic.h"
-#include "../formats/packhead.h"    // compressed header definition
+#include "../formats/packhead.h" // compressed header definition
+#include "../formats/tios.h"
 #include "pucrunch.h"
 
 #define VERBOSE_OUT stdout
@@ -36,6 +37,12 @@
 #define min(a,b) ((a<b)?(a):(b))
 #endif
 
+#if defined(__GNUC__) && __GNUC__ >= 4
+#define OFFSETOF __builtin_offsetof
+#else
+#define OFFSETOF(type,member) ((size_t) &(((type*)0)->member))
+#endif
+
 
 #define LRANGE          (((2<<maxGamma)-3)*256) /* 0..125, 126 -> 1..127 */
 #define MAXLZLEN        (2<<maxGamma)
@@ -43,7 +50,6 @@
 #define DEFAULT_LZLEN   LRANGE
 
 
-
 static unsigned short *rle, *elr, *lzlen, *lzpos;
 static int *length, inlen;
 static unsigned char *indata, *mode, *newesc;
@@ -178,9 +184,25 @@ static int SavePack(unsigned char *data, int size, EXP_FILE *fp, int escape,
 
     for(i=0; i<rleUsed; i++) re.value[i] = rleValues[i+1];
 
-    ExportWrite(fp, &cth, 1, sizeof(PackedHeader)); // write header
-    ExportWrite(fp, &re,  1, cth.rleentries);       // write rle values
-    ExportWrite(fp, data, size, 1);                 // write compressed data
+    {
+        int packedSize = sizeof(PackedHeader) + cth.rleentries + size + 6;
+        ExportWriteTI2(fp, packedSize);                 // write size bytes
+        ExportWrite(fp, &cth, 1, sizeof(PackedHeader)); // write header
+        ExportWrite(fp, &re,  1, cth.rleentries);       // write rle values
+        ExportWrite(fp, data, size, 1);                 // write compressed data
+
+        /* Now fix the on-computer size */
+        {
+            long position = ExportTell(fp);
+            HI4 packedSizeEnc;
+            packedSize += 2 + sizeof (TIOS_HOST_FILE_HEADER) + sizeof (TIOS_HOST_FILE_FOOTER);
+            WriteHI4(packedSizeEnc, packedSize);
+            ExportSeek(fp, OFFSETOF(TIOS_HOST_FILE_HEADER, FileSize));
+            fwrite(&packedSizeEnc, 4, 1, fp->File.File);
+            ExportSeek(fp, position);
+        }
+    }
+
     return 0;
 }