Changeset 909887 in git


Ignore:
Timestamp:
Jul 3, 2002, 2:42:51 PM (22 years ago)
Author:
Anne Frühbis-Krüger <anne@…>
Branches:
(u'spielwiese', 'd1d239e9808fca76a9497a01fa91ad4e8db6fba5')
Children:
deafd6a2ebd2eeebe22e9b6c82ce11770cc4dbdf
Parents:
99cf46c6d746d44334fd90b60f628aa80b34c3a8
Message:
*anne: module generator in version providing support for:
       - Singular procedures
       - simplified C/C++ routines
       - C/C++ routines
       - help and example sections for the first 2 types of procedures
       not yet supported: checksum for .bin file


git-svn-id: file:///usr/local/Singular/svn/trunk@6185 2c84dea3-7e68-4137-9b89-c4e89433aadc
Location:
modules/modgen
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • modules/modgen/creat_top.cc

    r99cf46c r909887  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: creat_top.cc,v 1.16 2002-07-01 12:31:32 anne Exp $ */
     4/* $Id: creat_top.cc,v 1.17 2002-07-03 12:42:49 anne Exp $ */
    55/*
    66* ABSTRACT: lib parsing
     
    6969
    7070/*========================================================================*/
    71 /* SINGULAR procedures sollen nicht in modules geladen werden!!
    72 *  Dieser code wird daher momentan nicht benoetigt
    73 * void write_add_singular_proc(FILE *fp)
    74 * {
    75 *   fprintf(fp, "\nidhdl add_singular_proc(char *procname, int line,\n");
    76 *   fprintf(fp, "                       long pos, long end, BOOLEAN pstatic)\n");
    77 *   fprintf(fp, "{\n");
    78 *   fprintf(fp, "  idhdl h;\n");
    79 *   fprintf(fp, "  procinfov pi;\n\n");
    80 *   fprintf(fp, "  h = enter_id(procname, NULL, PROC_CMD);\n");
    81 *   fprintf(fp, "  if(h == NULL) return NULL;\n");
    82 *   fprintf(fp, "\n");
    83 *   fprintf(fp, "  IDDATA(h)=(char *) pi;\n");
    84 *   fprintf(fp, "\n");
    85 * //  fprintf(fp, "  pi->libname = omStrDup(libname);\n");
    86 *   fprintf(fp, "  pi->procname = omStrDup(procname);\n");
    87 *   fprintf(fp, "  pi->language = LANG_SINGULAR;\n");
    88 *   fprintf(fp, "  pi->ref = 1;\n");
    89 *   fprintf(fp, "  pi->is_static = pstatic;\n");
    90 *   fprintf(fp, "  pi->data.s.proc_start = pos;\n");
    91 *   fprintf(fp, "  pi->data.s.def_end    = pos;\n");
    92 *   fprintf(fp, "  pi->data.s.help_start = 0L;\n");
    93 *   fprintf(fp, "  pi->data.s.help_end   = 0L;\n");
    94 *   fprintf(fp, "  pi->data.s.body_start = pos;\n");
    95 *   fprintf(fp, "  pi->data.s.body_end   = end;\n");
    96 *   fprintf(fp, "  pi->data.s.proc_end   = end;\n");
    97 *   fprintf(fp, "  pi->data.s.example_start = 0L;\n");
    98 *   fprintf(fp, "  pi->data.s.proc_lineno = line;\n");
    99 *   fprintf(fp, "  pi->data.s.body_lineno = line;\n");
    100 *   fprintf(fp, "  pi->data.s.example_lineno = 0;\n");
    101 *   fprintf(fp, "  pi->data.s.body = NULL;\n");
    102 *   fprintf(fp, "  pi->data.s.help_chksum = 0;\n");
    103 *   fprintf(fp, "  \n");
    104 *   fprintf(fp, "  return(h);\n");
    105 *   fprintf(fp, "}\n");
    106 *   modlineno+=30;
    107 * }
    108 */
     71 void write_add_singular_proc(FILE *fp)
     72 {
     73   fprintf(fp, "\nidhdl add_singular_proc(FILE* binfp, char *procname,
     74                                          int line,\n");
     75   fprintf(fp, "                       long pos, long end, BOOLEAN pstatic)\n");
     76   fprintf(fp, "{\n");
     77   fprintf(fp, "  idhdl h;\n");
     78   fprintf(fp, "  procinfov pi;\n");
     79   fprintf(fp, "  char *tempstr;\n");
     80   fprintf(fp, "  h = enter_id(procname, NULL, PROC_CMD);\n");
     81   fprintf(fp, "  if(h == NULL) return NULL;\n");
     82   fprintf(fp, "\n");
     83   fprintf(fp, "  pi = IDPROC(h);\n");
     84   fprintf(fp, "\n");
     85   fprintf(fp, "  pi->libname = omStrDup(currPack->libname);\n");
     86   fprintf(fp, "  pi->procname = omStrDup(procname);\n");
     87   fprintf(fp, "  pi->language = LANG_SINGULAR;\n");
     88   fprintf(fp, "  pi->ref = 1;\n");
     89   fprintf(fp, "  pi->is_static = pstatic;\n");
     90   fprintf(fp, "  pi->data.s.proc_start = pos;\n");
     91   fprintf(fp, "  pi->data.s.def_end    = pos;\n");
     92   fprintf(fp, "  pi->data.s.help_start = 0L;\n");
     93   fprintf(fp, "  pi->data.s.help_end   = 0L;\n");
     94   fprintf(fp, "  pi->data.s.body_start = pos;\n");
     95   fprintf(fp, "  pi->data.s.body_end   = end;\n");
     96   fprintf(fp, "  pi->data.s.proc_end   = end;\n");
     97   fprintf(fp, "  pi->data.s.example_start = 0L;\n");
     98   fprintf(fp, "  pi->data.s.proc_lineno = line;\n");
     99   fprintf(fp, "  pi->data.s.body_lineno = line;\n");
     100   fprintf(fp, "  pi->data.s.example_lineno = 0;\n");
     101   fprintf(fp, "  pi->data.s.help_chksum = 0;\n");
     102   fprintf(fp, "  \n");
     103   fprintf(fp, "  rewind(binfp);\n");
     104   fprintf(fp, "  fseek(binfp,pos,SEEK_CUR);\n");
     105   fprintf(fp, "  tempstr=(char *)omAlloc(end-pos+2);\n");
     106   fprintf(fp, "  memset(tempstr,0,end-pos+2);\n");
     107   fprintf(fp, "  fread(tempstr,sizeof(char),end-pos+1,binfp);\n");
     108   fprintf(fp, "  pi->data.s.body = omStrDup(tempstr);\n");
     109   fprintf(fp, "  omFree(tempstr);\n\n");
     110   fprintf(fp, "  return(h);\n");
     111   fprintf(fp, "}\n");
     112   modlineno+=30;
     113 }
    109114
    110115/*========================================================================*/
     
    119124  fprintf(fp, "int mod_init(int(*iiAddCproc)())\n{\n");
    120125  fprintf(fp, "  idhdl h;\n");
    121   fprintf(fp, "   fill_help_package();\n");
    122   fprintf(fp, "  \n");
    123   fprintf(fp, "   fill_example_package();\n");
     126  fprintf(fp, "  char * tempstr;\n");
     127  fprintf(fp, "  FILE * binfp; \n\n");
     128  fprintf(fp, "  tempstr = (char *)omAlloc(strlen(currPack->libname)+5);\n");
     129  fprintf(fp, "  memset(tempstr,0,strlen(currPack->libname)+1);\n");
     130  fprintf(fp, "  memcpy(tempstr,currPack->libname,strlen(currPack->libname));\n");
     131  fprintf(fp, "  memcpy(tempstr+strlen(currPack->libname)-3,\".bin\",4);\n");
     132  fprintf(fp, "  if ((binfp = fopen(tempstr,\"r\")) == NULL)\n");
     133  fprintf(fp, "    return -1;\n\n");
     134
     135  fprintf(fp, "  fill_help_package();\n");
     136  fprintf(fp, "  fill_example_package();\n\n");
     137
     138
    124139}
    125140
  • modules/modgen/grammar.y

    r99cf46c r909887  
    11/*
    2  * $Id: grammar.y,v 1.18 2002-07-01 12:31:32 anne Exp $
     2 * $Id: grammar.y,v 1.19 2002-07-03 12:42:49 anne Exp $
    33 */
    44
     
    330330        {
    331331          if(debug>2)printf("SG-PROCDEF:\n");
    332           write_singular_end(&module_def, yylineno);
    333         }
    334         | procdecl proccode procdeclexample
     332          write_singular_end(&module_def, &procedure_decl, yylineno);
     333          setup_proc(&module_def, &procedure_decl);
     334          write_helpfile_help(&module_def, &procedure_decl);
     335        }
     336        | procdeclsg proccode procdeclexample
    335337        {
    336338          if(debug>2)printf("SG-PROCDEF mit example:\n");
    337339          fflush(module_def.fmtfp);
    338           write_singular_end(&module_def, yylineno);
     340          write_singular_end(&module_def, &procedure_decl, yylineno);
     341          setup_proc(&module_def, &procedure_decl);
     342          write_helpfile_help(&module_def, &procedure_decl);
    339343        }
    340344;
     
    342346procdeclsg: procdeclsg2 '{'
    343347        {
    344           setup_proc(&module_def, &procedure_decl);
    345348        }
    346349        | procdeclsg2 procdeclhelp '{'
    347350        {
    348           setup_proc(&module_def, &procedure_decl);
    349351        }
    350352        ;
     
    352354procdeclsg2: procdecl1 '(' sgtypelist ')'
    353355         {
    354            write_singular_parameter(&module_def, yylineno, "list", "#");
    355356           procedure_decl.lineno_other = yylineno;
    356357         }
    357358        | procdecl1
    358359         {
    359            write_singular_parameter(&module_def, yylineno, "list", "#");
    360360           procedure_decl.lineno_other = yylineno;
    361361         }
    362362        | procdecl1 '(' ')'
    363363         {
    364            write_singular_parameter(&module_def, yylineno, "list", "#");
    365364           procedure_decl.lineno_other = yylineno;
    366365         }
     
    386385        {
    387386          if(debug>2)printf("PROCDEF:\n");
     387          write_helpfile_help(&module_def, &procedure_decl);
    388388        }
    389389        | procdecl proccode procdeclexample
    390390        {
    391391          if(debug>2)printf("PROCDEF mit example:\n");
     392          write_helpfile_help(&module_def, &procedure_decl);
    392393          fflush(module_def.fmtfp);
    393394        }
  • modules/modgen/main.cc

    r99cf46c r909887  
    163163  if(module_def.fmtfp   != NULL) fclose(module_def.fmtfp);
    164164  if(module_def.modfp   != NULL) fclose(module_def.modfp);
     165  if(module_def.binfp   != NULL) fclose(module_def.binfp);
    165166  if(module_def.modfp_h != NULL) fclose(module_def.modfp_h);
    166   if(module_def.binfp   != NULL) fclose(module_def.binfp);
     167  if(module_def.docfp   != NULL) fclose(module_def.docfp);
     168  return 0;
    167169}
  • modules/modgen/makefile.cc

    r99cf46c r909887  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: makefile.cc,v 1.11 2002-07-01 12:31:33 anne Exp $ */
     4/* $Id: makefile.cc,v 1.12 2002-07-03 12:42:50 anne Exp $ */
    55/*
    66* ABSTRACT: lib parsing
     
    117117 
    118118  fprintf(fp, "distclean: clean\n");
    119   fprintf(fp, "\trm -f %s.cc %s.h Makefile\n\n", module->name, module->name);
     119  fprintf(fp, "\trm -f %s.cc %s.h Makefile *.bin *.pl\n\n",
     120               module->name, module->name);
    120121}
    121122
     
    130131  fprintf(fp, "\t${MKINSTALLDIRS} ${instdir}/modules\n");
    131132  fprintf(fp, "\t${INSTALL_PROGRAM} %s.so ${instdir}/modules/%s.so\n",
     133          module->targetname, module->targetname);
     134  fprintf(fp, "\t${INSTALL_PROGRAM} %s.bin ${instdir}/modules/%s.bin\n",
    132135          module->targetname, module->targetname);
    133136}
  • modules/modgen/misc.cc

    r99cf46c r909887  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: misc.cc,v 1.16 2002-07-01 12:31:33 anne Exp $ */
     4/* $Id: misc.cc,v 1.17 2002-07-03 12:42:50 anne Exp $ */
    55/*
    66* ABSTRACT: lib parsing
     
    227227                    idtyp t, void *arg1 = NULL, void *arg2 = NULL);
    228228} valid_vars[] = {
    229   { "help",         VAR_STRING,  VAR_HELP,    write_main_variable },
    230   { "info",         VAR_STRING,  VAR_INFO,    write_main_variable },
    231   { "package",      VAR_STRING,  VAR_MODULE,  0 },
    232   { "version",      VAR_STRING,  VAR_VERSION, write_main_variable },
     229  { "help",         VAR_STRING,  VAR_HELP,     write_main_variable },
     230  { "info",         VAR_STRING,  VAR_INFO,     write_main_variable },
     231  { "package",      VAR_STRING,  VAR_MODULE,   0 },
     232  { "version",      VAR_STRING,  VAR_VERSION,  write_main_variable },
     233  { "category",     VAR_STRING,  VAR_CATEGORY, write_main_variable },
    233234  { NULL,           VAR_UNKNOWN, VAR_NONE, 0 }
    234235};
     
    498499    fprintf(fp, "\n");    modlineno+=1;
    499500    fprintf(fp, "#line %d \"%s.cc\"\n", modlineno++, module);
    500 /* Laden von SINGULAR proceduren innerhalb eines moduls derzeit nicht vorgesehen
    501 *    write_add_singular_proc(fp);
    502 */
     501    write_add_singular_proc(fp);
    503502    fprintf(fp, "\n");
    504503   
  • modules/modgen/modgen.h

    r99cf46c r909887  
    11/*
    2  *  $Id: modgen.h,v 1.14 2002-07-01 12:31:33 anne Exp $
     2 *  $Id: modgen.h,v 1.15 2002-07-03 12:42:50 anne Exp $
    33 *
    44 */
     
    8787  FILE * binfp;           /* include singular procedures are stored
    8888                             in an extra file */
     89  FILE * docfp;           /* help/example is stored in this file
     90                             for building the reference manual */
    8991  char * filename;        /* inputfile to parse */
    9092  char * name;            /* name of the module directory*/
     
    9294  unsigned int major, minor, level;
    9395  char * version;
     96  char * category;
    9497  char * revision;
    9598  char * info;
    96   char * helpfile;
    9799  char * c_code;
    98100  procdefv procs;
     
    122124
    123125typedef enum { VAR_NONE, VAR_MODULE, VAR_HELP, VAR_INFO, VAR_VERSION,
    124                VAR_TYPECHECK, VAR_RETURN, VAR_FUNCTION
     126               VAR_TYPECHECK, VAR_RETURN, VAR_FUNCTION, VAR_CATEGORY
    125127} var_token;
    126128
     
    195197extern void write_singular_parameter(moddefv module,int lineno,
    196198                                     char *typname, char *varname);
    197 extern void write_singular_end(moddefv module,int lineno);
     199extern void write_singular_end(moddefv module, procdefv proc,int lineno);
     200extern int write_helpfile_help(moddefv module, procdefv proc);
    198201
    199202extern void write_codeline(moddefv module, procdefv proc,
  • modules/modgen/proc.cc

    r99cf46c r909887  
    11/*
    2  * $Id: proc.cc,v 1.18 2002-07-01 12:31:33 anne Exp $
     2 * $Id: proc.cc,v 1.19 2002-07-03 12:42:51 anne Exp $
    33 */
    44
     
    5252 
    5353        /* write call to add procname to list */
    54         fprintf(module->modfp, "  iiAddCproc(\"%s\",\"%s\",%s, mod_%s);\n",
    55                 module->name, proc->procname,
     54        fprintf(module->modfp,
     55                "  iiAddCproc(currPack->libname,\"%s\",%s, mod_%s);\n",
     56                proc->procname,
    5657                proc->is_static ? "TRUE" : "FALSE",
    5758                proc->procname);
     
    6768       
    6869      case LANG_SINGULAR:
    69         fprintf(module->modfp,"#if 0\n");
    7070        fprintf(module->modfp,
    71                 "  h = add_singular_proc(\"%s\", %d, %ld, %ld, %s);\n",
     71                "  h = add_singular_proc(binfp,\"%s\", %d, %ld, %ld, %s);\n",
    7272                proc->procname, proc->lineno,
    7373                proc->sing_start, proc->sing_end,
     
    7777  }
    7878 
    79   //  printf(" done\n");
    8079}
    8180
     
    263262}
    264263
     264/*========================================================================*/
    265265void write_function_singularcmd(
    266266  moddefv module,
     
    358358)
    359359{
     360  fprintf(module->modfp, "  fclose(binfp);\n");
    360361  fprintf(module->modfp, "  return 0;\n}\n\n");
    361362  fflush(module->modfp);
     
    481482
    482483/*========================================================================*/
    483 /*
    484     if(pi->param[0].typ==SELF_CMD) {
    485       if(pi->c_code != NULL) fprintf(fp, "%s\n", pi->c_code);
    486  
    487       fprintf(fp, "  return(%s(res,h));\n", pi->funcname);
    488       fprintf(fp, "}\n\n");
    489     }
    490     else {
    491 */
    492484
    493485void write_function_errorhandling(
     
    519511      case LANG_SINGULAR:
    520512        fprintf(module->binfp, "}\n// end of procedure %s\n\n", pi->procname);
    521         fprintf(module->modfp, "  if( h != NULL) {\n");
    522         fprintf(module->modfp, "    IDPROC(h)->data.s.body_end = %ld;\n",
    523                 ftell(module->binfp));
    524         fprintf(module->modfp, "    IDPROC(h)->data.s.proc_end = %ld;\n",
    525                 ftell(module->binfp));
    526         fprintf(module->modfp, "  }\n");
    527513        break;
    528514  }
     
    569555    char filename[512];
    570556
    571     //filename = (char *)malloc(strlen(module->name)+5+4);
    572     //sprintf(filename, "tmp/%s.bin", module->name);
    573     strcpy(filename, build_filename(module, module->name, 3));
     557    strcpy(filename, build_filename(module, module->targetname, 3));
    574558
    575559    if( (module->binfp = fopen(filename, "w")) == NULL) {
    576       //free(filename);
    577560      return -1;
    578561    }
    579562    if(trace)printf("Creating %s, ", filename);fflush(stdout);
    580 
    581     //free(filename);
    582563  }
    583564 
     
    586567          module->filename);
    587568  fprintf(module->binfp, "// proc %s\n", proc->procname);
     569  fflush(module->binfp);
    588570  proc->sing_start = ftell(module->binfp);
    589571 
    590572  return 0;
    591573}
     574
     575/*========================================================================*/
     576int write_helpfile_help(
     577  moddefv module,
     578  procdefv proc
     579  )
     580{
     581  if(module->docfp==NULL) {
     582    char filename[512];
     583
     584    strcpy(filename, build_filename(module, module->targetname, 4));
     585    if( (module->docfp = fopen(filename, "w")) == NULL) {
     586      return -1;
     587    }
     588    if(trace)printf("Creating %s, ", filename);fflush(stdout);
     589    fprintf(module->docfp, "$library = \"%s.so\";\n", module->targetname);
     590    fprintf(module->docfp, "$version = \"%s\";\n", module->version);
     591    fprintf(module->docfp, "$category = <<EOT;\n");
     592    fprintf(module->docfp, "%s\nEOT\n",module->category);
     593    fprintf(module->docfp, "$info = <<EOT;\n");
     594    fprintf(module->docfp, "%s\nEOT\n",module->info);
     595  }
     596
     597  /* */
     598  fprintf(module->docfp, "push(@procs, \"%s\");\n",proc->procname);
     599  fprintf(module->docfp, "$help{\"%s\"} = << EOT;\n",proc->procname);
     600  fprintf(module->docfp, "%s\nEOT\n",proc->help_string);
     601  fprintf(module->docfp, "$example{\"%s\"} = << EOT;\n",proc->procname);
     602  fprintf(module->docfp, "%s\nEOT\n\n",proc->example_string);
     603
     604  return 0;
     605
    592606
    593607/*========================================================================*/
     
    605619void write_singular_end(
    606620  moddefv module,
     621  procdefv proc,
    607622  int lineno
    608623  )
    609624{
    610   fprintf(module->modfp, "#endif\n");
     625  fprintf(module->binfp, "%s.so\n",module->targetname);
     626  fflush(module->binfp);
     627  proc->sing_end = ftell(module->binfp);
    611628}
    612629
     
    624641          fprintf(module->binfp, "// #line %d \"%s\"\n",
    625642                                          lineno, module->filename);
    626         fprintf(module->binfp, "%s", line); break;
     643        fprintf(module->binfp,"%s",line);
     644        break;
    627645
    628646      case LANG_C:
  • modules/modgen/utils.cc

    r99cf46c r909887  
    11/*
    2  * $Id: utils.cc,v 1.11 2001-05-23 20:11:49 anne Exp $
     2 * $Id: utils.cc,v 1.12 2002-07-03 12:42:51 anne Exp $
    33 */
    44
     
    110110          snprintf(p, sizeof(p), "%s/%s.bin", module->name, text);
    111111          break;
     112        case 4:
     113          snprintf(p, sizeof(p), "%s/%s.pl", module->name, text);
     114          break;
    112115        default:
    113116          snprintf(p, sizeof(p), "%s/%s", module->name, text);
Note: See TracChangeset for help on using the changeset viewer.