OSDN Git Service

81cfd0ff1956743c1d3fc7f7e92e3292292d8460
[pf3gnuchains/pf3gnuchains3x.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 ; Records the -OPC arg which specifies the path to the .opc file.
24 (define -opc-file-path #f)
25 (define (opc-file-path)
26   (if -opc-file-path
27       -opc-file-path
28       (error ".opc file unspecified, missing -OPC argument"))
29 )
30
31 (define opc-arguments
32   (list
33    (list "-OPC" "file" "specify path to .opc file"
34          (lambda (arg) (set! -opc-file-path arg))
35          #f)
36    (list "-H" "file" "generate $arch-desc.h in <file>"
37          #f
38          (lambda (arg) (file-write arg cgen-desc.h)))
39    (list "-C" "file" "generate $arch-desc.c in <file>"
40          #f
41          (lambda (arg) (file-write arg cgen-desc.c)))
42    (list "-O" "file" "generate $arch-opc.h in <file>"
43          #f
44          (lambda (arg) (file-write arg cgen-opc.h)))
45    (list "-P" "file" "generate $arch-opc.c in <file>"
46          #f
47          (lambda (arg) (file-write arg cgen-opc.c)))
48    (list "-Q" "file" "generate $arch-opinst.c in <file>"
49          #f
50          (lambda (arg) (file-write arg cgen-opinst.c)))
51    (list "-B" "file" "generate $arch-ibld.h in <file>"
52          #f
53          (lambda (arg) (file-write arg cgen-ibld.h)))
54    (list "-L" "file" "generate $arch-ibld.in in <file>"
55          #f
56          (lambda (arg) (file-write arg cgen-ibld.in)))
57    (list "-A" "file" "generate $arch-asm.in in <file>"
58          #f
59          (lambda (arg) (file-write arg cgen-asm.in)))
60    (list "-D" "file" "generate $arch-dis.in in <file>"
61          #f
62          (lambda (arg) (file-write arg cgen-dis.in)))
63    )
64 )
65
66 ; (-R "file" "generate $cpu-reloc.h") ; FIXME: wip (rename to -abi.h?)
67 ; (-S "file" "generate cpu-$cpu.c") ; FIXME: wip (bfd's cpu-$cpu.c)
68 ; ((-R) (file-write *arg* cgen-reloc.c))
69 ; ((-S) (file-write *arg* cgen-bfdcpu.c))
70
71 ; Kept global so it's available to the other .scm files.
72 (define srcdir ".")
73
74 ; Scan argv for -s srcdir.
75 ; We can't process any other args until we find the cgen source dir.
76 ; The result is srcdir.
77 ; We assume "-s" isn't the argument to another option.  Unwise, yes.
78 ; Alternatives are to require it to be the first argument or at least preceed
79 ; any option with a "-s" argument, or to put knowledge of the common argument
80 ; set and common argument parsing code in every top level file.
81
82 (define (find-srcdir argv)
83   (let loop ((argv argv))
84     (if (null? argv)
85         (error "`-s srcdir' not present, can't load cgen"))
86     (if (string=? "-s" (car argv))
87         (begin
88           (if (null? (cdr argv))
89               (error "missing srcdir arg to `-s'"))
90           (cadr argv))
91         (loop (cdr argv))))     
92 )
93
94 ; Main routine, parses options and calls generators.
95
96 (define (cgen-opc argv)
97   (let ()
98
99     ; Find and set srcdir, then load all Scheme code.
100     ; Drop the first argument, it is the script name (i.e. argv[0]).
101     (set! srcdir (find-srcdir (cdr argv)))
102     (set! %load-path (cons srcdir %load-path))
103     (load-files srcdir)
104
105     (display-argv argv)
106
107     (cgen #:argv argv
108           #:app-name "opcodes"
109           #:arg-spec opc-arguments
110           #:init opcodes-init!
111           #:finish opcodes-finish!
112           #:analyze opcodes-analyze!)
113     )
114 )
115
116 (cgen-opc (program-arguments))