2000-08-12 18:34:37 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2000 Stephen Williams (steve@icarus.com)
|
|
|
|
|
*
|
|
|
|
|
* This source code is free software; you can redistribute it
|
|
|
|
|
* and/or modify it in source code form 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
|
|
|
|
*/
|
|
|
|
|
#if !defined(WINNT) && !defined(macintosh)
|
2000-10-07 21:45:42 +02:00
|
|
|
#ident "$Id: stub.c,v 1.15 2000/10/07 19:45:43 steve Exp $"
|
2000-08-12 18:34:37 +02:00
|
|
|
#endif
|
|
|
|
|
|
2000-08-20 06:13:56 +02:00
|
|
|
/*
|
|
|
|
|
* This is a sample target module. All this does is write to the
|
|
|
|
|
* output file some information about each object handle when each of
|
|
|
|
|
* the various object functions is called. This can be used to
|
|
|
|
|
* understand the behavior of the core as it uses a target module.
|
|
|
|
|
*/
|
|
|
|
|
|
2000-08-12 18:34:37 +02:00
|
|
|
# include <ivl_target.h>
|
|
|
|
|
# include <stdio.h>
|
|
|
|
|
|
|
|
|
|
static FILE*out;
|
|
|
|
|
|
|
|
|
|
int target_start_design(ivl_design_t des)
|
|
|
|
|
{
|
|
|
|
|
const char*path = ivl_get_flag(des, "-o");
|
|
|
|
|
if (path == 0) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
out = fopen(path, "w");
|
|
|
|
|
if (out == 0) {
|
|
|
|
|
perror(path);
|
|
|
|
|
return -2;
|
|
|
|
|
}
|
|
|
|
|
|
2000-10-05 07:03:01 +02:00
|
|
|
fprintf(out, "root module = %s;\n", ivl_get_root_name(des));
|
2000-08-12 18:34:37 +02:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void target_end_design(ivl_design_t des)
|
|
|
|
|
{
|
|
|
|
|
fclose(out);
|
|
|
|
|
}
|
|
|
|
|
|
2000-08-14 06:39:56 +02:00
|
|
|
int target_net_const(const char*name, ivl_net_const_t net)
|
|
|
|
|
{
|
2000-10-05 07:03:01 +02:00
|
|
|
unsigned idx;
|
|
|
|
|
unsigned wid = ivl_const_pins(net);
|
|
|
|
|
const char*bits = ivl_const_bits(net);
|
|
|
|
|
|
|
|
|
|
fprintf(out, "LPM_CONSTANT %s: %s%u'b", name,
|
|
|
|
|
ivl_const_signed(net)? "+- ":"",
|
|
|
|
|
wid);
|
|
|
|
|
|
|
|
|
|
for (idx = 0 ; idx < wid ; idx += 1)
|
|
|
|
|
fprintf(out, "%c", bits[wid-1-idx]);
|
|
|
|
|
|
2000-10-07 01:46:50 +02:00
|
|
|
fprintf(out, " (%s", ivl_nexus_name(ivl_const_pin(net, 0)));
|
|
|
|
|
for (idx = 1 ; idx < wid ; idx += 1)
|
|
|
|
|
fprintf(", %s", ivl_nexus_name(ivl_const_pin(net, idx)));
|
|
|
|
|
|
|
|
|
|
fprintf(out, ")\n");
|
2000-08-14 06:39:56 +02:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2000-08-19 20:12:42 +02:00
|
|
|
int target_net_event(const char*name, ivl_net_event_t net)
|
|
|
|
|
{
|
|
|
|
|
fprintf(out, "STUB: %s: event\n", name);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int target_net_logic(const char*name, ivl_net_logic_t net)
|
|
|
|
|
{
|
2000-08-26 02:54:03 +02:00
|
|
|
unsigned npins, idx;
|
|
|
|
|
|
2000-10-05 07:03:01 +02:00
|
|
|
switch (ivl_logic_type(net)) {
|
2000-09-19 06:15:27 +02:00
|
|
|
case IVL_LO_AND:
|
2000-10-05 07:03:01 +02:00
|
|
|
fprintf(out, "and %s (%s", name,
|
|
|
|
|
ivl_nexus_name(ivl_logic_pin(net, 0)));
|
2000-08-20 06:13:56 +02:00
|
|
|
break;
|
2000-10-07 01:46:50 +02:00
|
|
|
case IVL_LO_BUF:
|
|
|
|
|
fprintf(out, "buf %s (%s", name,
|
|
|
|
|
ivl_nexus_name(ivl_logic_pin(net, 0)));
|
|
|
|
|
break;
|
2000-10-07 21:45:42 +02:00
|
|
|
case IVL_LO_BUFZ:
|
|
|
|
|
fprintf(out, "bufz %s (%s", name,
|
|
|
|
|
ivl_nexus_name(ivl_logic_pin(net, 0)));
|
|
|
|
|
break;
|
2000-09-19 06:15:27 +02:00
|
|
|
case IVL_LO_OR:
|
2000-10-05 07:03:01 +02:00
|
|
|
fprintf(out, "or %s (%s", name,
|
|
|
|
|
ivl_nexus_name(ivl_logic_pin(net, 0)));
|
|
|
|
|
break;
|
|
|
|
|
case IVL_LO_XOR:
|
|
|
|
|
fprintf(out, "xor %s (%s", name,
|
|
|
|
|
ivl_nexus_name(ivl_logic_pin(net, 0)));
|
2000-08-20 06:13:56 +02:00
|
|
|
break;
|
|
|
|
|
default:
|
2000-10-05 07:03:01 +02:00
|
|
|
fprintf(out, "unsupported gate %s: \n", name);
|
2000-08-20 06:13:56 +02:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2000-10-05 07:03:01 +02:00
|
|
|
npins = ivl_logic_pins(net);
|
2000-08-26 02:54:03 +02:00
|
|
|
for (idx = 1 ; idx < npins ; idx += 1)
|
2000-10-05 07:03:01 +02:00
|
|
|
fprintf(out, ", %s", ivl_nexus_name(ivl_logic_pin(net,idx)));
|
2000-08-26 02:54:03 +02:00
|
|
|
|
|
|
|
|
fprintf(out, ");\n");
|
|
|
|
|
|
2000-08-19 20:12:42 +02:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int target_net_probe(const char*name, ivl_net_probe_t net)
|
|
|
|
|
{
|
|
|
|
|
fprintf(out, "STUB: %s: probe\n", name);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2000-08-27 17:51:50 +02:00
|
|
|
|
2000-09-24 17:46:00 +02:00
|
|
|
int target_net_signal(const char*name, ivl_signal_t net)
|
2000-08-27 17:51:50 +02:00
|
|
|
{
|
2000-09-24 17:46:00 +02:00
|
|
|
const char*type = "?";
|
|
|
|
|
const char*port = "";
|
|
|
|
|
|
|
|
|
|
switch (ivl_signal_type(net)) {
|
|
|
|
|
case IVL_SIT_REG:
|
|
|
|
|
type = "reg";
|
|
|
|
|
break;
|
|
|
|
|
case IVL_SIT_WIRE:
|
|
|
|
|
type = "wire";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (ivl_signal_port(net)) {
|
|
|
|
|
|
|
|
|
|
case IVL_SIP_INPUT:
|
|
|
|
|
port = "input ";
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case IVL_SIP_OUTPUT:
|
|
|
|
|
port = "output ";
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case IVL_SIP_INOUT:
|
|
|
|
|
port = "inout ";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2000-10-05 07:03:01 +02:00
|
|
|
fprintf(out, "%s %s[%u] %s\n", type, port,
|
2000-09-24 17:46:00 +02:00
|
|
|
ivl_signal_pins(net), name);
|
|
|
|
|
|
2000-08-27 17:51:50 +02:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2000-09-24 04:21:53 +02:00
|
|
|
static void show_expression(ivl_expr_t net, unsigned ind)
|
|
|
|
|
{
|
|
|
|
|
const ivl_expr_type_t code = ivl_expr_type(net);
|
|
|
|
|
|
|
|
|
|
switch (code) {
|
2000-09-26 02:30:07 +02:00
|
|
|
|
|
|
|
|
case IVL_EX_NUMBER: {
|
|
|
|
|
const char*bits = ivl_expr_bits(net);
|
|
|
|
|
unsigned width = ivl_expr_width(net);
|
|
|
|
|
unsigned idx;
|
|
|
|
|
|
|
|
|
|
fprintf(out, "%*s<number=%u'b", ind, "", width);
|
|
|
|
|
for (idx = width ; idx > 0 ; idx -= 1)
|
|
|
|
|
fprintf(out, "%c", bits[idx-1]);
|
|
|
|
|
|
|
|
|
|
fprintf(out, ", %s>\n", ivl_expr_signed(net)? "signed"
|
|
|
|
|
: "unsigned");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2000-09-24 04:21:53 +02:00
|
|
|
case IVL_EX_STRING:
|
2000-09-26 02:30:07 +02:00
|
|
|
fprintf(out, "%*s<string=\"%s\", width=%u>\n", ind, "",
|
2000-09-24 04:21:53 +02:00
|
|
|
ivl_expr_string(net), ivl_expr_width(net));
|
|
|
|
|
break;
|
2000-09-26 02:30:07 +02:00
|
|
|
|
2000-10-05 07:03:01 +02:00
|
|
|
case IVL_EX_SFUNC:
|
|
|
|
|
fprintf(out, "%*s<function=\"%s\", width=%u>\n", ind, "",
|
|
|
|
|
ivl_expr_name(net), ivl_expr_width(net));
|
|
|
|
|
break;
|
|
|
|
|
|
2000-09-26 02:30:07 +02:00
|
|
|
case IVL_EX_SIGNAL:
|
2000-09-24 04:21:53 +02:00
|
|
|
fprintf(out, "%*s<signal=%s, width=%u>\n", ind, "",
|
|
|
|
|
ivl_expr_name(net), ivl_expr_width(net));
|
|
|
|
|
break;
|
2000-09-26 02:30:07 +02:00
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
fprintf(out, "%*s<expr_type=%u>\n", ind, "", code);
|
|
|
|
|
break;
|
2000-09-24 04:21:53 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2000-09-19 06:15:27 +02:00
|
|
|
static void show_statement(ivl_statement_t net, unsigned ind)
|
|
|
|
|
{
|
|
|
|
|
const ivl_statement_type_t code = ivl_statement_type(net);
|
|
|
|
|
|
|
|
|
|
switch (code) {
|
|
|
|
|
case IVL_ST_ASSIGN:
|
2000-10-07 01:46:50 +02:00
|
|
|
fprintf(out, "%*sASSIGN <lwidth=%u>\n", ind, "",
|
|
|
|
|
ivl_stmt_lwidth(net));
|
|
|
|
|
show_expression(ivl_stmt_rval(net), ind+4);
|
2000-09-19 06:15:27 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case IVL_ST_BLOCK: {
|
|
|
|
|
unsigned cnt = ivl_stmt_block_count(net);
|
|
|
|
|
unsigned idx;
|
|
|
|
|
fprintf(out, "%*sbegin\n", ind, "");
|
|
|
|
|
for (idx = 0 ; idx < cnt ; idx += 1) {
|
|
|
|
|
ivl_statement_t cur = ivl_stmt_block_stmt(net, idx);
|
|
|
|
|
show_statement(cur, ind+4);
|
|
|
|
|
}
|
|
|
|
|
fprintf(out, "%*send\n", ind, "");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case IVL_ST_CONDIT: {
|
|
|
|
|
ivl_statement_t t = ivl_stmt_cond_true(net);
|
|
|
|
|
ivl_statement_t f = ivl_stmt_cond_false(net);
|
|
|
|
|
|
|
|
|
|
fprintf(out, "%*sif (...)\n", ind, "");
|
|
|
|
|
if (t)
|
|
|
|
|
show_statement(t, ind+4);
|
|
|
|
|
else
|
|
|
|
|
fprintf(out, "%*s;\n", ind+4, "");
|
|
|
|
|
|
|
|
|
|
if (f) {
|
|
|
|
|
fprintf(out, "%*selse\n", ind, "");
|
|
|
|
|
show_statement(f, ind+4);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case IVL_ST_DELAY:
|
|
|
|
|
fprintf(out, "%*s#%lu\n", ind, "", ivl_stmt_delay_val(net));
|
|
|
|
|
show_statement(ivl_stmt_sub_stmt(net), ind+2);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case IVL_ST_NOOP:
|
|
|
|
|
fprintf(out, "%*s/* noop */;\n", ind, "");
|
|
|
|
|
break;
|
|
|
|
|
|
2000-09-24 04:21:53 +02:00
|
|
|
case IVL_ST_STASK: {
|
|
|
|
|
unsigned idx;
|
|
|
|
|
fprintf(out, "%*sCall %s(%u parameters);\n", ind, "",
|
|
|
|
|
ivl_stmt_name(net), ivl_stmt_parm_count(net));
|
|
|
|
|
for (idx = 0 ; idx < ivl_stmt_parm_count(net) ; idx += 1)
|
|
|
|
|
show_expression(ivl_stmt_parm(net, idx), ind+4);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2000-09-19 06:15:27 +02:00
|
|
|
|
2000-09-26 02:30:07 +02:00
|
|
|
case IVL_ST_TRIGGER:
|
|
|
|
|
fprintf(out, "%*s-> ...\n", ind, "");
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
2000-09-19 06:15:27 +02:00
|
|
|
case IVL_ST_WAIT:
|
|
|
|
|
fprintf(out, "%*s@(...)\n", ind, "");
|
|
|
|
|
show_statement(ivl_stmt_sub_stmt(net), ind+2);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case IVL_ST_WHILE:
|
|
|
|
|
fprintf(out, "%*swhile (<?>)\n", ind, "");
|
|
|
|
|
show_statement(ivl_stmt_sub_stmt(net), ind+2);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
fprintf(out, "%*sunknown statement type (%u)\n", ind, "", code);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2000-08-14 06:39:56 +02:00
|
|
|
int target_process(ivl_process_t net)
|
|
|
|
|
{
|
2000-10-05 07:03:01 +02:00
|
|
|
switch (ivl_process_type(net)) {
|
2000-09-18 03:24:32 +02:00
|
|
|
case IVL_PR_INITIAL:
|
2000-09-24 04:21:53 +02:00
|
|
|
fprintf(out, "initial\n");
|
2000-09-18 03:24:32 +02:00
|
|
|
break;
|
|
|
|
|
case IVL_PR_ALWAYS:
|
2000-09-24 04:21:53 +02:00
|
|
|
fprintf(out, "always\n");
|
2000-09-18 03:24:32 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2000-10-05 07:03:01 +02:00
|
|
|
show_statement(ivl_process_stmt(net), 4);
|
2000-09-19 06:15:27 +02:00
|
|
|
|
2000-08-14 06:39:56 +02:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2000-08-12 18:34:37 +02:00
|
|
|
/*
|
|
|
|
|
* $Log: stub.c,v $
|
2000-10-07 21:45:42 +02:00
|
|
|
* Revision 1.15 2000/10/07 19:45:43 steve
|
|
|
|
|
* Put logic devices into scopes.
|
|
|
|
|
*
|
2000-10-07 01:46:50 +02:00
|
|
|
* Revision 1.14 2000/10/06 23:46:51 steve
|
|
|
|
|
* ivl_target updates, including more complete
|
|
|
|
|
* handling of ivl_nexus_t objects. Much reduced
|
|
|
|
|
* dependencies on pointers to netlist objects.
|
|
|
|
|
*
|
2000-10-05 07:03:01 +02:00
|
|
|
* Revision 1.13 2000/10/05 05:03:01 steve
|
|
|
|
|
* xor and constant devices.
|
|
|
|
|
*
|
2000-09-26 02:30:07 +02:00
|
|
|
* Revision 1.12 2000/09/26 00:30:07 steve
|
|
|
|
|
* Add EX_NUMBER and ST_TRIGGER to dll-api.
|
|
|
|
|
*
|
2000-09-24 17:46:00 +02:00
|
|
|
* Revision 1.11 2000/09/24 15:46:00 steve
|
|
|
|
|
* API access to signal type and port type.
|
|
|
|
|
*
|
2000-09-24 04:21:53 +02:00
|
|
|
* Revision 1.10 2000/09/24 02:21:53 steve
|
|
|
|
|
* Add support for signal expressions.
|
|
|
|
|
*
|
2000-09-22 05:58:30 +02:00
|
|
|
* Revision 1.9 2000/09/22 03:58:30 steve
|
|
|
|
|
* Access to the name of a system task call.
|
|
|
|
|
*
|
2000-09-19 06:15:27 +02:00
|
|
|
* Revision 1.8 2000/09/19 04:15:27 steve
|
|
|
|
|
* Introduce the means to get statement types.
|
|
|
|
|
*
|
2000-09-18 03:24:32 +02:00
|
|
|
* Revision 1.7 2000/09/18 01:24:32 steve
|
|
|
|
|
* Get the structure for ivl_statement_t worked out.
|
|
|
|
|
*
|
2000-08-27 17:51:50 +02:00
|
|
|
* Revision 1.6 2000/08/27 15:51:51 steve
|
|
|
|
|
* t-dll iterates signals, and passes them to the
|
|
|
|
|
* target module.
|
|
|
|
|
*
|
|
|
|
|
* Some of NetObj should return char*, not string.
|
|
|
|
|
*
|
2000-08-26 02:54:03 +02:00
|
|
|
* Revision 1.5 2000/08/26 00:54:03 steve
|
|
|
|
|
* Get at gate information for ivl_target interface.
|
|
|
|
|
*
|
2000-08-20 06:13:56 +02:00
|
|
|
* Revision 1.4 2000/08/20 04:13:57 steve
|
|
|
|
|
* Add ivl_target support for logic gates, and
|
|
|
|
|
* make the interface more accessible.
|
|
|
|
|
*
|
2000-08-19 20:12:42 +02:00
|
|
|
* Revision 1.3 2000/08/19 18:12:42 steve
|
|
|
|
|
* Add target calls for scope, events and logic.
|
|
|
|
|
*
|
2000-08-14 06:39:56 +02:00
|
|
|
* Revision 1.2 2000/08/14 04:39:57 steve
|
|
|
|
|
* add th t-dll functions for net_const, net_bufz and processes.
|
|
|
|
|
*
|
2000-08-12 18:34:37 +02:00
|
|
|
* Revision 1.1 2000/08/12 16:34:37 steve
|
|
|
|
|
* Start stub for loadable targets.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|