From 081f3974604b961809dbf19ebb94d2d22be49608 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Fri, 27 Jun 2008 14:58:03 +0100 Subject: [PATCH] Implement LPM part select --- tgt-vhdl/lpm.cc | 26 ++++++++++++++++++++++++++ tgt-vhdl/vhdl_syntax.hh | 1 + 2 files changed, 27 insertions(+) diff --git a/tgt-vhdl/lpm.cc b/tgt-vhdl/lpm.cc index 3d67ddf93..00f7240e1 100644 --- a/tgt-vhdl/lpm.cc +++ b/tgt-vhdl/lpm.cc @@ -58,6 +58,30 @@ static int draw_binop_lpm(vhdl_arch *arch, ivl_lpm_t lpm, vhdl_binop_t op) return 0; } +int draw_part_select_lpm(vhdl_arch *arch, ivl_lpm_t lpm) +{ + vhdl_var_ref *selfrom = nexus_to_var_ref(arch->get_scope(), ivl_lpm_data(lpm, 0)); + if (NULL == selfrom) + return 1; + + vhdl_expr *off = nexus_to_var_ref(arch->get_scope(), ivl_lpm_data(lpm, 1)); + if (NULL == off) + return 1; + + vhdl_var_ref *out = nexus_to_var_ref(arch->get_scope(), ivl_lpm_q(lpm, 0)); + if (NULL == out) + return 1; + + // Array indexes must be integers + vhdl_type integer(VHDL_TYPE_INTEGER); + off = off->cast(&integer); + + selfrom->set_slice(off); + arch->add_stmt(new vhdl_cassign_stmt(out, selfrom)); + + return 0; +} + int draw_lpm(vhdl_arch *arch, ivl_lpm_t lpm) { switch (ivl_lpm_type(lpm)) { @@ -67,6 +91,8 @@ int draw_lpm(vhdl_arch *arch, ivl_lpm_t lpm) return draw_binop_lpm(arch, lpm, VHDL_BINOP_SUB); case IVL_LPM_MULT: return draw_binop_lpm(arch, lpm, VHDL_BINOP_MULT); + case IVL_LPM_PART_VP: + return draw_part_select_lpm(arch, lpm); default: error("Unsupported LPM type: %d", ivl_lpm_type(lpm)); return 1; diff --git a/tgt-vhdl/vhdl_syntax.hh b/tgt-vhdl/vhdl_syntax.hh index d650d2cd6..16cf8109a 100644 --- a/tgt-vhdl/vhdl_syntax.hh +++ b/tgt-vhdl/vhdl_syntax.hh @@ -56,6 +56,7 @@ public: void emit(std::ofstream &of, int level) const; const std::string &get_name() const { return name_; } + void set_slice(vhdl_expr *s) { slice_ = s; } private: std::string name_; vhdl_expr *slice_;