OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # Copyright 2014 the V8 project authors. All rights reserved. | 3 # Copyright 2013 the V8 project authors. All rights reserved. |
4 # Redistribution and use in source and binary forms, with or without | 4 # Redistribution and use in source and binary forms, with or without |
5 # modification, are permitted provided that the following conditions are | 5 # modification, are permitted provided that the following conditions are |
6 # met: | 6 # met: |
7 # | 7 # |
8 # * Redistributions of source code must retain the above copyright | 8 # * Redistributions of source code must retain the above copyright |
9 # notice, this list of conditions and the following disclaimer. | 9 # notice, this list of conditions and the following disclaimer. |
10 # * Redistributions in binary form must reproduce the above | 10 # * Redistributions in binary form must reproduce the above |
11 # copyright notice, this list of conditions and the following | 11 # copyright notice, this list of conditions and the following |
12 # disclaimer in the documentation and/or other materials provided | 12 # disclaimer in the documentation and/or other materials provided |
13 # with the distribution. | 13 # with the distribution. |
14 # * Neither the name of Google Inc. nor the names of its | 14 # * Neither the name of Google Inc. nor the names of its |
15 # contributors may be used to endorse or promote products derived | 15 # contributors may be used to endorse or promote products derived |
16 # from this software without specific prior written permission. | 16 # from this software without specific prior written permission. |
17 # | 17 # |
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 | 29 |
30 # This utility concatenates several files into one. On Unix-like systems | 30 # This is a utility for populating the lookup table for the |
31 # it is equivalent to: | 31 # approximation of trigonometric functions. |
32 # cat file1 file2 file3 ...files... > target | |
33 # | |
34 # The reason for writing a seperate utility is that 'cat' is not available | |
35 # on all supported build platforms, but Python is, and hence this provides | |
36 # us with an easy and uniform way of doing this on all platforms. | |
37 | 32 |
38 import optparse | 33 import sys, math |
39 | 34 |
| 35 SAMPLES = 1800 |
40 | 36 |
41 def Concatenate(filenames): | 37 TEMPLATE = """\ |
42 """Concatenate files. | 38 // Copyright 2013 Google Inc. All Rights Reserved. |
43 | 39 |
44 Args: | 40 // This file was generated from a python script. |
45 files: Array of file names. | |
46 The last name is the target; all earlier ones are sources. | |
47 | 41 |
48 Returns: | 42 #include "src/v8.h" |
49 True, if the operation was successful. | 43 #include "src/trig-table.h" |
50 """ | |
51 if len(filenames) < 2: | |
52 print "An error occured generating %s:\nNothing to do." % filenames[-1] | |
53 return False | |
54 | 44 |
55 try: | 45 namespace v8 { |
56 with open(filenames[-1], "wb") as target: | 46 namespace internal { |
57 for filename in filenames[:-1]: | |
58 with open(filename, "rb") as current: | |
59 target.write(current.read()) | |
60 return True | |
61 except IOError as e: | |
62 print "An error occured when writing %s:\n%s" % (filenames[-1], e) | |
63 return False | |
64 | 47 |
| 48 const double TrigonometricLookupTable::kSinTable[] = |
| 49 { %(sine_table)s }; |
| 50 const double TrigonometricLookupTable::kCosXIntervalTable[] = |
| 51 { %(cosine_table)s }; |
| 52 const int TrigonometricLookupTable::kSamples = %(samples)i; |
| 53 const int TrigonometricLookupTable::kTableSize = %(table_size)i; |
| 54 const double TrigonometricLookupTable::kSamplesOverPiHalf = |
| 55 %(samples_over_pi_half)s; |
| 56 |
| 57 } } // v8::internal |
| 58 """ |
65 | 59 |
66 def main(): | 60 def main(): |
67 parser = optparse.OptionParser() | 61 pi_half = math.pi / 2 |
68 parser.set_usage("""Concatenate several files into one. | 62 interval = pi_half / SAMPLES |
69 Equivalent to: cat file1 ... > target.""") | 63 sin = [] |
70 (options, args) = parser.parse_args() | 64 cos_times_interval = [] |
71 exit(0 if Concatenate(args) else 1) | 65 table_size = SAMPLES + 2 |
72 | 66 |
| 67 for i in range(0, table_size): |
| 68 sample = i * interval |
| 69 sin.append(repr(math.sin(sample))) |
| 70 cos_times_interval.append(repr(math.cos(sample) * interval)) |
| 71 |
| 72 output_file = sys.argv[1] |
| 73 output = open(str(output_file), "w") |
| 74 output.write(TEMPLATE % { |
| 75 'sine_table': ','.join(sin), |
| 76 'cosine_table': ','.join(cos_times_interval), |
| 77 'samples': SAMPLES, |
| 78 'table_size': table_size, |
| 79 'samples_over_pi_half': repr(SAMPLES / pi_half) |
| 80 }) |
73 | 81 |
74 if __name__ == "__main__": | 82 if __name__ == "__main__": |
75 main() | 83 main() |
OLD | NEW |