From babe694366d2a638319e7c7cb3b60e076d4eef1e Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Tue, 10 Jun 2008 13:58:41 +0100 Subject: [PATCH] Generate port mappings --- tgt-vhdl/scope.cc | 9 ++++----- tgt-vhdl/vhdl_syntax.cc | 29 +++++++++++++++++++++++++++-- tgt-vhdl/vhdl_syntax.hh | 13 +++++++++++-- 3 files changed, 42 insertions(+), 9 deletions(-) diff --git a/tgt-vhdl/scope.cc b/tgt-vhdl/scope.cc index 5de2dd702..baf47162c 100644 --- a/tgt-vhdl/scope.cc +++ b/tgt-vhdl/scope.cc @@ -217,7 +217,6 @@ static void map_signal(ivl_signal_t to, vhdl_entity *parent, ivl_nexus_ptr_t ptr = ivl_nexus_ptr(nexus, i); if ((sig = ivl_nexus_ptr_sig(ptr)) != NULL) { const char *basename = ivl_signal_basename(sig); - std::cout << "checking " << basename << std::endl; if (sig == to) { // Don't map a signal to itself! continue; @@ -226,8 +225,10 @@ static void map_signal(ivl_signal_t to, vhdl_entity *parent, // It's a signal declared in the parent // Pick this one (any one will do as they're all // connected together if there's more than one) - std::cout << "= " << std::hex << sig << std::endl; - std::cout << "-> " << ivl_signal_basename(sig) << std::endl; + vhdl_var_ref *ref = + new vhdl_var_ref(basename, vhdl_type::std_logic()); + inst->map_port(ivl_signal_basename(to), ref); + return; } } @@ -247,8 +248,6 @@ static void port_map(ivl_scope_t scope, vhdl_entity *parent, int nsigs = ivl_scope_sigs(scope); for (int i = 0; i < nsigs; i++) { ivl_signal_t sig = ivl_scope_sig(scope, i); - - const char *basename = ivl_signal_basename(sig); ivl_signal_port_t mode = ivl_signal_port(sig); switch (mode) { diff --git a/tgt-vhdl/vhdl_syntax.cc b/tgt-vhdl/vhdl_syntax.cc index 9593ca385..844d8ba9f 100644 --- a/tgt-vhdl/vhdl_syntax.cc +++ b/tgt-vhdl/vhdl_syntax.cc @@ -255,11 +255,36 @@ vhdl_comp_inst::vhdl_comp_inst(const char *inst_name, const char *comp_name) } +void vhdl_comp_inst::map_port(const char *name, vhdl_expr *expr) +{ + port_map_t pmap = { name, expr }; + mapping_.push_back(pmap); +} + void vhdl_comp_inst::emit(std::ofstream &of, int level) const { - // If there are no ports or generics we don't need to mention them... emit_comment(of, level); - of << inst_name_ << ": " << comp_name_ << ";"; + of << inst_name_ << ": " << comp_name_; + + // If there are no ports or generics we don't need to mention them... + if (mapping_.size() > 0) { + newline(of, indent(level)); + of << "port map ("; + + int sz = mapping_.size(); + port_map_list_t::const_iterator it; + for (it = mapping_.begin(); it != mapping_.end(); ++it) { + newline(of, indent(indent(level))); + of << (*it).name << " => "; + (*it).expr->emit(of, level); + if (--sz > 0) + of << ","; + } + newline(of, indent(level)); + of << ")"; + } + + of << ";"; newline(of, level); } diff --git a/tgt-vhdl/vhdl_syntax.hh b/tgt-vhdl/vhdl_syntax.hh index 2e351e3b2..15cd12e03 100644 --- a/tgt-vhdl/vhdl_syntax.hh +++ b/tgt-vhdl/vhdl_syntax.hh @@ -351,6 +351,15 @@ private: vhdl_port_mode_t mode_; }; +/* + * A mapping from port name to an expression. + */ +struct port_map_t { + std::string name; + vhdl_expr *expr; +}; + +typedef std::list port_map_list_t; /* * Instantiation of component. This is really only a placeholder @@ -362,10 +371,10 @@ public: virtual ~vhdl_comp_inst() {} void emit(std::ofstream &of, int level) const; + void map_port(const char *name, vhdl_expr *expr); private: std::string comp_name_, inst_name_; - - // TODO: Port mappings, etc. + port_map_list_t mapping_; };