URL
https://opencores.org/ocsvn/scarts/scarts/trunk
Subversion Repositories scarts
[/] [scarts/] [trunk/] [toolchain/] [scarts-binutils/] [binutils-2.19.1/] [cgen/] [read.scm] - Rev 6
Compare with Previous | Blame | View Log
; Top level file for reading and recording .cpu file contents. ; Copyright (C) 2000, 2001, 2006, 2009 Red Hat, Inc. ; This file is part of CGEN. ; See file COPYING.CGEN for details. ; This file [and its subordinates] contain no C code (well, as little as ; possible). That lives at a layer above us. ; A .cpu file consists of several sections: ; ; - basic definitions (e.g. cpu variants, word size, endianness, etc.) ; - enums (enums are used throughout so by convention there is a special ; section in which they're defined) ; - attributes ; - instruction fields and formats ; - hardware descriptions (e.g. registers, allowable immediate values) ; - model descriptions (e.g. pipelines, latencies, etc.) ; - instruction operands (mapping of insn fields to associated hardware) ; - instruction definitions ; - macro instruction definitions ; TODO: ; - memory access, layout, etc. ; - floating point quirks ; - ability to describe an ABI ; - anything else that comes along ; Notes: ; - by convention most objects are subclasses of <ident> (having name, comment, ; and attrs elements and they are the first three elements of any .cpu file ; entry ; Guidelines: ; - Try to conform to R5RS, try to limit guile-ness. ; The current code is undoubtedly off in many places. ; Conventions: ; [I want there to be a plethora of conventions and I want them strictly ; adhered to. ??? There's probably a few violations here and there. ; No big deal - fix them!] ; These conventions are subject to revision. ; ; - procs/vars local to a file are named "-foo" ; - only routines that emit application code begin with "gen-" ; - symbols beginning with "c-" are either variables containing C code ; or procedures that generate C code, similarily for C++ and "c++-" ; - variables containing C code begin with "c-" ; - only routines that emit an entire file begin with "cgen-" ; - all .cpu file elements shall have -foo-parse and -foo-read procedures ; - global vars containing class definitions shall be named "<class-name>" ; - procs related to a particular class shall be named "class-name-proc-name", ; class-name may be abbreviated ; - procs that test whether something is an object of a particular class ; shall be named "class-name?" ; - in keeping with Scheme conventions, predicates shall have a "?" suffix ; - in keeping with Scheme conventions, methods and procedures that modify an ; argument or have other side effects shall have a "!" suffix, ; usually these procs return "*UNSPECIFIED*" ; - all -foo-parse,parse-foo procs shall have `context' as the first arg ; [FIXME: not all such procs have been converted] ; - stay away from non-portable C symbols. ; Variables representing misc. global constants. ; A list of three numbers designating the cgen version: major minor fixlevel. ; The "50" is a generic indicator that we're between 1.1 and 1.2. ; A list of two numbers designating the description language version. ; Note that this is different from -CGEN-VERSION. ; See section "RTL Versions" of the docs. ;; List of supported versions "Invalid major version number""Invalid minor version number""Unsupported/invalid rtl version""Setting RTL version to ""."" ...\n"; Which application is in use (UNKNOWN, DESC, OPCODES, SIMULATOR, ???). ; This is mostly for descriptive purposes. ; Things are organized so that files can be compiled with Hobbit for ; experimentation. Thus we need one file that loads all the other files. ; This is that file, though it would make sense to move the code in this ; file to another. ; If a routine to initialize compiled-in code is defined, run it. ; If this is set to #f, the file is always loaded. ; Don't override any current setting, e.g. from dev.scm. ; Unlink file if we're reloaded (say in an interactive session). ; Dynamic loading is enabled by setting LIBCPU.SO to the pathname of the .so. ; List of loaded files. ; Return non-zero if FILE was loaded last time through. ; Record FILE as compiled in. ; Load FILE if SYM is not compiled in. ; Return non-#f if FUNC is present in DYNOBJ. "init_""Skipping "", dynamically loaded.\n""Skipping "", already loaded.\n""pmacros""cos""slib/logical""slib/sort"; Used to pretty-print debugging messages. "slib/pp"; Used by pretty-print. "slib/random""slib/genwrite""utils""utils-cgen""utils_cgen""attr""enum""mach""model""types""mode""ifield""iformat""hardware""operand""insn""minsn""decode""rtl""rtl""rtl-traverse""rtl_traverse""rtl-xform""rtx_simplify""rtx-funcs""rtx_funcs""rtl-c""rtl_c""semantics""sem-frags""sem_frags""utils-gen""utils_gen""pgmr-tools""pgmr_tools"; Reader state data. ; All state regarding the reading of a .cpu file is kept in an object of ; class <reader>. ; Class to record info for each top-level `command' (for lack of a better ; word) in the description file. ; Top level commands are things like define-*. ; argument spec to `lambda' ; lambda that processes the entry ; Return help text for COMMAND. "Arguments: ""\n"; A pair of two lists: machs to keep, machs to drop. ; The default is "keep all machs", "drop none". ; Main reader state class. ; Selected machs to keep. ; A pair of two lists: the car lists the machs to keep, the cdr ; lists the machs to drop. Two special entries are `all' and ; `base'. Both are only valid in the keep list. `base' is a ; place holder for objects that are common to all machine ; variants in the architecture, it is the default value of the ; MACH attribute. If `all' is present the drop list is still ; processed. ; Selected isas to keep or `all'. ; Boolean indicating if command tracing is on. ; Boolean indicating if pmacro tracing is on. ; Currently select cpu family, computed from `keep-mach'. ; Some applications don't care, and this is moderately ; expensive to compute so we use delay/force. ; Associative list of file entry commands ; (e.g. define-insn, etc.). ; Each entry is (name . command-object). ; The current source location. ; This is recorded here by the higher level reader and is ; fetched by commands as necessary. ; Accessors. ; Reader state for current .cpu file. ; Return the current source location in readable form. ; FIXME: Currently unused, keep for reference for awhile. ;; Blech, we don't have a current reader location. That's odd. ;; Fall back to the current input port's location. "<input>"":"":";;; Signal a parse error while reading a .cpu file. ;;; If CONTEXT is #f, use a default context of the current reader location ;;; and an empty prefix. ;;; If MAYBE-HELP-TEXT is specified, elide the last trailing \n. ;;; Multiple lines of help text need embedded newlines, and should be no longer ;;; than 79 characters. "While reading description""Error"": ""\n~A:\n@ ~A:\n\n~A: ~A: ~S~A""""\n\n"; Return the current source location. ; ; If CURRENT-READER is uninitialized, return "unspecified" location. ; This is done so that things like define-pmacro work in interactive mode. ; Process a macro-expanded entry. ;; Set the current source location for better diagnostics. ;; Access with current-reader-location. "Processing command:\n @ ""location unknown""\n";; Variable number of trailing arguments. "Incorrect number of arguments to "", expecting at least ";; Fixed number of arguments. "Incorrect number of arguments to "", expecting ""unknown entry type";; Process 1 or more macro-expanded entries. ;; ENTRY is expected to have a location-property object property. ;; NOTE: This is "public" so the .eval pmacro can use it. ;; This is also used by -cmd-if. ;; () is used to indicate a no-op ;; nothing to do ;; `begin' is used to group a collection of entries into one, ;; since pmacro can only return one expression (borrowed from ;; Scheme of course). ;; Recurse in case there are nested begins. ; Process file entry ENTRY. ; LOC is a <location> object for ENTRY. "improperly formed entry"; First do macro expansion, but not if define-pmacro of course. ; ??? Singling out define-pmacro this way seems a bit odd. The way to look ; at it, I guess, is to think of define-pmacro as (currently) the only ; "syntactic" command (it doesn't pre-evaluate its arguments). ; Read in and process FILE. ; ; It would be nice to get the line number of the beginning of the object, ; but that's extra work, so for now we do the simple thing and use ; port-line after we've read an entry. ; done ;; ??? The location we pass here isn't ideal. ;; Ideally we'd pass the start location of the ;; expression, instead we currently pass the end ;; location (it's easier). ;; ??? Use source-properties of entry, and only if ;; not present fall back on current-input-location. ; Cpu data is recorded in an object of class <arch>. ; This is necessary as we need to allow recording of multiple cpu descriptions ; simultaneously. ; Class <arch> is defined in mach.scm. ; Global containing all data of the currently selected architecture. ; `keep-mach' processing. ; Return the currently selected cpu family. ; If a specific cpu family has been selected, each machine that is kept must ; be in that cpu family [so there's no ambiguity in the result]. ; This is a moderately expensive computation so use delay/force. ; Return a boolean indicating if CPU-NAME is to be kept. ; ??? Currently this is always true. Note that this doesn't necessarily apply ; to machs in CPU-NAME. ; Cover proc to set `keep-mach'. ; MACH-NAME-LIST is a comma separated string of machines to keep and drop ; (if prefixed with !). ; Reset current-cpu. "no machs selected""machs from different cpu families selected"; Validate the user-provided keep-mach list against the list of machs ; specified in the .cpu file (in define-arch). "unknown mach to keep:""unknown mach to drop:"; Return #t if a machine in MACH-LIST, a list of symbols, is to be kept. ; If any machine in MACH-LIST is to be kept, the result is #t. ; If MACH-LIST is the empty list (no particular mach specified, thus the base ; mach), the result is #t. ; keep if K(ept) or ALL? and not D(ropped) ; Return non-#f if the object containing ATLIST is to be kept. ; OBJ is the container object or #f if there is none. ; The object is kept if its attribute list specifies a `MACH' that is ; kept (and not dropped) or does not have the `MACH' attribute (which means ; it has the default value which means it's for use with all machines). ; The MACH attribute is not created until the .cpu file is read in which ; is too late for us [we will get called for builtin objects]. ; Thus we peek inside the attribute list directly. ; ??? Maybe postpone creation of builtins until after define-arch? ; Return a boolean indicating if the object containing ATLIST is to be kept. ; OBJ is the container object or #f if there is none. ; The object is kept if both its isa and its mach are kept. ; Return a boolean indicating if multiple cpu families are being kept. ; Return a boolean indicating if everything is kept. ; Ensure all cpu families were kept, necessary for generating files that ; encompass the entire architecture. "no can do, all cpu families not selected"; Ensure exactly one cpu family was kept, necessary for generating files that ; are specific to one cpu family. "no can do, multiple cpu families selected"; `keep-isa' processing. ; Cover proc to set `keep-isa'. ; ISA-NAME-LIST is a comma separated string of isas to keep. ; ??? We don't support the !drop notation of keep-mach processing. ; Perhaps we should as otherwise there are two different styles the user ; has to remember. On the other hand, !drop support is moderately complicated, ; and it can be added in an upward compatible manner later. ; Validate the user-provided keep-isa list against the list of isas ; specified in the .cpu file (in define-arch). "unknown isa to keep:"; Return currently selected isa (there must be exactly one). "multiple isas selected""multiple isas selected"; Return #t if an isa in ISA-LIST, a list of symbols, is to be kept. ; If any isa in ISA-LIST is to be kept, the result is #t. ; If ISA-LIST is the empty list (no particular isa specified) use the default ; isa. ; Return #t if the object containing ATLIST is to be kept. ; OBJ is the container object or #f if there is none. ; The object is kept if its attribute list specifies an `ISA' that is ; kept or does not have the `ISA' attribute (which means it has the default ; value) and the default isa is being kept. ; Return non-#f if object OBJ is to be kept, according to its ISA attribute. ; Return a boolean indicating if multiple isas are being kept. ; Return list of isa names currently being kept. ;; Tracing support. ;; This is akin to the "logit" support, but is for specific things that ;; can be named (whereas logit support is based on a simple integer verbosity ;; level). ;;; Enable the specified tracing. ;;; TRACE-OPTIONS is a comma-separated list of things to trace. ;;; ;;; Currently supported tracing: ;;; commands - trace invocation of description file commands (e.g. define-insn) ;;; pmacros - trace pmacro expansion ;;; all - trace everything ;;; ;;; [If we later need to support disabling some tracing, one way is to ;;; recognize an "-" in front of an option.] "commands""pmacros""all""commands""pmacros""all";; handled above "-t "; If #f, treat reserved fields as operands and extract them with the insn. ; Code can then be emitted in the extraction routines to validate them. ; If #t, treat reserved fields as part of the opcode. ; This complicates the decoding process as these fields have to be ; checked too. ; ??? Unimplemented. ; Process options passed in on the command line. ; OPTIONS is a space separated string of name=value values. ; Each application is required to provide: option-init!, option-set!. ; ignore extraneous spaces "Setting option `""' to \"""\".\n"; Application specific object creation support. ; ; Each entry in the .cpu file has a basic container class. ; Each application adds functionality by subclassing the container ; and registering with set-for-new! the proper class to create. ; ??? Not sure this is the best way to handle this, but it does keep the ; complexity down while not requiring as dynamic a language as I had before. ; ??? Class local variables would provide a more efficient way to do this. ; Assuming one wants to continue on this route. ; Lookup the class registered with set-for-new! ; If none registered, return PARENT. ; .cpu file loader support ;; Initialize a new <reader> object. ;; This doesn't add cgen-specific commands, leaving each element (ifield, ;; hardware, etc.) to add their own. ;; The "result" is stored in global CURRENT-READER. "Specify the RTL version being used.\n""Include a file.\n""(if test then . else)\n"; Rather than add cgen-internal specific stuff to pmacros.scm, we create ; the pmacro commands here. "\ Define a preprocessor-style macro. "; Prepare to parse a .cpu file. ; This initializes the application independent tables. ; KEEP-MACH specifies what machs to keep. ; KEEP-ISA specifies what isas to keep. ; OPTIONS is a list of options to control code generation. ; The values are application dependent. ; The order here is important. ; Must be done first. ; Install any builtin objects. ; This is deferred until define-arch is read. ; One reason is that attributes MACH and ISA don't exist until then. ; The order here is important. ; This is mainly for the insn attributes. ; Do anything necessary for the application independent parts after parsing ; a .cpu file. ; The lists get cons'd in reverse order. One thing this does is change them ; back to file order, it makes things easier for the human viewer. ; The order here is generally the reverse of init-parse-cpu!. ; Must be done last. ; Perform a global error checking pass after the .cpu file has been read in. ; ??? None yet. ; TODO: ; - all hardware elements with same name must have same rank and ; compatible modes (which for now means same float mode or all int modes) ; .cpu file include mechanism "Including file ""/"" ...\n""/""Resuming previous file ...\n"; Version of `if' invokable at the top level of a description file. ; This is a work-in-progress. Its presence in the description file is ok, ; but the implementation will need to evolve. "wrong number of arguments to `if'"; ??? rtx-eval test "only (if (keep-mach?|keep-isa?|application-is? ...) ...) are currently supported"; Top level routine for loading .cpu files. ; FILE is the name of the .cpu file to load. ; KEEP-MACH is a string of comma separated machines to keep ; (or not keep if prefixed with !). ; KEEP-ISA is a string of comma separated isas to keep. ; OPTIONS is the OPTIONS argument to -init-parse-cpu!. ; TRACE-OPTIONS is a random list of things to trace. ; APP-INITER! is an application specific zero argument proc (thunk) ; to call after -init-parse-cpu! ; APP-FINISHER! is an application specific zero argument proc to call after ; -finish-parse-cpu! ; ANALYZER! is a zero argument proc to call after loading the .cpu file. ; It is expected to set up various tables and things useful for the application ; in question. ; ; This function isn't local because it's used by dev.scm. "Loading cpu description "" ...\n""Processing cpu description "" ...\n"; Argument parsing utilities. ; Generate a usage message. ; ERRTYPE is one of 'help, 'unknown, 'missing. ; OPTION is the option that had the error or "" if ERRTYPE is 'help. "Unknown option: ""\n""Missing argument: ""\n""Unknown error!\n""Usage: cgen arguments ...\n"" """" - ""\n""""\n""...\n"; Poor man's getopt. ; [We don't know where to find the real one until we've parsed the args, ; and this isn't something we need to get too fancy about anyways.] ; The result is always ((a . b) . c). ; If the argument is valid, the result is ((opt-spec . arg) . remaining-argv), ; or (('unknown . option) . remaining-argv) if `option' isn't recognized, ; or (('missing . option) . remaining argv) if `option' is missing a required ; argument, ; or ((#f . #f) . #f) if there are no more arguments. ; OPT-SPEC is a list of option specs. ; Each element is an alist of at least 3 elements: option argument help-text. ; `option' is a string or symbol naming the option. e.g. -a, --help, "-i". ; symbols are supported for backward compatibility, -i is a complex number. ; `argument' is a string naming the argument or #f if the option takes no ; arguments. ; `help-text' is a string that is printed with the usage information. ; Elements beyond `help-text' are ignored. ; must be option that doesn't take an argument ; Return (cadr args) or print a pretty error message if not possible. "option processing""missing argument to"; List of common arguments. ; ; ??? Another useful arg would be one that says "do file generation with ; arguments specified up til now, then continue with next batch of args". "-a""arch-file""specify path of .cpu file to load""-b""use debugging evaluator, for backtraces""-d""start interactive debugging session""-f""flags""specify a set of flags to control code generation""-h""print usage information""--help""print usage information""-i""isa-list""specify isa-list entries to keep""-m""mach-list""specify mach-list entries to keep""-s""srcdir""set srcdir""-t""trace-options""specify list of things to trace""Options:""commands - trace cgen commands (e.g. define-insn)""pmacros - trace pmacro expansion""all - trace everything""-v""increment verbosity level""--version""print version info"; Default place to look. ; This gets overridden to point to the directory of the loaded .cpu file. ; ??? Ideally this would be local to this file. "/cpu"; Accessors for application option specs ; Parse options and call generators. ; ARGS is a #:keyword delimited list of arguments. ; #:app-name name ; #:arg-spec optspec ; FIXME: rename to #:opt-spec ; #:init init-routine ; #:finish finish-routine ; #:analyze analysis-routine ; #:argv command-line-arguments ; ; ARGSPEC is a list of (option option-arg comment option-handler) elements. ; OPTION-HANDLER is either (lambda () ...) or (lambda (arg) ...) and ; processes the option. "unknown""cgen""cgen: unknown argument"; ARGS has been processed, now we can process ARGV. ; application's args are queued here "all"; default is all machs "all"; default is all isas ""; default is off, for speed """-a""-b""-d""cgen-""> ""-f""-h""""--help""""-i""-m""-s"; ignore, already processed by caller "-t""-v""--version""Cpu tools GENerator version ""."".""RTL version ""."; Else this is an application specific option. ; Record it for later processing. Note that they're ; recorded in reverse order (easier). This is undone ; later. ; end of loop ; All arguments have been parsed. "-a option missing, no architecture specified";; Start another repl loop if -d. ;; Awkward. Both places are useful, though this is more useful. ;; Done with processing the arguments. Application arguments ;; are processed in two passes. This is because the app may ;; have arguments that specify things that affect file ;; generation (e.g. to specify another input file) and we ;; don't want to require an ordering of the options. ; end of lambda ; Main entry point called by application file generators.