home *** CD-ROM | disk | FTP | other *** search
/ ftp.parl.clemson.edu / 2015-02-07.ftp.parl.clemson.edu.tar / ftp.parl.clemson.edu / pub / coven / coven-utils-1.1.tgz / coven-utils-1.1.tar / utils / coven-language / outgen.c < prev    next >
C/C++ Source or Header  |  2003-01-28  |  4KB  |  168 lines

  1. /*
  2.  * (C) 2001 Clemson University
  3.  *
  4.  * See COPYING in top-level directory.
  5.  */
  6.  
  7.  
  8. #include <stdio.h>
  9. #include <Coven_lang.h>
  10. #include <symbol.h>
  11.  
  12. void output_begin()
  13. {
  14.        fprintf(out_file, "#include \"coven.h\"\n\n");
  15. }
  16.  
  17. void output_begin_mod_decls()
  18. {
  19.     fprintf(out_file,"struct COVEN_Mod_Decl _coven_mod_decl_array[] = {\n");
  20. }
  21.  
  22. void output_mod_decl (sym_ent_p mod)
  23. {
  24.     fprintf(out_file,"  {\n"
  25.                      "    %s, \n"
  26.              "    \"%s\"\n"
  27.              "  },\n", mod->value.mod->path,
  28.         mod->name);
  29. }
  30.  
  31. void output_end_mod_decls(int num_mods)
  32. {
  33.     fprintf(out_file,"};\n\n"
  34.       "struct COVEN_Mods _coven_mods = {\n"
  35.       "  %d, _coven_mod_decl_array\n"
  36.       "};\n\n", num_mods);
  37. }
  38.  
  39. void output_begin_const_decls()
  40. {
  41.        fprintf(out_file,"struct COVEN_Const_Decl _coven_constant_array[] = "
  42.       "{\n");
  43. }
  44.  
  45. void output_const_decl(sym_ent_p con)
  46. {
  47.        char ct[64];
  48.     if(!strcmp(con->value.con->type->name, "int")) {
  49.         snprintf(ct, 64, "COVEN_INT");
  50.     }
  51.     else if(!strcmp(con->value.con->type->name, "float")) {
  52.         snprintf(ct, 64, "COVEN_FLOAT");
  53.     }
  54.     else if(!strcmp(con->value.con->type->name, "double")) {
  55.         snprintf(ct, 64, "COVEN_DOUBLE");
  56.     }
  57.     else if(!strcmp(con->value.con->type->name, "string")) {
  58.         snprintf(ct, 64, "COVEN_STRING");
  59.     }
  60.     else
  61.         yyerror("CRAP, can't handle this type yet. :(\n");
  62.     fprintf(out_file,"  {%s, \"%s\", \"%s\"},\n", ct, 
  63.       con->name, con->value.con->cvalue);
  64. }
  65.  
  66. void output_end_const_decls(int num_consts)
  67. {
  68.        fprintf(out_file,"};\n\n"
  69.                      "struct COVEN_Consts _coven_constants = {\n"
  70.              "  %d, \n"
  71.              "  _coven_constant_array\n"
  72.              "};\n\n", num_consts);
  73. }
  74.  
  75. void output_start_mod_call(sym_ent_p sym)
  76. {
  77.        fprintf(out_file,"struct COVEN_Mod_Binding _%s_%d_array[] = {\n",
  78.       sym->name, sym->value.mod->times_called);
  79. }
  80.  
  81. void output_end_mod_call(sym_ent_p sym)
  82. {
  83.        /* count how many args this module has, there should be a better
  84.      * way to do this, perhaps we should store it */
  85.        int num_args = 0;
  86.        sym_ent_p cur = sym->value.mod->args;
  87.     while(cur != NULL) {
  88.         cur = cur->next;
  89.         num_args++;
  90.     }
  91.        fprintf(out_file,"};\n\n"
  92.                      "struct COVEN_Mod_Binding_Table _%s_%d = {\n"
  93.              "  %d,\n"
  94.              "  0,\n"
  95.              "  _%s_%d_array\n"
  96.              "};\n\n",
  97.       sym->name, sym->value.mod->times_called, num_args,
  98.       sym->name, sym->value.mod->times_called);
  99. }
  100.  
  101. void output_mod_binding(sym_ent_p sym, int arg_num, char *global_binding)
  102. {
  103.        char *local_binding;
  104.     sym_ent_p cur = sym->value.mod->args;
  105.     int cur_arg = 0;
  106.  
  107.     while(cur != NULL && cur_arg != arg_num) {
  108.         cur_arg++;
  109.         cur = cur->next;
  110.     }
  111.     /* cur should now be pointing to our local binding symbol */
  112.     if(cur == NULL) {
  113.         yyerror("parser error - argument disappeared.\n");
  114.     }
  115.  
  116.     local_binding = cur->name;
  117.     
  118.        fprintf(out_file,"  {\"%s\", \"%s\"},\n",
  119.       local_binding, global_binding);
  120. }
  121.  
  122. void output_all_mod_calls(mod_call_p first_call)
  123. {
  124.        mod_call_p cur = first_call;
  125.     int num_calls = 0;
  126.  
  127.     fprintf(out_file,"struct COVEN_Mod_Call _coven_mod_call_array[] = {\n");
  128.     while(cur != NULL) {
  129.         fprintf(out_file,"  {\"%s\", %s, %d, %s, %s},\n",
  130.           cur->name, cur->proc, cur->thread, cur->btable,
  131.           cur->loop);
  132.         cur = cur->next;
  133.         num_calls++;
  134.     }
  135.     fprintf(out_file,"};\n\n");
  136.     fprintf(out_file,"struct COVEN_Mod_Calls _coven_mod_calls = {\n"
  137.                      "  %d,\n"
  138.              "  _coven_mod_call_array,\n"
  139.              "};\n\n", num_calls);
  140. }
  141.  
  142. void output_loop(int loop_num, char *loop_tag, int initial_val, char *cmp_type,
  143.   char *cmp_tag, int incr_val, int begin_mod, int end_mod)
  144. {
  145.     fprintf(out_file,"struct COVEN_Loop _coven_loop_%d = {\n"
  146.                      "  \"%s\",\n"
  147.              "  %d,\n"
  148.              "  %s,\n"
  149.              "  \"%s\",\n"
  150.              "  %d,\n"
  151.              "  %d,\n"
  152.              "  %d,\n"
  153.              "};\n\n",
  154.       loop_num, loop_tag, initial_val, cmp_type, cmp_tag,
  155.       incr_val, begin_mod, end_mod);
  156. }
  157.  
  158. void output_program(int nmt, int nst)
  159. {
  160.     fprintf(out_file,"struct COVEN_Program _coven_program = {\n"
  161.                      "  %d,\n"
  162.              "  %d,\n"
  163.              "  &_coven_constants,\n"
  164.              "  &_coven_mods,\n"
  165.              "  &_coven_mod_calls,\n"
  166.              "};\n", nmt, nst);
  167. }
  168.