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

Last change on this file since 94 was 94, checked in by rosiere, 15 years ago

Update document on Vhdl generation.

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