cvsuser 03/11/21 08:28:30
Modified: include/parrot packfile.h
src packfile.c packout.c
Log:
PackFile-19
* dont scan PF constants twice during pack
* cleanup and simplififcations
Revision Changes Path
1.52 +2 -3 parrot/include/parrot/packfile.h
Index: packfile.h
===================================================================
RCS file: /cvs/public/parrot/include/parrot/packfile.h,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -w -r1.51 -r1.52
--- packfile.h 21 Nov 2003 13:50:09 -0000 1.51
+++ packfile.h 21 Nov 2003 16:28:28 -0000 1.52
@@ -1,6 +1,6 @@
/* packfile.h
*
-* $Id: packfile.h,v 1.51 2003/11/21 13:50:09 leo Exp $
+* $Id: packfile.h,v 1.52 2003/11/21 16:28:28 leo Exp $
*
* History:
* Rework by Melvin; new bytecode format, make bytecode portable.
@@ -327,8 +327,7 @@
size_t PackFile_Constant_pack_size(struct PackFile_Constant * self);
-void PackFile_Constant_pack(struct PackFile_Constant * self,
- opcode_t * packed);
+opcode_t * PackFile_Constant_pack(struct PackFile_Constant *, opcode_t *);
void PackFile_Constant_destroy(struct PackFile_Constant * self);
1.120 +8 -6 parrot/src/packfile.c
Index: packfile.c
===================================================================
RCS file: /cvs/public/parrot/src/packfile.c,v
retrieving revision 1.119
retrieving revision 1.120
diff -u -w -r1.119 -r1.120
--- packfile.c 21 Nov 2003 14:26:03 -0000 1.119
+++ packfile.c 21 Nov 2003 16:28:30 -0000 1.120
@@ -7,7 +7,7 @@
** This program is free software. It is subject to the same
** license as Parrot itself.
**
-** $Id: packfile.c,v 1.119 2003/11/21 14:26:03 leo Exp $
+** $Id: packfile.c,v 1.120 2003/11/21 16:28:30 leo Exp $
**
** History:
** Rework by Melvin; new bytecode format, make bytecode portable.
@@ -76,8 +76,9 @@
static void pf_debug_destroy (struct PackFile_Segment *self);
/* internal definitions */
-#define ROUND_UP(val,size) ((((val) + (size - 1))/(size)) * (size))
+#define ROUND_UP(val,size) (((val) + ((size) - 1))/(size))
+size_t cstring_packed_size(const char *s);
/******************************************************************************
=head1 PackFile Manipulation Functions
@@ -94,7 +95,8 @@
*/
-static size_t cstring_packed_size(const char *s)
+size_t
+cstring_packed_size(const char *s)
{
UINTVAL str_len;
@@ -102,7 +104,7 @@
return 0;
str_len = strlen(s);
- return ROUND_UP(str_len + 1, sizeof(opcode_t)) / sizeof(opcode_t);
+ return ROUND_UP(str_len + 1, sizeof(opcode_t));
}
/***************************************
@@ -1035,7 +1037,7 @@
UINTVAL str_len;
size += 3; /* type, offset, size */
str_len = strlen (dir->segments[i]->name);
- size += ROUND_UP(str_len + 1, sizeof(opcode_t)) / sizeof(opcode_t);
+ size += ROUND_UP(str_len + 1, sizeof(opcode_t));
}
if (align && size % align)
size += (align - size % align); /* pad/align it */
@@ -1069,7 +1071,7 @@
size_t str_len = strlen (seg->name);
*cursor++ = seg->type;
strcpy ((char *)cursor, seg->name);
- cursor += ROUND_UP(str_len + 1, sizeof(opcode_t)) / sizeof(opcode_t);
+ cursor += ROUND_UP(str_len + 1, sizeof(opcode_t));
*cursor++ = seg->file_offset;
*cursor++ = seg->op_count;
}
1.31 +14 -24 parrot/src/packout.c
Index: packout.c
===================================================================
RCS file: /cvs/public/parrot/src/packout.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -w -r1.30 -r1.31
--- packout.c 21 Nov 2003 14:26:03 -0000 1.30
+++ packout.c 21 Nov 2003 16:28:30 -0000 1.31
@@ -7,7 +7,7 @@
** This program is free software. It is subject to the same
** license as Parrot itself.
**
-** $Id: packout.c,v 1.30 2003/11/21 14:26:03 leo Exp $
+** $Id: packout.c,v 1.31 2003/11/21 16:28:30 leo Exp $
** History:
** Rework by Melvin; new bytecode format, make bytecode portable.
** (Do endian conversion and wordsize transforms on the fly.)
@@ -16,6 +16,7 @@
#include "parrot/parrot.h"
#include "parrot/packfile.h"
+#include <assert.h>
/***************************************
Determine the size of the buffer needed in order to pack the PackFile into a
@@ -123,9 +124,7 @@
*cursor++ = self->const_count;
for (i = 0; i < self->const_count; i++) {
- PackFile_Constant_pack(self->constants[i], cursor);
-
- cursor += PackFile_Constant_pack_size(self->constants[i]);
+ cursor = PackFile_Constant_pack(self->constants[i], cursor);
}
return cursor;
@@ -160,13 +159,15 @@
(Note this padding is not yet implemented for FLOATVALs.)
***************************************/
-void
+/* this will go away soon */
+extern size_t cstring_packed_size(const char *s);
+
+opcode_t *
PackFile_Constant_pack(struct PackFile_Constant *self, opcode_t *cursor)
{
char *charcursor;
size_t i;
opcode_t padded_size;
- opcode_t packed_size;
struct PMC *key;
*cursor++ = self->type;
@@ -187,9 +188,6 @@
padded_size += sizeof(opcode_t) - (padded_size % sizeof(opcode_t));
}
- /* Include space for flags, encoding, type, and size fields. */
- packed_size = 4 + padded_size / sizeof(opcode_t);
-
*cursor++ = PObj_get_FLAGS(self->u.string); /* only constant_FLAG */
*cursor++ = self->u.string->encoding->index;
*cursor++ = self->u.string->type->index;
@@ -205,20 +203,14 @@
charcursor += self->u.string->bufused;
if (self->u.string->bufused % sizeof(opcode_t)) {
- for (i = 0;
- i <
- (sizeof(opcode_t) -
+ for (i = 0; i < (sizeof(opcode_t) -
(self->u.string->bufused % sizeof(opcode_t))); i++) {
- charcursor[i] = 0;
+ *charcursor++ = 0;
}
}
}
- /* If cursor is needed below, uncomment the following and
- * ignore the gcc -Wcast-align warning. charcursor is
- * guaranteed to be aligned correctly by the padding logic
- * above.
- * cursor = (opcode_t *) charcursor;
- */
+ assert( ((int)charcursor & 3) == 0);
+ LVALUE_CAST(char *, cursor) = charcursor;
break;
case PFC_PMC:
@@ -229,14 +221,12 @@
case enum_class_Continuation:
case enum_class_Coroutine:
{
- size_t len;
char *s = ((struct Parrot_Sub*)PMC_sub(key))->packed;
- len = strlen(s) + 1;
-
strcpy((char *) cursor, s);
#if TRACE_PACKFILE_PMC
fprintf(stderr, "PMC_packed '%s'\n", (char*) cursor);
#endif
+ cursor += cstring_packed_size(s);
}
break;
default:
@@ -246,9 +236,8 @@
break;
case PFC_KEY:
- packed_size = sizeof(opcode_t);
for (i = 0, key = self->u.key; key; key = PMC_data(key), i++)
- packed_size += 2 * sizeof(opcode_t);
+ ;
/* number of key components */
*cursor++ = i;
/* and now type / value per component */
@@ -297,6 +286,7 @@
Parrot_exit(1);
break;
}
+ return cursor;
}
/*