OSDN Git Service

Hand patch: update to github/binutils.
[pf3gnuchains/pf3gnuchains4x.git] / cgen / sid-decode.scm
index adb3157..999f47c 100644 (file)
@@ -1,5 +1,5 @@
 ; Decoder generation.
-; Copyright (C) 2000 Red Hat, Inc.
+; Copyright (C) 2000, 2002, 2003, 2009 Red Hat, Inc.
 ; This file is part of CGEN.
 
 ; Return decode entries for each insn.
@@ -7,7 +7,7 @@
 ; big array.  It doesn't matter too much (yet).  Generating one big array is
 ; simpler.
 
-(define (-gen-decode-insn-globals insn-list)
+(define (/gen-decode-insn-globals insn-list)
   ; Print the higher detailed stuff at higher verbosity.
   (logit 2 "Processing decode insn globals ...\n")
 
@@ -46,11 +46,8 @@ bool @prefix@_idesc::idesc_table_initialized_p = false;\n\n"
           (if (with-scache?)
               (if pbb?
                   "0, "
-                  (string-append (-gen-sem-fn-name insn) ", "))
-              "")
-           (if (with-parallel?)
-               (string-append (-gen-write-fn-name sfmt) ", ")
-               "")
+                  (string-append (/gen-sem-fn-name insn) ", "))
+              "") 
           "\"" (string-upcase name) "\", "
           (gen-cpu-insn-enum (current-cpu) insn)
           ", "
@@ -64,7 +61,7 @@ bool @prefix@_idesc::idesc_table_initialized_p = false;\n\n"
 
 ; Return a function that lookups up virtual insns.
 
-(define (-gen-virtual-insn-finder)
+(define (/gen-virtual-insn-finder)
   (string-list
    "\
 // Given a canonical virtual insn id, return the target specific one.
@@ -104,26 +101,26 @@ bool @prefix@_idesc::idesc_table_initialized_p = false;\n\n"
 \f
 ; Return enum name of format FMT.
 
-(define (-gen-fmt-enum fmt)
+(define (/gen-fmt-enum fmt)
   (string-upcase (gen-sym fmt))
 )
 
 ; Return names of semantic fns for INSN.
 ; ??? Make global, call from gen-semantic-fn, blah blah blah.
 
-(define (-gen-sem-fn-name insn)
+(define (/gen-sem-fn-name insn)
   (string-append "@prefix@_sem_" (gen-sym insn))
 )
 
 ; Return decls of each semantic fn.
 
-(define (-gen-sem-fn-decls)
+(define (/gen-sem-fn-decls)
   (string-write
    "// Decls of each semantic fn.\n\n"
    "using @cpu@::@prefix@_sem_fn;\n"
    (string-list-map (lambda (insn)
                      (string-list "extern @prefix@_sem_fn "
-                                  (-gen-sem-fn-name insn)
+                                  (/gen-sem-fn-name insn)
                                   ";\n"))
                    (scache-engine-insns))
    "\n"
@@ -131,32 +128,13 @@ bool @prefix@_idesc::idesc_table_initialized_p = false;\n\n"
 )
 
 
-;; and the same for writeback functions
-
-(define (-gen-write-fn-name sfmt)
-  (string-append "@prefix@_write_" (gen-sym sfmt))
-)
-
-
-(define (-gen-write-fn-decls)
-  (string-write
-   "// Decls of each writeback fn.\n\n"
-   "using @cpu@::@prefix@_write_fn;\n"
-   (string-list-map (lambda (sfmt)
-                     (string-list "extern @prefix@_write_fn "
-                                  (-gen-write-fn-name sfmt)
-                                  ";\n"))
-                   (current-sfmt-list))
-   "\n"
-   )
-)
 
 \f
 ; idesc, argbuf, and scache types
 
 ; Generate decls for the insn descriptor table type IDESC.
 
-(define (-gen-idesc-decls)
+(define (/gen-idesc-decls)
   (string-append 
    "
 // Forward decls.
@@ -164,14 +142,9 @@ struct @cpu@_cpu;
 struct @prefix@_scache;
 "
    (if (with-parallel?)
-       "struct @prefix@_parexec;\n" "")
-   (if (with-parallel?)
-       "typedef void (@prefix@_sem_fn) (@cpu@_cpu* cpu, @prefix@_scache* sem, @prefix@_parexec* par_exec);"
+       "typedef void (@prefix@_sem_fn) (@cpu@_cpu* cpu, @prefix@_scache* sem, int tick, @prefix@::write_stacks &buf);"
        "typedef sem_status (@prefix@_sem_fn) (@cpu@_cpu* cpu, @prefix@_scache* sem);")
    "\n"
-   (if (with-parallel?)
-       "typedef sem_status (@prefix@_write_fn) (@cpu@_cpu* cpu, @prefix@_scache* sem, @prefix@_parexec* par_exec);"
-       "")
    "\n"   
 "
 // Instruction descriptor.
@@ -192,12 +165,6 @@ struct @prefix@_idesc {
   @prefix@_sem_fn* execute;\n\n"
        "")
 
-   (if (with-parallel?)
-       "\
-  // scache write executor for this insn
-  @prefix@_write_fn* writeback;\n\n"
-       "")
-
    "\
   const char* insn_name;
   enum @prefix@_insn_type sem_index;
@@ -222,10 +189,10 @@ struct @prefix@_idesc {
 ")
 )
 
-; Utility of -gen-argbuf-fields-union to generate the definition for
+; Utility of /gen-argbuf-fields-union to generate the definition for
 ; <sformat-abuf> SBUF.
 
-(define (-gen-argbuf-elm sbuf)
+(define (/gen-argbuf-elm sbuf)
   (logit 2 "Processing sbuf format " (obj:name sbuf) " ...\n")
   (string-list
    "  struct { /* " (obj:comment sbuf) " */\n"
@@ -242,15 +209,15 @@ struct @prefix@_idesc {
    "  } " (gen-sym sbuf) ";\n")
 )
 
-; Utility of -gen-scache-decls to generate the union of extracted ifields.
+; Utility of /gen-scache-decls to generate the union of extracted ifields.
 
-(define (-gen-argbuf-fields-union)
+(define (/gen-argbuf-fields-union)
   (string-list
    "\
 // Instruction argument buffer.
 
 union @prefix@_sem_fields {\n"
-   (string-list-map -gen-argbuf-elm (current-sbuf-list))
+   (string-list-map /gen-argbuf-elm (current-sbuf-list))
    "\
   // This one is for chain/cti-chain virtual insns.
   struct {
@@ -269,9 +236,9 @@ union @prefix@_sem_fields {\n"
    )
 )
 
-(define (-gen-scache-decls)
+(define (/gen-scache-decls)
   (string-list
-   (-gen-argbuf-fields-union)
+   (/gen-argbuf-fields-union)
    "\
 // Simulator instruction cache.
 
@@ -300,7 +267,7 @@ struct @prefix@_scache {
   // argument buffer
   @prefix@_sem_fields fields;
 
-" (if (or (with-profile?) (with-parallel-write?))
+" (if (with-any-profile?)
       (string-append "
   // writeback flags
   // Only used if profiling or parallel execution support enabled during
@@ -337,7 +304,7 @@ struct @prefix@_scache {
 ; Return C code to record <ifield> F for the semantic handler
 ; in a local variable rather than an ARGBUF struct.
 
-(define (-gen-record-argbuf-ifld f sfmt)
+(define (/gen-record-argbuf-ifld f sfmt)
   (string-append "  " (gen-ifld-argbuf-ref f)
                 " = " (gen-extracted-ifld-value f) ";\n")
 )
@@ -346,7 +313,7 @@ struct @prefix@_scache {
 ; string argument to fprintf, character indicating type of third arg, value.
 ; The type is one of: x.
 
-(define (-gen-trace-argbuf-ifld f sfmt)
+(define (/gen-trace-argbuf-ifld f sfmt)
   (string-append
    ; FIXME: Add method to return fprintf format string.
    ", \"" (gen-sym f) " 0x%x\""
@@ -442,7 +409,7 @@ struct @prefix@_scache {
 ; the ARGBUF struct.
 ; ??? Later allow target to provide an `extract' expression.
 
-(define (-gen-op-extract op sfmt local?)
+(define (/gen-op-extract op sfmt local?)
   (send (op:type op) 'gen-extract op sfmt local?)
 )
 
@@ -450,7 +417,7 @@ struct @prefix@_scache {
 ; string argument to fprintf, character indicating type of third arg, value.
 ; The type is one of: x.
 
-(define (-gen-op-trace-extract op sfmt)
+(define (/gen-op-trace-extract op sfmt)
   (send (op:type op) 'gen-trace-extract op sfmt)
 )
 
@@ -482,7 +449,7 @@ struct @prefix@_scache {
 (define (gen-sfmt-op-argbuf-assigns sfmt)
   (let ((operands (sfmt-extracted-operands sfmt)))
     (string-list-map (lambda (op)
-                      (-gen-op-extract op sfmt #t))
+                      (/gen-op-extract op sfmt #t))
                     operands))
 )
 \f
@@ -492,14 +459,14 @@ struct @prefix@_scache {
 ; Return C code to record insn field data for <sformat> SFMT.
 ; This is used when with-scache.
 
-(define (-gen-record-args sfmt)
+(define (/gen-record-args sfmt)
   (let ((operands (sfmt-extracted-operands sfmt))
        (iflds (sfmt-needed-iflds sfmt)))
     (string-list
      "  /* Record the fields for the semantic handler.  */\n"
-     (string-list-map (lambda (f) (-gen-record-argbuf-ifld f sfmt))
+     (string-list-map (lambda (f) (/gen-record-argbuf-ifld f sfmt))
                      iflds)
-     (string-list-map (lambda (op) (-gen-op-extract op sfmt #f))
+     (string-list-map (lambda (op) (/gen-op-extract op sfmt #f))
                      operands)
      "  if (UNLIKELY(current_cpu->trace_extract_p))\n"
      "    {\n"
@@ -545,23 +512,21 @@ struct @prefix@_scache {
 ; is kept to the extraction phase.  If someone wants to put forth some real
 ; data, this might then be changed (or at least noted).
 
-(define (-gen-record-profile-args sfmt)
+(define (/gen-record-profile-args sfmt)
   (let ((in-ops (find op-profilable? (sfmt-in-ops sfmt)))
        (out-ops (find op-profilable? (sfmt-out-ops sfmt)))
        )
-    (if (and (null? in-ops) (null? out-ops))
+    (if (or (not (with-any-profile?)) (and (null? in-ops) (null? out-ops)))
        ""
        (string-list
-        "#if WITH_PROFILE_MODEL_P\n"
         "  /* Record the fields for profiling.  */\n"
-        "  if (PROFILE_MODEL_P (current_cpu))\n"
+        "  if (UNLIKELY (current_cpu->trace_counter_p || current_cpu->final_insn_count_p))\n"
         "    {\n"
         (string-list-map (lambda (op) (op:record-profile op sfmt #f))
                          in-ops)
         (string-list-map (lambda (op) (op:record-profile op sfmt #t))
                          out-ops)
         "    }\n"
-        "#endif\n"
         )))
 )
 
@@ -572,7 +537,7 @@ struct @prefix@_scache {
 ; by the semantic code.  This is currently done by recording this information
 ; with the format.
 
-(define (-gen-extract-fn sfmt)
+(define (/gen-extract-fn sfmt)
   (logit 2 "Processing extractor for \"" (sfmt-key sfmt) "\" ...\n")
   (string-list
    "void
@@ -587,9 +552,9 @@ struct @prefix@_scache {
    "\n"
    (gen-extract-ifields (sfmt-iflds sfmt) (sfmt-length sfmt) "    " #f)
    "\n"
-   (-gen-record-args sfmt)
+   (/gen-record-args sfmt)
    "\n"
-   ;(-gen-record-profile-args sfmt) ??? not supported yet
+   (/gen-record-profile-args sfmt)
    (gen-undef-field-macro sfmt)
    "}\n\n"
    )
@@ -597,12 +562,12 @@ struct @prefix@_scache {
 
 ; For each format, return its extraction function.
 
-(define (-define-all-extractor-fns)
+(define (/define-all-extractor-fns)
   (logit 2 "Processing extractor fn bodies ...\n")
-  (string-list-map -gen-extract-fn (current-sfmt-list))
+  (string-list-map /gen-extract-fn (current-sfmt-list))
 )
 
-(define (-declare-all-extractor-fns)
+(define (/declare-all-extractor-fns)
   (logit 2 "Processing extractor fn declarations ...\n")
   (string-map (lambda (sfmt)
                (string-append "
@@ -617,11 +582,8 @@ static void
 ; build the first decode table.  If nil, we compute 8 bits of it (FIXME)
 ; ourselves.
 ; LSB0? is non-#f if bit number 0 is the least significant bit.
-; FIXME: Need to be perfect for every subtable, or allow target more control.
-; Leave for later (and don't give target more control until oodles of effort
-; have been spent trying to be perfect! ... or close enough).
 
-(define (-gen-decode-fn insn-list initial-bitnums lsb0?)
+(define (/gen-decode-fn insn-list initial-bitnums lsb0?)
   (assert (with-scache?))
 
   ; Compute the initial DECODE-BITSIZE as the minimum of all insn lengths.
@@ -629,29 +591,32 @@ static void
   ; of the instruction.
   ; ??? Make this a parameter later but only if necessary.
 
-  (let ((decode-bitsize (apply min (map insn-base-mask-length insn-list))))
+  (let ((decode-bitsize (state-base-insn-bitsize)))
 
     ; Compute INITIAL-BITNUMS if not supplied.
     ; 0 is passed for the start bit (it is independent of lsb0?)
     (if (null? initial-bitnums)
-       (set! initial-bitnums (decode-get-best-bits insn-list nil
-                                                   0 ; startbit
-                                                   8 ; max
-                                                   decode-bitsize
-                                                   lsb0?)))
-
+       (set! initial-bitnums
+             (if (= 0 (length insn-list))
+                 (list 0) ; dummy value
+                 (decode-get-best-bits insn-list nil
+                                       0 ; startbit
+                                       8 ; max
+                                       decode-bitsize
+                                       lsb0?))))
+       
     ; All set.  gen-decoder does the hard part, we just print out the result. 
     (let ((decode-code (gen-decoder insn-list initial-bitnums
                                    decode-bitsize
                                    "    " lsb0?
-                                   (current-insn-lookup 'x-invalid)
+                                   (current-insn-lookup 'x-invalid #f)
                                    #t)))
 
       (string-write
        "
 // Declare extractor functions
 "
-       -declare-all-extractor-fns
+       /declare-all-extractor-fns
 
        "
 
@@ -695,14 +660,14 @@ void
 
 "
 
-       -define-all-extractor-fns
+       /define-all-extractor-fns
        )))
 )
 \f
 ; Entry point.  Generate decode.h.
 
 (define (cgen-decode.h)
-  (logit 1 "Generating " (gen-cpu-name) " decode.h ...\n")
+  (logit 1 "Generating " (gen-cpu-name) "-decode.h ...\n")
 
   (sim-analyze-insns!)
 
@@ -710,12 +675,23 @@ void
   (set-with-parallel?! (state-parallel-exec?))
 
   (string-write
-   (gen-copyright "Decode header for @prefix@."
-                 copyright-cygnus package-cygnus-simulators)
+   (gen-c-copyright "Decode header for @prefix@."
+                 copyright-red-hat package-red-hat-simulators)
    "\
 #ifndef @PREFIX@_DECODE_H
 #define @PREFIX@_DECODE_H
 
+"
+   (if (with-parallel?)
+       "\
+namespace @prefix@ {
+// forward declaration of struct in -defs.h
+struct write_stacks;
+}
+
+"
+       "")
+"\
 namespace @cpu@ {
 
 using namespace cgen;
@@ -726,8 +702,8 @@ typedef UINT @prefix@_insn_word;
 "
    (lambda () (gen-cpu-insn-enum-decl (current-cpu)
                                      (non-multi-insns (non-alias-insns (current-insn-list)))))
-   -gen-idesc-decls
-   -gen-scache-decls
+   /gen-idesc-decls
+   /gen-scache-decls
 
    "\
 } // end @cpu@ namespace
@@ -736,11 +712,7 @@ typedef UINT @prefix@_insn_word;
    ; ??? The semantic functions could go in the cpu's namespace.
    ; There's no pressing need for it though.
    (if (with-scache?)
-       -gen-sem-fn-decls
-       "")
-
-   (if (with-parallel?)
-       -gen-write-fn-decls
+       /gen-sem-fn-decls
        "")
 
    "\
@@ -751,7 +723,7 @@ typedef UINT @prefix@_insn_word;
 ; Entry point.  Generate decode.cxx.
 
 (define (cgen-decode.cxx)
-  (logit 1 "Generating " (gen-cpu-name) " decode.cxx ...\n")
+  (logit 1 "Generating " (gen-cpu-name) "-decode.cxx ...\n")
 
   (sim-analyze-insns!)
 
@@ -762,18 +734,21 @@ typedef UINT @prefix@_insn_word;
   (rtl-c-config! #:rtl-cover-fns? #t)
 
   (string-write
-   (gen-copyright "Simulator instruction decoder for @prefix@."
-                 copyright-cygnus package-cygnus-simulators)
+   (gen-c-copyright "Simulator instruction decoder for @prefix@."
+                 copyright-red-hat package-red-hat-simulators)
    "\
 
+#if HAVE_CONFIG_H
+#include \"config.h\"
+#endif
 #include \"@cpu@.h\"
 
 using namespace @cpu@; // FIXME: namespace organization still wip
 \n"
 
-   (lambda () (-gen-decode-insn-globals (non-multi-insns (non-alias-insns (current-insn-list)))))
-   -gen-virtual-insn-finder
-   (lambda () (-gen-decode-fn (non-multi-insns (real-insns (current-insn-list)))
+   (lambda () (/gen-decode-insn-globals (non-multi-insns (non-alias-insns (current-insn-list)))))
+   /gen-virtual-insn-finder
+   (lambda () (/gen-decode-fn (real-insns (current-insn-list))
                              (state-decode-assist)
                              (current-arch-insn-lsb0?)))
    )