develooper Front page | perl.cvs.parrot | Postings from January 2009

[svn:parrot] r34746 - in trunk: . compilers/pirc/new config/gen/makefiles

From:
kjs
Date:
January 1, 2009 08:30
Subject:
[svn:parrot] r34746 - in trunk: . compilers/pirc/new config/gen/makefiles
Message ID:
20090101163050.2CFA1CB9FA@x12.develooper.com
Author: kjs
Date: Thu Jan  1 08:30:49 2009
New Revision: 34746

Added:
   trunk/compilers/pirc/new/pircapi.c   (contents, props changed)
   trunk/compilers/pirc/new/pircapi.h   (contents, props changed)
Modified:
   trunk/MANIFEST
   trunk/compilers/pirc/new/main.c
   trunk/compilers/pirc/new/pirerr.c
   trunk/compilers/pirc/new/pirsymbol.c
   trunk/config/gen/makefiles/pirc.in

Log:
[pirc] refactoring of functions. + update MANIFEST.


Modified: trunk/MANIFEST
==============================================================================
--- trunk/MANIFEST	(original)
+++ trunk/MANIFEST	Thu Jan  1 08:30:49 2009
@@ -1,7 +1,7 @@
 # ex: set ro:
 # $Id$
 #
-# generated by tools/dev/mk_manifest_and_skip.pl Wed Dec 31 16:13:18 2008 UT
+# generated by tools\dev\mk_manifest_and_skip.pl Thu Jan  1 16:29:53 2009 UT
 #
 # See tools/dev/install_files.pl for documentation on the
 # format of this file.
@@ -165,6 +165,8 @@
 compilers/pirc/new/main.c                                   []
 compilers/pirc/new/pir.l                                    []
 compilers/pirc/new/pir.y                                    []
+compilers/pirc/new/pircapi.c                                []
+compilers/pirc/new/pircapi.h                                []
 compilers/pirc/new/pircompiler.c                            []
 compilers/pirc/new/pircompiler.h                            []
 compilers/pirc/new/pircompunit.c                            []
@@ -3187,6 +3189,7 @@
 t/README                                                    []
 t/TESTS_STATUS.pod                                          []
 t/benchmark/benchmarks.t                                    []
+t/codingstd/c_arg_assert.t                                  []
 t/codingstd/c_code_coda.t                                   []
 t/codingstd/c_cppcomments.t                                 []
 t/codingstd/c_function_docs.t                               []

Modified: trunk/compilers/pirc/new/main.c
==============================================================================
--- trunk/compilers/pirc/new/main.c	(original)
+++ trunk/compilers/pirc/new/main.c	Thu Jan  1 08:30:49 2009
@@ -1,6 +1,6 @@
 /*
  * $Id$
- * Copyright (C) 2007-2008, The Perl Foundation.
+ * Copyright (C) 2007-2009, The Perl Foundation.
  */
 
 
@@ -16,6 +16,7 @@
 #include "pirheredoc.h"
 #include "pirregalloc.h"
 #include "piremit.h"
+#include "pircapi.h"
 
 /* global variable to set parser in debug mode.
  * It is not clear to me whether the global can be replaced
@@ -88,30 +89,6 @@
 
 
 /*
-
-=item C<static FILE *
-open_file(char const * const filename, char const * const mode)>
-
-Function to open the file given by C<filename>, in the mode given by C<mode>
-Microsoft visual studio provides a "safer" variant of fopen(); this
-function hides the selection of the appropriate variant.
-
-=cut
-
-*/
-static FILE *
-open_file(char const * const filename, char const * const mode) {
-    FILE *fp = NULL;
-
-#ifdef _MSC_VER
-    fopen_s(&fp, filename, mode);
-#else
-    fp = fopen(filename, mode);
-#endif
-    return fp;
-}
-
-/*
 static void
 print_data_sizes(void) {
     printf("size of symbol: %u\n", sizeof(symbol));
@@ -131,157 +108,7 @@
 } parser_args;
 
 
-/*
-
-This will be the proper declaration after testing for thread-safety:
-
-void parse_file(int flexdebug, FILE *infile, char * const filename, int flags,
-                char * const outputfile)
-
-*/
-
-void init_scanner_state(yyscan_t yyscanner);
-
-void
-parse_file(int flexdebug, FILE *infile, char * const filename, int flags, int thr_id,
-           unsigned macro_size, char * const outputfile)
-{
-    yyscan_t     yyscanner;
-    lexer_state *lexer     = NULL;
-
-    /* create a yyscan_t object */
-    yypirlex_init(&yyscanner);
-    /* set debug flag */
-    yypirset_debug(flexdebug, yyscanner);
-    /* set the input file */
-    yypirset_in(infile, yyscanner);
-    /* set the extra parameter in the yyscan_t structure */
-    lexer = new_lexer(filename, flags);
-    lexer->macro_size = macro_size;
-
-    /* initialize the scanner state */
-    init_scanner_state(yyscanner);
-
-    if (strstr(filename, ".pasm")) { /* PASM mode */
-        SET_FLAG(lexer->flags, LEXER_FLAG_PASMFILE);
-    }
-
-    yypirset_extra(lexer, yyscanner);
-    /* and store the yyscanner in the lexer, so they're close buddies */
-    lexer->yyscanner = yyscanner;
-    /* go parse */
-    yypirparse(yyscanner, lexer);
-
-
-    if (lexer->parse_errors == 0) {
-        char outfile[20];
-        sprintf(outfile, "output_thr_%d", thr_id);
-        lexer->outfile = open_file(outfile, "w");
-        if (lexer->outfile == NULL) {
-            fprintf(stderr, "Failed to open file %s\n", outfile);
-            lexer->outfile = stdout;
-        }
-
-        if (TEST_FLAG(lexer->flags, LEXER_FLAG_NOOUTPUT)) /* handy for testing the compiler */
-            fprintf(stdout, "ok\n");
-        else if (TEST_FLAG(lexer->flags, LEXER_FLAG_PREPROCESS))
-            emit_pir_subs(lexer, outputfile);
-        else if (TEST_FLAG(lexer->flags, LEXER_FLAG_OUTPUTPBC))
-            emit_pbc(lexer);
-        else
-            /*
-            fprintf(stderr, "Parse successful!\n");
-            */
-            print_subs(lexer);
-
-
-        fclose(lexer->outfile);
-
-        if (TEST_FLAG(lexer->flags, LEXER_FLAG_WARNINGS))
-            check_unused_symbols(lexer);
-
-    }
-
-    /* there may have been errors during the instruction generation, check again here. */
-    if (lexer->parse_errors > 0)
-        fprintf(stderr, "There were %d errors\n", lexer->parse_errors);
-
-    fclose(infile);
-
-
-    /* XXX just want to make sure pirc doesn't segfault when doing bytecode stuff. */
-    if (TEST_FLAG(lexer->flags, LEXER_FLAG_OUTPUTPBC))
-        fprintf(stderr, "pirc ok\n");
-
-    /* clean up after playing */
-    release_resources(lexer);
-    yypirlex_destroy(yyscanner);
-
-}
-
-/*
-
-Parse a PIR string.
-
-*/
-void
-parse_string(char *pirstring, int flags, int pasminput, unsigned macro_size) {
-    yyscan_t yyscanner;
-    lexer_state *lexer = NULL;
-
-
-    /* create a yyscan_t object */
-    yypirlex_init(&yyscanner);
-
-    yypirset_debug(0, yyscanner);
-
-
-    /* set the extra parameter in the yyscan_t structure */
-    lexer = new_lexer("<pir string>", flags);
-    lexer->macro_size = macro_size;
-    yypirset_extra(lexer, yyscanner);
-    lexer->yyscanner = yyscanner;
 
-    /* initialize the scanner state */
-    init_scanner_state(yyscanner);
-
-    /* set the scanner to a string buffer and go parse */
-    yypir_scan_string(pirstring, yyscanner);
-
-    if (pasminput) { /* PASM mode */
-        SET_FLAG(lexer->flags, LEXER_FLAG_PASMFILE);
-    }
-
-
-    yypirparse(yyscanner, lexer);
-
-    if (lexer->parse_errors == 0) {
-
-        print_subs(lexer);
-
-        if (TEST_FLAG(lexer->flags, LEXER_FLAG_WARNINGS))
-            check_unused_symbols(lexer);
-    }
-
-    /* there may have been errors during the instruction generation, check again here. */
-    if (lexer->parse_errors > 0)
-        fprintf(stderr, "There were %d errors\n", lexer->parse_errors);
-
-    /* XXX just want to make sure pirc doesn't segfault when doing bytecode stuff. */
-    if (TEST_FLAG(lexer->flags, LEXER_FLAG_OUTPUTPBC)) {
-        emit_pbc(lexer);
-    }
-
-
-    fprintf(stderr, "ok\n");
-    /* clean up after playing */
-    release_resources(lexer);
-
-       /* clean up after playing */
-    yypirlex_destroy(yyscanner);
-
-
-}
 
 /*
 

Added: trunk/compilers/pirc/new/pircapi.c
==============================================================================
--- (empty file)
+++ trunk/compilers/pirc/new/pircapi.c	Thu Jan  1 08:30:49 2009
@@ -0,0 +1,227 @@
+/*
+ * $Id$
+ * Copyright (C) 2009, The Perl Foundation.
+ */
+
+
+
+#include "pirparser.h"
+#include "pircompiler.h"
+#include "piremit.h"
+#include "piryy.h"
+#include "pirlexer.h"
+#include "pircapi.h"
+
+/*
+
+=head1 DESCRIPTION
+
+
+=head1 FUNCTIONS
+
+=over 4
+
+=cut
+
+*/
+
+
+void init_scanner_state(yyscan_t yyscanner);
+
+
+/*
+
+=item C<FILE *
+open_file(char const * const filename, char const * const mode)>
+
+Function to open the file given by C<filename>, in the mode given by C<mode>
+Microsoft visual studio provides a "safer" variant of fopen(); this
+function hides the selection of the appropriate variant.
+
+=cut
+
+*/
+FILE *
+open_file(char const * const filename, char const * const mode) {
+    FILE *fp = NULL;
+
+#ifdef _MSC_VER
+    fopen_s(&fp, filename, mode);
+#else
+    fp = fopen(filename, mode);
+#endif
+    return fp;
+}
+
+
+/*
+
+This will be the proper declaration after testing for thread-safety:
+
+void parse_file(int flexdebug, FILE *infile, char * const filename, int flags,
+                char * const outputfile)
+
+*/
+
+
+
+void
+parse_file(int flexdebug, FILE *infile, char * const filename, int flags, int thr_id,
+           unsigned macro_size, char * const outputfile)
+{
+    yyscan_t     yyscanner;
+    lexer_state *lexer     = NULL;
+
+    /* create a yyscan_t object */
+    yypirlex_init(&yyscanner);
+    /* set debug flag */
+    yypirset_debug(flexdebug, yyscanner);
+    /* set the input file */
+    yypirset_in(infile, yyscanner);
+    /* set the extra parameter in the yyscan_t structure */
+    lexer = new_lexer(filename, flags);
+    lexer->macro_size = macro_size;
+
+    /* initialize the scanner state */
+    init_scanner_state(yyscanner);
+
+    if (strstr(filename, ".pasm")) { /* PASM mode */
+        SET_FLAG(lexer->flags, LEXER_FLAG_PASMFILE);
+    }
+
+    yypirset_extra(lexer, yyscanner);
+    /* and store the yyscanner in the lexer, so they're close buddies */
+    lexer->yyscanner = yyscanner;
+    /* go parse */
+    yypirparse(yyscanner, lexer);
+
+
+    if (lexer->parse_errors == 0) {
+        char outfile[20];
+        sprintf(outfile, "output_thr_%d", thr_id);
+        lexer->outfile = open_file(outfile, "w");
+        if (lexer->outfile == NULL) {
+            fprintf(stderr, "Failed to open file %s\n", outfile);
+            lexer->outfile = stdout;
+        }
+
+        if (TEST_FLAG(lexer->flags, LEXER_FLAG_NOOUTPUT)) /* handy for testing the compiler */
+            fprintf(stdout, "ok\n");
+        else if (TEST_FLAG(lexer->flags, LEXER_FLAG_PREPROCESS))
+            emit_pir_subs(lexer, outputfile);
+        else if (TEST_FLAG(lexer->flags, LEXER_FLAG_OUTPUTPBC))
+            emit_pbc(lexer);
+        else
+            /*
+            fprintf(stderr, "Parse successful!\n");
+            */
+            print_subs(lexer);
+
+
+        fclose(lexer->outfile);
+
+        if (TEST_FLAG(lexer->flags, LEXER_FLAG_WARNINGS))
+            check_unused_symbols(lexer);
+
+    }
+
+    /* there may have been errors during the instruction generation, check again here. */
+    if (lexer->parse_errors > 0)
+        fprintf(stderr, "There were %d errors\n", lexer->parse_errors);
+
+    fclose(infile);
+
+
+    /* XXX just want to make sure pirc doesn't segfault when doing bytecode stuff. */
+    if (TEST_FLAG(lexer->flags, LEXER_FLAG_OUTPUTPBC))
+        fprintf(stderr, "pirc ok\n");
+
+    /* clean up after playing */
+    release_resources(lexer);
+    yypirlex_destroy(yyscanner);
+
+}
+
+
+/*
+
+Parse a PIR string.
+
+*/
+void
+parse_string(char *pirstring, int flags, int pasminput, unsigned macro_size) {
+    yyscan_t yyscanner;
+    lexer_state *lexer = NULL;
+
+
+    /* create a yyscan_t object */
+    yypirlex_init(&yyscanner);
+
+    yypirset_debug(0, yyscanner);
+
+
+    /* set the extra parameter in the yyscan_t structure */
+    lexer = new_lexer("<pir string>", flags);
+    lexer->macro_size = macro_size;
+    yypirset_extra(lexer, yyscanner);
+    lexer->yyscanner = yyscanner;
+
+    /* initialize the scanner state */
+    init_scanner_state(yyscanner);
+
+    /* set the scanner to a string buffer and go parse */
+    yypir_scan_string(pirstring, yyscanner);
+
+    if (pasminput) { /* PASM mode */
+        SET_FLAG(lexer->flags, LEXER_FLAG_PASMFILE);
+    }
+
+
+    yypirparse(yyscanner, lexer);
+
+    if (lexer->parse_errors == 0) {
+
+        print_subs(lexer);
+
+        if (TEST_FLAG(lexer->flags, LEXER_FLAG_WARNINGS))
+            check_unused_symbols(lexer);
+    }
+
+    /* there may have been errors during the instruction generation, check again here. */
+    if (lexer->parse_errors > 0)
+        fprintf(stderr, "There were %d errors\n", lexer->parse_errors);
+
+    /* XXX just want to make sure pirc doesn't segfault when doing bytecode stuff. */
+    if (TEST_FLAG(lexer->flags, LEXER_FLAG_OUTPUTPBC)) {
+        emit_pbc(lexer);
+    }
+
+
+    fprintf(stderr, "ok\n");
+    /* clean up after playing */
+    release_resources(lexer);
+
+       /* clean up after playing */
+    yypirlex_destroy(yyscanner);
+
+
+}
+
+
+
+/*
+
+=back
+
+=cut
+
+*/
+
+/*
+ * Local variables:
+ *   c-file-style: "parrot"
+ * End:
+ * vim: expandtab shiftwidth=4:
+ */
+
+

Added: trunk/compilers/pirc/new/pircapi.h
==============================================================================
--- (empty file)
+++ trunk/compilers/pirc/new/pircapi.h	Thu Jan  1 08:30:49 2009
@@ -0,0 +1,25 @@
+/*
+ * $Id$
+ * Copyright (C) 2009, The Perl Foundation.
+ */
+
+#ifndef PARROT_PIR_PIRCAPI_H_GUARD
+#define PARROT_PIR_PIRCAPI_H_GUARD
+
+#include <stdio.h>
+
+FILE * open_file(char const * const filename, char const * const mode);
+
+void parse_string(char *pirstring, int flags, int pasminput, unsigned macro_size);
+
+void parse_file(int flexdebug, FILE *infile, char * const filename, int flags, int thr_id,
+                unsigned macro_size, char * const outputfile);
+
+#endif /* PARROT_PIR_PIRCAPI_H_GUARD */
+
+/*
+ * Local variables:
+ *   c-file-style: "parrot"
+ * End:
+ * vim: expandtab shiftwidth=4:
+ */

Modified: trunk/compilers/pirc/new/pirerr.c
==============================================================================
--- trunk/compilers/pirc/new/pirerr.c	(original)
+++ trunk/compilers/pirc/new/pirerr.c	Thu Jan  1 08:30:49 2009
@@ -1,15 +1,15 @@
 /*
  * $Id$
- * Copyright (C) 2007-2008, The Perl Foundation.
+ * Copyright (C) 2008, The Perl Foundation.
  */
 
 #include <stdio.h>
 #include <stdarg.h>
 #include "pircompiler.h"
-
 #include "pirparser.h"
 #include "piryy.h"
 #include "pirlexer.h"
+
 /*
 
 =head1 FUNCTIONS

Modified: trunk/compilers/pirc/new/pirsymbol.c
==============================================================================
--- trunk/compilers/pirc/new/pirsymbol.c	(original)
+++ trunk/compilers/pirc/new/pirsymbol.c	Thu Jan  1 08:30:49 2009
@@ -48,7 +48,6 @@
 
 */
 
-extern char const pir_register_types[5];
 
 #define NO_REG_ALLOCATED    -1
 
@@ -85,7 +84,6 @@
     sym->info.color    = next_register(lexer, sym->info.type);
 
     if (TEST_FLAG(lexer->flags, LEXER_FLAG_REGALLOC)) {
-
         sym->info.interval = new_live_interval(lexer->lsr, lexer->stmt_counter, sym->info.type);
 
         /* set the reference of the interval to the symbol's color */
@@ -298,14 +296,12 @@
         symbol *sym = bucket_symbol(buck);
 
         if (STREQ(sym->info.id.name, name)) {
-            fprintf(stderr, "found symbol %c:%s\n", pir_register_types[sym->info.type], name);
 
             if (sym->info.color == NO_REG_ALLOCATED)  /* no PASM register assigned yet */
                 /* get a new reg from vanilla reg. allocator */
                 assign_vanilla_register(lexer, sym);
             else  /* update end point of interval */
                 if (TEST_FLAG(lexer->flags, LEXER_FLAG_REGALLOC)) {
-                    fprintf(stderr, "updating live of symbol %s\n", name);
                     sym->info.interval->endpoint = lexer->stmt_counter;
                 }
 
@@ -369,7 +365,10 @@
     while (iter != NULL) {
         if (iter->info.id.regno == regno) {
 
+            /*
             fprintf(stderr, "Found regster $%c%d\n", pir_register_types[type], regno);
+            */
+
             /* update the end point of this register's live interval */
             if (TEST_FLAG(lexer->flags, LEXER_FLAG_REGALLOC))
                 iter->info.interval->endpoint = lexer->stmt_counter;

Modified: trunk/config/gen/makefiles/pirc.in
==============================================================================
--- trunk/config/gen/makefiles/pirc.in	(original)
+++ trunk/config/gen/makefiles/pirc.in	Thu Jan  1 08:30:49 2009
@@ -37,7 +37,8 @@
 new/pirmacro.c \
 new/pirregalloc.c \
 new/bcgen.c \
-new/pirerr.c
+new/pirerr.c \
+new/pircapi.c 
 
 OBJS          = \
 new/main$(O) \
@@ -52,7 +53,8 @@
 new/pirregalloc$(O) \
 new/bcgen$(O) \
 new/pirpcc$(O) \
-new/pirerr$(O)
+new/pirerr$(O) \
+new/pircapi$(O)
 
 .c$(O) :
 	@$(PERL) ../../tools/dev/cc_flags.pl -v ../../CFLAGS $(CC) "" $(CFLAGS) -I$(@D) @cc_o_out@$@ -c $<
@@ -79,6 +81,7 @@
 new/bcgen$(O): new/bcgen.c new/bcgen.h
 new/pirpcc$(O): new/pirpcc.c new/pirpcc.h
 new/pirerr$(O): new/pirerr.c new/pirerr.h
+new/pircapi$(O): new/pircapi.c new/pircapi.h
 
 test: all
 	podchecker $(SOURCES) README.pod



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