OSDN Git Service

Hand patch: update to github/binutils.
[pf3gnuchains/pf3gnuchains4x.git] / cgen / cgen-opc.scm
1 ; CPU description file generator for the GNU Binutils.
2 ; This is invoked to build: $arch-desc.[ch], $arch-opinst.c,
3 ; $arch-opc.h, $arch-opc.c, $arch-asm.in, $arch-dis.in, and $arch-ibld.[ch].
4 ; Copyright (C) 2000, 2009 Red Hat, Inc.
5 ; This file is part of CGEN.
6 ;
7 ; This is a standalone script, we don't load anything until we parse the
8 ; -s argument (keeps reliance off of environment variables, etc.).
9
10 ; Load the various support routines.
11
12 (define (load-files srcdir)
13   (load (string-append srcdir "/read.scm"))
14   (load (string-append srcdir "/desc.scm"))
15   (load (string-append srcdir "/desc-cpu.scm"))
16   (load (string-append srcdir "/opcodes.scm"))
17   (load (string-append srcdir "/opc-asmdis.scm"))
18   (load (string-append srcdir "/opc-ibld.scm"))
19   (load (string-append srcdir "/opc-itab.scm"))
20   (load (string-append srcdir "/opc-opinst.scm"))
21 )
22
23 (define opc-arguments
24   (list
25    (list "-OPC" "file" "specify path to .opc file"
26          (lambda (arg) (set-opc-file-path! arg))
27          #f)
28    (list "-H" "file" "generate $arch-desc.h in <file>"
29          #f
30          (lambda (arg) (file-write arg cgen-desc.h)))
31    (list "-C" "file" "generate $arch-desc.c in <file>"
32          #f
33          (lambda (arg) (file-write arg cgen-desc.c)))
34    (list "-O" "file" "generate $arch-opc.h in <file>"
35          #f
36          (lambda (arg) (file-write arg cgen-opc.h)))
37    (list "-P" "file" "generate $arch-opc.c in <file>"
38          #f
39          (lambda (arg) (file-write arg cgen-opc.c)))
40    (list "-Q" "file" "generate $arch-opinst.c in <file>"
41          #f
42          (lambda (arg) (file-write arg cgen-opinst.c)))
43    (list "-B" "file" "generate $arch-ibld.h in <file>"
44          #f
45          (lambda (arg) (file-write arg cgen-ibld.h)))
46    (list "-L" "file" "generate $arch-ibld.in in <file>"
47          #f
48          (lambda (arg) (file-write arg cgen-ibld.in)))
49    (list "-A" "file" "generate $arch-asm.in in <file>"
50          #f
51          (lambda (arg) (file-write arg cgen-asm.in)))
52    (list "-D" "file" "generate $arch-dis.in in <file>"
53          #f
54          (lambda (arg) (file-write arg cgen-dis.in)))
55    )
56 )
57
58 ; (-R "file" "generate $cpu-reloc.h") ; FIXME: wip (rename to -abi.h?)
59 ; (-S "file" "generate cpu-$cpu.c") ; FIXME: wip (bfd's cpu-$cpu.c)
60 ; ((-R) (file-write *arg* cgen-reloc.c))
61 ; ((-S) (file-write *arg* cgen-bfdcpu.c))
62
63 ; Kept global so it's available to the other .scm files.
64 (define srcdir ".")
65
66 ; Scan argv for -s srcdir.
67 ; We can't process any other args until we find the cgen source dir.
68 ; The result is srcdir.
69 ; We assume "-s" isn't the argument to another option.  Unwise, yes.
70 ; Alternatives are to require it to be the first argument or at least preceed
71 ; any option with a "-s" argument, or to put knowledge of the common argument
72 ; set and common argument parsing code in every top level file.
73
74 (define (find-srcdir argv)
75   (let loop ((argv argv))
76     (if (null? argv)
77         (error "`-s srcdir' not present, can't load cgen"))
78     (if (string=? "-s" (car argv))
79         (begin
80           (if (null? (cdr argv))
81               (error "missing srcdir arg to `-s'"))
82           (cadr argv))
83         (loop (cdr argv))))     
84 )
85
86 ; Main routine, parses options and calls generators.
87
88 (define (cgen-opc argv)
89   (let ()
90
91     ; Find and set srcdir, then load all Scheme code.
92     ; Drop the first argument, it is the script name (i.e. argv[0]).
93     (set! srcdir (find-srcdir (cdr argv)))
94     (set! %load-path (cons srcdir %load-path))
95     (load-files srcdir)
96
97     (display-argv argv)
98
99     (cgen #:argv argv
100           #:app-name "opcodes"
101           #:arg-spec opc-arguments
102           #:init opcodes-init!
103           #:finish opcodes-finish!
104           #:analyze opcodes-analyze!)
105     )
106 )
107
108 (cgen-opc (program-arguments))