C To VHDL Converter in A Codesign Environment: June 1994
C To VHDL Converter in A Codesign Environment: June 1994
C To VHDL Converter in A Codesign Environment: June 1994
net/publication/3560856
CITATIONS READS
7 388
3 authors, including:
Sri Parameswaran
UNSW Sydney
234 PUBLICATIONS 1,889 CITATIONS
SEE PROFILE
All content following this page was uploaded by Sri Parameswaran on 15 September 2014.
100
0-8186-6215" $03.00 0 1994 IEEE
Algorithm
(High Level Language
e.g. C)
- ----- - __ _ Automatic
_ _ _CA_D Tools
_
71
Synthesis
Process
(Other Microprocessors,
floating point units,
transputers, etc.)
Timing
Circuitry
to switch
between
processors
- Address bus
101
The consistent use of a familiar language such as C The structure of the code produced by C2VHDL is
means design time for products is greatly reduced. In turn, influenced by the nature of the HSC process, as well as the
time to market for profit oriented products is minimised. limitations imposed by SYNT, in the form of SynVHDL.
By employing testability and simulation in the design A section of C code is converted to VHDL with a single
process, off-the-shelf algorithms may be used in future ENTITY ... PORT description, and a single
products. It is important to reduce design effort through ARCHITECTURE body. SYNT can only synthesize for a
the reuse of standard algorithms. single VHDL process, and requires a totally behavioural
The ability to perform automated design of hardware is VHDL description. The ARCHITECTURE is therefore
essential to the HSC process. The code is initially composed in a behavioural fashion, consisting of only one
described using the C language. VHDL is derived from the process.
language ADA. Consequently it is similar to C as far as The PORT description details the transfer of
standard high-level constructs are concerned. The process information across the hardwarekoftware boundary. In the
we use in C2VHDL is based around this fact. The design case of HSC, the software partition must transfer data
of the system is based on GNU CC [51, and its GCC across this PORT interface. The current implementation
compiler (version 2.4.3.1). The GCC code is centred of SYNT doesn't allow the use of PROCEDURES or
around a YACC 16] description of the C language. FUNCTIONS in VHDL. This will not present a great
The YACC parser (c-parse.y) is composed of problem as far as the HSC process is concerned. Its
productions. When these productions are triggered, the C interest is in converting compound code sections to
code associated with them is executed. By strategically hardware. As chip area is at a premium, it isn't necessary
placing C code on the productions which parse variable to convert larger sections of code. This is in keeping with
declarations, the identifiers and their types are recorded. the concept that critical bottlenecks will consist of several
Once the declaration section is finished this information is compound code sections.
written to the VHDL output file, with the appropriate The conversion to VHDL of assignment constructs
change in style to suit the VHDL code. The same involving various combinations of operators is performed
procedure is applied to all of the C constructs to produce a by firstly breaking the statement into the individual
complete VHDL description of the original C code. calculations. This is achieved by creating temporary
The VHDL code produced from this parsing process is variables for each term in the calculation. This not only
consequently passed through the synthesis package SYNT. maintains the precedence of operators, but also prevents
The form of VHDL implemented by SYNT is called calculations being placed in the conditional clause of IF ...
SynVHDL. It is a proper subset of VHDL, in that there THEN statements and the like.
have been no additions made to the VHDL language. It The size of data types and variables is maintained
does however fail to embrace all of the constructs found in throughout the conversion. By using pointers when
standard VHDL. This in turn limits the ability for passing information across the chip boundary, the data
C2VHDL to convert all constructs found in the C transfer interface is minimised. This is also reflected in
language successfully to VHDL. As SynVHDL improves chip-area utilisation. Usually, the smaller the data
on its subset of VHDL, so too will C2VHDL improve on interface, the fewer the on-chip registers that are required.
its ability to support the full constructs of the C language. The conversion to VHDL of conditional statements is
The limitations aren't seen to be of great significance reasonably straight-forward. The use of temporary
however, with most major C constructs being supported. variables can be seen in the example of Figure 3.
as-IO := g;
as-11 := 3;
IF as-10 > a-1 1 THEN
g := 4;
p <= 6 ;
ELSE
g := 5 ;
p <= 2;
END IF;
~ ~~ ~
102
The temporary variables are optimized out in the before the update, is used in the actual expression. In
synthesis package SYNT. general, all of the standard operators may be applied.
Another example is the switch on case statements
which are converted to CASE on WHEN statements. Each
case must end in a break at this stage. This is to prevent 3 An example
flow on to the next case statement, as this isn’t directly
supported in VHDL. The default is converted to a WHEN The Appendix in section 7 at the end of this paper,
OTHERS construct. It isn’t necessary to include the includes two separate descriptions. The first is a C
default statement, as WHEN OTHERS will be included program listing. The second is the VHDL description
regardless. It isn‘t necessary to have any statements after which our C2VHDL converter has produced. C2VHDL
the default if so desired. If multiple case options are placed does not produce code for all C.
at the same statement in the code, this is handled by As we are limited by the VHDL subset that SYNT
ORing the options together in the equivalent WHEN takes, only those constructs which SYNT can handle have
statement, as can be seen in the example of Figure 4. been implemented. For instance SYNT cannot handle
The handling of f o r loops is through conversion to a floating point numbers, therefore we have not allowed
WHILE loop, with ST1 going before the loop, ST2 is the floating point numbers in C. The VHDL description
conditional of the loop itself and ST3 going as the last which results from this program also does not have an
statement of the loop. This works even for multiple “entity” section. This is because the program can be
statements in any of STI or ST3, as can be seen in the tailored for differing types of input output (such as serial
examples in Figure 5. input output or parallel input output) using the same
The other types of loops are handled similarly. The architecture. Finally, there are a large number of
handling of pre and post incrementing is handled with temporary values. These are removed by SYNT when it
temporary variables. If the post operation occurs within does register allocation. These temporary values also help
other expressions, it is handled by updating the variable SYNT achieve a more efficient hardware synthesis.
itself. The temporary variable, which holds the value
b = 2346; b := 2346;
for (a = 1; a < 10; b = b + 4, a++) { a:= 1;
b=b!3; as-62 := a;
1 as-63 := 10;
WHILE as-62 < as-63 LOOP
as-67 := b;
a s h 8 := 3;
b := as-67 I as-68;
as-64 := b;
as-65 := 4;
b := as-64 + as-65;
as-66 := a;
a : = a + 1;
END LOOP;
104
Handout from First Int'l Workshop on Hardware-Software [ 111 K. O'Brien, M. Rahmouni, P. Kission, M. Aichouchi, A.
Codesign, Estes Park, Colo., 1992. Jemai, H. Ding, A. A. Jerraya, "AMICAL - Interactive
[lo] R. Gupta, CC. Coelho, and G. De Micheli, "Synthesis Architectural Synthesis Based on VHDL - User's
and Simulation of Digital Systems Containing Manual," System-Level Synthesis Group, Laboratoire
Interacting Hardware and Software Components," Proc. TIMMNPG, 46, Avenue Felix Viallet, 3803 1, Grenoble
DAC, IEEE CS Press, Los Alamitos, Calif., Order No. CEDEX, FRANCE
2822, 1992, pp. 225-230. (email: obrien @rhone.imag. fr).
7 Appendix
t--;
#include <stdio.h> continue;
g = g + 1 ;
int i; 1 while (t > OL);
while (t > OL) (
int A(char *h, short j, char r) ( t--;
unsigned char matt; t++;
char s[231; break;
int 8; g=g+1;
long a; I
int b = 46; if ( g > 10)
char d; g = 4;
unsigned char *e; else
char f[157]; g = 5;
long t; (g > 10) ? (g = 4) : (g = 5 ) ;
a = 10 + sizeof(int);
matt = 'a' + 3; a = 15 - sizeof(1ong);
b = i + 4 ; a = 24 sizWf(char);
i = 1; a = 24 / sizeof(float);
b = 1; a = 56 % sizeof(typeof(f)1 ;
i = i + b ; a = sizeof(f);
j=j*5; a = 12 * (-34 && sizeof(typeof(char))) + 52;
j = 5 * j ; a = 12 (-34 I 1 sizeof(typeof(char))) + 52;
g = 0; a = (34 & 23) / 45;
switch (g) ( a = (34 I 23) / 45;
case 1: a += I; a = -34 3;
break; a = 35 4;A
case 2: a += 2; a=a+l;
break; a = a + (b 62);
case 3 : a = a << 3;
case 9: a += 3; a = a >> 2;
break; a / = (7 + b);
case 4: a=a*7;
case 8: a += 4; a = 4 + -7 + !a + -a;
break; a = 4 + !7 + ! O + !a;
1 a = --b;
switch (g) ( b = 2346;
case 5: b / = 3 ; for (a = 1; a < 10; b = b + 4, a++) (
break; b=b/3;
1 I
switch ( g ) { for (a = 1; a < 10; b = b + 4, a++)
case 5 : b=b/3;
for (t = 0; t < 10; tt+) ( if (a < b) (
a * = 4; a = 3;
break; b++ ;
1 I else t
break; b = 4;
default: a++;
a++; )
1 1
do (
105
a := a + 3;
ARCHITECTURE behaviour OF C2VHDL IS
BEGIN WHEN 4 I 8 =>
PROCESS a := a + 4;
VARIABLE ftell : long;
VARIABLE i : int; WHEN OTHERS =>
VARIABLE h : varpointer; NULL;
VARIABLE j : short; END CASE;
VARIABLE r : char;
VARIABLE matt : unsignedchar; CASE g IS
VARIABLE g : int; WHEN 5 =>.
VARIABLE a : long; as-11 := b;
VARIABLE b : int := 46; as-12 := 3;
vARIABLJ3 d : char; b := as-11 1 as-12;
VARIABLE e : varpointer;
VARIABLE t : long; WHEN OTHERS =>
NULL;
VARIABLE as-1 : int4; END CASE;
VARIABLE as-2 : int4;
VARIABLE as-3 : int4; CASE g IS
VARIABLE a s 9 : int4; WHEN 5 =>
VARIABLE 86-5 : int4;
VARIABLE as-6 : int4; t := 0;
VARIABLE as-7 : int2;
VARIABLE as-8 : int4; as-13 := t;
VARIABLE as-9 : int4; as-14 := 10;
VARIABLE as-10 : int2; WHILE as-13 < as-14 LOOP
a := a 4:
and so on .. .
_- EXIT;
VARIABLE as-142 : int4; as-15 := t;
VARIABLE as-143 : int4; t := t + 1;
VARIABLE as-144 : int4; END LOOP;
WHEN OTHERS =>
BEGIN NULL;
as-1 := 97; as-16 := a;
a s 3 := 3; a := a + 1;
matt := as-1 + as-2; END CASE;
I WHEN 3 I 9 =>
106
a := as-52 + as-53;
END LOOP;
a s 3 4 := - 34;
as-29 := g;
as-55 := 1;
as-30 := 10;
IF NOT(as-54 = 0 ) OR NOT(as-55 = 0) THEN
IF as-29 > a s 3 0 THEN
as-56 := 1;
g := 4;
ELSE
a s 3 6 := 0;
ELSE
END IF;
g := 5;
a s 3 7 := 12;
as-58 := (as-56);
END IF;
as-59 := a s 3 7 as-58;
as-60 := 52;
as-31 := g;
a := as-59 + as-60;
as-32 := 10;
IF (as-31 > as-32) THE&'
as-61 := 34;
g := 4;
as-62 := 23;
IF as-61 < 0 THEN
ELSE
as-61 := as-61 + 2147483647;
g := 5;
as-61 := as-61 + I;
END IF;
END IF;
IF as-62 < 0 THEN
a s 4 2 := as-62 + 2147483647;
a s 2 3 := lo;
as-62 := as-62 + 1;
a s 2 4 := 4;
END IF;
a := as-33 + as-34;
as-63 := 0;
a s 3 5 := 15; as-64 := 1;
FOR as3 IN 0 To 31 LOOP
as-36 := 4;
IF ((as-61 / 2) /= ((as-61 + 1) / 2)) AND
a := a s 3 5 - as-36;
((as-62 / 21 /= ((as-62 + 1) / 2)) THEN
as-63 := as-63 + as-64;
as-37 := 24;
END IF;
as-38 := 1;
as-61 := as-61 / 2;
a := as-37 * as-38;
as-62 := as-62 / 2 ;
as-64 := as-64 * 2;
as-39 := 24;
END LOOP;
as-40 := 4;
as-65 := (as-63);
FOR a s j IN 0 TO 31 LOOP
as-66 := 45;
IF ((as-39 / 2) /= ((as-39 + 1) / 2)) THEN
FOR a s 2 IN 0 TO 31 LOOP
as-4lfasj) := '1'
IF ((as-65 / 2) f = ((as-65 + 1) / 2)) THEN
ELSE
as-67fasj) := '1'
as-4ltasj) := ' 0 '
ELSE
END IF;
as-67tasj) := '0'
IF ((as-40 / 2) /= ((as-40 + 1) / 2)) THEN
END IF;
as-42(asjt := '1'
IF ((as-66 / 21 /= ((as-66 + 1) / 2 ) ) THEN
ELSE
as_68(asjt := '1'
as-42fasj) := '0'
USE
END IF;
as-68tas3) := ' 0 '
END m P
a := as-44;
END IF;
END LOOP
a := as-70;
as-45 := 56;
as-46 := 157;
as-71 := 34;
a := a s 9 5 MOD as-46;
as-72 := 23;
IF as-71 -z 0 THEN
a := 157;
as-71 := as-71 + 2147483647;
as-47 := - 34; as-71 := as-71 + 1;
END IF;
as-48 := 1;
IF as-72 -z 0 THEN
IF NOTlaS-47 = 0) AND "(as-48 = 0) THEN
as-72 := as-72 + 2147483647;
as-49 := 1;
as-72 := as-72 + 1;
ELSE
END IF;
as-49 := 0;
as-73 := 0;
EM) IF;
as-74 := 1;
as-50 := 12;
FOR a s j IN 0 TO 31 LOOP
a k 5 l := (as-49);
IF ((as-71 / 2) /= ((as-71 + 1) / 2)) OR
as-52 := as-50 as-51;
(as-72 / 2 ) /= ((as-72 + 1) / 2)) THEN
as-53 := 52;
as-73 := as-73 + as-74;
END IF;
as-71 := as-71 / 2;
107
as-72 := as-72 / 2; as-101 := a;
as-74 := as-74 2; as-102 := 7;
END LOOP; a := as-101 * as-102;
as-75 := (as-73);
as-76 := 45; as-103 := 4;
FOR a s 2 IN 0 TO 31 Ixx)P as-104 := (2147483647 - 7);
IF ((as-75 / 2) /= ((as-75 + 1) / 2 ) ) THEN IF a = 0 THEN
as_77(asj) := '1' as-105 := 1;
ELSE ELSE
as-77(asj) := ' 0 ' as-105 := 0;
END IF; END IF;
IF ((as-76 / 2) /= ((as-76 + 1) / 2)) THEN as-106 := as-103 + as-104;
as_78(asj) := '1' as-107 := as-105;
ELSE as-108 := as-106 + as-107;
as,78(asj) := ' 0 ' as-109 := (2147483647 - a);
END IF; a := as-108 + as-109;
END LOOP
a := as-80; IF 7 = 0 THEN
as-110 := 1;
as-81 := - 34; ELSE
as-82 := 3; as-110 := 0;
a := as-81 as-82; END IF;
as-111 := 4;
as33 := 35; as-112 := as-110;
as-84 := 4; IF 0 = 0 THEN
IF as-83 < 0 THEN as-113 := 1;
as-83 := as-83 + 2147483647; ELSE
as-83 := as-83 + 1; as-113 := 0;
PID IF; END IF;
IF as-84 < 0 THEN as-114 := as-111 + as-112;
as-84 := as-84 + 2147483647; as-115 := as-113;
as34 := as-84 + 1; IF a = 0 THEN
END IF; as-116 := 1;
a s 3 5 := 0; ELSE
as-86 := 1; as-116 := 0;
FOR a s j IN 0 TO 31 LOOP END IF;
IF ((as-83 / 2) / = ((as-83 + 1) / 2)) XOR as-117 := as-114 + as-115;
((as-84 / 2) / = ((as-84 + 1) 1 2)) THEN as-118 := as-116;
as-85 := as-85 + as-86; a := as-117 + as-118;
END IF;
a s 3 3 := as-83 / 2; b := b - 1;
as-84 := as34 / 2; a := b:
as-86 : = as-86 2;
END L m P ; b := 2346;
a := as-85;
as-87 := a; a := 1;
as-88 := 1;
a := a s 3 7 + as-88; as-119 := a;
as-120 := 10;
as-89 := b; WHILE as-119 < as-120 LOOP
as-90 := 62; as-124 := b;
as-91 := a; as-125 := 3;
as-92 := (as-89 as-90); FOR a s 2 IN 0 TO 31 LOOP
a := as-91 + as-92; IF ((as-124 / 2 ) / = ((as-124 + 1) / 2 ) )
THEN
as-93 := a; as-126(as-j) := '1'
as-94 := 3; ELSE
a := as-93 * (2 ** as-94); as-126(as-j) := '0'
END IF;
as-95 := a; IF ((as-125 / 2) / = ((as-125 + 1) / 2 ) )
as-96 := 2; THEN
a := as-95 / (2 ** as-96); as_127(asj) := '1'
ELSE
as-97 := 7; as-127(as-j) := '0'
as48 := b; PID IF;
as-99 := a; PID LOOP
as-100 := (as-97 + as-98); b : = as-129;
a := as-99 / as-100;
108
b := as-140;
as-121 := b;
as-122 := 4; as-132 := b;
b := as-121 + as-122; as-133 := 4;
b := as-132 + as-133;
as-123 := a;
a := a + 1; as-134 := a;
END LOOP; a := a + 1;
END LOOP;
a := 1;
as-141 := a;
as-130 := a; as-142 := b;
as-131 := 10; I F as-141 < as-142 THEN
WHILE as-130 < as-131 LQOP a := 3;
as-135 := b;
as-136 := 3; as-143 := b;
FOR a s 2 IN 0 TO 31 LOOP b : = b + 1;
I F ((as-135 / 2) / = ((as-135 + 1) / 2 ) ) ELSE
THEN
b := 4;
as-137 (as-j) := ' 1 '
ELSE as-144 := a;
as_137(asj) : = ' 0 ' a := a + 1;
END I F ; END IF;
I F ((as-136 / 2) / = ((as-136 + 1) / 2 ) )
THEN WAIT ON clk UNTIL (in-rdy = '1');
as-138(as-j) := '1' END PROCESS;
ELSE END behaviour;
as,138(as-j) := ' 0 '
END I F ;
END LOOP
109