Front page | perl.cvs.parrot |
Postings from January 2009
[svn:parrot] r34999 - in branches/bcanno: compilers/imcc include/parrot src
From:
jonathan
Date:
January 5, 2009 09:59
Subject:
[svn:parrot] r34999 - in branches/bcanno: compilers/imcc include/parrot src
Message ID:
20090105175929.30814CB9F9@x12.develooper.com
Author: jonathan
Date: Mon Jan 5 09:59:28 2009
New Revision: 34999
Modified:
branches/bcanno/compilers/imcc/imcc.y
branches/bcanno/compilers/imcc/imcparser.c
branches/bcanno/compilers/imcc/pbc.c
branches/bcanno/include/parrot/packfile.h
branches/bcanno/src/packfile.c
Log:
[core][imcc] Store bytecode annotations in the packfile. This also tweaks a few other things, including associating the code and annotations segments when unpacking. Followed the model of debug segments, though may change both in the future.
Modified: branches/bcanno/compilers/imcc/imcc.y
==============================================================================
--- branches/bcanno/compilers/imcc/imcc.y (original)
+++ branches/bcanno/compilers/imcc/imcc.y Mon Jan 5 09:59:28 2009
@@ -932,8 +932,9 @@
{
/* We'll want to store an entry while emitting instructions, so just
* store annotation like it's an instruction. */
- $$ = MK_I(interp, IMCC_INFO(interp)->cur_unit, ".annotate",
-2, $2, $3);
+ SymReg * const key = mk_const(interp, $2, 'S');
+ $$ = MK_I(interp, IMCC_INFO(interp)->cur_unit, ".annotate", 2, key, $3);
+ mem_sys_free($2);
}
;
Modified: branches/bcanno/compilers/imcc/imcparser.c
==============================================================================
--- branches/bcanno/compilers/imcc/imcparser.c (original)
+++ branches/bcanno/compilers/imcc/imcparser.c Mon Jan 5 09:59:28 2009
@@ -3059,8 +3059,9 @@
{
/* We'll want to store an entry while emitting instructions, so just
* store annotation like it's an instruction. */
- (yyval.i) = MK_I(interp, IMCC_INFO(interp)->cur_unit, ".annotate",
-2, (yyvsp[(2) - (3)].s), (yyvsp[(3) - (3)].sr));
+ SymReg * const key = mk_const(interp, (yyvsp[(2) - (3)].s), 'S');
+ (yyval.i) = MK_I(interp, IMCC_INFO(interp)->cur_unit, ".annotate", 2, key, (yyvsp[(3) - (3)].sr));
+ mem_sys_free((yyvsp[(2) - (3)].s));
}
break;
Modified: branches/bcanno/compilers/imcc/pbc.c
==============================================================================
--- branches/bcanno/compilers/imcc/pbc.c (original)
+++ branches/bcanno/compilers/imcc/pbc.c Mon Jan 5 09:59:28 2009
@@ -2163,12 +2163,18 @@
}
if (ins->opname && strcmp(ins->opname, ".annotate") == 0) {
- /* It's an annotation. Add annotations seg if we're missing one. */
- printf("annotation to emit\n");
+ /* It's an annotation. */
+ int annotation_type;
+
+ /* Add annotations seg if we're missing one. */
if (!interp->code->annotations) {
/* Create segment. */
+ char *name = mem_sys_allocate(strlen(interp->code->base.name) + 5);
+ strcpy(name, interp->code->base.name);
+ strcpy(name + strlen(name), "_ANN");
interp->code->annotations = PackFile_Segment_new_seg(interp, interp->code->base.dir,
- PF_ANNOTATIONS_SEG, "ANNOTATIONS", 1);
+ PF_ANNOTATIONS_SEG, name, 1);
+ interp->code->annotations->code = interp->code;
/* Create initial group. */
PackFile_Annotations_add_group(interp, interp->code->annotations,
@@ -2176,7 +2182,23 @@
}
/* Add annotation. */
-
+ switch (ins->symregs[1]->set) {
+ case 'I':
+ annotation_type = PF_ANNOTATION_KEY_TYPE_INT;
+ break;
+ case 'N':
+ annotation_type = PF_ANNOTATION_KEY_TYPE_NUM;
+ break;
+ case 'S':
+ annotation_type = PF_ANNOTATION_KEY_TYPE_STR;
+ break;
+ default:
+ IMCC_fatal(interp, 1, "e_pbc_emit:"
+ "invalid type for annotation value\n");
+ }
+ PackFile_Annotations_add_entry(interp, interp->code->annotations,
+ IMCC_INFO(interp)->pc - interp->code->base.data,
+ ins->symregs[0]->color, annotation_type, ins->symregs[1]->color);
}
else if (ins->opname && *ins->opname) {
SymReg *addr, *r;
Modified: branches/bcanno/include/parrot/packfile.h
==============================================================================
--- branches/bcanno/include/parrot/packfile.h (original)
+++ branches/bcanno/include/parrot/packfile.h Mon Jan 5 09:59:28 2009
@@ -230,10 +230,7 @@
typedef struct PackFile_Annotations_Entry {
opcode_t bytecode_offset;
opcode_t key;
- union {
- opcode_t integer;
- opcode_t constant;
- } value;
+ opcode_t value;
} PackFile_Annotations_Entry;
typedef struct PackFile_Annotations {
Modified: branches/bcanno/src/packfile.c
==============================================================================
--- branches/bcanno/src/packfile.c (original)
+++ branches/bcanno/src/packfile.c Mon Jan 5 09:59:28 2009
@@ -3955,7 +3955,7 @@
for (i = 0; i < self->num_entries; i++) {
*cursor++ = self->entries[i]->bytecode_offset;
*cursor++ = self->entries[i]->key;
- *cursor++ = self->entries[i]->value.integer;
+ *cursor++ = self->entries[i]->value;
}
return cursor;
@@ -3973,7 +3973,9 @@
opcode_t *PackFile_Annotations_unpack(PARROT_INTERP, PackFile_Segment *seg,
opcode_t *cursor) {
PackFile_Annotations *self = (PackFile_Annotations *)seg;
- INTVAL i;
+ INTVAL i, str_len;
+ PackFile_ByteCode *code;
+ char *code_name;
/* Unpack keys. */
self->num_keys = PF_fetch_opcode(seg->pf, &cursor);
@@ -4000,9 +4002,24 @@
self->entries[i] = mem_allocate_typed(PackFile_Annotations_Entry);
self->entries[i]->bytecode_offset = PF_fetch_opcode(seg->pf, &cursor);
self->entries[i]->key = PF_fetch_opcode(seg->pf, &cursor);
- self->entries[i]->value.integer = PF_fetch_opcode(seg->pf, &cursor);
+ self->entries[i]->value = PF_fetch_opcode(seg->pf, &cursor);
}
+ /* Need to associate this segment with the applicable code segment. */
+ code_name = str_dup(self->base.name);
+ str_len = strlen(code_name);
+ code_name[str_len - 4] = 0;
+ code = (PackFile_ByteCode *)PackFile_find_segment(interp,
+ self->base.dir, code_name, 0);
+ if (!code || code->base.type != PF_BYTEC_SEG) {
+ Parrot_ex_throw_from_c_args(interp, NULL, 1,
+ "Code '%s' not found for annotations segment '%s'\n",
+ code_name, self->base.name);
+ }
+ self->code = code;
+ code->annotations = self;
+ mem_sys_free(code_name);
+
return cursor;
}
@@ -4019,7 +4036,7 @@
PackFile_Annotations *self = (PackFile_Annotations *)seg;
INTVAL i;
- default_dump_header(interp, self);
+ default_dump_header(interp, (PackFile_Segment *)self);
/* Dump keys. */
Parrot_io_printf(interp, "\n keys => [\n");
@@ -4102,32 +4119,62 @@
Adds a new bytecode annotation entry. Takes the annotations segment to add the
entry to, the current bytecode offset (assumed to be the greatest one so far
-in the currently active group), the annotation key, the annotation value type
-(one of PF_ANNOTATION_KEY_TYPE_INT, PF_ANNOTATION_KEY_TYPE_STR or
-PF_ANNOTATION_KEY_TYPE_NUM) and the value (set the appropriate of the last
-three parameters; those mapping to types other than the specified annotaiton
-value type will be ignored).
+in the currently active group), the annotation key (as an index into the constats
+table), the annotation value type (one of PF_ANNOTATION_KEY_TYPE_INT,
+PF_ANNOTATION_KEY_TYPE_STR or PF_ANNOTATION_KEY_TYPE_NUM) and the value. The value
+will be an integer literal in the case of type being PF_ANNOTATION_KEY_TYPE_INT, or
+an index into the constants table otherwise.
*/
void PackFile_Annotations_add_entry(PARROT_INTERP, struct PackFile_Annotations *self,
- opcode_t offset, STRING *key, INTVAL type, INTVAL integer_value,
- FLOATVAL number_value, STRING *string_value) {
+ opcode_t offset, opcode_t key, opcode_t type, opcode_t value) {
INTVAL i;
opcode_t key_id = 0;
/* See if we already have this key. */
+ STRING *key_name = PF_CONST(self->code, key)->u.string;
for (i = 0; i < self->num_keys; i++) {
STRING *test_key = PF_CONST(self->code, self->keys[i]->name)->u.string;
- if (string_equal(interp, test_key, key) == 0) {
+ if (string_equal(interp, test_key, key_name) == 0) {
key_id = 0;
break;
}
}
if (key_id == 0) {
- /* We do nee have it. Add. */
-
+ /* We do nee have it. Add key entry. */
+ if (self->keys)
+ self->keys = mem_sys_realloc(self->keys, (1 + self->num_keys) *
+ sizeof(PackFile_Annotations_Key *));
+ else
+ self->keys = mem_allocate_n_typed(self->num_keys + 1, PackFile_Annotations_Key *);
+ key_id = self->num_keys;
+ self->keys[key_id] = mem_allocate_typed(PackFile_Annotations_Key);
+ self->num_keys++;
+
+ /* Populate it. */
+ self->keys[key_id]->name = key;
+ self->keys[key_id]->type = type;
}
+ else {
+ /* Ensure key types are compatible. */
+ if (self->keys[key_id]->type != type)
+ Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
+ "Annotations with different types of value used for key '%S'\n",
+ key_name);
+ }
+
+ /* Add annotations entry. */
+ if (self->entries)
+ self->entries = mem_sys_realloc(self->entries, (1 + self->num_entries) *
+ sizeof(PackFile_Annotations_Entry *));
+ else
+ self->entries = mem_allocate_n_typed(self->num_entries + 1, PackFile_Annotations_Entry *);
+ self->entries[self->num_entries] = mem_allocate_typed(PackFile_Annotations_Entry);
+ self->entries[self->num_entries]->bytecode_offset = offset;
+ self->entries[self->num_entries]->key = key_id;
+ self->entries[self->num_entries]->value = value;
+ self->num_entries++;
}
-
[svn:parrot] r34999 - in branches/bcanno: compilers/imcc include/parrot src
by jonathan