| Index: tools/generate-trig-table.py
|
| diff --git a/tools/lexer_generator/test_suite.py b/tools/generate-trig-table.py
|
| similarity index 53%
|
| copy from tools/lexer_generator/test_suite.py
|
| copy to tools/generate-trig-table.py
|
| index 19d0b07efeedf7604a29aa9eaa66e1be3d1337bc..14d4472aadb28ad5947f83a42b83edec568a12cf 100644
|
| --- a/tools/lexer_generator/test_suite.py
|
| +++ b/tools/generate-trig-table.py
|
| @@ -1,3 +1,5 @@
|
| +#!/usr/bin/env python
|
| +#
|
| # Copyright 2013 the V8 project authors. All rights reserved.
|
| # Redistribution and use in source and binary forms, with or without
|
| # modification, are permitted provided that the following conditions are
|
| @@ -25,22 +27,58 @@
|
| # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
| -from unittest import TestLoader, TextTestRunner, TestSuite
|
| +# This is a utility for populating the lookup table for the
|
| +# approximation of trigonometric functions.
|
| +
|
| +import sys, math
|
| +
|
| +SAMPLES = 1800
|
| +
|
| +TEMPLATE = """\
|
| +// Copyright 2013 Google Inc. All Rights Reserved.
|
| +
|
| +// This file was generated from a python script.
|
| +
|
| +#include "v8.h"
|
| +#include "trig-table.h"
|
|
|
| -from automata_test import *
|
| -from code_generator_test import *
|
| -from lexer_test import *
|
| -from rule_parser_test import *
|
| -from transition_key_test import *
|
| +namespace v8 {
|
| +namespace internal {
|
| +
|
| + const double TrigonometricLookupTable::kSinTable[] =
|
| + { %(sine_table)s };
|
| + const double TrigonometricLookupTable::kCosXIntervalTable[] =
|
| + { %(cosine_table)s };
|
| + const int TrigonometricLookupTable::kSamples = %(samples)i;
|
| + const int TrigonometricLookupTable::kTableSize = %(table_size)i;
|
| + const double TrigonometricLookupTable::kSamplesOverPiHalf =
|
| + %(samples_over_pi_half)s;
|
| +
|
| +} } // v8::internal
|
| +"""
|
| +
|
| +def main():
|
| + pi_half = math.pi / 2
|
| + interval = pi_half / SAMPLES
|
| + sin = []
|
| + cos_times_interval = []
|
| + table_size = SAMPLES + 2
|
| +
|
| + for i in range(0, table_size):
|
| + sample = i * interval
|
| + sin.append(repr(math.sin(sample)))
|
| + cos_times_interval.append(repr(math.cos(sample) * interval))
|
| +
|
| + output_file = sys.argv[1]
|
| + output = open(str(output_file), "w")
|
| + output.write(TEMPLATE % {
|
| + 'sine_table': ','.join(sin),
|
| + 'cosine_table': ','.join(cos_times_interval),
|
| + 'samples': SAMPLES,
|
| + 'table_size': table_size,
|
| + 'samples_over_pi_half': repr(SAMPLES / pi_half)
|
| + })
|
|
|
| if __name__ == "__main__":
|
| - loader = TestLoader()
|
| - suite = TestSuite((
|
| - loader.loadTestsFromTestCase(TransitionKeyTestCase),
|
| - loader.loadTestsFromTestCase(AutomataTestCase),
|
| - loader.loadTestsFromTestCase(RuleParserTestCase),
|
| - loader.loadTestsFromTestCase(LexerTestCase),
|
| - loader.loadTestsFromTestCase(CodeGeneratorTestCase),
|
| - ))
|
| - runner = TextTestRunner(verbosity = 2)
|
| - runner.run(suite)
|
| + main()
|
| +
|
|
|