LEFT | RIGHT |
(no file at all) | |
1 #!/usr/bin/env perl | 1 #!/usr/bin/env perl |
2 # Copyright 2009 The Go Authors. All rights reserved. | 2 # Copyright 2009 The Go Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style | 3 # Use of this source code is governed by a BSD-style |
4 # license that can be found in the LICENSE file. | 4 # license that can be found in the LICENSE file. |
5 | 5 |
6 # This program reads a file containing function prototypes | 6 # This program reads a file containing function prototypes |
7 # (like syscall_darwin.go) and generates system call bodies. | 7 # (like syscall_darwin.go) and generates system call bodies. |
8 # The prototypes are marked by lines beginning with "//sys" | 8 # The prototypes are marked by lines beginning with "//sys" |
9 # and read like func declarations if //sys is replaced by func, but: | 9 # and read like func declarations if //sys is replaced by func, but: |
10 # * The parameter lists must give a name for each argument. | 10 # * The parameter lists must give a name for each argument. |
(...skipping 10 matching lines...) Expand all Loading... |
21 | 21 |
22 use strict; | 22 use strict; |
23 | 23 |
24 my $cmdline = "mksyscall.pl " . join(' ', @ARGV); | 24 my $cmdline = "mksyscall.pl " . join(' ', @ARGV); |
25 my $errors = 0; | 25 my $errors = 0; |
26 my $_32bit = ""; | 26 my $_32bit = ""; |
27 my $plan9 = 0; | 27 my $plan9 = 0; |
28 my $openbsd = 0; | 28 my $openbsd = 0; |
29 my $netbsd = 0; | 29 my $netbsd = 0; |
30 my $dragonfly = 0; | 30 my $dragonfly = 0; |
| 31 my $nacl = 0; |
31 my $arm = 0; # 64-bit value should use (even, odd)-pair | 32 my $arm = 0; # 64-bit value should use (even, odd)-pair |
32 | 33 |
33 if($ARGV[0] eq "-b32") { | 34 if($ARGV[0] eq "-b32") { |
34 $_32bit = "big-endian"; | 35 $_32bit = "big-endian"; |
35 shift; | 36 shift; |
36 } elsif($ARGV[0] eq "-l32") { | 37 } elsif($ARGV[0] eq "-l32") { |
37 $_32bit = "little-endian"; | 38 $_32bit = "little-endian"; |
38 shift; | 39 shift; |
39 } | 40 } |
40 if($ARGV[0] eq "-plan9") { | 41 if($ARGV[0] eq "-plan9") { |
41 $plan9 = 1; | 42 $plan9 = 1; |
42 shift; | 43 shift; |
43 } | 44 } |
44 if($ARGV[0] eq "-openbsd") { | 45 if($ARGV[0] eq "-openbsd") { |
45 $openbsd = 1; | 46 $openbsd = 1; |
46 shift; | 47 shift; |
47 } | 48 } |
48 if($ARGV[0] eq "-netbsd") { | 49 if($ARGV[0] eq "-netbsd") { |
49 $netbsd = 1; | 50 $netbsd = 1; |
50 shift; | 51 shift; |
51 } | 52 } |
52 if($ARGV[0] eq "-dragonfly") { | 53 if($ARGV[0] eq "-dragonfly") { |
53 $dragonfly = 1; | 54 $dragonfly = 1; |
| 55 shift; |
| 56 } |
| 57 if($ARGV[0] eq "-nacl") { |
| 58 $nacl = 1; |
54 shift; | 59 shift; |
55 } | 60 } |
56 if($ARGV[0] eq "-arm") { | 61 if($ARGV[0] eq "-arm") { |
57 $arm = 1; | 62 $arm = 1; |
58 shift; | 63 shift; |
59 } | 64 } |
60 | 65 |
61 if($ARGV[0] =~ /^-/) { | 66 if($ARGV[0] =~ /^-/) { |
62 print STDERR "usage: mksyscall.pl [-b32 | -l32] [file ...]\n"; | 67 print STDERR "usage: mksyscall.pl [-b32 | -l32] [file ...]\n"; |
63 exit 1; | 68 exit 1; |
(...skipping 24 matching lines...) Expand all Loading... |
88 chomp; | 93 chomp; |
89 s/\s+/ /g; | 94 s/\s+/ /g; |
90 s/^\s+//; | 95 s/^\s+//; |
91 s/\s+$//; | 96 s/\s+$//; |
92 my $nonblock = /^\/\/sysnb /; | 97 my $nonblock = /^\/\/sysnb /; |
93 next if !/^\/\/sys / && !$nonblock; | 98 next if !/^\/\/sys / && !$nonblock; |
94 | 99 |
95 # Line must be of the form | 100 # Line must be of the form |
96 # func Open(path string, mode int, perm int) (fd int, errno error) | 101 # func Open(path string, mode int, perm int) (fd int, errno error) |
97 # Split into name, in params, out params. | 102 # Split into name, in params, out params. |
98 » if(!/^\/\/sys(nb)? (\w+)\(([^()]*)\)\s*(?:\(([^()]+)\))?\s*(?:=\s*(SYS_[
A-Z0-9_]+))?$/) { | 103 » if(!/^\/\/sys(nb)? (\w+)\(([^()]*)\)\s*(?:\(([^()]+)\))?\s*(?:=\s*((?i)S
YS_[A-Z0-9_]+))?$/) { |
99 print STDERR "$ARGV:$.: malformed //sys declaration\n"; | 104 print STDERR "$ARGV:$.: malformed //sys declaration\n"; |
100 $errors = 1; | 105 $errors = 1; |
101 next; | 106 next; |
102 } | 107 } |
103 my ($func, $in, $out, $sysname) = ($2, $3, $4, $5); | 108 my ($func, $in, $out, $sysname) = ($2, $3, $4, $5); |
104 | 109 |
105 # Split argument lists on comma. | 110 # Split argument lists on comma. |
106 my @in = parseparamlist($in); | 111 my @in = parseparamlist($in); |
107 my @out = parseparamlist($out); | 112 my @out = parseparamlist($out); |
108 | 113 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 } | 217 } |
213 } else { | 218 } else { |
214 print STDERR "$ARGV:$.: too many arguments to system call\n"; | 219 print STDERR "$ARGV:$.: too many arguments to system call\n"; |
215 } | 220 } |
216 | 221 |
217 # System call number. | 222 # System call number. |
218 if($sysname eq "") { | 223 if($sysname eq "") { |
219 $sysname = "SYS_$func"; | 224 $sysname = "SYS_$func"; |
220 $sysname =~ s/([a-z])([A-Z])/${1}_$2/g; # turn FooBar into Foo_B
ar | 225 $sysname =~ s/([a-z])([A-Z])/${1}_$2/g; # turn FooBar into Foo_B
ar |
221 $sysname =~ y/a-z/A-Z/; | 226 $sysname =~ y/a-z/A-Z/; |
| 227 if($nacl) { |
| 228 $sysname =~ y/A-Z/a-z/; |
| 229 } |
222 } | 230 } |
223 | 231 |
224 # Actual call. | 232 # Actual call. |
225 my $args = join(', ', @args); | 233 my $args = join(', ', @args); |
226 my $call = "$asm($sysname, $args)"; | 234 my $call = "$asm($sysname, $args)"; |
227 | 235 |
228 # Assign return values. | 236 # Assign return values. |
229 my $body = ""; | 237 my $body = ""; |
230 my @ret = ("_", "_", "_"); | 238 my @ret = ("_", "_", "_"); |
231 my $do_errno = 0; | 239 my $do_errno = 0; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 // $cmdline | 304 // $cmdline |
297 // MACHINE GENERATED BY THE COMMAND ABOVE; DO NOT EDIT | 305 // MACHINE GENERATED BY THE COMMAND ABOVE; DO NOT EDIT |
298 | 306 |
299 package syscall | 307 package syscall |
300 | 308 |
301 import "unsafe" | 309 import "unsafe" |
302 | 310 |
303 $text | 311 $text |
304 EOF | 312 EOF |
305 exit 0; | 313 exit 0; |
LEFT | RIGHT |