OpenCores
URL https://opencores.org/ocsvn/hf-risc/hf-risc/trunk

Subversion Repositories hf-risc

[/] [hf-risc/] [trunk/] [tools/] [riscv-gnu-toolchain-master/] [gcc/] [gcc/] [common/] [config/] [riscv/] [riscv-common.c] - Blame information for rev 13

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 13 serginhofr
/* Common hooks for RISC-V.
2
   Copyright (C) 1989-2014 Free Software Foundation, Inc.
3
 
4
This file is part of GCC.
5
 
6
GCC is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 3, or (at your option)
9
any later version.
10
 
11
GCC is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
GNU General Public License for more details.
15
 
16
You should have received a copy of the GNU General Public License
17
along with GCC; see the file COPYING3.  If not see
18
<http://www.gnu.org/licenses/>.  */
19
 
20
#include "config.h"
21
#include "system.h"
22
#include "coretypes.h"
23
#include "tm.h"
24
#include "common/common-target.h"
25
#include "common/common-target-def.h"
26
#include "opts.h"
27
#include "flags.h"
28
#include "errors.h"
29
 
30
/* Parse a RISC-V ISA string into an option mask.  */
31
 
32
static void
33
riscv_parse_arch_string (const char *isa, int *flags)
34
{
35
  const char *p = isa;
36
 
37
  if (strncmp (p, "RV32", 4) == 0)
38
    *flags |= MASK_32BIT, p += 4;
39
  else if (strncmp (p, "RV64", 4) == 0)
40
    *flags &= ~MASK_32BIT, p += 4;
41
 
42
  if (*p++ != 'I')
43
    {
44
      error ("-march=%s: ISA strings must begin with I, RV32I, or RV64I", isa);
45
      return;
46
    }
47
 
48
  *flags &= ~MASK_MULDIV;
49
  if (*p == 'M')
50
    *flags |= MASK_MULDIV, p++;
51
 
52
  *flags &= ~MASK_ATOMIC;
53
  if (*p == 'A')
54
    *flags |= MASK_ATOMIC, p++;
55
 
56
  *flags |= MASK_SOFT_FLOAT_ABI;
57
  if (*p == 'F')
58
    *flags &= ~MASK_SOFT_FLOAT_ABI, p++;
59
 
60
  if (*p == 'D')
61
    {
62
      p++;
63
      if (!TARGET_HARD_FLOAT)
64
        {
65
          error ("-march=%s: the D extension requires the F extension", isa);
66
          return;
67
        }
68
    }
69
  else if (TARGET_HARD_FLOAT)
70
    {
71
      error ("-march=%s: single-precision-only is not yet supported", isa);
72
      return;
73
    }
74
 
75
  *flags &= ~MASK_RVC;
76
  if (*p == 'C')
77
    *flags |= MASK_RVC, p++;
78
 
79
  /* FIXME: For now we just stop parsing when faced with a
80
     non-standard RISC-V ISA extension, partially becauses of a
81
     problem with the naming scheme. */
82
  if (*p == 'X')
83
    return;
84
 
85
  if (*p)
86
    {
87
      error ("-march=%s: unsupported ISA substring %s", isa, p);
88
      return;
89
    }
90
}
91
 
92
static int
93
riscv_flags_from_arch_string (const char *isa)
94
{
95
  int flags = 0;
96
  riscv_parse_arch_string (isa, &flags);
97
  return flags;
98
}
99
 
100
/* Implement TARGET_HANDLE_OPTION.  */
101
 
102
static bool
103
riscv_handle_option (struct gcc_options *opts,
104
                     struct gcc_options *opts_set ATTRIBUTE_UNUSED,
105
                     const struct cl_decoded_option *decoded,
106
                     location_t loc ATTRIBUTE_UNUSED)
107
{
108
  switch (decoded->opt_index)
109
    {
110
    case OPT_march_:
111
      riscv_parse_arch_string (decoded->arg, &opts->x_target_flags);
112
      return true;
113
 
114
    default:
115
      return true;
116
    }
117
}
118
 
119
/* Implement TARGET_OPTION_OPTIMIZATION_TABLE.  */
120
static const struct default_options riscv_option_optimization_table[] =
121
  {
122
    { OPT_LEVELS_1_PLUS, OPT_fsection_anchors, NULL, 1 },
123
    { OPT_LEVELS_1_PLUS, OPT_fomit_frame_pointer, NULL, 1 },
124
    { OPT_LEVELS_NONE, 0, NULL, 0 }
125
  };
126
 
127
#undef TARGET_OPTION_OPTIMIZATION_TABLE
128
#define TARGET_OPTION_OPTIMIZATION_TABLE riscv_option_optimization_table
129
 
130
#undef TARGET_DEFAULT_TARGET_FLAGS
131
#define TARGET_DEFAULT_TARGET_FLAGS                             \
132
  (TARGET_DEFAULT                                               \
133
   | riscv_flags_from_arch_string (RISCV_ARCH_STRING_DEFAULT)   \
134
   | (TARGET_64BIT_DEFAULT ? 0 : MASK_32BIT))
135
 
136
#undef TARGET_HANDLE_OPTION
137
#define TARGET_HANDLE_OPTION riscv_handle_option
138
 
139
struct gcc_targetm_common targetm_common = TARGETM_COMMON_INITIALIZER;

powered by: WebSVN 2.1.0

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