OSDN Git Service

* sim.scm (/operand-number-elaboration-written?): New variable.
[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 (lambda (cpu)
45                       (let* ((cpu-name (gen-sym cpu))
46                              (CPU-NAME (string-upcase cpu-name)))
47                         (string-list "#ifdef WANT_CPU_" CPU-NAME "\n"
48                                      (/gen-cpu-header cpu "eng")
49                                      "#include \"cgen-engine.h\"\n"
50                                      (/gen-cpu-header cpu "cpu")
51                                      ; FIXME: Shorten "decode" to "dec".
52                                      (/gen-cpu-header cpu "decode")
53                                      "#endif\n\n")))
54                     (current-cpu-list))
55    )
56 )
57
58 ; Subroutine of /gen-cpuall-decls to generate cpu-specific structure entries.
59 ; The result is "struct <cpu>_<type-name> <member-name>;".
60 ; INDENT is the amount to indent by.
61 ; CPU is the cpu object.
62
63 (define (/gen-cpu-specific-decl indent cpu type-name member-name)
64   (let* ((cpu-name (gen-sym cpu))
65          (CPU-NAME (string-upcase cpu-name)))
66     (string-append
67      "#ifdef WANT_CPU_" CPU-NAME "\n"
68      (spaces indent)
69      "struct " cpu-name "_" type-name " " member-name ";\n"
70      "#endif\n"))
71 )
72
73 ; Return C declarations of cpu-specific structs.
74 ; These are defined here to achieve a simple and moderately type-safe
75 ; inheritance.  In the non-cpu-specific files, these structs consist of
76 ; just the baseclass.  In cpu-specific files, the baseclass is augmented
77 ; with the cpu-specific data.
78
79 (define (/gen-cpuall-decls)
80   (string-list
81    (gen-argbuf-type #f)
82    (gen-scache-type #f)
83    )
84 )
85 \f
86 ; Top level generators for non-cpu-specific files.
87
88 ; Generate arch.h
89 ; This file defines non cpu family specific data about the architecture
90 ; and also data structures that combine all variants (e.g. cpu struct).
91 ; It is intended to be included before sim-basics.h and sim-base.h.
92
93 (define (cgen-arch.h)
94   (logit 1 "Generating " (current-arch-name) "'s arch.h ...\n")
95
96   (string-write
97    (gen-c-copyright "Simulator header for @arch@."
98                   CURRENT-COPYRIGHT CURRENT-PACKAGE)
99    "#ifndef @ARCH@_ARCH_H\n"
100    "#define @ARCH@_ARCH_H\n"
101    "\n"
102    "#define TARGET_BIG_ENDIAN 1\n\n" ; FIXME
103    ;(gen-mem-macros)
104    ;"/* FIXME: split into 32/64 parts */\n"
105    ;"#define WI SI\n"
106    ;"#define UWI USI\n"
107    ;"#define AI USI\n\n"
108    /gen-cpuall-defines
109    /gen-support-decls
110    /gen-arch-model-decls
111    "#endif /* @ARCH@_ARCH_H */\n"
112    )
113 )
114
115 ; Generate arch.c
116 ; This file defines non cpu family specific data about the architecture.
117
118 (define (cgen-arch.c)
119   (logit 1 "Generating " (current-arch-name) "'s arch.c ...\n")
120
121   (string-write
122    (gen-c-copyright "Simulator support for @arch@."
123                   CURRENT-COPYRIGHT CURRENT-PACKAGE)
124    "\
125 #include \"sim-main.h\"
126 #include \"bfd.h\"
127
128 "
129    /gen-mach-data
130    )
131 )
132
133 ; Generate cpuall.h
134 ; This file pulls together all of the cpu variants .h's.
135 ; It is intended to be included after sim-base.h/cgen-sim.h.
136
137 (define (cgen-cpuall.h)
138   (logit 1 "Generating " (current-arch-name) "'s cpuall.h ...\n")
139
140   (string-write
141    (gen-c-copyright "Simulator CPU header for @arch@."
142                   CURRENT-COPYRIGHT CURRENT-PACKAGE)
143    "#ifndef @ARCH@_CPUALL_H\n"
144    "#define @ARCH@_CPUALL_H\n"
145    "\n"
146    /gen-cpuall-includes
147    /gen-mach-decls
148    /gen-cpuall-decls
149    "#endif /* @ARCH@_CPUALL_H */\n"
150    )
151 )
152
153 ; Generate ops.c
154 ; No longer used.
155
156 (define (cgen-ops.c)
157   (logit 1 "Generating " (current-arch-name) "'s ops.c ...\n")
158
159   (string-write
160    (gen-c-copyright "Simulator operational support for @arch@."
161                   CURRENT-COPYRIGHT CURRENT-PACKAGE)
162    "\
163 #define MEMOPS_DEFINE_INLINE
164
165 #include \"config.h\"
166 #include <signal.h>
167 #include \"ansidecl.h\"
168 #include \"bfd.h\"
169 #include \"tconfig.h\"
170 #include \"cgen-sim.h\"
171 #include \"memops.h\"
172
173 /* FIXME: wip */
174 int pow2masks[] = {
175   0, 0, 1, -1, 3, -1, -1, -1, 7, -1, -1, -1, -1, -1, -1, -1, 15
176 };
177
178 "
179    gen-mode-defs
180    )
181 )