; Decoder generation.
-; Copyright (C) 2000, 2002, 2003 Red Hat, Inc.
+; Copyright (C) 2000, 2002, 2003, 2009 Red Hat, Inc.
; This file is part of CGEN.
; Return decode entries for each insn.
; 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")
(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)
", "
; 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.
\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"
)
-;; 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.
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.
@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;
")
)
-; 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"
" } " (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 {
)
)
-(define (-gen-scache-decls)
+(define (/gen-scache-decls)
(string-list
- (-gen-argbuf-fields-union)
+ (/gen-argbuf-fields-union)
"\
// Simulator instruction cache.
// argument buffer
@prefix@_sem_fields fields;
-" (if (or (with-any-profile?) (with-parallel-write?))
+" (if (with-any-profile?)
(string-append "
// writeback flags
// Only used if profiling or parallel execution support enabled during
; 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")
)
; 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\""
; 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?)
)
; 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)
)
(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
; 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"
; 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"
)))
)
; 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
"\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"
)
; 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 "
; 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.
; 0 is passed for the start bit (it is independent of lsb0?)
(if (null? initial-bitnums)
(set! initial-bitnums
- (if (= 0 (length insn-list)) (list 0) ; dummy value
+ (if (= 0 (length insn-list))
+ (list 0) ; dummy value
(decode-get-best-bits insn-list nil
0 ; startbit
8 ; max
(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
"
"
- -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!)
#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;
"
(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
; ??? 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
"")
"\
; 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!)
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?)))
)