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

📄 stor-layout.c

📁 这是完整的gcc源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
/* C-compiler utilities for types and variables storage layout   Copyright (C) 1987, 1988 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 1, 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, 675 Mass Ave, Cambridge, MA 02139, USA.  */#include "config.h"#include <stdio.h>#include "tree.h"#include "rtl.h"   /* For GET_MODE_SIZE */#define MAX(x,y) ((x) > (y) ? (x) : (y))#define MIN(x,y) ((x) < (y) ? (x) : (y))#define CEIL(x,y) (((x) + (y) - 1) / (y))/* Data type for the expressions representing sizes of data types.   It is the first integer type laid out.   In C, this is int.  */tree sizetype;/* An integer constant with value 0 whose type is sizetype.  */tree size_zero_node;/* An integer constant with value 1 whose type is sizetype.  */tree size_one_node;#define GET_MODE_ALIGNMENT(MODE)   \  MIN (BIGGEST_ALIGNMENT, 	   \       MAX (1, (GET_MODE_UNIT_SIZE (MODE) * BITS_PER_UNIT)))/* Chain of all permanent types we have allocated since last   call to get_permanent_types.  */tree permanent_type_chain;/* Chain of all temporary types we have allocated in this function.  */tree temporary_type_chain;/* When the chains is not null, these point at the last   types on the two chains.  These help us tell whether a type   is already on a chain.  */tree permanent_type_end;tree temporary_type_end;/* Put the newly-made type T   on either permanent_type_chain or temporary_type_chain.   Types that are const or volatile variants of other types   are not put on any chain, since in the gdb symbol segment   we do not make those distinctions.   If T is already on the chain, we do nothing.  */voidchain_type (t)     tree t;{  if (TYPE_MAIN_VARIANT (t) != t)    return;  if (TREE_CHAIN (t) != 0)    return;  if (TREE_PERMANENT (t))    {      /* If T is on the chain at the end, don't chain it to itself!  */      if (t == permanent_type_end)	return;      /* Add T to the end of the chain.  */      if (permanent_type_chain == 0)	permanent_type_chain = t;      else	TREE_CHAIN (permanent_type_end) = t;      permanent_type_end = t;    }  else    {      if (t == temporary_type_end)	return;      if (temporary_type_chain == 0)	temporary_type_chain = t;      else	TREE_CHAIN (temporary_type_end) = t;      temporary_type_end = t;    }}/* Get a chain of all permanent types made since this function   was last called.  */treeget_permanent_types (){  register tree tem = permanent_type_chain;  permanent_type_chain = 0;  permanent_type_end = 0;  return tem;}/* Get a chain of all temporary types made since this function   was last called.  */treeget_temporary_types (){  register tree tem = temporary_type_chain;  temporary_type_chain = 0;  temporary_type_end = 0;  return tem;}/* SAVE_EXPRs for sizes of types and decls, waiting to be expanded.  */static tree pending_sizes;/* Nonzero means cannot safely call expand_expr now,   so put variable sizes onto `pending_sizes' instead.  */int immediate_size_expand;treeget_pending_sizes (){  tree chain = pending_sizes;  pending_sizes = 0;  return chain;}/* Given a size SIZE that isn't constant, return a SAVE_EXPR   to serve as the actual size-expression for a type or decl.  */static treevariable_size (size)     tree size;{  size = save_expr (size);  if (global_bindings_p ())    {      error ("variable-size type declared outside of any function");      return build_int (1);    }  if (immediate_size_expand)    expand_expr (size, 0, VOIDmode, 0);  else    pending_sizes = tree_cons (0, size, pending_sizes);  return size;}/* Return the machine mode to use for an aggregate of SIZE bits.   Note!!!  We only use a non-BLKmode mode if the size matches exactly.   There used to be the idea of using DImode for anything whose   size was less than DImode but more than SImode.  This does not work   because DImode moves cannot be used to store such objects in memory.  */#ifndef MAX_FIXED_MODE_SIZE#define MAX_FIXED_MODE_SIZE GET_MODE_BITSIZE (DImode)#endifstaticenum machine_modeagg_mode (size)     unsigned int size;{  register int units = size / BITS_PER_UNIT;  register enum machine_mode t, val;  if (size % BITS_PER_UNIT != 0)    return BLKmode;  if (size > MAX_FIXED_MODE_SIZE)    return BLKmode;  /* Get the last mode which has this size.  */  val = BLKmode;  for (t = QImode; GET_MODE_CLASS (t) == MODE_INT;       t = (enum machine_mode) ((int) t + 1))    if (GET_MODE_SIZE (t) == units)      val = t;  return val;}/* Round the value SIZE up to the next size of some machine mode.  */intround_size (size)     int size;{  enum machine_mode t;  for (t = QImode; (int) t < (int) BLKmode;       t = (enum machine_mode) ((int) t + 1))    if (GET_MODE_BITSIZE (t) >= size)      return GET_MODE_BITSIZE (t);  abort ();}/* Return an INTEGER_CST with value V and type from `sizetype'.  */treebuild_int (v)     unsigned int v;{  register tree t;  /* Type-size nodes already made for small sizes.  */  static tree size_table[33];  if (v < 33 && size_table[v] != 0)    return size_table[v];  if (v < 33)    {      int temp = allocation_temporary_p ();      /* Make this a permanent node.  */      if (temp)	end_temporary_allocation ();      t = build_int_2 (v, 0);      TREE_TYPE (t) = sizetype;      size_table[v] = t;      if (temp)	resume_temporary_allocation ();    }  else    {      t = build_int_2 (v, 0);      TREE_TYPE (t) = sizetype;    }  return t;}/* Combine operands OP1 and OP2 with arithmetic operation OPC.   OPC is a tree code.  Data type is taken from `sizetype',   If the operands are constant, so is the result.  */treegenop (opc, op1, op2)     enum tree_code opc;     tree op1, op2;{  /* Handle the special case of two integer constants faster.  */  if (TREE_CODE (op1) == INTEGER_CST && TREE_CODE (op2) == INTEGER_CST)    {      /* And some specific cases even faster than that.  */      if (opc == PLUS_EXPR	  && TREE_INT_CST_LOW (op1) == 0	  && TREE_INT_CST_HIGH (op1) == 0)	return op2;      if (opc == MINUS_EXPR	  && TREE_INT_CST_LOW (op2) == 0	  && TREE_INT_CST_HIGH (op2) == 0)	return op1;      if (opc == MULT_EXPR	  && TREE_INT_CST_LOW (op1) == 1	  && TREE_INT_CST_HIGH (op1) == 0)	return op2;      if (opc == CEIL_DIV_EXPR	  && TREE_INT_CST_LOW (op1) == TREE_INT_CST_LOW (op2)	  && TREE_INT_CST_HIGH (op1) == TREE_INT_CST_HIGH (op2))	return size_one_node;      /* Handle general case of two integer constants.  */      return combine (opc, op1, op2);    }  if (op1 == error_mark_node || op2 == error_mark_node)    return error_mark_node;  return fold (build (opc, sizetype, op1, op2));}/* Convert a size which is SIZE when expressed in unit INUNITS   into the units OUTUNITS.  Rounds up if conversion is not exact.   If SIZE is constant, so is the result.  */treeconvert_units (size, inunits, outunits)   tree size;   register int inunits, outunits;{  register tree t;  if (inunits == outunits)    return size;  /* Check for inunits divisible by outunits.     In that case, just multiply by their ratio.  */  if (0 == (inunits % outunits))    return genop (MULT_EXPR, size, build_int (inunits / outunits));  /* The inverse case.  */  if (0 == (outunits % inunits))    {      /* Discard anything in SIZE to round it up to a multiple	 of a number N that divides our current divisor.  */      if (TREE_CODE (size) == MULT_EXPR	  && TREE_CODE (TREE_OPERAND (size, 1)) == INTEGER_CST	  && 0 == (outunits / inunits) % TREE_INT_CST_LOW (TREE_OPERAND (size, 1))	  && TREE_CODE (TREE_OPERAND (size, 0)) == CEIL_DIV_EXPR	  && tree_int_cst_equal (TREE_OPERAND (size, 1),				 TREE_OPERAND (TREE_OPERAND (size, 0), 1)))	size = TREE_OPERAND (TREE_OPERAND (size, 0), 0);      return genop (CEIL_DIV_EXPR, size, build_int (outunits / inunits));    }  /* The general case.  */  t = genop (MULT_EXPR, size,	     build_int (inunits)); /* convert to bits */  return genop (CEIL_DIV_EXPR, t,		build_int (outunits)); /* then to outunits */}/* Set the size, mode and alignment of a ..._DECL node.   TYPE_DECL does need this for C++.  It is up to language-specific   code to intialize the DECL_OFFSET of TYPE_DECL nodes.   Note that LABEL_DECL and CONST_DECL nodes do not need this,   and FUNCTION_DECL nodes have them set up in a special (and simple) way.   Don't call layout_decl for them.   KNOWN_ALIGN is the amount of alignment we can assume this   decl has with no special effort.  It is relevant only for FIELD_DECLs   and depends on the previous fields.   All that matters about KNOWN_ALIGN is which powers of 2 divide it.   If KNOWN_ALIGN is 0, it means, "as much alignment as you like":   the record will be aligned to suit.  */voidlayout_decl (decl, known_align)     tree decl;     unsigned known_align;{  register tree type = TREE_TYPE (decl);  register enum tree_code code = TREE_CODE (decl);  int spec_size = DECL_SIZE_UNIT (decl);  int bitsize;  if (code == CONST_DECL)    return;  if (code != VAR_DECL && code != PARM_DECL && code != RESULT_DECL      && code != FIELD_DECL && code != TYPE_DECL)    abort ();  if (type == error_mark_node)    {      type = void_type_node;      spec_size = 0;    }  if (TYPE_SIZE_UNIT (type) == 0)

⌨️ 快捷键说明

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