source: trunk/IPs/systemC/processor/Morpheo/Behavioural/src/Vhdl_std_logic.cpp @ 95

Last change on this file since 95 was 95, checked in by rosiere, 16 years ago

1) Update Prediction Table - New architecture (systemC) done (and tested) -> need change interface in top level
2) Change documentation on VHDL generation
3) Change VHDL constant (case std_logic and std_logic_vector)

  • Property svn:keywords set to Id
File size: 3.6 KB
Line 
1#ifdef VHDL
2
3/*
4 * $Id: Vhdl_std_logic.cpp 95 2008-12-16 16:24:26Z rosiere $
5 *
6 * [ Description ]
7 *
8 */
9
10#include <math.h>
11#include "Behavioural/include/Vhdl.h"
12#include "Common/include/ToBase2.h"
13
14namespace morpheo              {
15namespace behavioural          {
16
17#undef  FUNCTION
18#define FUNCTION "Vhdl::std_logic"
19  std::string std_logic (uint32_t size)
20  {
21    log_printf(FUNC,Behavioural,FUNCTION,"Begin");
22
23    std::string type;
24
25    if (size == 1)
26      type = "std_logic";
27    else
28      type = "std_logic_vector(" + toString(size-1) + " downto 0)";
29
30    log_printf(FUNC,Behavioural,FUNCTION,"End");
31
32    return type;
33  };
34
35#undef  FUNCTION
36#define FUNCTION "Vhdl::std_logic_conv"
37  std::string std_logic_conv (uint32_t size, std::string value)
38  {
39    log_printf(FUNC,Behavioural,FUNCTION,"Begin");
40
41    std::string conv;
42
43    if (size == 1)
44      conv = "'"+toString(value)+"'";
45    else
46      conv = "conv_std_logic_vector("+value+","+toString(size)+")";
47
48    log_printf(FUNC,Behavioural,FUNCTION,"End");
49
50    return conv;
51  };
52
53  std::string std_logic_conv (uint32_t size, uint32_t value)
54  {
55    log_printf(FUNC,Behavioural,FUNCTION,"Begin");
56    std::string _return = std_logic_conv(size,toString(value));
57    log_printf(FUNC,Behavioural,FUNCTION,"End");
58
59    return _return;
60  };
61
62#undef  FUNCTION
63#define FUNCTION "Vhdl::std_logic_cst"
64  std::string std_logic_cst (uint32_t size, uint32_t value)
65  {
66    log_printf(FUNC,Behavioural,FUNCTION,"Begin");
67
68    std::string conv;
69
70    if (size == 1)
71      conv = "'"+toString(value&1)+"'";
72    else
73      conv = "\""+toBase2<uint32_t>(value,size)+"\"";
74
75    log_printf(FUNC,Behavioural,FUNCTION,"End");
76
77    return conv;
78  };
79
80#undef  FUNCTION
81#define FUNCTION "Vhdl::std_logic_range"
82  std::string std_logic_range (uint32_t size, uint32_t max, uint32_t min, bool force)
83  {
84    log_printf(FUNC,Behavioural,FUNCTION,"Begin");
85    std::string type;
86
87    if (force)
88      {
89        type = "("+toString(max)+" downto "+toString(min)+")";
90      }
91    else
92      {
93        if (max == min)
94          {
95            type = "("+toString(max)+")";
96          }
97        else
98          {
99            if (size < 2)
100              type = "";
101            else
102              type = "("+toString(max)+" downto "+toString(min)+")";
103          }
104      }
105
106    log_printf(FUNC,Behavioural,FUNCTION,"End");
107
108    return type;
109  };
110
111  std::string std_logic_range (uint32_t max, uint32_t min, bool force)
112  {
113    log_printf(FUNC,Behavioural,FUNCTION,"Begin");
114    std::string type;
115
116    if (force)
117      {
118        type = "("+toString(max)+" downto "+toString(min)+")";
119      }
120    else
121      {
122        if (max == min)
123          {
124            type = "("+toString(max)+")";
125          }
126        else
127          {
128            if (max == 0)
129              type = "";
130            else
131              type = "("+toString(max)+" downto "+toString(min)+")";
132          }
133      }
134
135    log_printf(FUNC,Behavioural,FUNCTION,"End");
136
137    return type;
138  };
139
140  std::string std_logic_range (uint32_t size, bool force)
141  {
142    log_printf(FUNC,Behavioural,FUNCTION,"Begin");
143    std::string _return = std_logic_range(size-1,0,force);
144    log_printf(FUNC,Behavioural,FUNCTION,"End");
145
146    return _return;
147  }
148
149#undef  FUNCTION
150#define FUNCTION "Vhdl::std_logic_others"
151  std::string std_logic_others (uint32_t size, bool cst  )
152  {
153    log_printf(FUNC,Behavioural,FUNCTION,"Begin");
154
155    std::string _return;
156
157    if (size < 2)
158      _return = "'"+toString(cst)+"'";
159    else
160      _return = "(others => '"+toString(cst)+"')";
161
162    log_printf(FUNC,Behavioural,FUNCTION,"End");
163
164    return _return;
165  }
166
167}; // end namespace behavioural         
168}; // end namespace morpheo             
169
170#endif
Note: See TracBrowser for help on using the repository browser.