OpenCores
URL https://opencores.org/ocsvn/tcp_socket/tcp_socket/trunk

Subversion Repositories tcp_socket

[/] [tcp_socket/] [trunk/] [chips2/] [examples/] [example_3.py] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 jondawson
#!/usr/bin/env python
2
 
3
import subprocess
4
import atexit
5
from math import pi
6
 
7
children = []
8
def cleanup():
9
    for child in children:
10
        print "Terminating child process"
11
        child.terminate()
12
atexit.register(cleanup)
13
 
14
def run_c(file_name):
15
    process = subprocess.Popen(["../c2verilog", "iverilog", "run", str(file_name)])
16
    children.append(process)
17
    process.wait()
18
    children.remove(process)
19
 
20
def test():
21
    run_c("sort.c")
22
 
23
def indent(lines):
24
    return "\n    ".join(lines.splitlines())
25
 
26
def generate_docs():
27
 
28
    documentation = """
29
 
30
Implement Quicksort
31
-------------------
32
 
33
This example sorts an array of data using the
34
`Quick Sort algorithm <http://en.wikipedia.org/wiki/Quicksort>`_
35
 
36
The quick-sort algorithm is a recurrsive algorithm, but *Chips* does not
37
support recursive functions. Since the level of recursion is bounded, it is
38
possible to implement the function using an explicitly created stack.
39
 
40
.. code-block:: c
41
 
42
    %s
43
 
44
The algorithm is tested using an array containing out of order values. The program correctly sorts the array::
45
 
46
 
47
 
48
 
49
 
50
 
51
 
52
 
53
 
54
 
55
 
56
 
57
 
58
 
59
 
60
 
61
 
62
         1 (report at line: 122 in file: sort.c)
63
         2 (report at line: 122 in file: sort.c)
64
         3 (report at line: 122 in file: sort.c)
65
         4 (report at line: 122 in file: sort.c)
66
         5 (report at line: 122 in file: sort.c)
67
         6 (report at line: 122 in file: sort.c)
68
         7 (report at line: 122 in file: sort.c)
69
         8 (report at line: 122 in file: sort.c)
70
         9 (report at line: 122 in file: sort.c)
71
        10 (report at line: 122 in file: sort.c)
72
        11 (report at line: 122 in file: sort.c)
73
        12 (report at line: 122 in file: sort.c)
74
        13 (report at line: 122 in file: sort.c)
75
        14 (report at line: 122 in file: sort.c)
76
        15 (report at line: 122 in file: sort.c)
77
        16 (report at line: 122 in file: sort.c)
78
 
79
"""%indent(open("sort.c").read())
80
 
81
    document = open("../docs/source/examples/example_3.rst", "w").write(documentation)
82
 
83
test()
84
generate_docs()

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.