コード例 #1
0
ファイル: main.c プロジェクト: ashwinraghav/Cqual
/* Compile an entire file of output from cpp, named NAME.
   Write a file of assembly output and various debugging dumps.  */
static void compile_file(char *name)
{
  FILE *ifile;

#if !USE_CPPLIB
  /* Open input file.  */

  if (name == 0 || !strcmp (name, "-"))
    {
      ifile = stdin;
      name = "stdin";
    }
  else
    ifile = fopen (name, "r");
  if (ifile == 0)
    pfatal_with_name (name);

#ifdef IO_BUFFER_SIZE
  setvbuf(ifile, (char *) xmalloc (IO_BUFFER_SIZE), _IOFBF, IO_BUFFER_SIZE);
#endif
#endif /* !USE_CPPLIB */

  set_nomem_handler(outofmemory);

  set_input(ifile, name);
  init_lex(); /* needs to go before init_semantics, since inits
		 dummy_location */
  init_semantics();

  if (yyparse () != 0)
    {
      if (errorcount == 0)
	fprintf (stderr, "Errors detected in input file (your bison.simple is out of date)");
    }

  fclose (ifile);

  if (errorcount == 0)
    {
      /*if (flag_parse_only)
	{
	  fprintf(stderr, "\nDONE. Unparsing............\n\n");
	  unparse(stdout, the_program);
	}
      else
      exit(exec_cc1(the_program));*/

      if (the_program)
	{
	  parsed_file pf;

	  pf = ralloc(parse_region, struct parsed_file);
	  pf->name = name;
	  pf->program = the_program;
	  dd_add_last(parse_region, parsed_files, pf);

	  analyze(the_program);
	}
    }
}
コード例 #2
0
ファイル: scc.c プロジェクト: 7ym0n/note
/***********************************************************
 * 功能:	初始化
 **********************************************************/
void init ()
{
	line_num = 1;
    init_lex();

	syntax_state = SNTX_NUL;
	syntax_level = 0;
}
コード例 #3
0
ファイル: syn.c プロジェクト: zgthompson/fa14
void init_syn(syn_state *ss, FILE *input, FILE *output, FILE *debug) {
    lex_state *ls = malloc( sizeof(lex_state) );
    init_lex(ls, input, output, debug);
    ss->ls = ls;
    ss->input = input;
    ss->output = output;
    ss->debug = debug;
    ss->error_count = 0;
}
コード例 #4
0
ファイル: main.c プロジェクト: lamproae/cflow
void
init()
{
     if (level_indent[0] == NULL) 
	  level_indent[0] = "    "; /* 4 spaces */
     if (level_indent[1] == NULL)
	  level_indent[1] = level_indent[0];
     if (level_end[0] == NULL)
	  level_end[0] = "";
     if (level_end[1] == NULL)
	  level_end[1] = "";
     
     init_lex(debug > 2);
     init_parse();
}
コード例 #5
0
ファイル: main.c プロジェクト: he110world/junk
PUBLIC int main(int argc, char **argv)
{
     init_lex();
     init_symtab();
     init_type();
     init_lib();

     if (argc != 2) 
	  filename = "standard input";
     else {
	  filename = argv[1];
	  if ((yyin = fopen(filename, "r")) == NULL) {
	       perror(filename);
	       exit(1);
	  }
     }

     yyparse();
     return (err_count == 0 ? 0 : 1);
}
コード例 #6
0
ファイル: main.cpp プロジェクト: Distrotech/groff
void do_file(FILE *fp, const char *filename)
{
  string linebuf;
  string str;
  string fn(filename);
  fn += '\0';
  normalize_for_lf(fn);
  current_filename = fn.contents();
  if (output_format == troff)
    printf(".lf 1 %s\n", current_filename);
  current_lineno = 0;
  while (read_line(fp, &linebuf)) {
    if (linebuf.length() >= 4
	&& linebuf[0] == '.' && linebuf[1] == 'l' && linebuf[2] == 'f'
	&& (linebuf[3] == ' ' || linebuf[3] == '\n' || compatible_flag)) {
      put_string(linebuf, stdout);
      linebuf += '\0';
      if (interpret_lf_args(linebuf.contents() + 3))
	current_lineno--;
    }
    else if (linebuf.length() >= 4
	     && linebuf[0] == '.'
	     && linebuf[1] == 'E'
	     && linebuf[2] == 'Q'
	     && (linebuf[3] == ' ' || linebuf[3] == '\n'
		 || compatible_flag)) {
      put_string(linebuf, stdout);
      int start_lineno = current_lineno + 1;
      str.clear();
      for (;;) {
	if (!read_line(fp, &linebuf))
	  fatal("end of file before .EN");
	if (linebuf.length() >= 3 && linebuf[0] == '.' && linebuf[1] == 'E') {
	  if (linebuf[2] == 'N'
	      && (linebuf.length() == 3 || linebuf[3] == ' '
		  || linebuf[3] == '\n' || compatible_flag))
	    break;
	  else if (linebuf[2] == 'Q' && linebuf.length() > 3
		   && (linebuf[3] == ' ' || linebuf[3] == '\n'
		       || compatible_flag))
	    fatal("nested .EQ");
	}
	str += linebuf;
      }
      str += '\0';
      start_string();
      init_lex(str.contents(), current_filename, start_lineno);
      non_empty_flag = 0;
      inline_flag = 0;
      yyparse();
      restore_compatibility();
      if (non_empty_flag) {
	if (output_format == mathml)
	  putchar('\n');
        else {
	  printf(".lf %d\n", current_lineno - 1);
	  output_string();
	}
      }
      if (output_format == troff)
	printf(".lf %d\n", current_lineno);
      put_string(linebuf, stdout);
    }
    else if (start_delim != '\0' && linebuf.search(start_delim) >= 0
	     && inline_equation(fp, linebuf, str))
      ;
    else
      put_string(linebuf, stdout);
  }
  current_filename = 0;
  current_lineno = 0;
}
コード例 #7
0
ファイル: main.cpp プロジェクト: Distrotech/groff
// Handle an inline equation.  Return 1 if it was an inline equation,
// otherwise.
static int inline_equation(FILE *fp, string &linebuf, string &str)
{
  linebuf += '\0';
  char *ptr = &linebuf[0];
  char *start = delim_search(ptr, start_delim);
  if (!start) {
    // It wasn't a delimiter after all.
    linebuf.set_length(linebuf.length() - 1); // strip the '\0'
    return 0;
  }
  start_string();
  inline_flag = 1;
  for (;;) {
    if (no_newline_in_delim_flag && strchr(start + 1, end_delim) == 0) {
      error("missing `%1'", end_delim);
      char *nl = strchr(start + 1, '\n');
      if (nl != 0)
	*nl = '\0';
      do_text(ptr);
      break;
    }
    int start_lineno = current_lineno;
    *start = '\0';
    do_text(ptr);
    ptr = start + 1;
    str.clear();
    for (;;) {
      char *end = strchr(ptr, end_delim);
      if (end != 0) {
	*end = '\0';
	str += ptr;
	ptr = end + 1;
	break;
      }
      str += ptr;
      if (!read_line(fp, &linebuf))
	fatal("unterminated `%1' at line %2, looking for `%3'",
	      start_delim, start_lineno, end_delim);
      linebuf += '\0';
      ptr = &linebuf[0];
    }
    str += '\0';
    if (output_format == troff && html) {
      printf(".as1 %s ", LINE_STRING);
      html_begin_suppress();
      printf("\n");
    }
    init_lex(str.contents(), current_filename, start_lineno);
    yyparse();
    if (output_format == troff && html) {
      printf(".as1 %s ", LINE_STRING);
      html_end_suppress();
      printf("\n");
    }
    if (output_format == mathml)
      printf("\n");
    if (xhtml) {
      /* skip leading spaces */
      while ((*ptr != '\0') && (*ptr == ' '))
	ptr++;
    }
    start = delim_search(ptr, start_delim);
    if (start == 0) {
      char *nl = strchr(ptr, '\n');
      if (nl != 0)
	*nl = '\0';
      do_text(ptr);
      break;
    }
  }
  restore_compatibility();
  if (output_format == troff)
    printf(".lf %d\n", current_lineno);
  output_string();
  if (output_format == troff)
    printf(".lf %d\n", current_lineno + 1);
  return 1;
}
コード例 #8
0
ファイル: main.c プロジェクト: amery/clip-angelo
int
main(int argc, char **argv)
{
   int /*ch, */ i, ii, ret, err_flag = 0;

   clock_t beg, end, Beg, End;

   int files = 0;

   struct tms ts;

   char buf[256];

   char *e;

   prgname = strrchr(argv[0], '/');

   if (prgname)
      prgname++;
   else
      prgname = argv[0];

   e = getenv("CLIP_HOSTCS");
   if (e && *e)
   {
      sourceCharset = targetCharset = strdup(e);
   }
   else if (!e)
   {
      e = getenv("CLIP_LANG");
      if (e == NULL)
	 e = getenv("LANG");
      if (!e || !*e || !strcmp(e, "C"))
	 e = getenv("LC_MESSAGES");
      if (!e || !*e || !strcmp(e, "C"))
	 e = getenv("LC_ALL");
      if (e && *e)
      {
	 char *s = strrchr(e, '.');

	 if (s)
	 {
	    snprintf(buf, sizeof(buf), "%s", s + 1);
	    for (s = buf; *s; s++)
	       *s = tolower(*s);
	    sourceCharset = targetCharset = strdup(buf);
	 }
      }
   }

   {
      e = getenv("CLIP_LANG");
      if (e == NULL)
	 e = getenv("LANG");
      if (!e || !*e || !strcmp(e, "C"))
	 e = getenv("LC_MESSAGES");
      if (!e || !*e || !strcmp(e, "C"))
	 e = getenv("LC_ALL");
      if (e && *e)
      {
	 char *s = strrchr(e, '.');

	 if (s)
	 {
	    snprintf(buf, sizeof(buf), "%s", s + 1);
	    for (s = buf; *s; s++)
	       *s = tolower(*s);
	    out_charset = strdup(buf);
	 }
      }
   }

   {
      char *locale;

      locale = getenv("CLIP_LANG");
      if (!locale || !*locale)
	 locale = getenv("LANG");
      /*if (locale && *locale &&
         strcasecmp(locale, "C") && strcasecmp(locale, "POSIX")) */
      /*
         setlocale(LC_ALL, locale);
       */
   }

   if (!sourceCharset)
      sourceCharset = targetCharset = strdup("c");

   getEnvironment();

   init_Coll(&includePaths, NULL, NULL);
   init_Coll(&lib_dirs, NULL, NULL);
   init_Coll(&arglibs, NULL, NULL);

#if 1
   insert_Coll(&includePaths, ".");
   snprintf(buf, sizeof(buf), "%s/include", CLIPROOT);
   insert_Coll(&includePaths, strdup(buf));
#ifdef STD_LIBDIR
   snprintf(buf, sizeof(buf), STD_LIB_DIR);
   insert_Coll(&lib_dirs, strdup(buf));
#endif
   snprintf(buf, sizeof(buf), "%s/lib", CLIPROOT);
   insert_Coll(&lib_dirs, strdup(buf));
#endif
   init_Coll(&predefines, NULL, NULL);
   init_Coll(&poName, NULL, NULL);
   init_Coll(&paName, NULL, NULL);
   init_Coll(&include_files, NULL, NULL);

   snprintf(buf, sizeof(buf), "__CLIP__=\"%s\"", CLIP_VERSION);
   append_Coll(&predefines, strdup(buf));

   init_module();

   {
      char buf[256], *s;

      s = getenv("HOME");
      if (s && *s)
      {
	 snprintf(buf, sizeof(buf), "%s/.cliprc", s);
	 getrc(buf);
      }

   }

   getrc(".cliprc");

   {
      char buf[256], *s;

      DIR *dp;

      s = CLIPROOT;
      if (s && *s)
      {
	 snprintf(buf, sizeof(buf), "%s/.cliprc", s);
	 getrc(buf);
      }

      snprintf(buf, sizeof(buf), "%s/cliprc", CLIPROOT);
      dp = opendir(buf);
      if (dp)
      {
	 struct dirent *ep;

	 struct stat st;

	 Coll files;

	 int i;

	 init_Coll(&files, free, strcmp);
	 while ((ep = readdir(dp)))
	 {
	    snprintf(buf, sizeof(buf), "%s/cliprc/%s", CLIPROOT, ep->d_name);
	    if (stat(buf, &st))
	       continue;
	    if (!S_ISREG(st.st_mode))
	       continue;
	    if (access(buf, R_OK))
	       continue;
	    insert_Coll(&files, strdup(buf));
	 }
	 closedir(dp);

	 for (i = 0; i < files.count_of_Coll; i++)
	 {
		 char *name = (char *) files.items_of_Coll[i];

	    getrc(name);
	 }

	 destroy_Coll(&files);
      }
   }

   argc--;
   argv++;
   get_opt(argc, argv);

   argc -= optind;
   argv += optind;

   if (err_flag)
      return 1;

#if 0
   insert_Coll(&includePaths, ".");
   snprintf(buf, sizeof(buf), "%s/include", CLIPROOT);
   insert_Coll(&includePaths, strdup(buf));
#ifdef STD_LIBDIR
   snprintf(buf, sizeof(buf), STD_LIBDIR);
   insert_Coll(&lib_dirs, strdup(buf));
#endif
   snprintf(buf, sizeof(buf), "%s/lib", CLIPROOT);
   insert_Coll(&lib_dirs, strdup(buf));
#endif

   if (syntax_tree_flag)
   {
      write_obj_flag = 0;
      codegen_flag = 1;
      compile_flag = 0;
      pcode_flag = 0;
      pc_flag = 0;
      asm_flag = 0;
      exec_flag = 0;
   }

   if (!write_obj_flag)
   {
      /*codegen_flag = 0; */
      compile_flag = 0;
   }
   if (preproc_flag)
   {
      write_obj_flag = 0;
      codegen_flag = 0;
      syntax_tree_flag = 0;
      compile_flag = 0;
      exec_flag = 0;
      pcode_flag = 0;
      pc_flag = 0;
      asm_flag = 0;
      shared_flag = 0;
   }

   if (pcode_flag)
   {
      pc_flag = 0;
      asm_flag = 0;
      shared_flag = 0;
   }

   if (pc_flag)
   {
      pcode_flag = 1;
#ifdef USE_AS
      if (use_asm)
	 asm_flag = 1;
      else
	 asm_flag = 0;
#endif
   }

   if (xpc_flag)
   {
      pcode_flag = 1;
      pc_flag = 1;
#ifdef USE_AS
      if (use_asm)
	 asm_flag = 0;
      else
	 asm_flag = 1;
#endif
   }

#if 0
   if (shared_flag && pcode_flag)
   {
      v_printf(0, "conflict between -s and -p flags\n");
      exit(1);
   }
#endif

   if (pcode_flag && c_flag)
   {
      v_printf(0, "conflict between -c and -p flags\n");
      exit(1);
   }

   /*if ( exec_flag && !main_flag && !shared_flag)
      {
      v_printf(0, "-e(xec) flag without -M(ain) or -s(hared) flags\n");
      exit(2);
      } */

   if (pcode_flag)
   {
      compile_flag = 0;
   }

   if (nomain_flag && main_flag)
   {
      v_printf(0, "conflict between -n and -m flags\n");
      exit(1);
   }

   if (!exec_flag && oname)
   {
      char *e;

      if (oname[0] == '/')
	 snprintf(buf, sizeof(buf), "%s", oname);
      else
	 snprintf(buf, sizeof(buf), "%s%s%s", outdir ? outdir : "", outdir ? "/" : "", oname);
      e = strrchr(buf, '/');
      if (e)
      {
	 *e = 0;
	 outdir = strdup(buf);
      }
   }

   if (!outdir)
      outdir = ".";

   if (outdir)
   {
      char cdir[256];

      getcwd(cdir, sizeof(cdir));

      if (!chdir(outdir))
      {
	 getcwd(buf, sizeof(buf));
	 outdir = strdup(buf);
	 chdir(cdir);
      }
      else
      {
	 yyerror("cannot change to output dir '%s': %s", outdir, strerror(errno));
	 exit(1);
      }
   }

   if (!preproc_flag)
   {
      v_printf(2, "set source charset to %s\n", sourceCharset);
      v_printf(2, "set target charset to %s\n", targetCharset);
   }

   init_lex();
   init_parser();

   if (argc < 1)
      ii = -1;
   else
      ii = 0;

   Beg = times(&ts);
   if (argc > 0)
   {
      for (i = 0; i < argc; i++)
      {
	 char *e;

	 e = argv[i];
	 if (e[0] == '-' && e[1] == 'L')
	 {
	    insert_Coll(&lib_dirs, strdup(e + 2));
	    continue;
	 }
	 e = strrchr(argv[i], '.');
	 if (!e)
	 {
	    e = argv[i];
	    if (e[0] == '-' && e[1] == 'l')
	       /*append_Coll(&arglibs, strdup(e+2)) */ ;
	    else
	       yyerror("unknown file type '' file '%s'", argv[i]);
	    continue;
	 }
	 else if (!strcasecmp(e, ".po"))
	    insert_Coll(&poName, strdup(argv[i]));
	 else if (!strcasecmp(e, ".pa"))
	    insert_Coll(&paName, strdup(argv[i]));
	 else if (strcasecmp(e, ".prg") && strcasecmp(e, ".c") && strcasecmp(e, ".cc") && strcasecmp(e, OBJSUF) && strcasecmp(e, SOBJSUF) && strcasecmp(e, ".a") && strcasecmp(e, ".lib"))
	 {
	    /*yywarning("unknown file type '%s' file '%s'", e, argv[i]); */
	    continue;
	 }
      }
   }

   for (; clic_errorcount == 0 && ii < argc; ii++)
   {
      ++files;
      if (ii < 0)
      {
	 v_printf(1, "no input files, so use stdin; -h will help\n");
	 fflush(stderr);
	 set_locale_name("stdin");
	 ret = clic_parse("stdin", stdin);
	 add_name("stdin");
      }
      else
      {
	 char *e;

	 e = strrchr(argv[ii], '.');
	 add_name(argv[ii]);

	 if (!e)
	    continue;
	 else if (!strcasecmp(e, ".c") || !strcasecmp(e, ".cc") || !strcasecmp(e, ".cpp"))
	 {
	    if (!preproc_flag)
	    {
	       v_printf(1, "process file '%s' ..", argv[ii]);
	       v_neednl = 1;
	    }

	    beg = times(&ts);
	    compile_CFile(argv[ii]);
	    end = times(&ts);

	    if (!preproc_flag)
	    {
	       v_neednl = 0;
	       if (clic_errorcount == 0)
		  v_printf(1, ".. done, %s\n", diff_clock(beg, end));
	       else
		  pr_errorcount(1);
	    }
	    continue;
	 }
	 else if (strcasecmp(e, ".prg"))
	 {
	    continue;
	 }

	 if (ii > 0)
	    main_flag = 0;

	 if (!preproc_flag)
	 {
	    v_printf(1, "parsing file '%s' ..", argv[ii]);
	    v_neednl = 1;
	 }
	 beg = times(&ts);
	 set_locale_name(argv[ii]);
	 ret = clic_parse(argv[ii], 0);
	 end = times(&ts);

	 if (!preproc_flag)
	 {
	    v_neednl = 0;
	    if (clic_errorcount == 0)
	       v_printf(1, ".. done (%d/%d %s, %d %s, %s)\n",
			clic_line, all_lines, _clic_ngettext("line", "lines", clic_line), clic_warncount, _clic_ngettext("warning", "warnings", clic_warncount), diff_clock(beg, end));
	    else
	       vr_printf(1, "%d %s, %d %s\n", clic_errorcount, _clic_ngettext("error", "errors", clic_errorcount), clic_warncount, _clic_ngettext("warning", "warnings", clic_warncount));
	 }
      }
      if (ret)
	 break;

      if (clic_errorcount == 0 && codegen_flag)
      {
	 v_printf(2, "codegen file '%s' ..", curFile->name_of_File);
	 v_neednl = 1;
	 beg = times(&ts);
	 codegen_File(curFile);
	 end = times(&ts);
	 v_neednl = 0;
	 if (clic_errorcount == 0)
	    v_printf(2, ".. done, %s\n", diff_clock(beg, end));
	 else
	    pr_errorcount(2);
      }
      if (clic_errorcount == 0 && syntax_tree_flag)
      {
	 print_File(curFile);
      }
      if (clic_errorcount == 0 && write_obj_flag)
      {
	 if (pcode_flag)
	 {
	    long len;

	    v_printf(1, "writing file '%s' ..", curFile->s_cname_of_File);
	    v_neednl = 1;
	    beg = times(&ts);
	    write_OFile(curFile, &len);
	    write_names(curFile);
	    end = times(&ts);
	    v_neednl = 0;
	    if (clic_errorcount == 0)
	       v_printf(1, ".. done, %ld %s ,%s\n", len, _clic_ngettext("byte", "bytes", len), diff_clock(beg, end));
	    else
	       pr_errorcount(1);
	 }
	 else
	 {
	    v_printf(2, "writing file '%s' ..", curFile->s_cname_of_File);
	    v_neednl = 1;
	    write_File(curFile);
	    write_names(curFile);
	    v_neednl = 0;
	    if (clic_errorcount == 0)
	       v_printf(2, ".. done\n");
	    else
	       pr_errorcount(2);
	 }
      }

      if (clic_errorcount == 0 && (compile_flag || pc_flag))
      {
	 if (ii)
	    main_flag = 0;
	 v_printf(1, "compile file '%s' ..", curFile->s_cname_of_File);
	 v_neednl = 1;
	 beg = times(&ts);
	 compile_File(curFile->cname_of_File);
	 end = times(&ts);
	 v_neednl = 0;
	 if (clic_errorcount == 0)
	    v_printf(1, ".. done, %s\n", diff_clock(beg, end));
	 else
	    pr_errorcount(1);

	 if (clic_errorcount == 0 && shared_flag && !exec_flag)
	 {
	    v_printf(1, "make shared object '%s' ..", curFile->s_cname_of_File);
	    v_neednl = 1;
	    beg = times(&ts);
	    share_File(curFile->cname_of_File);
	    end = times(&ts);
	    v_neednl = 0;
	    if (clic_errorcount == 0)
	       v_printf(1, ".. done, %s\n", diff_clock(beg, end));
	    else
	       pr_errorcount(1);

	 }
      }

      if (ii < 0)
	 break;

      delete_File(curFile);
      curFile = NULL;
   }

   if (clic_errorcount == 0 && exec_flag)
   {
      char cmd[1024 * 8], *e;

      char cfuncname[256], ofuncname[256];

      char *libroot;

      int i;

      Coll ex, nm;

      init_Coll(&ex, free, strcasecmp);
      init_Coll(&nm, free, strcasecmp);
#ifdef STD_LIBDIR
      libroot = 0;
#else
      libroot = CLIPROOT;
#endif

      ++files;
#ifdef STD_LIBDIR
      if (eshared_flag || shared_flag)
      {
	 snprintf(cmd, sizeof(cmd), "-lclip");
	 add_name(cmd);
      }
      else
#endif
      {
	 e = (eshared_flag || shared_flag) ? CLIPSLIB : CLIPLIB;
	 lib_name(cmd, sizeof(cmd), libroot, "lib", e, strlen(e));
	 add_name(cmd);
      }
      for (e = CLIPLIBS; *e;)
      {
	 int l;

	 l = strspn(e, " \t");
	 e += l;
	 l = strcspn(e, " \t");
	 if (!l)
	    break;
	 lib_name(cmd, sizeof(cmd), libroot, "lib", e, l);
	 add_name(cmd);
	 e += l;
      }
      for (e = ADDLIBS; *e;)
      {
	 int l;

	 l = strspn(e, " \t");
	 e += l;
	 l = strcspn(e, " \t");
	 if (!l)
	    break;
	 memcpy(cmd, e, l);
	 cmd[l] = 0;
	 add_name(cmd);
	 e += l;
      }
      add_name(MATHLIB);
      add_name(DLLIB);

      /* generate _cfunctions */
      if (asm_flag)
	 sprintf(cfuncname, "%s_ref.s", oname);
      else
	 sprintf(cfuncname, "%s_ref.c", oname);
      sprintf(ofuncname, "%s_ref.o", oname);
      v_printf(1, "generate reference file '%s' ..", cfuncname);
      v_neednl = 1;
      beg = times(&ts);
      write_Cfunc(cfuncname, onum, ovect, &ex, &nm);
      check_names(&ex, &nm);
      end = times(&ts);
      v_neednl = 0;
      if (clic_errorcount == 0)
	 v_printf(1, ".. done, %s\n", diff_clock(beg, end));
      else
	 pr_errorcount(1);
      if (clic_errorcount)
	 goto end;

      v_printf(1, "compile file '%s' ..", cfuncname);
      v_neednl = 1;
      beg = times(&ts);
      compile_File(cfuncname);
      end = times(&ts);
      v_neednl = 0;
      if (clic_errorcount == 0)
	 v_printf(1, ".. done, %s\n", diff_clock(beg, end));
      else
	 pr_errorcount(1);

#ifdef USE_LD
      if (use_asm && (shared_flag || eshared_flag))
      {
	 int ll;

	 const char *ld_prg, *ld_end;

	 if (shared_flag || eshared_flag)
	 {
	    ld_prg = LD_PRG;
	    ld_end = LD_END;
	 }
	 else
	 {
	    ld_prg = LDS_PRG;
	    ld_end = LDS_END;
	 }

	 snprintf(cmd, sizeof(cmd), "%s", ld_prg);
	 ll = strlen(cmd);
	 for (e = cmd + ll, i = 0; i < lib_dirs.count_of_Coll; ++i)
	 {
		 snprintf(e, sizeof(cmd) - ll, " -L%s", (char *) lib_dirs.items_of_Coll[i]);
	    ll = strlen(cmd);
	    e = cmd + ll;
	 }
	 ll = strlen(cmd);
	 snprintf(cmd + ll, sizeof(cmd) - ll, " %s %s %s -o %s", optLevel ? COPT : "", genDebug ? CDBG : "", ofuncname, oname);
	 ll = strlen(cmd);
	 for (e = cmd + ll, i = 0; i < onum; ++i)
	 {
	    snprintf(e, sizeof(cmd) - ll, " %s", ovect[i]);
	    ll = strlen(cmd);
	    e = cmd + ll;
	 }
	 ll = strlen(cmd);
	 snprintf(cmd + ll, sizeof(cmd) - ll, " %s", ld_end);
      }
      else
#endif
      {
	 sprintf(cmd, "%s", CC);
	 for (e = cmd + strlen(cmd), i = 0; i < includePaths.count_of_Coll; ++i)
	 {
		 sprintf(e, " %s %s", INCLUDE_FLAG, (char *) includePaths.items_of_Coll[i]);
	    e = cmd + strlen(cmd);
	 }

	 for (e = cmd + strlen(cmd), i = 0; i < lib_dirs.count_of_Coll; ++i)
	 {
		 sprintf(e, " -L%s", (char *) lib_dirs.items_of_Coll[i]);
	    e = cmd + strlen(cmd);
	 }

	 sprintf(cmd + strlen(cmd), " %s %s %s %s %s %s %s", optLevel ? COPT : "", genDebug ? CDBG : "", CFLAGS, ADDCFLAGS, ofuncname, OUT_FLAG, oname);
	 for (e = cmd + strlen(cmd), i = 0; i < onum; ++i)
	 {
	    sprintf(e, " %s", ovect[i]);
	    e = cmd + strlen(cmd);
	 }
      }

      v_printf(1, "make file '%s' ..", oname);
      v_neednl = 1;
      beg = times(&ts);
      v_printf(2, "%s\n", cmd);
      if (system(cmd))
	 yyerror("C level error in command: %s", cmd);
      else if (rmc_flag)
      {
	 unlink(cfuncname);
	 unlink(ofuncname);
      }

      end = times(&ts);
      v_neednl = 0;
      if (clic_errorcount == 0)
	 v_printf(1, ".. done, %s\n", diff_clock(beg, end));
      else
	 pr_errorcount(1);
   }

 end:
   End = times(&ts);

   resume_parser();
   resume_lex();
   resume_locale();

   if (!preproc_flag)
      v_printf(1, "clip: %d %s, %s\n", files, _clic_ngettext("file", "files", files), diff_clock(Beg, End));
   return clic_errorcount == 0 ? 0 : 1;
}
コード例 #9
0
static void init_compiler (int	 argc,
			   char *argv[])
{
   extern void	init_lex (void);
   extern void	init_msg_processing (char *[]);
   extern void	init_src_input (void);
   extern void	init_type (void);
   extern void	process_cmd_line (int, char *[]);
   extern void	init_cond_comp(void);
   extern void	enter_predefined_macros(void);
   extern void	init_parse_prog_unit(void);
   extern void	init_PDGCS (void);
   extern void	set_up_token_tables(void);
   extern void  sgi_cmd_line(int *argc, char **argv[]);
   extern char *operator_str[];
   extern void	verify_semantic_tbls(void);

   	  int	idx;


   TRACE (Func_Entry, "init_compiler", NULL);

   init_date_time_info ();		/* set compilation data and time      */
   init_msg_processing (argv);		/* initialize for messages.  Must     */
					/* preceed process_cmd_line.	      */

# ifdef _DEBUG
   check_defines_compatibility();	/* Is the compiler built correctly?   */
   check_enums_for_change();	        /* Some enums must not be changed.    */
# endif

# if 0
   check_license();
# endif

   /* allocate memory for data structures required across compilation units.  */
   /* These must preceed process_cmd_line.                                    */

   TBL_ALLOC (global_line_tbl);
   TBL_ALLOC (global_name_tbl);
   TBL_ALLOC (global_attr_tbl);
   TBL_ALLOC (global_type_tbl);
   TBL_ALLOC (global_bounds_tbl);
   TBL_ALLOC (global_ir_tbl);
   TBL_ALLOC (global_ir_list_tbl);
   TBL_ALLOC (global_sh_tbl);
   TBL_ALLOC (file_path_tbl);
   TBL_ALLOC (str_pool);

   init_release_level ();		/* Set up release_level from system   */

   str_pool[0].name_long	= 0;
   str_pool[1].name_long	= 0;
   str_pool[2].name_long	= LARGE_WORD_FOR_TBL_SRCH;
   str_pool_idx			= 2;

   TBL_REALLOC_CK(global_name_tbl, 2);
   CLEAR_TBL_NTRY(global_name_tbl, 1);
   CLEAR_TBL_NTRY(global_name_tbl, 2);
   GN_NAME_IDX(1)	= 1;
   GN_NAME_LEN(1)	= HOST_BYTES_PER_WORD;
   GN_NAME_IDX(2)	= 2;
   GN_NAME_LEN(2)	= HOST_BYTES_PER_WORD;

   /* Initialize the bounds table for deferred shape arrays */

   TBL_REALLOC_CK(global_bounds_tbl, 7);

   for (idx = BD_DEFERRED_1_IDX; idx <= BD_DEFERRED_7_IDX; idx++) {
      CLEAR_TBL_NTRY(global_bounds_tbl, idx);
      GB_ARRAY_CLASS(idx)	= Deferred_Shape;
      GB_RANK(idx)		= idx;
   }

   /* Initialize the conditional compilation tables.  It must be done before  */
   /* the command line processing because of the -D and -U options.           */

   init_cond_comp ();

   get_machine_chars();

   set_up_token_tables();

   /* The following routines sets things such as target_ieee, target_triton   */
   /* two_word_fcd, word_byte_size ect...                                     */

   set_compile_info_for_target();


   comp_phase = Cmdline_Parsing;

   cif_name[0] = NULL_CHAR;

   assembly_listing_file[0] = NULL_CHAR;

   debug_file_name[0] = NULL_CHAR;

# if (defined(_TARGET_OS_IRIX) || defined(_TARGET_OS_LINUX))
   /* sgi_cmd_line does some option manipulation, process SGI specific        */
   /* command line options, and strips out things that the front-end doesn't  */
   /* need to see.                                                            */

   sgi_cmd_line (&argc,&argv);
# endif


   process_cmd_line (argc, argv);	/* pass input args		      */


# if defined(_INTEGER_1_AND_2)

   if (on_off_flags.integer_1_and_2) {
      bit_size_tbl[Integer_1] = 8;
      bit_size_tbl[Integer_2] = 16;
      bit_size_tbl[Logical_1] = 8;
      bit_size_tbl[Logical_2] = 16;

      storage_bit_size_tbl[Integer_1] = 8;
      storage_bit_size_tbl[Integer_2] = 16;
      storage_bit_size_tbl[Logical_1] = 8;
      storage_bit_size_tbl[Logical_2] = 16;

      storage_bit_prec_tbl[Integer_1] = 8;
      storage_bit_prec_tbl[Integer_2] = 16;
      storage_bit_prec_tbl[Logical_1] = 8;
      storage_bit_prec_tbl[Logical_2] = 16;

      stride_mult_unit_in_bits[Integer_1] = 8;
      stride_mult_unit_in_bits[Integer_2] = 16;
      stride_mult_unit_in_bits[Logical_1] = 8;
      stride_mult_unit_in_bits[Logical_2] = 16;

      linear_to_arith[Integer_1] = AR_Int_8_S;
      linear_to_arith[Integer_2] = AR_Int_16_S;

      input_arith_type[Integer_1] = AR_Int_8_U;
      input_arith_type[Integer_2] = AR_Int_16_U;

      strcpy(arith_type_string[Integer_1], "AR_Int_8_U");
      strcpy(arith_type_string[Integer_2], "AR_Int_16_U");
   }
# endif

   comp_phase = Pass1_Parsing;

   /* only -V info requested */

   if (argc == 2 && cmd_line_flags.verify_option) {
      print_id_line();
      exit_compiler(RC_OKAY);
   }

   if (num_errors != 0) {		/* command line errors	      */
      PRINTMSG(0, 912, Log_Summary, 0, num_errors);
      exit_compiler(RC_USER_ERROR);
   }

   /* Call init_cif even if the user did NOT request Compiler Information     */
   /* File (CIF) output because the CIF is used for messaging.		      */
   
   init_cif(comp_date_time, release_level);

   some_scp_in_err	= FALSE;
   clearing_blk_stk	= FALSE;

   init_type();
        
   make_table_changes ();

   init_sytb ();		 /* Must be before src_input for err msgs */


   /* Enter conditional compilation predefined macros.  This must happen      */
   /* after process_cmd_line because it calls GETPMC (and the information     */
   /* from GETPMC is needed to set the predefined macros that depend on the   */
   /* target machine).  This call must also happen after target_triton and    */
   /* target_ieee have been set so that we can get _CRAYIEEE set correctly.   */
   /* And finally, this call must come before init_src_input because that     */
   /* procedure gets the first source line - which could be a conditional     */
   /* compilation directive.					              */

   enter_predefined_macros();

   /* Must do the first call here so that tables needed by conditional        */
   /* compilation are set up.						      */

   init_parse_prog_unit();	

   init_src_input();

   if (on_off_flags.preprocess_only) {
      preprocess_only_driver();
      issue_deferred_msgs();

      TRACE (Func_Exit, "init_compiler", NULL);

      return;
   }

   init_lex ();

   max_field_len = (long) sbrk(0);	/* Keep track of memory usage         */

# if defined(_HOST_OS_MAX)
   max_field_len &= (1 << 32) - 1;
# endif


   /* Pathological case:  The file is empty.  At least an END statement must  */
   /* be present to constitute a valid Fortran program.                       */

   if (LA_CH_CLASS == Ch_Class_EOF) {
      PRINTMSG(0, 1391, Log_Warning, 0, src_file);
      issue_deferred_msgs();
   }


# ifdef _NAME_SUBSTITUTION_INLINING
   if (!dump_flags.preinline)
# endif
      init_PDGCS();

# ifdef _DEBUG
   verify_semantic_tbls();	/* Make sure flags and messages agree. */

   if (strcmp(operator_str[The_Last_Opr], "The_Last_Opr") != 0) {
      PRINTMSG(1, 689, Internal, 0);
   }
# endif

   TRACE (Func_Exit, "init_compiler", NULL);

   return;
 
}  /* init_compiler */