⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 grant.c

📁 gcc-2.95.3 Linux下最常用的C编译器
💻 C
📖 第 1 页 / 共 5 页
字号:
/* Implement grant-file output & seize-file input for CHILL.   Copyright (C) 1992, 93, 94, 95, 1996, 1998 Free Software Foundation, Inc.This file is part of GNU CC.GNU CC is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU CC is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU CC; see the file COPYING.  If not, write tothe Free Software Foundation, 59 Temple Place - Suite 330,Boston, MA 02111-1307, USA.  */#include "config.h"#include "system.h"#include "tree.h"#include "ch-tree.h"#include "lex.h"#include "flags.h"#include "actions.h"#include "input.h"#include "rtl.h"#include "tasking.h"#include "toplev.h"#include "output.h"#define APPEND(X,Y) X = append (X, Y)#define PREPEND(X,Y) X = prepend (X, Y);#define FREE(x) strfree (x)#define ALLOCAMOUNT	10000/* may be we can handle this in a more exciting way,   but this also should work for the moment */#define MAYBE_NEWLINE(X)                       \do                                             \{                                              \  if (X->len && X->str[X->len - 1] != '\n')    \    APPEND (X, ";\n");                         \} while (0)extern tree process_type;extern char *asm_file_name;extern char *dump_base_name;/* forward declarations *//* variable indicates compilation at module level */int chill_at_module_level = 0;/* mark that a SPEC MODULE was generated */static int spec_module_generated = 0;/* define version strings */extern char *gnuchill_version;extern char *version_string;/* define a faster string handling */typedef struct{  char	*str;  int		len;  int		allocated;} MYSTRING;/* structure used for handling multiple grant files */char	*grant_file_name;MYSTRING	*gstring = NULL;MYSTRING        *selective_gstring = NULL;static MYSTRING *decode_decl                PROTO((tree));static MYSTRING *decode_constant            PROTO((tree));static void      grant_one_decl             PROTO((tree));static MYSTRING *get_type                   PROTO((tree));static MYSTRING *decode_mode                PROTO((tree));static MYSTRING *decode_prefix_rename       PROTO((tree));static MYSTRING *decode_constant_selective  PROTO((tree, tree));static MYSTRING *decode_mode_selective      PROTO((tree, tree));static MYSTRING *get_type_selective         PROTO((tree, tree));static MYSTRING *decode_decl_selective      PROTO((tree, tree));/* list of the VAR_DECLs of the module initializer entries */tree      module_init_list = NULL_TREE;/* handle different USE_SEIZE_FILE's in case of selective granting */typedef struct SEIZEFILELIST{  struct SEIZEFILELIST *next;  tree filename;  MYSTRING *seizes;} seizefile_list;static seizefile_list *selective_seizes = 0;static MYSTRING *newstring (str)    char	*str;{    MYSTRING	*tmp = (MYSTRING *) xmalloc (sizeof (MYSTRING));    unsigned	len = strlen (str);        tmp->allocated = len + ALLOCAMOUNT;    tmp->str = xmalloc ((unsigned)tmp->allocated);    strcpy (tmp->str, str);    tmp->len = len;    return (tmp);}static voidstrfree (str)    MYSTRING	*str;{    free (str->str);    free (str);}static MYSTRING *append (inout, in)    MYSTRING	*inout;    char	*in;{    int	inlen = strlen (in);    int amount = ALLOCAMOUNT;    if (inlen >= amount)      amount += inlen;    if ((inout->len + inlen) >= inout->allocated)	inout->str = xrealloc (inout->str, inout->allocated += amount);    strcpy (inout->str + inout->len, in);    inout->len += inlen;    return (inout);}static MYSTRING *prepend (inout, in)    MYSTRING	*inout;    char	*in;{  MYSTRING *res = inout;  if (strlen (in))    {      res = newstring (in);      res = APPEND (res, inout->str);      FREE (inout);    }  return res;}voidgrant_use_seizefile (seize_filename)     char *seize_filename;{  APPEND (gstring, "<> USE_SEIZE_FILE \"");  APPEND (gstring, seize_filename);  APPEND (gstring, "\" <>\n");}static MYSTRING *decode_layout (layout)    tree layout;{  tree temp;  tree stepsize = NULL_TREE;  int  was_step = 0;  MYSTRING *result = newstring ("");  MYSTRING *work;  if (layout == integer_zero_node) /* NOPACK */    {      APPEND (result, " NOPACK");      return result;    }  if (layout == integer_one_node) /* PACK */    {      APPEND (result, " PACK");      return result;    }  APPEND (result, " ");  temp = layout;  if (TREE_PURPOSE (temp) == NULL_TREE)    {      APPEND (result, "STEP(");      was_step = 1;      temp = TREE_VALUE (temp);      stepsize = TREE_VALUE (temp);    }  APPEND (result, "POS(");  /* Get the starting word */  temp = TREE_PURPOSE (temp);  work = decode_constant (TREE_PURPOSE (temp));  APPEND (result, work->str);  FREE (work);  temp = TREE_VALUE (temp);  if (temp != NULL_TREE)    {      /* Get the starting bit */      APPEND (result, ", ");      work = decode_constant (TREE_PURPOSE (temp));      APPEND (result, work->str);      FREE (work);      temp = TREE_VALUE (temp);      if (temp != NULL_TREE)	{	  /* Get the length or the ending bit */	  tree what = TREE_PURPOSE (temp);	  if (what == integer_zero_node) /* length */	    {	      APPEND (result, ", ");	    }	  else	    {	      APPEND (result, ":");	    }	  work = decode_constant (TREE_VALUE (temp));	  APPEND (result, work->str);	  FREE (work);	}    }  APPEND (result, ")");  if (was_step)    {      if (stepsize != NULL_TREE)	{	  APPEND (result, ", ");	  work = decode_constant (stepsize);	  APPEND (result, work->str);	  FREE (work);	}      APPEND (result, ")");    }  return result;}static MYSTRING *grant_array_type (type)     tree type;{  MYSTRING	*result = newstring ("");  MYSTRING	*mode_string;  tree           layout;  int            varying = 0;  if (chill_varying_type_p (type))    {      varying = 1;      type = CH_VARYING_ARRAY_TYPE (type);    }  if (CH_STRING_TYPE_P (type))    {      tree fields = TYPE_DOMAIN (type);      tree maxval = TYPE_MAX_VALUE (fields);      if (TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)	APPEND (result, "CHARS (");      else	APPEND (result, "BOOLS (");      if (TREE_CODE (maxval) == INTEGER_CST)	{	  char	wrk[20];	  sprintf (wrk, HOST_WIDE_INT_PRINT_DEC,		   TREE_INT_CST_LOW (maxval) + 1);	  APPEND (result, wrk);	}      else if (TREE_CODE (maxval) == MINUS_EXPR	       && TREE_OPERAND (maxval, 1) == integer_one_node)	{	  mode_string = decode_constant (TREE_OPERAND (maxval, 0));	  APPEND (result, mode_string->str);	  FREE (mode_string);	}      else	{	  mode_string = decode_constant (maxval);	  APPEND (result, mode_string->str);	  FREE (mode_string);	  APPEND (result, "+1");	}      APPEND (result, ")");      if (varying)	APPEND (result, " VARYING");      return result;    }  APPEND (result, "ARRAY (");  if (TREE_CODE (TYPE_DOMAIN (type)) == INTEGER_TYPE     && TREE_TYPE (TYPE_DOMAIN (type)) == ridpointers[(int) RID_RANGE])    {      mode_string = decode_constant (TYPE_MIN_VALUE (TYPE_DOMAIN (type)));      APPEND (result, mode_string->str);      FREE (mode_string);            APPEND (result, ":");      mode_string = decode_constant (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));      APPEND (result, mode_string->str);      FREE (mode_string);    }  else    {      mode_string = decode_mode (TYPE_DOMAIN (type));      APPEND (result, mode_string->str);      FREE (mode_string);    }  APPEND (result, ") ");  if (varying)    APPEND (result, "VARYING ");  mode_string = get_type (TREE_TYPE (type));  APPEND (result, mode_string->str);  FREE (mode_string);  layout = TYPE_ATTRIBUTES (type);  if (layout != NULL_TREE)    {      mode_string = decode_layout (layout);      APPEND (result, mode_string->str);      FREE (mode_string);    }      return result;}static MYSTRING *grant_array_type_selective (type, all_decls)     tree type;     tree all_decls;{  MYSTRING	*result = newstring ("");  MYSTRING	*mode_string;  int            varying = 0;  if (chill_varying_type_p (type))    {      varying = 1;      type = CH_VARYING_ARRAY_TYPE (type);    }  if (CH_STRING_TYPE_P (type))    {      tree fields = TYPE_DOMAIN (type);      tree maxval = TYPE_MAX_VALUE (fields);      if (TREE_CODE (maxval) != INTEGER_CST)	{	  if (TREE_CODE (maxval) == MINUS_EXPR	      && TREE_OPERAND (maxval, 1) == integer_one_node)	    {	      mode_string = decode_constant_selective (TREE_OPERAND (maxval, 0), all_decls);	      if (mode_string->len)		APPEND (result, mode_string->str);	      FREE (mode_string);	    }	  else	    {	      mode_string = decode_constant_selective (maxval, all_decls);	      if (mode_string->len)		APPEND (result, mode_string->str);	      FREE (mode_string);	    }	}      return result;    }  if (TREE_CODE (TYPE_DOMAIN (type)) == INTEGER_TYPE     && TREE_TYPE (TYPE_DOMAIN (type)) == ridpointers[(int) RID_RANGE])    {      mode_string = decode_constant_selective (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), all_decls);      if (mode_string->len)	APPEND (result, mode_string->str);      FREE (mode_string);            mode_string = decode_constant_selective (TYPE_MAX_VALUE (TYPE_DOMAIN (type)), all_decls);      if (mode_string->len)	{	  MAYBE_NEWLINE (result);	  APPEND (result, mode_string->str);	}      FREE (mode_string);    }  else    {      mode_string = decode_mode_selective (TYPE_DOMAIN (type), all_decls);      if (mode_string->len)	APPEND (result, mode_string->str);      FREE (mode_string);    }  mode_string = get_type_selective (TREE_TYPE (type),  all_decls);  if (mode_string->len)    {      MAYBE_NEWLINE (result);      APPEND (result, mode_string->str);    }  FREE (mode_string);  return result;}static MYSTRING *get_tag_value (val)    tree	val;{  MYSTRING	*result;      if (TREE_CODE (val) == CONST_DECL && DECL_NAME (val))    {      result = newstring (IDENTIFIER_POINTER (DECL_NAME (val)));    }  else if (TREE_CODE (val) == CONST_DECL)    {      /* it's a synonym -- get the value */      result = decode_constant (DECL_INITIAL (val));    }  else    {      result = decode_constant (val);    }  return (result);}static MYSTRING *get_tag_value_selective (val, all_decls)    tree	val;    tree        all_decls;{  MYSTRING	*result;      if (TREE_CODE (val) == CONST_DECL && DECL_NAME (val))      result = newstring ("");  else if (TREE_CODE (val) == CONST_DECL)    {      /* it's a synonym -- get the value */      result = decode_constant_selective (DECL_INITIAL (val), all_decls);    }  else    {      result = decode_constant_selective (val, all_decls);    }  return (result);}static MYSTRING *print_enumeral (type)     tree type;{  MYSTRING	*result = newstring ("");  tree	fields;#if 0  if (TYPE_LANG_SPECIFIC (type) == NULL)#endif    {            APPEND (result, "SET (");      for (fields = TYPE_VALUES (type);	   fields != NULL_TREE;	   fields = TREE_CHAIN (fields))	{	  if (TREE_PURPOSE (fields) == NULL_TREE)	    APPEND (result, "*");	  else	    {	      tree decl = TREE_VALUE (fields);	      APPEND (result, IDENTIFIER_POINTER (TREE_PURPOSE (fields)));	      if (TREE_CODE (decl) == CONST_DECL && DECL_INITIAL (decl))		{		  MYSTRING *val_string = decode_constant (DECL_INITIAL (decl));		  APPEND (result, " = ");		  APPEND (result, val_string->str);		  FREE (val_string);		}	    }	  if (TREE_CHAIN (fields) != NULL_TREE)	    APPEND (result, ",\n     ");	}      APPEND (result, ")");    }  return result;}static MYSTRING *print_enumeral_selective (type, all_decls)     tree type;     tree all_decls;{  MYSTRING	*result = newstring ("");  tree	fields;  for (fields = TYPE_VALUES (type);       fields != NULL_TREE;       fields = TREE_CHAIN (fields))    {      if (TREE_PURPOSE (fields) != NULL_TREE)	{	  tree decl = TREE_VALUE (fields);	  if (TREE_CODE (decl) == CONST_DECL && DECL_INITIAL (decl))	    {	      MYSTRING *val_string = decode_constant_selective (DECL_INITIAL (decl), all_decls);	      if (val_string->len)		APPEND (result, val_string->str);	      FREE (val_string);	    }	}    }  return result;}static MYSTRING *print_integer_type (type)     tree type;{  MYSTRING *result = newstring ("");  MYSTRING *mode_string;  char     *name_ptr;  tree	    base_type;  if (TREE_TYPE (type))    {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -