2008-06-16 20:41:01 +02:00
|
|
|
/*
|
|
|
|
|
* VHDL code generation for LPM devices.
|
|
|
|
|
*
|
2009-08-04 01:04:03 +02:00
|
|
|
* Copyright (C) 2008-2009 Nick Gasson (nick@nickg.me.uk)
|
2008-06-16 20:41:01 +02:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "vhdl_target.h"
|
2009-01-17 14:38:11 +01:00
|
|
|
#include "state.hh"
|
2008-06-16 20:41:01 +02:00
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <cassert>
|
|
|
|
|
|
2008-07-15 15:09:24 +02:00
|
|
|
/*
|
|
|
|
|
* Return the base of a part select.
|
|
|
|
|
*/
|
|
|
|
|
static vhdl_expr *part_select_base(vhdl_scope *scope, ivl_lpm_t lpm)
|
|
|
|
|
{
|
|
|
|
|
vhdl_expr *off;
|
|
|
|
|
ivl_nexus_t base = ivl_lpm_data(lpm, 1);
|
|
|
|
|
if (base != NULL)
|
2009-01-25 10:30:21 +01:00
|
|
|
off = readable_ref(scope, base);
|
2008-07-15 15:09:24 +02:00
|
|
|
else
|
|
|
|
|
off = new vhdl_const_int(ivl_lpm_base(lpm));
|
|
|
|
|
|
|
|
|
|
// Array indexes must be integers
|
|
|
|
|
vhdl_type integer(VHDL_TYPE_INTEGER);
|
|
|
|
|
return off->cast(&integer);
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-14 12:53:38 +02:00
|
|
|
static vhdl_expr *binop_lpm_to_expr(vhdl_scope *scope, ivl_lpm_t lpm, vhdl_binop_t op)
|
2008-07-07 22:45:27 +02:00
|
|
|
{
|
2008-07-16 17:20:08 +02:00
|
|
|
unsigned out_width = ivl_lpm_width(lpm);
|
2008-07-07 22:45:27 +02:00
|
|
|
vhdl_type *result_type =
|
2008-07-16 17:20:08 +02:00
|
|
|
vhdl_type::type_for(out_width, ivl_lpm_signed(lpm) != 0);
|
2008-07-07 22:45:27 +02:00
|
|
|
vhdl_binop_expr *expr = new vhdl_binop_expr(op, result_type);
|
2010-10-02 20:02:27 +02:00
|
|
|
|
2011-04-06 22:27:24 +02:00
|
|
|
for (unsigned i = 0; i < ivl_lpm_size(lpm); i++) {
|
2009-01-25 10:30:21 +01:00
|
|
|
vhdl_expr *e = readable_ref(scope, ivl_lpm_data(lpm, i));
|
2011-04-06 22:27:24 +02:00
|
|
|
if (NULL == e)
|
2008-07-07 22:45:27 +02:00
|
|
|
return NULL;
|
2008-06-16 20:49:24 +02:00
|
|
|
|
2011-04-06 22:27:24 +02:00
|
|
|
// It's possible that the inputs are a mixture of signed and unsigned
|
|
|
|
|
// in which case we must cast them to the output type
|
|
|
|
|
e = e->cast(vhdl_type::type_for(e->get_type()->get_width(),
|
|
|
|
|
ivl_lpm_signed(lpm) != 0));
|
|
|
|
|
|
|
|
|
|
// Bit of a hack: the LPM inputs are in the wrong order for concatenation
|
|
|
|
|
if (op == VHDL_BINOP_CONCAT)
|
|
|
|
|
expr->add_expr_front(e);
|
|
|
|
|
else
|
|
|
|
|
expr->add_expr(e);
|
2008-07-07 22:45:27 +02:00
|
|
|
}
|
2010-10-02 20:02:27 +02:00
|
|
|
|
2008-06-16 20:49:24 +02:00
|
|
|
if (op == VHDL_BINOP_MULT) {
|
|
|
|
|
// Need to resize the output to the desired size,
|
|
|
|
|
// as this does not happen automatically in VHDL
|
2010-10-02 20:02:27 +02:00
|
|
|
|
2008-06-16 20:49:24 +02:00
|
|
|
vhdl_fcall *resize =
|
|
|
|
|
new vhdl_fcall("Resize", vhdl_type::nsigned(out_width));
|
|
|
|
|
resize->add_expr(expr);
|
|
|
|
|
resize->add_expr(new vhdl_const_int(out_width));
|
2010-10-02 20:02:27 +02:00
|
|
|
|
2008-07-07 22:45:27 +02:00
|
|
|
return resize;
|
2008-06-16 20:49:24 +02:00
|
|
|
}
|
2008-07-07 22:45:27 +02:00
|
|
|
else
|
|
|
|
|
return expr;
|
2008-06-16 20:41:01 +02:00
|
|
|
}
|
|
|
|
|
|
2008-07-16 13:50:55 +02:00
|
|
|
static vhdl_expr *rel_lpm_to_expr(vhdl_scope *scope, ivl_lpm_t lpm, vhdl_binop_t op)
|
|
|
|
|
{
|
|
|
|
|
vhdl_binop_expr *expr = new vhdl_binop_expr(op, vhdl_type::boolean());
|
|
|
|
|
|
2010-08-04 21:55:36 +02:00
|
|
|
vhdl_expr *lhs = readable_ref(scope, ivl_lpm_data(lpm, 0));
|
|
|
|
|
if (NULL == lhs)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
vhdl_expr *rhs = readable_ref(scope, ivl_lpm_data(lpm, 1));
|
|
|
|
|
if (NULL == rhs) {
|
|
|
|
|
delete lhs;
|
|
|
|
|
return NULL;
|
2008-07-16 13:50:55 +02:00
|
|
|
}
|
2010-10-02 20:02:27 +02:00
|
|
|
|
2010-08-04 21:55:36 +02:00
|
|
|
// Ensure LHS and RHS are the same type
|
|
|
|
|
if (lhs->get_type() != rhs->get_type())
|
|
|
|
|
rhs = rhs->cast(lhs->get_type());
|
|
|
|
|
|
|
|
|
|
expr->add_expr(lhs);
|
|
|
|
|
expr->add_expr(rhs);
|
2008-07-16 13:50:55 +02:00
|
|
|
|
2010-08-04 22:10:24 +02:00
|
|
|
return expr;
|
2008-07-16 13:50:55 +02:00
|
|
|
}
|
|
|
|
|
|
2008-07-14 12:53:38 +02:00
|
|
|
static vhdl_expr *part_select_vp_lpm_to_expr(vhdl_scope *scope, ivl_lpm_t lpm)
|
2008-07-03 15:45:54 +02:00
|
|
|
{
|
2009-01-25 10:30:21 +01:00
|
|
|
vhdl_var_ref *selfrom = readable_ref(scope, ivl_lpm_data(lpm, 0));
|
2008-07-03 15:45:54 +02:00
|
|
|
if (NULL == selfrom)
|
2008-07-07 20:46:18 +02:00
|
|
|
return NULL;
|
2010-10-02 20:02:27 +02:00
|
|
|
|
2008-07-07 20:46:18 +02:00
|
|
|
vhdl_expr *off = part_select_base(scope, lpm);;
|
2008-06-27 15:58:03 +02:00
|
|
|
if (NULL == off)
|
2008-07-07 20:46:18 +02:00
|
|
|
return NULL;
|
2008-06-27 15:58:03 +02:00
|
|
|
|
2008-11-26 20:25:03 +01:00
|
|
|
if (selfrom->get_type()->get_width() > 1)
|
|
|
|
|
selfrom->set_slice(off, ivl_lpm_width(lpm) - 1);
|
2010-10-02 20:02:27 +02:00
|
|
|
|
2008-07-07 20:46:18 +02:00
|
|
|
return selfrom;
|
2008-06-27 15:58:03 +02:00
|
|
|
}
|
|
|
|
|
|
2008-07-15 15:09:24 +02:00
|
|
|
|
2008-07-14 12:53:38 +02:00
|
|
|
static vhdl_expr *part_select_pv_lpm_to_expr(vhdl_scope *scope, ivl_lpm_t lpm)
|
2010-10-02 20:02:27 +02:00
|
|
|
{
|
2009-01-25 10:30:21 +01:00
|
|
|
return readable_ref(scope, ivl_lpm_data(lpm, 0));
|
2008-07-03 15:45:54 +02:00
|
|
|
}
|
|
|
|
|
|
2008-07-14 12:53:38 +02:00
|
|
|
static vhdl_expr *ufunc_lpm_to_expr(vhdl_scope *scope, ivl_lpm_t lpm)
|
2008-06-30 17:35:29 +02:00
|
|
|
{
|
2008-07-18 15:31:12 +02:00
|
|
|
ivl_scope_t f_scope = ivl_lpm_define(lpm);
|
|
|
|
|
vhdl_fcall *fcall = new vhdl_fcall(ivl_scope_basename(f_scope), NULL);
|
2008-06-30 17:35:29 +02:00
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < ivl_lpm_size(lpm); i++) {
|
2009-01-25 10:30:21 +01:00
|
|
|
vhdl_var_ref *ref = readable_ref(scope, ivl_lpm_data(lpm, i));
|
2009-08-04 01:04:03 +02:00
|
|
|
if (NULL == ref) {
|
|
|
|
|
delete fcall;
|
2008-07-07 20:46:18 +02:00
|
|
|
return NULL;
|
2009-08-04 01:04:03 +02:00
|
|
|
}
|
2008-06-30 17:35:29 +02:00
|
|
|
|
|
|
|
|
fcall->add_expr(ref);
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-07 20:46:18 +02:00
|
|
|
return fcall;
|
2008-06-30 17:35:29 +02:00
|
|
|
}
|
|
|
|
|
|
2008-07-14 12:53:38 +02:00
|
|
|
static vhdl_expr *reduction_lpm_to_expr(vhdl_scope *scope, ivl_lpm_t lpm,
|
2008-07-20 16:10:00 +02:00
|
|
|
support_function_t f, bool invert)
|
2008-07-07 16:45:20 +02:00
|
|
|
{
|
2009-01-25 10:30:21 +01:00
|
|
|
vhdl_var_ref *ref = readable_ref(scope, ivl_lpm_data(lpm, 0));
|
2008-07-07 16:45:20 +02:00
|
|
|
if (NULL == ref)
|
2008-07-07 20:46:18 +02:00
|
|
|
return NULL;
|
2008-07-20 16:10:00 +02:00
|
|
|
|
2008-08-01 17:27:55 +02:00
|
|
|
vhdl_expr *result;
|
|
|
|
|
if (ref->get_type()->get_name() == VHDL_TYPE_STD_LOGIC)
|
|
|
|
|
result = ref;
|
|
|
|
|
else {
|
|
|
|
|
require_support_function(f);
|
|
|
|
|
vhdl_fcall *fcall = new vhdl_fcall(support_function::function_name(f),
|
|
|
|
|
vhdl_type::std_logic());
|
2010-10-02 20:02:27 +02:00
|
|
|
|
|
|
|
|
vhdl_type std_logic_vector(VHDL_TYPE_STD_LOGIC_VECTOR);
|
2008-08-01 17:27:55 +02:00
|
|
|
fcall->add_expr(ref->cast(&std_logic_vector));
|
2010-10-02 20:02:27 +02:00
|
|
|
|
2008-08-01 17:27:55 +02:00
|
|
|
result = fcall;
|
2010-10-02 20:02:27 +02:00
|
|
|
}
|
|
|
|
|
|
2008-07-07 16:45:20 +02:00
|
|
|
if (invert)
|
2008-07-07 20:46:18 +02:00
|
|
|
return new vhdl_unaryop_expr
|
2008-08-01 17:27:55 +02:00
|
|
|
(VHDL_UNARYOP_NOT, result, vhdl_type::std_logic());
|
2008-07-07 16:45:20 +02:00
|
|
|
else
|
2008-08-01 17:27:55 +02:00
|
|
|
return result;
|
2008-07-07 16:45:20 +02:00
|
|
|
}
|
|
|
|
|
|
2008-07-14 12:53:38 +02:00
|
|
|
static vhdl_expr *sign_extend_lpm_to_expr(vhdl_scope *scope, ivl_lpm_t lpm)
|
2008-07-07 20:27:52 +02:00
|
|
|
{
|
2009-01-25 10:30:21 +01:00
|
|
|
vhdl_expr *ref = readable_ref(scope, ivl_lpm_data(lpm, 0));
|
2008-07-07 20:46:18 +02:00
|
|
|
if (ref)
|
|
|
|
|
return ref->resize(ivl_lpm_width(lpm));
|
|
|
|
|
else
|
|
|
|
|
return NULL;
|
2008-07-07 20:27:52 +02:00
|
|
|
}
|
|
|
|
|
|
2008-07-14 12:53:38 +02:00
|
|
|
static vhdl_expr *array_lpm_to_expr(vhdl_scope *scope, ivl_lpm_t lpm)
|
|
|
|
|
{
|
|
|
|
|
ivl_signal_t array = ivl_lpm_array(lpm);
|
|
|
|
|
if (!seen_signal_before(array))
|
|
|
|
|
return NULL;
|
2010-10-02 20:02:27 +02:00
|
|
|
|
2008-07-14 12:53:38 +02:00
|
|
|
const char *renamed = get_renamed_signal(array).c_str();
|
2010-10-02 20:02:27 +02:00
|
|
|
|
2008-07-14 12:53:38 +02:00
|
|
|
vhdl_decl *adecl = scope->get_decl(renamed);
|
|
|
|
|
assert(adecl);
|
2010-10-02 20:02:27 +02:00
|
|
|
|
2008-07-14 12:53:38 +02:00
|
|
|
vhdl_type *atype = new vhdl_type(*adecl->get_type());
|
|
|
|
|
|
2009-01-25 10:30:21 +01:00
|
|
|
vhdl_expr *select = readable_ref(scope, ivl_lpm_select(lpm));
|
2009-08-04 01:04:03 +02:00
|
|
|
if (NULL == select) {
|
|
|
|
|
delete atype;
|
2008-07-14 12:53:38 +02:00
|
|
|
return NULL;
|
2009-08-04 01:04:03 +02:00
|
|
|
}
|
2010-10-02 20:02:27 +02:00
|
|
|
|
2008-07-14 12:53:38 +02:00
|
|
|
vhdl_var_ref *ref = new vhdl_var_ref(renamed, atype);
|
2008-07-17 17:41:34 +02:00
|
|
|
vhdl_type integer(VHDL_TYPE_INTEGER);
|
|
|
|
|
ref->set_slice(select->cast(&integer));
|
2010-10-02 20:02:27 +02:00
|
|
|
|
2008-07-14 12:53:38 +02:00
|
|
|
return ref;
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-15 19:01:37 +02:00
|
|
|
static vhdl_expr *shift_lpm_to_expr(vhdl_scope *scope, ivl_lpm_t lpm,
|
|
|
|
|
vhdl_binop_t shift_op)
|
|
|
|
|
{
|
2009-01-25 10:30:21 +01:00
|
|
|
vhdl_expr *lhs = readable_ref(scope, ivl_lpm_data(lpm, 0));
|
|
|
|
|
vhdl_expr *rhs = readable_ref(scope, ivl_lpm_data(lpm, 1));
|
2008-07-15 19:01:37 +02:00
|
|
|
if (!lhs || !rhs)
|
2010-10-02 20:02:27 +02:00
|
|
|
return NULL;
|
|
|
|
|
|
2008-07-15 19:01:37 +02:00
|
|
|
// The RHS must be an integer
|
|
|
|
|
vhdl_type integer(VHDL_TYPE_INTEGER);
|
|
|
|
|
vhdl_expr *r_cast = rhs->cast(&integer);
|
|
|
|
|
|
|
|
|
|
vhdl_type *rtype = new vhdl_type(*lhs->get_type());
|
|
|
|
|
return new vhdl_binop_expr(lhs, shift_op, r_cast, rtype);
|
|
|
|
|
}
|
|
|
|
|
|
2008-08-18 16:34:58 +02:00
|
|
|
static vhdl_expr *repeat_lpm_to_expr(vhdl_scope *scope, ivl_lpm_t lpm)
|
|
|
|
|
{
|
2009-01-25 10:30:21 +01:00
|
|
|
vhdl_expr *in = readable_ref(scope, ivl_lpm_data(lpm, 0));
|
2008-08-18 16:34:58 +02:00
|
|
|
return new vhdl_bit_spec_expr(NULL, in);
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-15 15:09:24 +02:00
|
|
|
static vhdl_expr *lpm_to_expr(vhdl_scope *scope, ivl_lpm_t lpm)
|
2008-06-16 20:41:01 +02:00
|
|
|
{
|
|
|
|
|
switch (ivl_lpm_type(lpm)) {
|
|
|
|
|
case IVL_LPM_ADD:
|
2008-07-14 12:53:38 +02:00
|
|
|
return binop_lpm_to_expr(scope, lpm, VHDL_BINOP_ADD);
|
2008-06-16 20:49:24 +02:00
|
|
|
case IVL_LPM_SUB:
|
2008-07-14 12:53:38 +02:00
|
|
|
return binop_lpm_to_expr(scope, lpm, VHDL_BINOP_SUB);
|
2008-06-16 20:49:24 +02:00
|
|
|
case IVL_LPM_MULT:
|
2008-07-14 12:53:38 +02:00
|
|
|
return binop_lpm_to_expr(scope, lpm, VHDL_BINOP_MULT);
|
2008-08-07 15:18:26 +02:00
|
|
|
case IVL_LPM_DIVIDE:
|
|
|
|
|
return binop_lpm_to_expr(scope, lpm, VHDL_BINOP_DIV);
|
|
|
|
|
case IVL_LPM_MOD:
|
|
|
|
|
return binop_lpm_to_expr(scope, lpm, VHDL_BINOP_MOD);
|
2008-07-07 15:48:57 +02:00
|
|
|
case IVL_LPM_CONCAT:
|
2011-04-06 22:27:24 +02:00
|
|
|
return binop_lpm_to_expr(scope, lpm, VHDL_BINOP_CONCAT);
|
2008-07-18 12:56:00 +02:00
|
|
|
case IVL_LPM_CMP_GE:
|
|
|
|
|
return rel_lpm_to_expr(scope, lpm, VHDL_BINOP_GEQ);
|
2008-09-02 20:07:38 +02:00
|
|
|
case IVL_LPM_CMP_GT:
|
|
|
|
|
return rel_lpm_to_expr(scope, lpm, VHDL_BINOP_GT);
|
2008-10-05 18:04:19 +02:00
|
|
|
case IVL_LPM_CMP_NE:
|
|
|
|
|
case IVL_LPM_CMP_NEE:
|
|
|
|
|
return rel_lpm_to_expr(scope, lpm, VHDL_BINOP_NEQ);
|
2008-07-18 12:58:26 +02:00
|
|
|
case IVL_LPM_CMP_EQ:
|
2008-07-16 13:50:55 +02:00
|
|
|
case IVL_LPM_CMP_EEQ:
|
|
|
|
|
return rel_lpm_to_expr(scope, lpm, VHDL_BINOP_EQ);
|
2008-06-27 15:58:03 +02:00
|
|
|
case IVL_LPM_PART_VP:
|
2008-07-14 12:53:38 +02:00
|
|
|
return part_select_vp_lpm_to_expr(scope, lpm);
|
|
|
|
|
case IVL_LPM_PART_PV:
|
|
|
|
|
return part_select_pv_lpm_to_expr(scope, lpm);
|
2008-06-30 17:35:29 +02:00
|
|
|
case IVL_LPM_UFUNC:
|
2008-07-14 12:53:38 +02:00
|
|
|
return ufunc_lpm_to_expr(scope, lpm);
|
2008-07-20 17:41:57 +02:00
|
|
|
case IVL_LPM_RE_AND:
|
|
|
|
|
return reduction_lpm_to_expr(scope, lpm, SF_REDUCE_AND, false);
|
2008-07-07 16:45:20 +02:00
|
|
|
case IVL_LPM_RE_NAND:
|
2008-07-20 17:41:57 +02:00
|
|
|
return reduction_lpm_to_expr(scope, lpm, SF_REDUCE_AND, true);
|
2008-07-07 16:45:20 +02:00
|
|
|
case IVL_LPM_RE_NOR:
|
2008-07-20 16:10:00 +02:00
|
|
|
return reduction_lpm_to_expr(scope, lpm, SF_REDUCE_OR, true);
|
2008-07-07 16:45:20 +02:00
|
|
|
case IVL_LPM_RE_OR:
|
2008-07-20 16:10:00 +02:00
|
|
|
return reduction_lpm_to_expr(scope, lpm, SF_REDUCE_OR, false);
|
2008-07-20 17:41:57 +02:00
|
|
|
case IVL_LPM_RE_XOR:
|
|
|
|
|
return reduction_lpm_to_expr(scope, lpm, SF_REDUCE_XOR, false);
|
2008-07-07 16:45:20 +02:00
|
|
|
case IVL_LPM_RE_XNOR:
|
2011-04-06 23:12:16 +02:00
|
|
|
return reduction_lpm_to_expr(scope, lpm, SF_REDUCE_XNOR, true);
|
2008-07-07 20:27:52 +02:00
|
|
|
case IVL_LPM_SIGN_EXT:
|
2008-07-14 12:53:38 +02:00
|
|
|
return sign_extend_lpm_to_expr(scope, lpm);
|
|
|
|
|
case IVL_LPM_ARRAY:
|
|
|
|
|
return array_lpm_to_expr(scope, lpm);
|
2008-07-15 19:01:37 +02:00
|
|
|
case IVL_LPM_SHIFTL:
|
|
|
|
|
return shift_lpm_to_expr(scope, lpm, VHDL_BINOP_SL);
|
|
|
|
|
case IVL_LPM_SHIFTR:
|
|
|
|
|
return shift_lpm_to_expr(scope, lpm, VHDL_BINOP_SR);
|
2008-08-18 16:34:58 +02:00
|
|
|
case IVL_LPM_REPEAT:
|
|
|
|
|
return repeat_lpm_to_expr(scope, lpm);
|
2008-06-16 20:41:01 +02:00
|
|
|
default:
|
|
|
|
|
error("Unsupported LPM type: %d", ivl_lpm_type(lpm));
|
2008-07-07 20:46:18 +02:00
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-08-03 13:46:50 +02:00
|
|
|
static int draw_mux_lpm(vhdl_arch *arch, ivl_lpm_t lpm)
|
|
|
|
|
{
|
|
|
|
|
int nselects = ivl_lpm_selects(lpm);
|
|
|
|
|
|
|
|
|
|
if (nselects > 1) {
|
|
|
|
|
error("Only 1 LPM select bit supported at the moment");
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vhdl_scope *scope = arch->get_scope();
|
2010-10-02 20:02:27 +02:00
|
|
|
|
2009-01-25 10:30:21 +01:00
|
|
|
vhdl_expr *s0 = readable_ref(scope, ivl_lpm_data(lpm, 0));
|
|
|
|
|
vhdl_expr *s1 = readable_ref(scope, ivl_lpm_data(lpm, 1));
|
2008-08-03 13:46:50 +02:00
|
|
|
|
2009-01-25 10:30:21 +01:00
|
|
|
vhdl_expr *sel = readable_ref(scope, ivl_lpm_select(lpm));
|
2008-08-03 13:46:50 +02:00
|
|
|
vhdl_expr *b1 = new vhdl_const_bit('1');
|
|
|
|
|
vhdl_expr *t1 =
|
|
|
|
|
new vhdl_binop_expr(sel, VHDL_BINOP_EQ, b1, vhdl_type::boolean());
|
2010-10-02 20:02:27 +02:00
|
|
|
|
2010-03-16 22:25:00 +01:00
|
|
|
vhdl_var_ref *out = nexus_to_var_ref(scope, ivl_lpm_q(lpm));
|
2008-08-03 13:46:50 +02:00
|
|
|
|
2008-10-05 18:08:19 +02:00
|
|
|
// Make sure s0 and s1 have the same type as the output
|
|
|
|
|
s0 = s0->cast(out->get_type());
|
|
|
|
|
s1 = s1->cast(out->get_type());
|
|
|
|
|
|
2008-08-03 13:46:50 +02:00
|
|
|
vhdl_cassign_stmt *s = new vhdl_cassign_stmt(out, s0);
|
|
|
|
|
s->add_condition(s1, t1);
|
|
|
|
|
|
|
|
|
|
arch->add_stmt(s);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-07 20:46:18 +02:00
|
|
|
int draw_lpm(vhdl_arch *arch, ivl_lpm_t lpm)
|
|
|
|
|
{
|
2008-08-03 13:46:50 +02:00
|
|
|
if (ivl_lpm_type(lpm) == IVL_LPM_MUX)
|
|
|
|
|
return draw_mux_lpm(arch, lpm);
|
2010-10-02 20:02:27 +02:00
|
|
|
|
2008-07-15 15:09:24 +02:00
|
|
|
vhdl_expr *f = lpm_to_expr(arch->get_scope(), lpm);
|
|
|
|
|
if (NULL == f)
|
2008-08-03 13:46:50 +02:00
|
|
|
return 1;
|
2010-10-02 20:02:27 +02:00
|
|
|
|
2010-03-16 22:25:00 +01:00
|
|
|
vhdl_var_ref *out = nexus_to_var_ref(arch->get_scope(), ivl_lpm_q(lpm));
|
2008-07-29 14:08:13 +02:00
|
|
|
if (ivl_lpm_type(lpm) == IVL_LPM_PART_PV) {
|
|
|
|
|
vhdl_expr *off = part_select_base(arch->get_scope(), lpm);
|
|
|
|
|
assert(off);
|
|
|
|
|
|
|
|
|
|
out->set_slice(off, ivl_lpm_width(lpm) - 1);
|
|
|
|
|
}
|
2010-08-04 22:10:24 +02:00
|
|
|
|
|
|
|
|
// Converting from Boolean to std_logic is a common case so should be
|
|
|
|
|
// replaced by an idiomatic VHDL construct rather than a call to a
|
|
|
|
|
// conversion function
|
|
|
|
|
|
|
|
|
|
bool bool_to_logic =
|
|
|
|
|
out->get_type()->get_name() == VHDL_TYPE_STD_LOGIC
|
|
|
|
|
&& f->get_type()->get_name() == VHDL_TYPE_BOOLEAN;
|
2010-10-02 20:02:27 +02:00
|
|
|
|
2010-08-04 22:10:24 +02:00
|
|
|
if (bool_to_logic) {
|
|
|
|
|
vhdl_cassign_stmt* s =
|
|
|
|
|
new vhdl_cassign_stmt(out, new vhdl_const_bit('0'));
|
|
|
|
|
s->add_condition(new vhdl_const_bit('1'), f);
|
|
|
|
|
arch->add_stmt(s);
|
|
|
|
|
}
|
2010-10-02 20:02:27 +02:00
|
|
|
else
|
2010-08-04 22:10:24 +02:00
|
|
|
arch->add_stmt(new vhdl_cassign_stmt(out, f->cast(out->get_type())));
|
2010-10-02 20:02:27 +02:00
|
|
|
|
2008-07-15 15:09:24 +02:00
|
|
|
return 0;
|
2008-06-16 20:41:01 +02:00
|
|
|
}
|
|
|
|
|
|