OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.2.2/] [gcc/] [config/] [alpha/] [vms-cc.c] - Diff between revs 38 and 154

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 38 Rev 154
/* VMS DEC C wrapper.
/* VMS DEC C wrapper.
   Copyright (C) 2001, 2003, 2007 Free Software Foundation, Inc.
   Copyright (C) 2001, 2003, 2007 Free Software Foundation, Inc.
   Contributed by Douglas B. Rupp (rupp@gnat.com).
   Contributed by Douglas B. Rupp (rupp@gnat.com).
 
 
This file is part of GCC.
This file is part of GCC.
 
 
GCC is free software; you can redistribute it and/or modify
GCC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
the Free Software Foundation; either version 3, or (at your option)
any later version.
any later version.
 
 
GCC is distributed in the hope that it will be useful,
GCC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
GNU General Public License for more details.
 
 
You should have received a copy of the GNU General Public License
You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3.  If not see
along with GCC; see the file COPYING3.  If not see
<http://www.gnu.org/licenses/>.  */
<http://www.gnu.org/licenses/>.  */
 
 
/* This program is a wrapper around the VMS DEC C compiler.
/* This program is a wrapper around the VMS DEC C compiler.
   It translates Unix style command line options into corresponding
   It translates Unix style command line options into corresponding
   VMS style qualifiers and then spawns the DEC C compiler.  */
   VMS style qualifiers and then spawns the DEC C compiler.  */
 
 
#include "config.h"
#include "config.h"
#include "system.h"
#include "system.h"
#include "coretypes.h"
#include "coretypes.h"
#include "tm.h"
#include "tm.h"
 
 
#undef PATH_SEPARATOR
#undef PATH_SEPARATOR
#undef PATH_SEPARATOR_STR
#undef PATH_SEPARATOR_STR
#define PATH_SEPARATOR ','
#define PATH_SEPARATOR ','
#define PATH_SEPARATOR_STR ","
#define PATH_SEPARATOR_STR ","
 
 
/* These can be set by command line arguments */
/* These can be set by command line arguments */
static int verbose = 0;
static int verbose = 0;
static int save_temps = 0;
static int save_temps = 0;
 
 
static int comp_arg_max = -1;
static int comp_arg_max = -1;
static const char **comp_args = 0;
static const char **comp_args = 0;
static int comp_arg_index = -1;
static int comp_arg_index = -1;
static char *objfilename = 0;
static char *objfilename = 0;
 
 
static char *system_search_dirs = (char *) "";
static char *system_search_dirs = (char *) "";
static char *search_dirs;
static char *search_dirs;
 
 
static char *default_defines = (char *) "";
static char *default_defines = (char *) "";
static char *defines;
static char *defines;
 
 
/* Translate a Unix syntax directory specification into VMS syntax.
/* Translate a Unix syntax directory specification into VMS syntax.
   If indicators of VMS syntax found, return input string.  */
   If indicators of VMS syntax found, return input string.  */
static char *to_host_dir_spec (char *);
static char *to_host_dir_spec (char *);
 
 
/* Translate a Unix syntax file specification into VMS syntax.
/* Translate a Unix syntax file specification into VMS syntax.
   If indicators of VMS syntax found, return input string.  */
   If indicators of VMS syntax found, return input string.  */
static char *to_host_file_spec (char *);
static char *to_host_file_spec (char *);
 
 
/* Add a translated arg to the list to be passed to DEC CC.  */
/* Add a translated arg to the list to be passed to DEC CC.  */
static void addarg (const char *);
static void addarg (const char *);
 
 
/* Preprocess the number of args in P_ARGC and contained in ARGV.
/* Preprocess the number of args in P_ARGC and contained in ARGV.
   Look for special flags, etc. that must be handled first.  */
   Look for special flags, etc. that must be handled first.  */
static void preprocess_args (int *, char **);
static void preprocess_args (int *, char **);
 
 
/* Process the number of args in P_ARGC and contained in ARGV. Look
/* Process the number of args in P_ARGC and contained in ARGV. Look
   for special flags, etc. that must be handled for the VMS compiler.  */
   for special flags, etc. that must be handled for the VMS compiler.  */
static void process_args (int *, char **);
static void process_args (int *, char **);
 
 
/* Action routine called by decc$to_vms */
/* Action routine called by decc$to_vms */
static int translate_unix (char *, int);
static int translate_unix (char *, int);


/* Add the argument contained in STR to the list of arguments to pass to the
/* Add the argument contained in STR to the list of arguments to pass to the
   compiler.  */
   compiler.  */
 
 
static void
static void
addarg (const char *str)
addarg (const char *str)
{
{
  int i;
  int i;
 
 
  if (++comp_arg_index >= comp_arg_max)
  if (++comp_arg_index >= comp_arg_max)
    {
    {
      const char **new_comp_args
      const char **new_comp_args
        = (const char **) xcalloc (comp_arg_max + 1000, sizeof (char *));
        = (const char **) xcalloc (comp_arg_max + 1000, sizeof (char *));
 
 
      for (i = 0; i <= comp_arg_max; i++)
      for (i = 0; i <= comp_arg_max; i++)
        new_comp_args [i] = comp_args [i];
        new_comp_args [i] = comp_args [i];
 
 
      if (comp_args)
      if (comp_args)
        free (comp_args);
        free (comp_args);
 
 
      comp_arg_max += 1000;
      comp_arg_max += 1000;
      comp_args = new_comp_args;
      comp_args = new_comp_args;
    }
    }
 
 
  comp_args [comp_arg_index] = str;
  comp_args [comp_arg_index] = str;
}
}
 
 
static void
static void
preprocess_args (int *p_argc, char *argv[])
preprocess_args (int *p_argc, char *argv[])
{
{
  int i;
  int i;
 
 
  for (i = 1; i < *p_argc; i++)
  for (i = 1; i < *p_argc; i++)
    {
    {
      if (strcmp (argv[i], "-o") == 0)
      if (strcmp (argv[i], "-o") == 0)
        {
        {
          char *buff, *ptr;
          char *buff, *ptr;
 
 
          i++;
          i++;
          ptr = to_host_file_spec (argv[i]);
          ptr = to_host_file_spec (argv[i]);
          objfilename = xstrdup (ptr);
          objfilename = xstrdup (ptr);
          buff = concat ("/obj=", ptr, NULL);
          buff = concat ("/obj=", ptr, NULL);
          addarg (buff);
          addarg (buff);
        }
        }
    }
    }
}
}
 
 
static void
static void
process_args (int *p_argc, char *argv[])
process_args (int *p_argc, char *argv[])
{
{
  int i;
  int i;
 
 
  for (i = 1; i < *p_argc; i++)
  for (i = 1; i < *p_argc; i++)
    {
    {
      if (strlen (argv[i]) < 2)
      if (strlen (argv[i]) < 2)
        continue;
        continue;
 
 
      if (strncmp (argv[i], "-I", 2) == 0)
      if (strncmp (argv[i], "-I", 2) == 0)
        {
        {
          char *ptr;
          char *ptr;
          int new_len, search_dirs_len;
          int new_len, search_dirs_len;
 
 
          ptr = to_host_dir_spec (&argv[i][2]);
          ptr = to_host_dir_spec (&argv[i][2]);
          new_len = strlen (ptr);
          new_len = strlen (ptr);
          search_dirs_len = strlen (search_dirs);
          search_dirs_len = strlen (search_dirs);
 
 
          search_dirs = xrealloc (search_dirs, search_dirs_len + new_len + 2);
          search_dirs = xrealloc (search_dirs, search_dirs_len + new_len + 2);
          if (search_dirs_len > 0)
          if (search_dirs_len > 0)
            strcat (search_dirs, PATH_SEPARATOR_STR);
            strcat (search_dirs, PATH_SEPARATOR_STR);
          strcat (search_dirs, ptr);
          strcat (search_dirs, ptr);
        }
        }
      else if (strncmp (argv[i], "-D", 2) == 0)
      else if (strncmp (argv[i], "-D", 2) == 0)
        {
        {
          char *ptr;
          char *ptr;
          int new_len, defines_len;
          int new_len, defines_len;
 
 
          ptr = &argv[i][2];
          ptr = &argv[i][2];
          new_len = strlen (ptr);
          new_len = strlen (ptr);
          defines_len = strlen (defines);
          defines_len = strlen (defines);
 
 
          defines = xrealloc (defines, defines_len + new_len + 4);
          defines = xrealloc (defines, defines_len + new_len + 4);
          if (defines_len > 0)
          if (defines_len > 0)
            strcat (defines, ",");
            strcat (defines, ",");
 
 
          strcat (defines, "\"");
          strcat (defines, "\"");
          strcat (defines, ptr);
          strcat (defines, ptr);
          strcat (defines, "\"");
          strcat (defines, "\"");
        }
        }
      else if (strcmp (argv[i], "-v") == 0)
      else if (strcmp (argv[i], "-v") == 0)
        verbose = 1;
        verbose = 1;
      else if (strcmp (argv[i], "-g0") == 0)
      else if (strcmp (argv[i], "-g0") == 0)
        addarg ("/nodebug");
        addarg ("/nodebug");
      else if (strcmp (argv[i], "-O0") == 0)
      else if (strcmp (argv[i], "-O0") == 0)
        addarg ("/noopt");
        addarg ("/noopt");
      else if (strncmp (argv[i], "-g", 2) == 0)
      else if (strncmp (argv[i], "-g", 2) == 0)
        addarg ("/debug");
        addarg ("/debug");
      else if (strcmp (argv[i], "-E") == 0)
      else if (strcmp (argv[i], "-E") == 0)
        addarg ("/preprocess");
        addarg ("/preprocess");
      else if (strcmp (argv[i], "-save-temps") == 0)
      else if (strcmp (argv[i], "-save-temps") == 0)
        save_temps = 1;
        save_temps = 1;
    }
    }
}
}
 
 
/* The main program.  Spawn the VMS DEC C compiler after fixing up the
/* The main program.  Spawn the VMS DEC C compiler after fixing up the
   Unix-like flags and args to be what VMS DEC C wants.  */
   Unix-like flags and args to be what VMS DEC C wants.  */
 
 
typedef struct dsc {unsigned short len, mbz; char *adr; } Descr;
typedef struct dsc {unsigned short len, mbz; char *adr; } Descr;
 
 
int
int
main (int argc, char **argv)
main (int argc, char **argv)
{
{
  int i;
  int i;
  char cwdev [128], *devptr;
  char cwdev [128], *devptr;
  int devlen;
  int devlen;
  char *cwd = getcwd (0, 1024);
  char *cwd = getcwd (0, 1024);
 
 
  devptr = strchr (cwd, ':');
  devptr = strchr (cwd, ':');
  devlen = (devptr - cwd) + 1;
  devlen = (devptr - cwd) + 1;
  strncpy (cwdev, cwd, devlen);
  strncpy (cwdev, cwd, devlen);
  cwdev [devlen] = '\0';
  cwdev [devlen] = '\0';
 
 
  search_dirs = xstrdup (system_search_dirs);
  search_dirs = xstrdup (system_search_dirs);
  defines = xstrdup (default_defines);
  defines = xstrdup (default_defines);
 
 
  addarg ("cc");
  addarg ("cc");
  preprocess_args (&argc , argv);
  preprocess_args (&argc , argv);
  process_args (&argc , argv);
  process_args (&argc , argv);
 
 
  if (strlen (search_dirs) > 0)
  if (strlen (search_dirs) > 0)
    {
    {
      addarg ("/include=(");
      addarg ("/include=(");
      addarg (search_dirs);
      addarg (search_dirs);
      addarg (")");
      addarg (")");
    }
    }
 
 
  if (strlen (defines) > 0)
  if (strlen (defines) > 0)
    {
    {
      addarg ("/define=(");
      addarg ("/define=(");
      addarg (defines);
      addarg (defines);
      addarg (")");
      addarg (")");
    }
    }
 
 
  for (i = 1; i < argc; i++)
  for (i = 1; i < argc; i++)
    {
    {
      int arg_len = strlen (argv[i]);
      int arg_len = strlen (argv[i]);
 
 
      if (strcmp (argv[i], "-o") == 0)
      if (strcmp (argv[i], "-o") == 0)
        i++;
        i++;
      else if (strcmp (argv[i], "-v" ) == 0
      else if (strcmp (argv[i], "-v" ) == 0
               || strcmp (argv[i], "-E") == 0
               || strcmp (argv[i], "-E") == 0
               || strcmp (argv[i], "-c") == 0
               || strcmp (argv[i], "-c") == 0
               || strncmp (argv[i], "-g", 2 ) == 0
               || strncmp (argv[i], "-g", 2 ) == 0
               || strncmp (argv[i], "-O", 2 ) == 0
               || strncmp (argv[i], "-O", 2 ) == 0
               || strcmp (argv[i], "-save-temps") == 0
               || strcmp (argv[i], "-save-temps") == 0
               || (arg_len > 2 && strncmp (argv[i], "-I", 2) == 0)
               || (arg_len > 2 && strncmp (argv[i], "-I", 2) == 0)
               || (arg_len > 2 && strncmp (argv[i], "-D", 2) == 0))
               || (arg_len > 2 && strncmp (argv[i], "-D", 2) == 0))
        ;
        ;
 
 
      /* Unix style file specs and VMS style switches look alike, so assume
      /* Unix style file specs and VMS style switches look alike, so assume
         an arg consisting of one and only one slash, and that being first, is
         an arg consisting of one and only one slash, and that being first, is
         really a switch.  */
         really a switch.  */
      else if ((argv[i][0] == '/') && (strchr (&argv[i][1], '/') == 0))
      else if ((argv[i][0] == '/') && (strchr (&argv[i][1], '/') == 0))
        addarg (argv[i]);
        addarg (argv[i]);
      else
      else
        {
        {
          /* Assume filename arg */
          /* Assume filename arg */
          char buff [256], *ptr;
          char buff [256], *ptr;
 
 
          ptr = to_host_file_spec (argv[i]);
          ptr = to_host_file_spec (argv[i]);
          arg_len = strlen (ptr);
          arg_len = strlen (ptr);
 
 
          if (ptr[0] == '[')
          if (ptr[0] == '[')
            sprintf (buff, "%s%s", cwdev, ptr);
            sprintf (buff, "%s%s", cwdev, ptr);
          else if (strchr (ptr, ':'))
          else if (strchr (ptr, ':'))
            sprintf (buff, "%s", ptr);
            sprintf (buff, "%s", ptr);
          else
          else
            sprintf (buff, "%s%s", cwd, ptr);
            sprintf (buff, "%s%s", cwd, ptr);
 
 
          ptr = xstrdup (buff);
          ptr = xstrdup (buff);
          addarg (ptr);
          addarg (ptr);
        }
        }
    }
    }
 
 
  addarg (NULL);
  addarg (NULL);
 
 
  if (verbose)
  if (verbose)
    {
    {
      int i;
      int i;
 
 
      for (i = 0; i < comp_arg_index; i++)
      for (i = 0; i < comp_arg_index; i++)
        printf ("%s ", comp_args [i]);
        printf ("%s ", comp_args [i]);
 
 
      putchar ('\n');
      putchar ('\n');
    }
    }
 
 
  {
  {
    int i;
    int i;
    int len = 0;
    int len = 0;
 
 
    for (i = 0; comp_args[i]; i++)
    for (i = 0; comp_args[i]; i++)
      len = len + strlen (comp_args[i]) + 1;
      len = len + strlen (comp_args[i]) + 1;
 
 
    {
    {
      char *allargs = (char *) alloca (len + 1);
      char *allargs = (char *) alloca (len + 1);
      Descr cmd;
      Descr cmd;
      int status;
      int status;
      int status1 = 1;
      int status1 = 1;
 
 
      for (i = 0; i < len + 1; i++)
      for (i = 0; i < len + 1; i++)
        allargs [i] = 0;
        allargs [i] = 0;
 
 
      for (i = 0; comp_args [i]; i++)
      for (i = 0; comp_args [i]; i++)
        {
        {
          strcat (allargs, comp_args [i]);
          strcat (allargs, comp_args [i]);
          strcat (allargs, " ");
          strcat (allargs, " ");
        }
        }
 
 
      cmd.adr = allargs;
      cmd.adr = allargs;
      cmd.len = len;
      cmd.len = len;
      cmd.mbz = 0;
      cmd.mbz = 0;
 
 
      i = LIB$SPAWN (&cmd, 0, 0, 0, 0, 0, &status);
      i = LIB$SPAWN (&cmd, 0, 0, 0, 0, 0, &status);
 
 
      if ((i & 1) != 1)
      if ((i & 1) != 1)
        {
        {
          LIB$SIGNAL (i);
          LIB$SIGNAL (i);
          exit (1);
          exit (1);
        }
        }
 
 
      if ((status & 1) == 1 && (status1 & 1) == 1)
      if ((status & 1) == 1 && (status1 & 1) == 1)
        exit (0);
        exit (0);
 
 
      exit (1);
      exit (1);
    }
    }
  }
  }
}
}
 
 
static char new_host_filespec [255];
static char new_host_filespec [255];
static char new_host_dirspec [255];
static char new_host_dirspec [255];
static char filename_buff [256];
static char filename_buff [256];
 
 
static int
static int
translate_unix (char *name, int type ATTRIBUTE_UNUSED)
translate_unix (char *name, int type ATTRIBUTE_UNUSED)
{
{
  strcpy (filename_buff, name);
  strcpy (filename_buff, name);
  return 0;
  return 0;
}
}
 
 
static char *
static char *
to_host_dir_spec (char *dirspec)
to_host_dir_spec (char *dirspec)
{
{
  int len = strlen (dirspec);
  int len = strlen (dirspec);
 
 
  strcpy (new_host_dirspec, dirspec);
  strcpy (new_host_dirspec, dirspec);
 
 
  if (strchr (new_host_dirspec, ']') || strchr (new_host_dirspec, ':'))
  if (strchr (new_host_dirspec, ']') || strchr (new_host_dirspec, ':'))
    return new_host_dirspec;
    return new_host_dirspec;
 
 
  while (len > 1 && new_host_dirspec [len-1] == '/')
  while (len > 1 && new_host_dirspec [len-1] == '/')
    {
    {
      new_host_dirspec [len-1] = 0;
      new_host_dirspec [len-1] = 0;
      len--;
      len--;
    }
    }
 
 
  decc$to_vms (new_host_dirspec, translate_unix, 1, 2);
  decc$to_vms (new_host_dirspec, translate_unix, 1, 2);
  strcpy (new_host_dirspec, filename_buff);
  strcpy (new_host_dirspec, filename_buff);
 
 
  return new_host_dirspec;
  return new_host_dirspec;
 
 
}
}
 
 
static char *
static char *
to_host_file_spec (char *filespec)
to_host_file_spec (char *filespec)
{
{
  strcpy (new_host_filespec, "");
  strcpy (new_host_filespec, "");
  if (strchr (filespec, ']') || strchr (filespec, ':'))
  if (strchr (filespec, ']') || strchr (filespec, ':'))
    strcpy (new_host_filespec, filespec);
    strcpy (new_host_filespec, filespec);
  else
  else
    {
    {
      decc$to_vms (filespec, translate_unix, 1, 1);
      decc$to_vms (filespec, translate_unix, 1, 1);
      strcpy (new_host_filespec, filename_buff);
      strcpy (new_host_filespec, filename_buff);
    }
    }
 
 
  return new_host_filespec;
  return new_host_filespec;
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.