summaryrefslogtreecommitdiff
path: root/gcc/config/m32c/m32c-pragma.c
blob: 66278f165afca9be7d152c3399ed476d09b19e00 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/* M32C Pragma support
   Copyright (C) 2004-2016 Free Software Foundation, Inc.
   Contributed by Red Hat, Inc.

   This file is part of GCC.

   GCC is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3, or (at your option)
   any later version.

   GCC is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with GCC; see the file COPYING3.  If not see
   <http://www.gnu.org/licenses/>.  */

#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "tm.h"
#include "c-family/c-common.h"
#include "c-family/c-pragma.h"
#include "m32c-protos.h"

/* Implements the "GCC memregs" pragma.  This pragma takes only an
   integer, and is semantically identical to the -memregs= command
   line option.  The only catch is, the programmer should only use
   this pragma at the beginning of the file (preferably, in some
   project-wide header) to avoid ABI changes related to changing the
   list of available "registers".  */
static void
m32c_pragma_memregs (cpp_reader * reader ATTRIBUTE_UNUSED)
{
  /* on off */
  tree val;
  enum cpp_ttype type;
  HOST_WIDE_INT i;

  type = pragma_lex (&val);
  if (type == CPP_NUMBER)
    {
      if (tree_fits_uhwi_p (val))
	{
	  i = tree_to_uhwi (val);

	  type = pragma_lex (&val);
	  if (type != CPP_EOF)
	    warning (0, "junk at end of #pragma GCC memregs [0..16]");

	  if (0 <= i && i <= 16)
	    {
	      if (!ok_to_change_target_memregs)
		{
		  warning (0,
			   "#pragma GCC memregs must precede any function decls");
		  return;
		}
	      target_memregs = i;
	      m32c_conditional_register_usage ();
	    }
	  else
	    {
	      warning (0, "#pragma GCC memregs takes a number [0..16]");
	    }

	  return;
	}
    }

  error ("#pragma GCC memregs takes a number [0..16]");
}

/* Implements the "pragma ADDRESS" pragma.  This pragma takes a
   variable name and an address, and arranges for that variable to be
   "at" that address.  The variable is also made volatile.  */
static void
m32c_pragma_address (cpp_reader * reader ATTRIBUTE_UNUSED)
{
  /* on off */
  tree var, addr;
  enum cpp_ttype type;

  type = pragma_lex (&var);
  if (type == CPP_NAME)
    {
      type = pragma_lex (&addr);
      if (type == CPP_NUMBER)
	{
	  if (var != error_mark_node)
	    {
	      unsigned uaddr = tree_to_uhwi (addr);
	      m32c_note_pragma_address (IDENTIFIER_POINTER (var), uaddr);
	    }

	  type = pragma_lex (&var);
	  if (type != CPP_EOF)
	    {
	      error ("junk at end of #pragma ADDRESS");
	    }
	  return;
	}
    }
  error ("malformed #pragma ADDRESS variable address");
}

/* Implements REGISTER_TARGET_PRAGMAS.  */
void
m32c_register_pragmas (void)
{
  c_register_pragma ("GCC", "memregs", m32c_pragma_memregs);
  c_register_pragma (NULL, "ADDRESS", m32c_pragma_address);
  c_register_pragma (NULL, "address", m32c_pragma_address);

  /* R8C and M16C have 16-bit pointers in a 20-bit address zpace.
     M32C has 24-bit pointers in a 24-bit address space, so does not
     need far pointers, but we accept the qualifier anyway, as a
     no-op.  */
  if (TARGET_A16)
    c_register_addr_space ("__far", ADDR_SPACE_FAR);
  else
    c_register_addr_space ("__far", ADDR_SPACE_GENERIC);
}