develooper Front page | perl.cvs.parrot | Postings from December 2008

[svn:parrot] r33468 - in branches/bcanno: compilers/imcc include/parrot src

From:
jonathan
Date:
December 3, 2008 15:26
Subject:
[svn:parrot] r33468 - in branches/bcanno: compilers/imcc include/parrot src
Message ID:
20081203232640.66E22CB9AF@x12.develooper.com
Author: jonathan
Date: Wed Dec  3 15:26:39 2008
New Revision: 33468

Modified:
   branches/bcanno/compilers/imcc/imcc.l
   branches/bcanno/compilers/imcc/imcc.y
   branches/bcanno/compilers/imcc/pbc.c
   branches/bcanno/include/parrot/packfile.h
   branches/bcanno/src/packfile.c

Log:
[core] A bunch of hacking I did on the train that starts getting annotations tied into IMCC. Nothing working yet, and didn't have the right flex and bison to compile the updates.

Modified: branches/bcanno/compilers/imcc/imcc.l
==============================================================================
--- branches/bcanno/compilers/imcc/imcc.l	(original)
+++ branches/bcanno/compilers/imcc/imcc.l	Wed Dec  3 15:26:39 2008
@@ -322,6 +322,7 @@
 <pod>{EOL}      { IMCC_INFO(interp)->line++; }
 
 <*>".line"               return TK_LINE;
+<INITIAL,emit>".annotate" return ANNOTATE;
 <INITIAL,emit>".lex"     return LEXICAL;
 ".arg"                   return ARG;
 ".set_arg"               return ARG;

Modified: branches/bcanno/compilers/imcc/imcc.y
==============================================================================
--- branches/bcanno/compilers/imcc/imcc.y	(original)
+++ branches/bcanno/compilers/imcc/imcc.y	Wed Dec  3 15:26:39 2008
@@ -702,7 +702,7 @@
 %token <t> ADV_FLAT ADV_SLURPY ADV_OPTIONAL ADV_OPT_FLAG ADV_NAMED ADV_ARROW
 %token <t> NEW ADV_INVOCANT
 %token <t> NAMESPACE ENDNAMESPACE DOT_METHOD
-%token <t> SUB SYM LOCAL LEXICAL CONST
+%token <t> SUB SYM LOCAL LEXICAL CONST ANNOTATE
 %token <t> INC DEC GLOBAL_CONST
 %token <t> PLUS_ASSIGN MINUS_ASSIGN MUL_ASSIGN DIV_ASSIGN CONCAT_ASSIGN
 %token <t> BAND_ASSIGN BOR_ASSIGN BXOR_ASSIGN FDIV FDIV_ASSIGN MOD_ASSIGN
@@ -740,6 +740,7 @@
 %type <i> if_statement unless_statement
 %type <i> func_assign get_results
 %type <i> opt_invocant
+%type <i> annotate_directive
 %type <sr> target targetlist reg const var string result
 %type <sr> keylist keylist_force _keylist key maybe_ns
 %type <sr> vars _vars var_or_i _var_or_i label_op sub_label_op sub_label_op_c
@@ -823,6 +824,15 @@
          }
    ;
 
+annotate_directive:
+    ANNOTATE STRINGC const
+        {
+          /* 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);
+        }
+    ;
+
 hll_def:
 
      HLL STRINGC
@@ -1410,6 +1420,7 @@
    | FILECOMMENT               { $$ = 0; }
    | LINECOMMENT               { $$ = 0; }
    | line_directive            { $$ = 0; }
+   | annotate_directive        { $$ = $8; }
    ;
 
 labels:

Modified: branches/bcanno/compilers/imcc/pbc.c
==============================================================================
--- branches/bcanno/compilers/imcc/pbc.c	(original)
+++ branches/bcanno/compilers/imcc/pbc.c	Wed Dec  3 15:26:39 2008
@@ -1910,7 +1910,15 @@
             IMCC_INFO(interp)->npc);
     }
 
-    if (ins->opname && *ins->opname) {
+    if (ins->opname && strcmp(ins->opname, ".annotate") == 0) {
+        /* It's an annotation. Add annotations seg if we're missing one. */
+        if (!interp->code->annotations) {
+        }
+
+        /* Add annotation. */
+        
+    }
+    else if (ins->opname && *ins->opname) {
         SymReg  *addr, *r;
         opcode_t last_label = 1;
 

Modified: branches/bcanno/include/parrot/packfile.h
==============================================================================
--- branches/bcanno/include/parrot/packfile.h	(original)
+++ branches/bcanno/include/parrot/packfile.h	Wed Dec  3 15:26:39 2008
@@ -196,6 +196,7 @@
     struct PackFile_Debug *debugs;
     PackFile_ConstTable   *const_table;
     PackFile_FixupTable   *fixups;
+    struct PackFile_Annotations *annotations;
 };
 
 typedef struct PackFile_DebugFilenameMapping {
@@ -215,7 +216,6 @@
 #define PF_ANNOTATION_KEY_TYPE_INT 0
 #define PF_ANNOTATION_KEY_TYPE_STR 1
 #define PF_ANNOTATION_KEY_TYPE_NUM 2
-#define PF_ANNOTATION_KEY_TYPE_PMC 3
 
 typedef struct PackFile_Annotations_Key {
     opcode_t name;
@@ -244,6 +244,7 @@
     PackFile_Annotations_Group  **groups;
     opcode_t                    num_entries;
     PackFile_Annotations_Entry  **entries;
+    PackFile_ByteCode           *code;
 } PackFile_Annotations;
 
 typedef struct PackFile_Directory {

Modified: branches/bcanno/src/packfile.c
==============================================================================
--- branches/bcanno/src/packfile.c	(original)
+++ branches/bcanno/src/packfile.c	Wed Dec  3 15:26:39 2008
@@ -3816,7 +3816,114 @@
 */
 
 void PackFile_Annotations_dump(PARROT_INTERP, struct PackFile_Segment *seg) {
-    /* TODO */
+    PackFile_Annotations *self = (PackFile_Annotations *)seg;
+    INTVAL i;
+
+    /* Dump keys. */
+    PIO_printf(interp, "\n  keys => [\n");
+    for (i = 0; i < self->num_keys; i++) {
+        char *key_name = string_to_cstring(interp, PF_CONST(self->code,
+               self->keys[i]->name)->u.string);
+        PIO_printf(interp, "    #%d\n    [\n", i);
+        PIO_printf(interp, "        NAME => %s\n", key_name);
+        PIO_printf(interp, "        TYPE => %s\n",
+                self->keys[i]->type == PF_ANNOTATION_KEY_TYPE_INT ? "integer" :
+                self->keys[i]->type == PF_ANNOTATION_KEY_TYPE_STR ? "string" :
+                self->keys[i]->type == PF_ANNOTATION_KEY_TYPE_NUM ? "number" :
+                "PMC");
+        PIO_printf(interp, "    ],\n");
+        string_cstring_free(key_name);
+    }
+    PIO_printf(interp, "  ],\n");
+
+    /* Dump groups. */
+    PIO_printf(interp, "\n  groups => [\n");
+    for (i = 0; i < self->num_groups; i++) {
+        PIO_printf(interp, "    #%d\n    [\n", i);
+        PIO_printf(interp, "        BYTECODE_OFFSET => %d\n",
+                self->groups[i]->bytecode_offset);
+        PIO_printf(interp, "        ENTRIES_OFFSET => %d\n",
+                self->groups[i]->entries_offset);
+        PIO_printf(interp, "    ],\n");
+    }
+    PIO_printf(interp, "  ],\n");
+
+    /* Dump entries. */
+    PIO_printf(interp, "\n  entries => [\n");
+    for (i = 0; i < self->num_entries; i++) {
+        PIO_printf(interp, "    #%d\n    [\n", i);
+        PIO_printf(interp, "        BYTECODE_OFFSET => %d\n",
+                self->entries[i]->bytecode_offset);
+        PIO_printf(interp, "        KEY => %d\n",
+                self->entries[i]->key);
+        PIO_printf(interp, "        VALUE => %d\n",
+                self->entries[i]->value);
+        PIO_printf(interp, "    ],\n");
+    }
+    PIO_printf(interp, "  ],\n");
+}
+
+
+/*
+
+=item C<void PackFile_Annotations_add_group>
+
+Starts a new bytecode annotation group. Takes the offset in the bytecode where
+the new annotations group starts.
+
+*/
+
+void PackFile_Annotations_add_group(PARROT_INTERP, struct PackFile_Annotations *self,
+        opcode_t offset) {
+    /* Allocate extra space for the group in the groups array. */
+    if (self->groups)
+        self->groups = mem_sys_realloc(self->groups, (1 + self->num_groups) *
+                sizeof(PackFile_Annotations_Group *));
+    else
+        self->groups = mem_allocate_n_typed(self->num_groups + 1, PackFile_Annotations_Group *);
+    
+    /* Store details. */
+    self->groups[self->num_groups] = mem_allocate_typed(PackFile_Annotations_Group);
+    self->groups[self->num_groups]->bytecode_offset = offset;
+    self->groups[self->num_groups]->entries_offset = self->num_entries;
+
+    /* Increment group count. */
+    self->num_groups++;
+}
+
+
+/*
+
+=item C<void PackFile_Annotations_add_entry>
+
+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).
+
+*/
+
+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) {
+    INTVAL i;
+    opcode_t key_id = 0;
+
+    /* See if we already have this key. */
+    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) {
+            key_id = 0;
+            break;
+        }
+    }
+    if (key_id == 0) {
+        /* We do nee have it. Add. */
+
+    }
 }
 
 



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About