Exemple #1
0
gs_void_t gs_write (const gs_string_t filename)
{
  gs_count_t gs_length, unsigned_char_length, mem_seg_length;
  gs_int_t fd, lseek_rv, write_rv;

#ifdef Is_True_On
  flag_reachable_nodes((gs_t) gs_mempool[GS_ARENA].firstblock->mem);
#endif

  gs_arena_t *gs_arena = &gs_mempool[GS_ARENA];
  gs_arena_t *gs_unsigned_char_arena = &gs_mempool[IB_STRING_ARENA];

  gs_length = gs_arena->current_index;
  unsigned_char_length = gs_unsigned_char_arena->current_index;
  mem_seg_length = gs_length + unsigned_char_length;

  fd = open (filename, O_TRUNC|O_CREAT|O_RDWR, 0666);
  GS_ASSERT (!(fd < 0), "open failed.\n");
  lseek_rv = lseek (fd, mem_seg_length - 1, SEEK_SET);
  GS_ASSERT (lseek_rv != -1, "lseek failed.\n"); 
  write_rv = write (fd, " ", 1);
  GS_ASSERT (write_rv == 1, "write failed.\n");
  mem_seg = mmap (0, mem_seg_length, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
  GS_ASSERT (mem_seg != MAP_FAILED, "mmap failure.\n");

  // Convert physical addresses to indexes within the mem_seg.
  int i = 0;
  int size;
  gs_t p_in_memseg;
  gs_t t = (gs_t) gs_mempool_idx2address(GS_ARENA, 0);
  while (i < gs_arena->current_index) {
    p_in_memseg = (gs_t) (mem_seg + i);
    size = gspin_node_size(gs_code(t));
    memcpy(p_in_memseg, t, size);
#if 0
#ifdef Is_True_On
    _gs_em(p_in_memseg, false);
    if (gs_em(t) == false) {
      printf("leaked node: ");
      gs_dump(t);
    }
#endif
#endif

    if (gs_code_arity(gs_code(t)) > 0) { // convert kid pointers to indices
      int j;
      for (j = 0; j < gs_code_arity(gs_code(t)); j++)
        if (gs_operand(t, j) != NULL)
	  gs_set_operand(p_in_memseg, j, 
	        (gs_t) gs_mempool_address2byteofst(GS_ARENA, (char *)gs_operand(t, j)));
    }
    else if (gs_code(t) == IB_STRING) { // convert string pointer to index
	gs_string_t s = gs_s(t);
        _gs_u(p_in_memseg, 
	      gs_length + gs_mempool_address2byteofst(IB_STRING_ARENA, s));
        memcpy (mem_seg + gs_u(p_in_memseg), s, gs_slen(p_in_memseg));
    }

    i += gspin_node_size(gs_code(t));
    t = (gs_t) gs_mempool_idx2address(GS_ARENA, i);
    while (i < gs_arena->current_index && gs_code(t) == DOT) {
      i += 4;
      t = (gs_t) gs_mempool_idx2address(GS_ARENA, i);
    }
  }

  close (fd);
  return;
}
Exemple #2
0
//*******************************************************
// Process the cc1 command line arguments.
//*******************************************************
void
Process_Cc1_Command_Line(gs_t arg_list)
{
  INT i, j;
  char *cp;
  INT Src_Count = 0;
  BOOL opt_set = FALSE;
  INT argc = gs_length(arg_list);
  char *argv;

  // determine if it is C or C++ and set lang_cplus accordingly
  argv = gs_s(gs_index(arg_list, 0));
  char *command = Last_Pathname_Component(argv);
//printf("%s\n", command);
#ifdef FE_GNU_4_2_0
  lang_cplus = !strcmp(command, "cc1plus42");
#else
  lang_cplus = !strcmp(command, "cc1plus");
#endif

  if (lang_cplus)
    key_exceptions = 1;

  for (i = 1; i < argc; i++) {
      argv = gs_s(gs_index(arg_list, i));
//    printf("%s\n", argv);
      if ( *argv == '-' ) {
	  cp = argv+1;	    /* Pointer to next flag character */

	  switch ( *cp++ ) {

	  case 'a':
	      if (!strcmp( cp, "uxbase" )) 
		i++;
	      break;

	  case 'd':
	      if (!strcmp( cp, "umpbase" )) 
	      {
		i++;
		Orig_Src_File_Name = gs_s(gs_index(arg_list, i));
	      }
	      break;

	  case 'e':
	      if (lang_cplus && !strcmp( cp, "xceptions" ))
		key_exceptions = TRUE;
	      break;

	  case 'f':
	      if (!strcmp( cp, "no-exceptions" )) {
		key_exceptions = FALSE;
	      }
	      else if (lang_cplus && !strcmp( cp, "exceptions" )) {
		key_exceptions = TRUE;
	      }
	      else if (!strcmp( cp, "no-gnu-exceptions")) {
		// GNU exceptions off, turn off exception here also.
		key_exceptions = FALSE;
	      }
	      else if (!lang_cplus && !strcmp( cp, "no-c-omit-external")) {
		c_omit_external = FALSE;
	      }
	      else if (!lang_cplus && !strcmp( cp, "c-omit-external")) {
		c_omit_external = TRUE;
	      }
#ifdef FE_GNU_4_2_0
	      else if (!strcmp( cp, "no-cxx-openmp")) {
	        enable_cxx_openmp = FALSE;
	      }
	      else if (lang_cplus && !strcmp( cp, "cxx-openmp")) {
	        enable_cxx_openmp = TRUE;
	      }
#endif
	      break;

	  case 'g':		    /* Debug level: */
	      Debug_Level = Get_Numeric_Flag (&cp, 0, MAX_DEBUG_LEVEL, 2,
					      argv);
	      if (Debug_Level > 1 && !opt_set)
		  Opt_Level = 0;
	      break;

	  case 'i':
	      if (!strcmp( cp, "prefix" )) 
		i++;
	      break;

	  case 'm':
#ifndef TARG_MIPS
	      if (!strcmp( cp, "32" )) {
		TARGET_64BIT = FALSE;
	      }
	      else if (!strcmp( cp, "64" )) {
		TARGET_64BIT = TRUE;
	      }
	      else if (!strncmp( cp, "regparm=", 8 )) {
	        cp += 8;
	        Reg_Parm_Count = Get_Numeric_Flag (&cp, 0, 3, 0, argv ); 
	      }
	      else if (!strcmp( cp, "sseregparm" )) {
	        SSE_Reg_Parm = TRUE;
	      }
#else
	      // 11953: MIPS expects -mabi=n32 or -mabi=64
	      if (!strcmp( cp, "abi=n32" )) {
		TARGET_64BIT = FALSE;
	      }
	      else if (!strcmp( cp, "abi=64" )) {
		TARGET_64BIT = TRUE;
	      }
#endif
	      break;

	  case 'o':
	      if (*cp == 0)
		i++;
	      break;

	  case 'p':
	      if (!strcmp( cp, "static_as_global" )) {
		pstatic_as_global = TRUE;
	      }
	      break;
      
	  case 'O':		    /* Optimization level: */
	      Opt_Level = Get_Numeric_Flag (&cp, 0, MAX_OPT_LEVEL,
					    DEF_O_LEVEL, argv ); 
	      opt_set = TRUE;
	      break;

	  case 's':
	      if (!strcmp( cp, "pinfile" )) 
		i++;
	      break;
	    
	  case 'v':
	      Show_Progress = TRUE;
	      break;
	    
	  default:		    /* What's this? */
	      break;
	  }
      } else if (argv != NULL) {
	  Src_Count++;
	  FmtAssert(Src_Count == 1,
	  	    ("wgen passed more than one source file in command line"));
	  Src_File_Name = argv;
	  if (Orig_Src_File_Name == NULL)
	    Orig_Src_File_Name = argv;
      } 
  }
}