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

Subversion Repositories tcp_socket

[/] [tcp_socket/] [trunk/] [chips2/] [documents/] [compiler.rst] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 jondawson
C2VHDL
2
======
3
 
4
C2VHDL converts a subset of the C language into Verilog.
5
 
6
The project aims to provide:
7
 
8
 - A simpler, higher level alternative to VHDL and VERILOG.
9
 - A useful C subset which maps well onto FPGA devices.
10
 - A very simple implementation which is easy to modify maintain and distribute.
11
 - A fast and flexible verification environment using C.
12
 
13
Running existing C programs in FPGAs is not a primary objective.
14
 
15
Note:
16
 
17
C2VHDL was designed to target the VHDL language, but this branch outputs code to verilog.
18
 
19
What it Does
20
============
21
 
22
C2VHDL implements a decent subset of C, enough to do useful things in an FPGA:
23
 
24
 - most statements: if, while, for, break, continue, return, switch, case, default
25
 - functions
26
 - single dimension arrays
27
 - c style comments
28
 - c++ style comments
29
 - contstant folding
30
 - dead code removal
31
 - instruction level concurrency
32
 
33
What it Doesn't
34
===============
35
 
36
C2VHDL doesn't implement these thing that either don't work well in FPGAs, or that
37
I just haven't been implemented yet:
38
 
39
 - no libc
40
 - no float or double
41
 - no recursion
42
 - no pointers
43
 - no goto statement
44
 - no forward declarations
45
 - no struct
46
 - no union
47
 
48
Download
49
========
50
 
51
Python script: `c2vhdl.py`_.
52
 
53
.. _`c2vhdl.py` : https://github.com/downloads/dawsonjon/C2VHDL/c2vhdl.py
54
 
55
Installation
56
=============
57
 
58
1. First `install Python`_. You need *Python* 2.3 or later, but not *Python* 3.
59
2. Place c2vhdl.py somwhere in your execution path, or execute locally.
60
3. Thats it! You can now run c2vhdl.py
61
 
62
.. _`install Python` : http://python.org/download
63
 
64
How to use it
65
=============
66
 
67
Each C file is implemented as a Verilog component that can be used in a design.
68
 
69
Execution Model
70
---------------
71
 
72
When a design is reset, execution starts with the last function defined in
73
the C file. This need not be called *main*. The name of the last function
74
will be used as the name for the generated Verilog component. The C program will
75
appear to execute in sequence, although the compiler will execute instructions
76
concurrently if it does not affect the outcome of the program. This will allow
77
your program to take advantage of the inherent parallelism present in a hardware
78
design.
79
 
80
Of course if you want even more parallelism, you can have many C2VHDL
81
components in your device at the same time.
82
 
83
Adding Inputs and Outputs
84
-------------------------
85
 
86
If you want to add an input or an output to your Verilog component, you can achieve
87
this by calling functions with *special* names::
88
 
89
  int temp;
90
  temp = input_spam() //reads from an input called spam
91
  temp = input_eggs() //reads from an input called eggs
92
  output_fish(temp)   //writes to an output called fish
93
 
94
Reading or writing from inputs and outputs causes program execution to block
95
until data is available. This syncronises data tranfers with other components
96
executing in the same device, this method of passing data beween concurrent
97
processes is much simpler than the mutex/lock/semaphore mechanisms used in
98
multithreaded applications.
99
 
100
If you don't want to commit yourself to reading and input and blocking
101
execution, you can check if data is ready::
102
 
103
  int temp;
104
  if(ready_spam()){
105
    temp = input_spam()
106
  }
107
 
108
There is no equivilent function to check if an output is ready to recieve data,
109
this could cause deadlocks if both the sending and receiving end were waiting
110
for one another.
111
 
112
Debugging
113
---------
114
 
115
Since the language is a subset of C, you can use the usual C based tools for
116
debugging.  If you want to know what is going on in a Verilog simulation, you can
117
use these builtin debug functions::
118
 
119
  assert(0); //This will fail
120
  assert(a == 12); //This will fail if a is not 12
121
  report(1); //This will cause the simulator to print 1
122
  report(temp); //This will cause the simulator to print the value of temp
123
 
124
Command Line Usage
125
------------------
126
 
127
c2vhdl.py [options] 
128
 
129
compile options:
130
 
131
  no_reuse      : prevent register resuse
132
 
133
  no_concurrent : prevent concurrency
134
 
135
tool options:
136
 
137
  iverilog      : compiles using the iverilog compiler
138
 
139
  run           : runs compiled code, used with iverilog option

powered by: WebSVN 2.1.0

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