; CPU documentation generator, html output ; Copyright (C) 2003, Doug Evans ; This file is part of CGEN. See file COPYING.CGEN for details. ; ; TODO: ; - assumes names, comments, etc. don't interfere with html. ; Just like in generation of C there are routines to C-ize symbols, ; we need to pass output through an html-izer. ; - make generated html more readable, e.g. more indentation ; - should really print the semantics in pseudo-C, a much better form for ; the intended audience ; - registers that have multiple independent fields (like x86 eflags) ; need to be printed like instruction formats are ; - uses some deprecated html, use css at very least ; - multi-ifields ok? ; - mapping from operands to h/w isn't as clear as it needs to be ; - for insn formats, if field is large consider printing "n ... m", ; would want "n" left justified and "m" right justified though ; - for insn formats, consider printing them better, ; e.g. maybe generate image and include that instead ; - need ability to specify more prose for each architecture ; - assembler support ; - need to add docs to website that can be linked to here, rather than ; including generic cgen documentation here ; - function units, timing, etc. ; - instruction framing ; Global state variables. ; Specify which application. (set! APPLICATION 'DOC) ; String containing copyright text. (define CURRENT-COPYRIGHT #f) ; String containing text defining the package we're generating code for. (define CURRENT-PACKAGE #f) (define copyright-doc (cons "\ THIS FILE IS MACHINE GENERATED WITH CGEN. See the input .cpu file(s) for copyright information. " "\ ")) ; Initialize the options. (define (option-init!) (set! CURRENT-COPYRIGHT copyright-doc) (set! CURRENT-PACKAGE package-cgen) *UNSPECIFIED* ) ; Handle an option passed in from the command line. (define (option-set! name value) (case name ((copyright) (cond ((equal? value '("doc")) (set! CURRENT-COPYRIGHT copyright-doc)) (else (error "invalid copyright value" value)))) ((package) (cond ((equal? value '("cgen")) (set! CURRENT-PACKAGE package-cgen)) (else (error "invalid package value" value)))) (else (error "unknown option" name)) ) *UNSPECIFIED* ) ; Misc utilities. ; Return COPYRIGHT, with FILE-DESC as the first line ; and PACKAGE as the name of the package which the file belongs in. ; COPYRIGHT is a pair of (header . trailer). (define (gen-html-copyright file-desc copyright package) (string-append "\n\n") ) ; KIND is one of "Architecture" or "Instruction". ; TODO: Add author arg so all replies for this arch go to right person. (define (gen-html-header kind) (let* ((arch (symbol->string (current-arch-name))) (ARCH (string-upcase arch))) (string-list "\n" "\n" "\n" " \n" " \n" " \n" " \n" " \n" " " ARCH " " kind " Documentation\n" "\n" "\n" ) ) ) (define (gen-html-trailer) (string-list "\n" "


\n" "This documentation was machine generated from the cgen cpu description\n" "files for this architecture.\n" "
\n" "http://sources.redhat.com/cgen/\n" "\n" "\n" ) ) ; INSN-FILE is the name of the .html file containing instruction definitions. (define (gen-table-of-contents insn-file) (let ((ARCH (string-upcase (symbol->string (current-arch-name))))) (string-list "

\n" (string-append ARCH " Architecture Documentation") "

\n" "\n" "
\n" "DISCLAIMER: This documentation is derived from the cgen cpu description\n" "of this architecture, and does not represent official documentation\n" "of the chip maker.\n" "


\n" "\n" "

\n" "
\n" ; TODO: Move this to the cgen website, and include a link here. "In cgen-parlance, an architecture consists of machines and models.\n" "A `machine' is the specification of a variant of the architecture,\n" "and a `model' is the implementation of that specification.\n" "Typically there is a one-to-one correspondance between machine and model.\n" "The distinction allows for separation of what application programs see\n" "(the machine), and how to tune for the chip (what the compiler sees).\n" "
\n" "A \"cpu family\" is a cgen concoction to help organize the generated code.\n" "Chip variants that are quite dissimilar can be treated separately by the\n" "generated code even though they're both members of the same architecture.\n" )) ) ; Utility to print a list entry for NAME/COMMENT, kind KIND ; which is a link to the entry's description. ; KIND is one of "mach", "model", etc. (define (gen-list-entry name comment kind) (string-append "
  • " "string name) "\">" (->string name) " - " comment "\n" "
  • \n") ) ; Cover-fn to gen-list-entry for use with objects. (define (gen-obj-list-entry o kind) (gen-list-entry (obj:name o) (obj:comment o) kind) ) ; Utility to print the header for the description of TEXT. (define (gen-doc-header text anchor-name) (string-list "\n" "

    " text "

    \n" ) ) ; Cover-fn to gen-doc-header for use with objects. ; KIND is one of "mach", "model", etc. (define (gen-obj-doc-header o kind) (gen-doc-header (string-append (obj:str-name o) " - " (obj:comment o)) (string-append kind "-" (obj:str-name o))) ) ; Architecture page. (define (gen-cpu-intro cpu) (string-list "
  • \n" (obj:str-name cpu) " - " (obj:comment cpu) "\n" "
    \n" "
    \n" "Machines:\n" "\n" "
  • \n" "
    \n" ) ) (define (gen-mach-intro mach) (string-list "
  • \n" (obj:str-name mach) " - " (obj:comment mach) "\n" "
    \n" "
    \n" "Models:\n" "\n" "
  • \n" "
    \n" ) ) (define (gen-model-intro model) (string-list "
  • \n" (obj:str-name model) " - " (obj:comment model) "\n" "
    \n" "
  • \n" ) ) (define (gen-isa-intro isa) (string-list "
  • \n" (obj:str-name isa) " - " (obj:comment isa) "\n" "
    \n" ; FIXME: wip ; I'd like to include the .cpu file tag here, but using English text ; feels more appropriate. Having both is excessive. ; Pick one, and have a link to its description/tag. ; I'm leaning toward using the cgen tag here as we'll probably want ; access (via an html tag) to more than one-liner descriptions. "