OSDN Git Service

gen-all: Be smarter about what diffs to generate.
[pf3gnuchains/pf3gnuchains4x.git] / cgen / sim-arch.scm
1 ; Simulator generator support routines.
2 ; Copyright (C) 2000, 2009 Red Hat, Inc.
3 ; This file is part of CGEN.
4
5 ; Utilities of cgen-arch.h.
6
7 ; Return C macro definitions of the various supported cpus.
8
9 (define (/gen-cpuall-defines)
10   "" ; nothing yet
11 )
12
13 ; Return C declarations of misc. support stuff.
14 ; ??? Modes are now defined in sim/common/cgen-types.h but we will need
15 ; target specific modes.
16
17 (define (/gen-support-decls)
18   (string-append
19 ;   (gen-enum-decl 'mode_type "mode types"
20 ;                 "MODE_"
21 ;                 ; Aliases are not distinct from their real mode so ignore
22 ;                 ; them here.
23 ;                 (append (map list (map obj:name
24 ;                                        (mode-list-non-alias-values)))
25 ;                         '((max))))
26 ;   "#define MAX_MODES ((int) MODE_MAX)\n\n"
27    )
28 )
29 \f
30 ; Utilities of cgen-cpuall.h.
31
32 ; Subroutine of /gen-cpuall-includes.
33
34 (define (/gen-cpu-header cpu prefix)
35   (string-append "#include \"" prefix (cpu-file-transform cpu) ".h\"\n")
36 )
37
38 ; Return C code to include all the relevant headers for each cpu family,
39 ; conditioned on ifdef WANT_CPU_@CPU@.
40
41 (define (/gen-cpuall-includes)
42   (string-list
43    "/* Include files for each cpu family.  */\n\n"
44    (string-list-map
45     (lambda (cpu)
46       (let* ((cpu-name (gen-sym cpu))
47              (CPU-NAME (string-upcase cpu-name)))
48         (string-list "#ifdef WANT_CPU_" CPU-NAME "\n"
49                      (/gen-cpu-header cpu "eng")
50                      (/gen-cpu-header cpu "cpu")
51                      (/gen-cpu-header cpu "decode")
52                      "#endif\n\n")))
53     (current-cpu-list))
54    )
55 )
56
57 ; Subroutine of /gen-cpuall-decls to generate cpu-specific structure entries.
58 ; The result is "struct <cpu>_<type-name> <member-name>;".
59 ; INDENT is the amount to indent by.
60 ; CPU is the cpu object.
61
62 (define (/gen-cpu-specific-decl indent cpu type-name member-name)
63   (let* ((cpu-name (gen-sym cpu))
64          (CPU-NAME (string-upcase cpu-name)))
65     (string-append
66      "#ifdef WANT_CPU_" CPU-NAME "\n"
67      (spaces indent)
68      "struct " cpu-name "_" type-name " " member-name ";\n"
69      "#endif\n"))
70 )
71
72 ; Return C declarations of cpu-specific structs.
73 ; These are defined here to achieve a simple and moderately type-safe
74 ; inheritance.  In the non-cpu-specific files, these structs consist of
75 ; just the baseclass.  In cpu-specific files, the baseclass is augmented
76 ; with the cpu-specific data.
77
78 (define (/gen-cpuall-decls)
79   (string-list
80    (gen-argbuf-type #f)
81    (gen-scache-type #f)
82    )
83 )
84 \f
85 ; Top level generators for non-cpu-specific files.
86
87 ; Generate arch.h
88 ; This file defines non cpu family specific data about the architecture
89 ; and also data structures that combine all variants (e.g. cpu struct).
90 ; It is intended to be included before sim-basics.h and sim-base.h.
91
92 (define (cgen-arch.h)
93   (logit 1 "Generating " (current-arch-name) "'s arch.h ...\n")
94
95   (string-write
96    (gen-c-copyright "Simulator header for @arch@."
97                   CURRENT-COPYRIGHT CURRENT-PACKAGE)
98    "#ifndef @ARCH@_ARCH_H\n"
99    "#define @ARCH@_ARCH_H\n"
100    "\n"
101    "#define TARGET_BIG_ENDIAN 1\n\n" ; FIXME
102    ;(gen-mem-macros)
103    ;"/* FIXME: split into 32/64 parts */\n"
104    ;"#define WI SI\n"
105    ;"#define UWI USI\n"
106    ;"#define AI USI\n\n"
107    /gen-cpuall-defines
108    /gen-support-decls
109    /gen-arch-model-decls
110    "#endif /* @ARCH@_ARCH_H */\n"
111    )
112 )
113
114 ; Generate arch.c
115 ; This file defines non cpu family specific data about the architecture.
116
117 (define (cgen-arch.c)
118   (logit 1 "Generating " (current-arch-name) "'s arch.c ...\n")
119
120   (string-write
121    (gen-c-copyright "Simulator support for @arch@."
122                   CURRENT-COPYRIGHT CURRENT-PACKAGE)
123    "\
124 #include \"sim-main.h\"
125 #include \"bfd.h\"
126
127 "
128    /gen-mach-data
129    )
130 )
131
132 ; Generate cpuall.h
133 ; This file pulls together all of the cpu variants .h's.
134 ; It is intended to be included after sim-base.h/cgen-sim.h.
135
136 (define (cgen-cpuall.h)
137   (logit 1 "Generating " (current-arch-name) "'s cpuall.h ...\n")
138
139   (string-write
140    (gen-c-copyright "Simulator CPU header for @arch@."
141                   CURRENT-COPYRIGHT CURRENT-PACKAGE)
142    "#ifndef @ARCH@_CPUALL_H\n"
143    "#define @ARCH@_CPUALL_H\n"
144    "\n"
145    /gen-cpuall-includes
146    /gen-mach-decls
147    /gen-cpuall-decls
148    "#endif /* @ARCH@_CPUALL_H */\n"
149    )
150 )
151
152 ; Generate ops.c
153 ; No longer used.
154
155 (define (cgen-ops.c)
156   (logit 1 "Generating " (current-arch-name) "'s ops.c ...\n")
157
158   (string-write
159    (gen-c-copyright "Simulator operational support for @arch@."
160                   CURRENT-COPYRIGHT CURRENT-PACKAGE)
161    "\
162 #define MEMOPS_DEFINE_INLINE
163
164 #include \"config.h\"
165 #include <signal.h>
166 #include \"ansidecl.h\"
167 #include \"bfd.h\"
168 #include \"tconfig.h\"
169 #include \"cgen-sim.h\"
170 #include \"memops.h\"
171
172 /* FIXME: wip */
173 int pow2masks[] = {
174   0, 0, 1, -1, 3, -1, -1, -1, 7, -1, -1, -1, -1, -1, -1, -1, 15
175 };
176
177 "
178    gen-mode-defs
179    )
180 )