simon 01/09/10 02:50:40
Modified: . assemble.pl bytecode.c bytecode.h
Log:
Temporary hack to store string constants in bytecode and recreate them
at runtime.
Revision Changes Path
1.4 +14 -3 parrot/assemble.pl
Index: assemble.pl
===================================================================
RCS file: /home/perlcvs/parrot/assemble.pl,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -w -r1.3 -r1.4
--- assemble.pl 2001/09/07 20:07:25 1.3
+++ assemble.pl 2001/09/10 09:50:39 1.4
@@ -8,6 +8,8 @@
%pack_type = (i => 'l',
n => 'd',
);
+my $sizeof_packi = length(pack($pack_type{i},1024));
+
open OPCODES, "<opcode_table" or die "Can't get opcode table, $!/$^E";
while (<OPCODES>) {
@@ -90,8 +92,6 @@
return $constants{$s} = $#constants;
}
-my $sizeof_packi = length(pack($pack_type{i},1024));
-
sub emit_magic { print pack($pack_type{i}, 0x13155a1) }
# Dummy for now.
@@ -101,13 +101,24 @@
# First, compute how big it's going to be.
# The fields we'll need to fill in are: strlen, flags, encoding, type
my $size =0 ;
- $size += length($_)+4*$sizeof_packi for @constants;
+ for (@constants) {
+ $size += 4*$sizeof_packi;
+ $size += length($_);
+ $size += length($_) % $sizeof_packi; # Padding
+ }
+
+ $size += $sizeof_packi if @constants; # That's for the number of constants
print pack($pack_type{i}, $size);
+ return unless @constants; # Zero means end of segment.
+
+ # Then spit out how many constants there are, so we can allocate
+ print pack($pack_type{i}, scalar @constants);
# Now emit each constant
for (@constants) {
print pack($pack_type{i},0) x 3; # Flags, encoding, type
print pack($pack_type{i},length($_)); # Strlen followed by that many bytes.
print $_;
+ print "\0" x (length($_) % $sizeof_packi); # Padding;
}
}
1.3 +34 -3 parrot/bytecode.c
Index: bytecode.c
===================================================================
RCS file: /home/perlcvs/parrot/bytecode.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -w -r1.2 -r1.3
--- bytecode.c 2001/09/05 12:27:46 1.2
+++ bytecode.c 2001/09/10 09:50:39 1.3
@@ -64,9 +64,40 @@
read_constants_table(void** program_code)
{
IV len = GRAB_IV(program_code);
- /* For now, just skip over it */
- ((IV*)*program_code) += len;
+ IV num;
+ IV i = 0;
+ if (len == 0)
+ return;
+
+ num = GRAB_IV(program_code);
+ len -= sizeof(IV);
+
+ Parrot_string_constants = Allocate_Aligned(num * sizeof(STRING*));
+
+ while (len > 0) {
+ IV flags = GRAB_IV(program_code);
+ IV encoding = GRAB_IV(program_code);
+ IV type = GRAB_IV(program_code);
+ IV buflen = GRAB_IV(program_code);
+
+ len -= 4 * sizeof(IV);
+
+ Parrot_string_constants[i++] = string_make(*program_code /* ouch */,
buflen, encoding, flags, type);
+ (char*)*program_code += buflen;
+ len -= buflen;
+
+ /* Padding */
+ if (buflen % sizeof(IV)) {
+ len -= buflen % sizeof(IV);
+ (char*)*program_code += buflen % sizeof(IV);
+ }
+ num--;
+ if (len < 0 || (len > 0 && num == 0)) {
+ printf("Bytecode error: string constant segment corrupted: %i, %i\n",
len, num);
+ exit(1);
}
+ }
+}
/*
@@ -114,8 +145,8 @@
exit(1);
}
- read_constants_table(&program_code);
read_fixup_table(&program_code);
+ read_constants_table(&program_code);
return program_code;
}
1.2 +2 -0 parrot/bytecode.h
Index: bytecode.h
===================================================================
RCS file: /home/perlcvs/parrot/bytecode.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -w -r1.1 -r1.2
--- bytecode.h 2001/08/29 12:07:01 1.1
+++ bytecode.h 2001/09/10 09:50:39 1.2
@@ -10,4 +10,6 @@
void* init_bytecode(void* program_code);
+VAR_SCOPE STRING** Parrot_string_constants;
+
#endif