aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.8/gcc/config/sh/sh-c.c
blob: 4f3a41a46e74ea63a5766bb50de90d64105ee2d7 (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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/* Pragma handling for GCC for Renesas / SuperH SH.
   Copyright (C) 1993-2013 Free Software Foundation, Inc.
   Contributed by Joern Rennecke <joern.rennecke@st.com>.

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 "tree.h"
#include "tm_p.h"
#include "cpplib.h"
#include "c-family/c-common.h"
#include "target.h"

/* Handle machine specific pragmas to be semi-compatible with Renesas
   compiler.  */

/* Add ATTR to the attributes of the current function.  If there is no
   such function, save it to be added to the attributes of the next
   function.  */
static void
sh_add_function_attribute (const char *attr)
{
  tree id = get_identifier (attr);

  if (current_function_decl)
    decl_attributes (&current_function_decl,
		     tree_cons (id, NULL_TREE, NULL_TREE), 0);
  else
    {
      *sh_deferred_function_attributes_tail
	= tree_cons (id, NULL_TREE, *sh_deferred_function_attributes_tail);
      sh_deferred_function_attributes_tail
	= &TREE_CHAIN (*sh_deferred_function_attributes_tail);
    }
}

void
sh_pr_interrupt (struct cpp_reader *pfile ATTRIBUTE_UNUSED)
{
  sh_add_function_attribute ("interrupt_handler");
}

void
sh_pr_trapa (struct cpp_reader *pfile ATTRIBUTE_UNUSED)
{
  sh_add_function_attribute ("trapa_handler");
}

void
sh_pr_nosave_low_regs (struct cpp_reader *pfile ATTRIBUTE_UNUSED)
{
  sh_add_function_attribute ("nosave_low_regs");
}

#define builtin_define(TXT) cpp_define (pfile, TXT)
#define builtin_assert(TXT) cpp_assert (pfile, TXT)

/* Implement the TARGET_CPU_CPP_BUILTINS macro  */
void
sh_cpu_cpp_builtins (cpp_reader* pfile)
{
  builtin_define ("__sh__");
  builtin_assert ("cpu=sh");
  builtin_assert ("machine=sh");
  switch ((int) sh_cpu)
    {
    case PROCESSOR_SH1:
      builtin_define ("__sh1__");
      builtin_define ("__SH1__");
      break;
    case PROCESSOR_SH2:
      builtin_define ("__sh2__");
      builtin_define ("__SH2__");
      break;
    case PROCESSOR_SH2E:
      builtin_define ("__SH2E__");
      break;
    case PROCESSOR_SH2A:
      builtin_define ("__SH2A__");
      if (TARGET_SH2A_DOUBLE)
	builtin_define (TARGET_FPU_SINGLE
			? "__SH2A_SINGLE__" : "__SH2A_DOUBLE__");
      else
	builtin_define (TARGET_FPU_ANY
			? "__SH2A_SINGLE_ONLY__" : "__SH2A_NOFPU__");
      break;
    case PROCESSOR_SH3:
      builtin_define ("__sh3__");
      builtin_define ("__SH3__");
      if (TARGET_HARD_SH4)
	builtin_define ("__SH4_NOFPU__");
      break;
    case PROCESSOR_SH3E:
      builtin_define (TARGET_HARD_SH4 ? "__SH4_SINGLE_ONLY__" : "__SH3E__");
      break;
    case PROCESSOR_SH4:
      builtin_define (TARGET_FPU_SINGLE ? "__SH4_SINGLE__" : "__SH4__");
      break;
    case PROCESSOR_SH4A: \
      builtin_define ("__SH4A__");
      builtin_define (TARGET_SH4
		      ? (TARGET_FPU_SINGLE ? "__SH4_SINGLE__" : "__SH4__")
		      : TARGET_FPU_ANY ? "__SH4_SINGLE_ONLY__"
		      : "__SH4_NOFPU__");
      break;
    case PROCESSOR_SH5:
      {
	builtin_define_with_value ("__SH5__",
				   TARGET_SHMEDIA64 ? "64" : "32", 0);
	builtin_define_with_value ("__SHMEDIA__",
				   TARGET_SHMEDIA ? "1" : "0", 0);
	if (! TARGET_FPU_DOUBLE)
	  builtin_define ("__SH4_NOFPU__");
      }
    }
  if (TARGET_FPU_ANY)
    builtin_define ("__SH_FPU_ANY__");
  if (TARGET_FPU_DOUBLE)
    builtin_define ("__SH_FPU_DOUBLE__");
  if (TARGET_HITACHI)
    builtin_define ("__HITACHI__");
  if (TARGET_FMOVD)
    builtin_define ("__FMOVD_ENABLED__");
  builtin_define (TARGET_LITTLE_ENDIAN
		  ? "__LITTLE_ENDIAN__" : "__BIG_ENDIAN__");

  cpp_define_formatted (pfile, "__SH_ATOMIC_MODEL_%s__",
			selected_atomic_model ().cdef_name);
}