OSDN Git Service

2007-11-05 Dave Brolley <brolley@redhat.com>
[pf3gnuchains/sourceware.git] / cgen / cgen-intrinsics.scm
1 ; GCC "intrinsics" file entry point.
2 ;
3 ; This is invoked to build support files for registering intrinsic
4 ; functions within gcc. this code has a fair bit of target-specific
5 ; code in it. it's not a general-purpose module yet.
6 ;
7 ; Copyright (C) 2000 Red Hat, Inc.
8 ; This file is part of CGEN.
9 ;
10 ; This is a standalone script, we don't load anything until we parse the
11 ; -s argument (keeps reliance off of environment variables, etc.).
12
13 ; Load the various support routines.
14
15 (define (load-files srcdir)
16   ; Fix up Scheme to be what we use (guile is always in flux).
17   (primitive-load-path (string-append srcdir "/fixup.scm"))
18   (primitive-load-path (string-append srcdir "/guile.scm"))
19
20   (load (string-append srcdir "/read.scm"))
21   (load (string-append srcdir "/intrinsics.scm"))
22 )
23
24 (define intrinsics-isas '())
25
26 (define intrinsics-arguments
27   (list
28    (list "-K" "isa" "keep isa <isa> in intrinsics" #f
29          (lambda (args)
30            (for-each 
31             (lambda (arg) (set! intrinsics-isas (cons (string->symbol arg) intrinsics-isas)))
32             (string-cut args #\,))))
33    (list "-M" "file" "generate insns.md in <file>" #f
34          (lambda (arg) (file-write arg insns.md)))
35    (list "-N" "file" "generate intrinsics.h in <file>" #f
36          (lambda (arg) (file-write arg intrinsics.h)))
37    (list "-P" "file" "generate intrinsic-protos.h in <file>" #f
38          (lambda (arg) (file-write arg intrinsic-protos.h)))
39    (list "-T" "file" "generate intrinsic-testsuite.c in <file>" #f
40          (lambda (arg) (file-write arg intrinsic-testsuite.c)))))
41
42 ; Kept global so it's available to the other .scm files.
43 (define srcdir ".")
44
45 ; Scan argv for -s srcdir.
46 ; We can't process any other args until we find the cgen source dir.
47 ; The result is srcdir.
48 ; We assume "-s" isn't the argument to another option.  Unwise, yes.
49 ; Alternatives are to require it to be the first argument or at least preceed
50 ; any option with a "-s" argument, or to put knowledge of the common argument
51 ; set and common argument parsing code in every top level file.
52
53 (define (find-srcdir argv)
54   (let loop ((argv argv))
55     (if (null? argv)
56         (error "`-s srcdir' not present, can't load cgen"))
57     (if (string=? "-s" (car argv))
58         (begin
59           (if (null? (cdr argv))
60               (error "missing srcdir arg to `-s'"))
61           (cadr argv))
62         (loop (cdr argv))))     
63 )
64
65 ; Main routine, parses options and calls generators.
66
67 (define (cgen-intrinsics argv)
68   (let ()
69
70     ; Find and set srcdir, then load all Scheme code.
71     ; Drop the first argument, it is the script name (i.e. argv[0]).
72     (set! srcdir (find-srcdir (cdr argv)))
73     (set! %load-path (cons srcdir %load-path))
74     (load-files srcdir)
75
76     (display-argv argv)
77
78     (cgen #:argv argv
79           #:app-name "intrinsics"
80           #:arg-spec intrinsics-arguments
81           #:analyze intrinsics-analyze!)
82     )
83 )
84
85 (cgen-intrinsics (program-arguments))