URL
https://opencores.org/ocsvn/scarts/scarts/trunk
Subversion Repositories scarts
[/] [scarts/] [trunk/] [toolchain/] [scarts-binutils/] [binutils-2.19.1/] [cgen/] [utils-gen.scm] - Rev 6
Compare with Previous | Blame | View Log
; Application independent utilities for C/C++ code generation. ; Copyright (C) 2000, 2001, 2005, 2009 Red Hat, Inc. ; This file is part of CGEN. ; See file COPYING.CGEN for details. ; Attributes. """""""static const CGEN_ATTR_ENTRY ""_attr [] ATTRIBUTE_UNUSED = \n{\n {\"integer\", ""},\n { 0, 0 }\n};\n\n""_""static const CGEN_ATTR_ENTRY ""_attr""[] ATTRIBUTE_UNUSED =\n{\n"" { ""\"""\", ""_"" },\n"" { 0, 0 }\n""};\n\n"; Ifield extraction utilities. ; Return the C data type to use to hold an extracted and decoded ; <ifield> from an insn. Usually this is just an int, but for register ; numbers or large unsigned immediates, an unsigned int may be preferable. ; Then there's floats (??? which aren't handled yet). ; Return C declaration of variable(s) to hold <ifield> F. ; MACRO? is #t if the result is part of a macro. " "";"" \\\n""\n"; Return C code to extract a field from the base part of an insn. ; ; TOTAL-LENGTH is the total length of the value in VAL. ; BASE-VALUE is a C expression (string) containing the base part of the insn. "EXTRACT_""LSB0_""MSB0_""INT""UINT""unsupported mode class"" ("", "", "; ??? Is passing total-length right here? ", "")"; If the field doesn't have a special decode expression, ; just return the raw extracted value. Otherwise, emit ; the expression. ; cadr: fetches expression to be evaluated ; caar: fetches symbol in arglist ; cadar: fetches `pc' symbol in arglist "pc"; Subroutine of -gen-ifld-extract-beyond to extract the relevant value ; from WORD-NAME and move it into place. "(""EXTRACT_""LSB0""MSB0"; Only want sign extension for word with sign bit. "_INT (""_UINT ("; What to extract from. ", "; Size of this chunk. ", "; MSB of this chunk. ", "; Length of field within this chunk. ") << "; Adjustment for this chunk within a full field. ")"; Return C code to extract a field that extends beyond the base insn. ; ; Things get tricky in the non-integral-insn case (no kidding). ; This case includes every architecture with at least one insn larger ; than 32 bits, and all architectures where insns smaller than 32 bits ; can't be interpreted as an int. ; ??? And maybe other architectures not considered yet. ; We want to handle these reasonably fast as this includes architectures like ; the ARC and I960 where 99% of the insns are 32 bits, with a few insns that ; take a 32 bit immediate. It would be a real shame to unnecessarily slow down ; handling of 99% of the instruction set just for a few insns. Fortunately ; for these chips base-insn includes these insns, so things fall out naturally. ; ; BASE-LENGTH is base-insn-bitsize. ; TOTAL-LENGTH is the total length of the insn. ; VAR-LIST is a list of variables containing the insn. ; Each element in VAR-LIST is (name start length). ; The contents of the insn are in several variables: insn, word_[123...], ; where `insn' contains the "base insn" and `word_N' is a set of variables ; recording the rest of the insn, 32 bits at a time (with the last one ; containing whatever is left over). ; First compute the list of variables that contains pieces of the ; desired value. ;(word-start (ifld-word-offset f)) ;(word-length (ifld-word-length f)) ; extraction code ; extra processing to perform on extracted value ; Find which vars are needed and move the value into place. ")""(0""|"; If the field doesn't have a special decode expression, just return the ; raw extracted value. Otherwise, emit the expression. ; cadr: fetches expression to be evaluated ; caar: fetches symbol in arglist ; cadar: fetches `pc' symbol in arglist "pc"; Return C code to extract <ifield> F. " = "";"" \\\n""\n"; Return C code to extract a <multi-ifield> from an insn. ; This must have the same signature as gen-ifld-extract as both can be ; made methods in application code. ; The subfields must have already been extracted. ;; First, the block that extract the multi-ifield into the ifld variable ;; Next, the decode routine that modifies it " "" = ""pc"";\n""""\n"; Return C symbol of variable containing the extracted field value ; in the extraction code. E.g. f_rd = EXTRACT_UINT (insn, ...). ; Subroutine of gen-extract-ifields to compute arguments for -extract-chunk ; to extract values beyond the base insn. ; This is also used by gen-define-ifields to know how many vars are needed. ; ; The result is a list of (offset . length) pairs. ; ; ??? Here's a case where explicitly defined instruction formats can ; help - without them we can only use heuristics (which must evolve). ; At least all the details are tucked away here. ; For the aligned and forced case split the insn up into base-insn ; sized chunks. For the unaligned case, use a chunk-length of 32. ; 32 was chosen because the values are extracted into portable ints. "unknown alignment"; Always fetch full CHUNK-LENGTH-sized chunks here, ; even if we don't actually need that many bytes. ; gen-ifetch only handles "normal" fetch sizes, ; and -gen-extract-word already knows how to find what ; it needs if we give it too much. ; Subroutine of gen-define-ifmt-ifields and gen-extract-ifmt-ifields to ; insert the subfields of any multi-ifields present into IFLDS. ; Subfields are inserted before their corresponding multi-ifield as they ; are initialized in order. ; There's no real need to reverse the subfields here ; other than to keep them in order. ; Return C code to define local vars to contain IFIELDS. ; All insns using the result have the same TOTAL-LENGTH (in bits). ; INDENT is a string prepended to each line. ; MACRO? is #t if the code is part of a macro (and thus '\\' must be appended ; to each line). ; Define enough ints to hold the trailing part of the insn, ; N bits at a time. ; ??? This could be more intelligent of course. Later. ; ??? Making these global to us would allow filling them during ; decoding. "/* Contents of trailing part of insn. */"" \\\n""\n""UINT word_""; \\\n"";\n"""; Return C code to define local vars to contain IFIELDS of <iformat> IFMT. ; INDENT is a string prepended to each line. ; MACRO? is #t if the code is part of a macro (and thus '\\' must be appended ; to each line). ; USE-MACRO? is #t if instead of generating the fields, we return the macro ; that does that. "EXTRACT_""_VARS"" /*"" "" */\n"" ""#define "" \\\n""/* Instruction fields. */\n""unsigned int length;"; The last line doesn't have a trailing '\\'. "\n"; Subroutine of gen-extract-ifields to fetch one value into VAR-NAME. " "" = ""pc"";"" \\\n""\n"; Subroutine of gen-extract-ifields to compute the var-list arg to ; gen-ifld-extract-beyond. ; The result is a list of `(name start length)' elements describing the ; variables holding the parts of the insn. ; CHUNK-SPECS is a list of (offset . length) pairs. ; ??? lsb0? support ok? "insn"; Return C code to extract IFIELDS. ; All insns using the result have the same TOTAL-LENGTH (in bits). ; MACRO? is #t if the code is part of a macro (and thus '\\' must be appended ; to each line). ; ; Here is where we handle integral-insn vs non-integeral-insn architectures. ; ; Examples of architectures that can be handled as integral-insns are: ; sparc, m32r, mips, etc. ; ; Examples of architectures that can't be handled as integral insns are: ; arc, i960, fr30, i386, m68k. ; [i386,m68k are only mentioned for completeness. cgen ports of these ; would be great, but more thought is needed first] ; ; C variable `insn' is assumed to contain the base part of the insn ; (max base-insn-bitsize insn-bitsize). In the m32r case insn-bitsize ; can be less than base-insn-bitsize. ; ; ??? Need to see how well gcc optimizes this. ; ; ??? Another way to do this is to put this code in an inline function that ; gets passed pointers to each ifield variable. GCC is smart enough to ; produce optimal code for this, but other compilers may not have inlining ; or the indirection removal. I think the slowdown for a non-scache simulator ; would be phenomenal and while one can say "too bad, use gcc", I'm defering ; doing this for now. ; If the insn has a trailing part, fetch it. ; ??? Could have more intelligence here. Later. "word_"""; Dispatching on a method works better, as would a generic fn. ; ??? Written this way to pass through Hobbit, doesn't handle ; ((if foo a b) (arg1 arg2)). "insn""word_""insn""word_"; Return C code to extract the fields of <iformat> IFMT. ; MACRO? is #t if the code is part of a macro (and thus '\\' must be appended ; to each line). ; USE-MACRO? is #t if instead of generating the fields, we return the macro ; that does that. "EXTRACT_""_CODE""\n"" ""#define "" \\\n""""length = "";"" \\\n""\n"; The last line doesn't have a trailing '\\'. "\n"; Instruction format utilities. "@prefix@_sfmt_type""semantic formats in cpu family @cpu@""@PREFIX@_"