OSDN Git Service

change build directory to ./tmp-doc
[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 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   ; Fix up Scheme to be what we use (guile is always in flux).
13   (primitive-load-path (string-append srcdir "/fixup.scm"))
14
15   (load (string-append srcdir "/read.scm"))
16   (load (string-append srcdir "/desc.scm"))
17   (load (string-append srcdir "/desc-cpu.scm"))
18   (load (string-append srcdir "/html.scm"))
19 )
20
21 (define doc-arguments
22   (list
23    (list '-H "file" "generate $arch.html in <file>"
24          (lambda (arg) (file-write arg cgen.html)))
25    ; can't use '-I because that gets interpreted as a complex number
26    (list (string->symbol "-I") "file" "generate $arch-insn.html in <file>"
27          (lambda (arg) (file-write arg cgen-insn.html)))
28    (list '-N "file" "specify name of insn.html file"
29          (lambda (arg) (set! *insn-html-file-name* arg)))
30    )
31 )
32
33 ; Kept global so it's available to the other .scm files.
34 (define srcdir ".")
35
36 ; Scan argv for -s srcdir.
37 ; We can't process any other args until we find the cgen source dir.
38 ; The result is srcdir.
39 ; We assume "-s" isn't the argument to another option.  Unwise, yes.
40 ; Alternatives are to require it to be the first argument or at least preceed
41 ; any option with a "-s" argument, or to put knowledge of the common argument
42 ; set and common argument parsing code in every top level file.
43
44 (define (find-srcdir argv)
45   (let loop ((argv argv))
46     (if (null? argv)
47         (error "`-s srcdir' not present, can't load cgen"))
48     (if (string=? "-s" (car argv))
49         (begin
50           (if (null? (cdr argv))
51               (error "missing srcdir arg to `-s'"))
52           (cadr argv))
53         (loop (cdr argv))))     
54 )
55
56 ; Main routine, parses options and calls generators.
57
58 (define (cgen-doc argv)
59   (let ()
60
61     ; Find and set srcdir, then load all Scheme code.
62     ; Drop the first argument, it is the script name (i.e. argv[0]).
63     (set! srcdir (find-srcdir (cdr argv)))
64     (set! %load-path (cons srcdir %load-path))
65     (load-files srcdir)
66
67     (display-argv argv)
68
69     (cgen #:argv argv
70           #:app-name "doc"
71           #:arg-spec doc-arguments
72           #:init doc-init!
73           #:finish doc-finish!
74           #:analyze doc-analyze!)
75     )
76 )
77
78 (cgen-doc (program-arguments))