1 /*
2  *  Support functions for VHDL output.
3  *
4  *  Copyright (C) 2008-2010  Nick Gasson (nick@nickg.me.uk)
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License along
17  *  with this program; if not, write to the Free Software Foundation, Inc.,
18  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20 
21 #ifndef INC_SUPPORT_HH
22 #define INC_SUPPORT_HH
23 
24 #include "vhdl_syntax.hh"
25 
26 enum support_function_t {
27    SF_UNSIGNED_TO_BOOLEAN = 0,
28    SF_SIGNED_TO_BOOLEAN,
29    SF_BOOLEAN_TO_LOGIC,
30    SF_REDUCE_OR,
31    SF_REDUCE_AND,
32    SF_REDUCE_XOR,
33    SF_REDUCE_XNOR,
34    SF_TERNARY_LOGIC,
35    SF_TERNARY_UNSIGNED,
36    SF_TERNARY_SIGNED,
37    SF_LOGIC_TO_INTEGER,
38    SF_SIGNED_TO_LOGIC,
39    SF_UNSIGNED_TO_LOGIC
40 };
41 
42 class support_function : public vhdl_function {
43 public:
support_function(support_function_t type)44    explicit support_function(support_function_t type)
45       : vhdl_function(function_name(type), function_type(type)),
46         type_(type) {}
47    void emit(std::ostream &of, int level) const;
48    static const char *function_name(support_function_t type);
49    static vhdl_type *function_type(support_function_t type);
50 
51 private:
52    void emit_ternary(std::ostream &of, int level) const;
53    void emit_reduction(std::ostream &of, int level, const char *op,
54                        char unit) const;
55 
56    support_function_t type_;
57 };
58 
59 #endif
60