OSDN Git Service

Hand patch: update to github/binutils.
[pf3gnuchains/pf3gnuchains4x.git] / cgen / cgen-doc.scm
1 ; CPU description file generator for CGEN cpu documentation
2 ; This is invoked to build: $arch.html.
3 ; Copyright (C) 2003, 2009 Doug Evans
4 ; This file is part of CGEN.
5 ;
6 ; This is a standalone script, we don't load anything until we parse the
7 ; -s argument (keeps reliance off of environment variables, etc.).
8
9 ; Load the various support routines.
10
11 (define (load-files srcdir)
12   (load (string-append srcdir "/read.scm"))
13   (load (string-append srcdir "/desc.scm"))
14   (load (string-append srcdir "/desc-cpu.scm"))
15   (load (string-append srcdir "/html.scm"))
16 )
17
18 (define doc-arguments
19   (list
20    (list "-H" "file" "generate $arch.html in <file>"
21          #f
22          (lambda (arg) (file-write arg cgen.html)))
23    (list "-I" "file" "generate $arch-insn.html in <file>"
24          #f
25          (lambda (arg) (file-write arg cgen-insn.html)))
26    (list "-N" "file" "specify name of insn.html file"
27          #f
28          (lambda (arg) (set! *insn-html-file-name* arg)))
29    )
30 )
31
32 ; Kept global so it's available to the other .scm files.
33 (define srcdir ".")
34
35 ; Scan argv for -s srcdir.
36 ; We can't process any other args until we find the cgen source dir.
37 ; The result is srcdir.
38 ; We assume "-s" isn't the argument to another option.  Unwise, yes.
39 ; Alternatives are to require it to be the first argument or at least preceed
40 ; any option with a "-s" argument, or to put knowledge of the common argument
41 ; set and common argument parsing code in every top level file.
42
43 (define (find-srcdir argv)
44   (let loop ((argv argv))
45     (if (null? argv)
46         (error "`-s srcdir' not present, can't load cgen"))
47     (if (string=? "-s" (car argv))
48         (begin
49           (if (null? (cdr argv))
50               (error "missing srcdir arg to `-s'"))
51           (cadr argv))
52         (loop (cdr argv))))     
53 )
54
55 ; Main routine, parses options and calls generators.
56
57 (define (cgen-doc argv)
58   (let ()
59
60     ; Find and set srcdir, then load all Scheme code.
61     ; Drop the first argument, it is the script name (i.e. argv[0]).
62     (set! srcdir (find-srcdir (cdr argv)))
63     (set! %load-path (cons srcdir %load-path))
64     (load-files srcdir)
65
66     (display-argv argv)
67
68     (cgen #:argv argv
69           #:app-name "doc"
70           #:arg-spec doc-arguments
71           #:init doc-init!
72           #:finish doc-finish!
73           #:analyze doc-analyze!)
74     )
75 )
76
77 (cgen-doc (program-arguments))