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.
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.).
10 ; Load the various support routines.
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"))
23 ; Records the -OPC arg which specifies the path to the .opc file.
24 (define -opc-file-path #f)
25 (define (opc-file-path)
28 (error ".opc file unspecified, missing -OPC argument"))
33 (list "-OPC" "file" "specify path to .opc file"
34 (lambda (arg) (set! -opc-file-path arg))
36 (list "-H" "file" "generate $arch-desc.h in <file>"
38 (lambda (arg) (file-write arg cgen-desc.h)))
39 (list "-C" "file" "generate $arch-desc.c in <file>"
41 (lambda (arg) (file-write arg cgen-desc.c)))
42 (list "-O" "file" "generate $arch-opc.h in <file>"
44 (lambda (arg) (file-write arg cgen-opc.h)))
45 (list "-P" "file" "generate $arch-opc.c in <file>"
47 (lambda (arg) (file-write arg cgen-opc.c)))
48 (list "-Q" "file" "generate $arch-opinst.c in <file>"
50 (lambda (arg) (file-write arg cgen-opinst.c)))
51 (list "-B" "file" "generate $arch-ibld.h in <file>"
53 (lambda (arg) (file-write arg cgen-ibld.h)))
54 (list "-L" "file" "generate $arch-ibld.in in <file>"
56 (lambda (arg) (file-write arg cgen-ibld.in)))
57 (list "-A" "file" "generate $arch-asm.in in <file>"
59 (lambda (arg) (file-write arg cgen-asm.in)))
60 (list "-D" "file" "generate $arch-dis.in in <file>"
62 (lambda (arg) (file-write arg cgen-dis.in)))
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))
71 ; Kept global so it's available to the other .scm files.
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.
82 (define (find-srcdir argv)
83 (let loop ((argv argv))
85 (error "`-s srcdir' not present, can't load cgen"))
86 (if (string=? "-s" (car argv))
88 (if (null? (cdr argv))
89 (error "missing srcdir arg to `-s'"))
94 ; Main routine, parses options and calls generators.
96 (define (cgen-opc argv)
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))
109 #:arg-spec opc-arguments
111 #:finish opcodes-finish!
112 #:analyze opcodes-analyze!)
116 (cgen-opc (program-arguments))