Ejemplo n.º 1
0
void
main (INT argc,       /* Number of command line arguments */
      char *argv[],   /* Array of command line arguments */
      char *envp[])   /* Array of environment pointers */
{
   WN          *pu;
   INT32        inp_file_count;
   PU_Info     *pu_tree, *current_pu;

   /* Here are things that every process driver should do as soon as
    * possible upon start-up.
    */
   MEM_Initialize ();
   Init_Error_Handler (10);
   Set_Error_Line (ERROR_LINE_UNKNOWN);
   Set_Error_Phase ("IR Walker");
   Set_Error_File (NULL);

   Init_Operator_To_Opcode_Table ();
    
   /* Process the input file */
   inp_file_count = Get_Irb_File_Name (argc, argv);
   if (inp_file_count == 0)
   {
      Usage ();
      fprintf (stderr, "ERROR: missing input file on command line\n");
   }
   else if (inp_file_count > 1)
   {
      Usage ();
      fprintf (stderr, "ERROR: too many input files on command line\n");
   }
   else if (stat (Irb_File_Name, &statbuf) != 0)
   {
      fprintf (stderr, "ERROR: input file (%s) does not exist\n",
	       Irb_File_Name);
   }
   else
   {

#ifdef WRITE_IRB
      /* Setup output file */
      if (!oflag)
	(void) strcpy (filename_out, filename_in);
      (void) sprintf (temp_filename, "%s$%d", filename_out, (INT32) getpid ());
      (void) remove (temp_filename);
#endif

      /* User defined initialization code */
      Initialization ();

      /* Get the global symbol table, the string table, the constant table,
       * and the initialization table.
       */
      (void) Open_Input_Info (Irb_File_Name);
      pu_tree = Read_Global_Info (NULL);

#ifdef WRITE_IRB
      (void) Open_Output_Info (temp_filename);
#endif

      /* Process global symbol table. */
      process_stab (Global_Symtab);

      /* Loop thru all the PUs */
      process_pu (pu_tree);

      /* User defined termination code */
      Termination ();

#ifdef WRITE_IRB
      /* Finish up output file */
      Write_Global_Info (pu_tree);
      Close_Output_Info ();
      (void) remove (filename_out);
      (void) rename (temp_filename, filename_out);
#endif

   }
   
   exit (0);
} /* main */
Ejemplo n.º 2
0
INT
main (INT argc,       /* Number of command line arguments */
      char *argv[],   /* Array of command line arguments */
      char *envp[])   /* Array of environment pointers */
{
   WN          *pu;
   INT32        ecount = 0, wcount = 0, local_ecount = 0, local_wcount = 0;
   INT32        inp_file_count;
   PU_Info     *pu_tree, *current_pu;

   /* Here are things that every process driver should do as soon as
   * possible upon start-up.
   */
   MEM_Initialize();
   Init_Error_Handler(10);
   Set_Error_Line(ERROR_LINE_UNKNOWN);
   Set_Error_Phase("Whirl2c");
   Set_Error_File(NULL); /* Use stderr */

   Preconfigure(); /* Setup target and host specific info before flags */
   Process_Common_Options(argc, argv, envp); /* Common options */
   Configure();    /* Setup target and host specific info after flags */

   Init_Operator_To_Opcode_Table();
    
   /* Process the source files */
   inp_file_count = Get_Irb_File_Name(argc, argv);
   if (inp_file_count == 0)
   {
      Usage(argv[0]);
      fprintf(stderr, "ERROR: missing input file on command-line\n");
   }
   else if (inp_file_count > 1)
   {
      Usage(argv[0]);
      fprintf(stderr, "ERROR: too many input files on command-line\n");
   }
   else
   {
      /* Get the global symbol table, the string table, the constant table,
       * and the initialization table, before initializing the translation
       * to C.
       */
      (void)Open_Input_Info(Irb_File_Name);
      pu_tree = Read_Global_Info(NULL);
      W2C_Process_Command_Line(argc, argv, argc, argv);
      W2C_Init(TRUE/*emit_global_decls*/);

      /* Loop thru all the PUs */
      for (current_pu = pu_tree;
	   current_pu != NULL;
	   current_pu = PU_Info_next (current_pu)) {

	 Current_PU_Info = current_pu;
	 MEM_POOL_Push (MEM_pu_nz_pool_ptr);
	 Read_Local_Info (MEM_pu_nz_pool_ptr, current_pu);
	 pu = PU_Info_tree_ptr(current_pu);

	 W2C_Translate_Pu(pu, TRUE/*emit_global_decls*/);

	 if (PU_Info_child(current_pu)) {
	    fprintf(stderr, "WARNING: ignoring nested procedures in \"%s\"\n",
		    ST_name(PU_Info_proc_sym(current_pu)));
	 }

	 Free_Local_Info (current_pu);
	 MEM_POOL_Pop (MEM_pu_nz_pool_ptr);
      } /* for each PU */

      W2C_Fini(TRUE/*emit_global_decls*/);
      Cleanup_Files(TRUE, FALSE);
   }
   
   /* If we've seen errors, note them and terminate: */
   if (Get_Error_Count(&local_ecount, &local_wcount))
   {
      ecount += local_ecount;
      wcount += local_wcount;
   }
   if ( ecount > 0 )
   {
      Local_Terminate();
      Terminate(1);
   }
   
   exit(0);
} /* main */