Code rearrange. (Stephan Boettcher)

This commit is contained in:
steve 2001-11-06 03:07:21 +00:00
parent 0c4bea473c
commit bf9a8f5021
12 changed files with 512 additions and 312 deletions

View File

@ -16,7 +16,7 @@
# 59 Temple Place - Suite 330
# Boston, MA 02111-1307, USA
#
#ident "$Id: Makefile.in,v 1.30 2001/11/01 03:00:19 steve Exp $"
#ident "$Id: Makefile.in,v 1.31 2001/11/06 03:07:21 steve Exp $"
#
#
SHELL = /bin/sh
@ -65,7 +65,7 @@ vpi_vthr_vector.o vvp_vpi.o
O = main.o parse.o parse_misc.o lexor.o arith.o bufif.o compile.o debug.o \
functor.o fvectors.o npmos.o resolv.o symbols.o codes.o vthread.o schedule.o \
tables.o udp.o memory.o force.o $V
tables.o udp.o memory.o force.o event.o logic.o $V
vvp: $O
$(CXX) $(rdynamic) $(CXXFLAGS) $(LDFLAGS) -o vvp $O $(LIBS) $(dllib)

View File

@ -17,12 +17,10 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: compile.cc,v 1.112 2001/11/01 04:42:39 steve Exp $"
#ident "$Id: compile.cc,v 1.113 2001/11/06 03:07:21 steve Exp $"
#endif
# include "arith.h"
# include "bufif.h"
# include "npmos.h"
# include "compile.h"
# include "functor.h"
# include "resolv.h"
@ -33,7 +31,6 @@
# include "codes.h"
# include "schedule.h"
# include "vpi_priv.h"
# include "vthread.h"
# include "parse_misc.h"
#ifdef HAVE_MALLOC_H
# include <malloc.h>
@ -184,7 +181,7 @@ static symbol_table_t sym_vpi = 0;
* Add a functor to the symbol table
*/
static void define_functor_symbol(const char*label, vvp_ipoint_t ipt)
void define_functor_symbol(const char*label, vvp_ipoint_t ipt)
{
symbol_value_t val;
val.num = ipt;
@ -518,7 +515,7 @@ void compile_vpi_time_precision(long pre)
* and skip the symbol lookup.
*/
static void inputs_connect(vvp_ipoint_t fdx, unsigned argc, struct symb_s*argv)
void inputs_connect(vvp_ipoint_t fdx, unsigned argc, struct symb_s*argv)
{
for (unsigned idx = 0; idx < argc; idx += 1) {
@ -626,86 +623,6 @@ static void functor_reference(vvp_ipoint_t *ref, char *lab, unsigned idx)
free(lab);
}
/*
* The parser calls this function to create a functor. I allocate a
* functor, and map the name to the vvp_ipoint_t address for the
* functor. Also resolve the inputs to the functor.
*/
void compile_functor(char*label, char*type, unsigned argc, struct symb_s*argv)
{
functor_t obj;
if (strcmp(type, "OR") == 0) {
obj = new table_functor_s(ft_OR);
} else if (strcmp(type, "AND") == 0) {
obj = new table_functor_s(ft_AND);
} else if (strcmp(type, "BUF") == 0) {
obj = new table_functor_s(ft_BUF);
} else if (strcmp(type, "BUFIF0") == 0) {
obj = new vvp_bufif0_s;
} else if (strcmp(type, "BUFIF1") == 0) {
obj = new vvp_bufif1_s;
} else if (strcmp(type, "PMOS") == 0) {
obj = new vvp_pmos_s;
} else if (strcmp(type, "NMOS") == 0) {
obj= new vvp_nmos_s;
} else if (strcmp(type, "RPMOS") == 0) {
obj = new vvp_rpmos_s;
} else if (strcmp(type, "RNMOS") == 0) {
obj = new vvp_rnmos_s;
} else if (strcmp(type, "MUXZ") == 0) {
obj = new table_functor_s(ft_MUXZ);
} else if (strcmp(type, "EEQ") == 0) {
obj = new table_functor_s(ft_EEQ);
} else if (strcmp(type, "NAND") == 0) {
obj = new table_functor_s(ft_NAND);
} else if (strcmp(type, "NOR") == 0) {
obj = new table_functor_s(ft_NOR);
} else if (strcmp(type, "NOT") == 0) {
obj = new table_functor_s(ft_NOT);
} else if (strcmp(type, "XNOR") == 0) {
obj = new table_functor_s(ft_XNOR);
} else if (strcmp(type, "XOR") == 0) {
obj = new table_functor_s(ft_XOR);
} else {
yyerror("invalid functor type.");
free(type);
free(argv);
free(label);
return;
}
free(type);
assert(argc <= 4);
vvp_ipoint_t fdx = functor_allocate(1);
functor_define(fdx, obj);
define_functor_symbol(label, fdx);
free(label);
/* Connect the inputs of this functor to the given symbols. If
there are C<X> inputs, set the ival appropriately. */
inputs_connect(fdx, argc, argv);
free(argv);
}
static void make_extra_outputs(vvp_ipoint_t fdx, unsigned wid)
{
for (unsigned i=1; i < wid; i++) {
@ -1095,64 +1012,6 @@ void compile_memory_init(char *memid, unsigned i, unsigned char val)
idx++;
}
/*
** Create an event functor
** edge: compile_event(label, type, argc, argv)
** or: compile_event(label, NULL, argc, argv)
** name: compile_event(label, name, NULL, NULL)
*/
void compile_event(char*label, char*type,
unsigned argc, struct symb_s*argv)
{
event_functor_s::edge_t edge = vvp_edge_none;
if (argc && type) {
if (strcmp(type,"posedge") == 0)
edge = vvp_edge_posedge;
else if (strcmp(type,"negedge") == 0)
edge = vvp_edge_negedge;
else if (strcmp(type,"edge") == 0)
edge = vvp_edge_anyedge;
assert(argc <= 4 || edge == vvp_edge_none);
}
if (!argc && type) {
// "type" is the name of the named event
}
free(type);
functor_t obj = new event_functor_s(edge);
vvp_ipoint_t fdx = functor_allocate(1);
functor_define(fdx, obj);
define_functor_symbol(label, fdx);
free(label);
/* Run through the arguments looking for the functors that are
connected to my input ports. For each source functor that I
find, connect the output of that functor to the indexed
input by inserting myself (complete with the port number in
the vvp_ipoint_t) into the list that the source heads.
If the source functor is not declared yet, then don't do
the link yet. Save the reference to be resolved later. */
if (edge != vvp_edge_none)
inputs_connect(fdx, argc, argv);
else
// Are we sure that we have those .event/or
// drivers exclusively?
for (unsigned i=0; i<argc; i++) {
inputs_connect(fdx, 1, argv+i);
}
free(argv);
}
/*
* The parser uses this function to compile and link an executable
* opcode. I do this by looking up the opcode in the opcode_table. The
@ -1482,6 +1341,9 @@ vvp_ipoint_t debug_lookup_functor(const char*name)
/*
* $Log: compile.cc,v $
* Revision 1.113 2001/11/06 03:07:21 steve
* Code rearrange. (Stephan Boettcher)
*
* Revision 1.112 2001/11/01 04:42:39 steve
* Handle procedural constant functor pointers.
*

View File

@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: compile.h,v 1.36 2001/11/01 03:00:19 steve Exp $"
#ident "$Id: compile.h,v 1.37 2001/11/06 03:07:22 steve Exp $"
#endif
# include <stdio.h>
@ -39,6 +39,18 @@ extern void compile_init(void);
extern void compile_cleanup(void);
/*
* Connect a list of symbols to a contiguous set of ipoints.
* Constants C<?> are handled by setting the ival of the ipoint.
*/
extern void inputs_connect(vvp_ipoint_t fdx, unsigned argc, struct symb_s*argv);
/*
* Add a functor to the symbol table
*/
extern void define_functor_symbol(const char*label, vvp_ipoint_t ipt);
/*
* This is a count of errors encountered during compilation. If this
* is non-zero, then simulation is not recommended.
@ -208,6 +220,9 @@ extern void compile_net(char*label, char*name,
/*
* $Log: compile.h,v $
* Revision 1.37 2001/11/06 03:07:22 steve
* Code rearrange. (Stephan Boettcher)
*
* Revision 1.36 2001/11/01 03:00:19 steve
* Add force/cassign/release/deassign support. (Stephan Boettcher)
*

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: draw_tt.c,v 1.10 2001/10/09 02:28:17 steve Exp $"
#ident "$Id: draw_tt.c,v 1.11 2001/11/06 03:07:22 steve Exp $"
#endif
# include <stdio.h>
@ -594,7 +594,7 @@ static void draw_oct_table()
main()
{
printf("# include \"functor.h\"\n");
printf("# include \"logic.h\"\n");
draw_AND();
draw_BUF();
draw_BUFIF0();
@ -616,6 +616,9 @@ main()
/*
* $Log: draw_tt.c,v $
* Revision 1.11 2001/11/06 03:07:22 steve
* Code rearrange. (Stephan Boettcher)
*
* Revision 1.10 2001/10/09 02:28:17 steve
* Add the PMOS and NMOS functor types.
*

136
vvp/event.cc Normal file
View File

@ -0,0 +1,136 @@
/*
* Copyright (c) 2001 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)
#ident "$Id: event.cc,v 1.1 2001/11/06 03:07:22 steve Exp $"
#endif
# include "event.h"
# include "compile.h"
# include "vthread.h"
# include "schedule.h"
# include <string.h>
# include <assert.h>
#ifdef HAVE_MALLOC_H
# include <malloc.h>
#endif
event_functor_s::event_functor_s(edge_t e)
: edge(e), threads(0)
{}
event_functor_s::~event_functor_s()
{}
void event_functor_s::set(vvp_ipoint_t ptr, bool, unsigned val, unsigned)
{
old_ival = ival;
put(ptr, val);
/* Only go through the effort if there is someone interested
in the results... */
if (threads || out) {
bool edge_p = true;
if (edge) {
unsigned pp = ipoint_port(ptr);
unsigned oval = (old_ival >> 2*pp) & 3;
unsigned nval = (ival >> 2*pp) & 3;
unsigned val = (oval << 2) | nval;
edge_p = ((edge>>val) & 1) != 0;
}
if (edge_p) {
vthread_t tmp = threads;
threads = 0;
vthread_schedule_list(tmp);
if (out)
// only one output? Why not propagate?
schedule_assign(out, 0, 0);
}
}
}
/*
** Create an event functor
** edge: compile_event(label, type, argc, argv)
** or: compile_event(label, NULL, argc, argv)
** name: compile_event(label, name, NULL, NULL)
*/
void compile_event(char*label, char*type,
unsigned argc, struct symb_s*argv)
{
event_functor_s::edge_t edge = vvp_edge_none;
if (argc && type) {
if (strcmp(type,"posedge") == 0)
edge = vvp_edge_posedge;
else if (strcmp(type,"negedge") == 0)
edge = vvp_edge_negedge;
else if (strcmp(type,"edge") == 0)
edge = vvp_edge_anyedge;
assert(argc <= 4 || edge == vvp_edge_none);
}
if (!argc && type) {
// "type" is the name of the named event
}
free(type);
functor_t obj = new event_functor_s(edge);
vvp_ipoint_t fdx = functor_allocate(1);
functor_define(fdx, obj);
define_functor_symbol(label, fdx);
free(label);
/* Run through the arguments looking for the functors that are
connected to my input ports. For each source functor that I
find, connect the output of that functor to the indexed
input by inserting myself (complete with the port number in
the vvp_ipoint_t) into the list that the source heads.
If the source functor is not declared yet, then don't do
the link yet. Save the reference to be resolved later. */
if (edge != vvp_edge_none)
inputs_connect(fdx, argc, argv);
else
// Are we sure that we have those .event/or
// drivers exclusively?
for (unsigned i=0; i<argc; i++) {
inputs_connect(fdx, 1, argv+i);
}
free(argv);
}
/*
* $Log: event.cc,v $
* Revision 1.1 2001/11/06 03:07:22 steve
* Code rearrange. (Stephan Boettcher)
*
*/

73
vvp/event.h Normal file
View File

@ -0,0 +1,73 @@
#ifndef __event_H
#define __event_H
/*
* 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)
#ident "$Id: event.h,v 1.1 2001/11/06 03:07:22 steve Exp $"
#endif
# include "functor.h"
/*
* Event / edge detection functors
*/
struct event_functor_s: public edge_inputs_functor_s {
typedef unsigned short edge_t;
explicit event_functor_s(edge_t e);
virtual ~event_functor_s();
virtual void set(vvp_ipoint_t i, bool push, unsigned val, unsigned str);
edge_t edge;
vthread_t threads;
};
#define VVP_EDGE(a,b) (1<<(((a)<<2)|(b)))
const event_functor_s::edge_t vvp_edge_posedge
= VVP_EDGE(0,1)
| VVP_EDGE(0,2)
| VVP_EDGE(0,3)
| VVP_EDGE(2,1)
| VVP_EDGE(3,1)
;
const event_functor_s::edge_t vvp_edge_negedge
= VVP_EDGE(1,0)
| VVP_EDGE(1,2)
| VVP_EDGE(1,3)
| VVP_EDGE(2,0)
| VVP_EDGE(3,0)
;
const event_functor_s::edge_t vvp_edge_anyedge = 0x7bde;
const event_functor_s::edge_t vvp_edge_none = 0;
/*
* Callback functors.
*/
struct callback_functor_s *vvp_fvector_make_callback
(vvp_fvector_t, event_functor_s::edge_t = vvp_edge_none);
/*
* $Log: event.h,v $
* Revision 1.1 2001/11/06 03:07:22 steve
* Code rearrange. (Stephan Boettcher)
*
*/
#endif // __event_H

View File

@ -17,17 +17,13 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: functor.cc,v 1.31 2001/11/04 05:03:21 steve Exp $"
#ident "$Id: functor.cc,v 1.32 2001/11/06 03:07:22 steve Exp $"
#endif
# include "functor.h"
# include "schedule.h"
# include "vthread.h"
# include "vpi_priv.h"
# include "debug.h"
# include <assert.h>
# include <string.h>
# include <stdlib.h>
#ifdef HAVE_MALLOC_H
# include <malloc.h>
#endif
@ -107,60 +103,34 @@ void functor_define(vvp_ipoint_t point, functor_t obj)
functor_list[index1][index2] = obj;
}
void table_functor_s::set(vvp_ipoint_t ptr, bool push, unsigned v, unsigned)
functor_s::functor_s()
{
put(ptr, v);
/* Locate the new output value in the table. */
unsigned char val = table[ival >> 2];
val >>= 2 * (ival&0x03);
val &= 0x03;
put_oval(ptr, push, val);
out = 0;
port[0] = 0;
port[1] = 0;
port[2] = 0;
port[3] = 0;
ival = 0xaa;
oval = 2;
odrive0 = 6;
odrive1 = 6;
ostr = StX;
inhibit = 0;
#if defined(WITH_DEBUG)
breakpoint = 0;
#endif
}
/*
* An event functor is a probe of some sort that is looking for an edge
* of some specified type on any of its inputs. If it finds the right
* kind of edge, then it awakens all the threads that are waiting on
* this functor *and* it schedules an assign for any output it might
* have. The latter is to support wider event/or then a single functor
* can support.
*/
void event_functor_s::set(vvp_ipoint_t ptr, bool, unsigned val, unsigned)
functor_s::~functor_s()
{
old_ival = ival;
put(ptr, val);
/* Only go through the effort if there is someone interested
in the results... */
if (threads || out) {
bool edge_p = true;
if (edge) {
unsigned pp = ipoint_port(ptr);
unsigned oval = (old_ival >> 2*pp) & 3;
unsigned nval = (ival >> 2*pp) & 3;
unsigned val = (oval << 2) | nval;
edge_p = ((edge>>val) & 1) != 0;
}
if (edge_p) {
vthread_t tmp = threads;
threads = 0;
vthread_schedule_list(tmp);
if (out)
// only one output? Why not propagate?
schedule_assign(out, 0, 0);
}
}
}
// Special infrastructure functor types
extra_outputs_functor_s::~extra_outputs_functor_s()
{}
void extra_outputs_functor_s::set(vvp_ipoint_t i, bool push,
unsigned val, unsigned)
{
@ -170,6 +140,9 @@ void extra_outputs_functor_s::set(vvp_ipoint_t i, bool push,
base->set(base_, push, val);
}
extra_ports_functor_s::~extra_ports_functor_s()
{}
void extra_ports_functor_s::set(vvp_ipoint_t i, bool push,
unsigned val, unsigned str)
{
@ -177,6 +150,9 @@ void extra_ports_functor_s::set(vvp_ipoint_t i, bool push,
base->set(i, push, val, str);
}
extra_inputs_functor_s::~extra_inputs_functor_s()
{}
void extra_inputs_functor_s::set(vvp_ipoint_t i, bool push,
unsigned val, unsigned)
{
@ -186,9 +162,14 @@ void extra_inputs_functor_s::set(vvp_ipoint_t i, bool push,
base->set(ipoint_make(out,0), push, val);
}
edge_inputs_functor_s::~edge_inputs_functor_s()
{}
/*
* $Log: functor.cc,v $
* Revision 1.32 2001/11/06 03:07:22 steve
* Code rearrange. (Stephan Boettcher)
*
* Revision 1.31 2001/11/04 05:03:21 steve
* MacOSX 10.1 updates.
*

View File

@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: functor.h,v 1.36 2001/11/01 03:00:19 steve Exp $"
#ident "$Id: functor.h,v 1.37 2001/11/06 03:07:22 steve Exp $"
#endif
# include "pointers.h"
@ -32,11 +32,6 @@
extern void schedule_functor(vvp_ipoint_t fun, unsigned delay);
/*
*
* The major mode is selected by the mode parameter.
*
* MODE 0: TABLE MODE FUNCTORS
*
* The vvp_ipoint_t is an integral type that is 32bits. The low 2 bits
* select the port of the referenced functor, and the remaining 30
* index the functor itself. All together, the 32 bits can completely
@ -55,22 +50,9 @@ extern void schedule_functor(vvp_ipoint_t fun, unsigned delay);
* 1'bx : 10
* 1'bz : 11
*
* The function of the functor is defined by the table/event
* union. Normally, the truth table is the behavior and the functor
* output value is picked from the lookup table that the table pointer
* points to.
*
* MODE 42: LIFE, THE UNIVERSE AND EVERYTHING ELSE
*
* These functors are and escape for all other behaviors. This mode
* supports arbitrary complex behavior by replacing the truth table
* with a struct vvp_fobj_s pointer. This abstract class has virtual
* methods for receiving and retrieving values. See the vvp_fobj_s
* definition below.
*
* DRIVE STRENGTHS:
*
* The normal functor (modes 0) is not aware of strengths. It
* The normal functor is not aware of strengths. It
* generates strength simply by virtue of having strength
* specifications. The drive strength specification includes a drive0
* and drive1 strength, each with 8 possible values (that can be
@ -168,6 +150,7 @@ extern void functor_define(vvp_ipoint_t point, functor_t obj);
struct functor_s {
functor_s();
virtual ~functor_s();
/* This is the output for the device. */
vvp_ipoint_t out;
/* These are the input ports. */
@ -207,24 +190,6 @@ struct functor_s {
void force(unsigned val, unsigned str);
};
inline functor_s::functor_s()
{
out = 0;
port[0] = 0;
port[1] = 0;
port[2] = 0;
port[3] = 0;
ival = 0xaa;
oval = 2;
odrive0 = 6;
odrive1 = 6;
ostr = StX;
inhibit = 0;
#if defined(WITH_DEBUG)
breakpoint = 0;
#endif
}
/*
* Set the ival for input port ptr to value val.
*/
@ -340,19 +305,24 @@ unsigned functor_get(vvp_ipoint_t ptr)
* the inputs it is connected to, creating new propagation event on
* the way.
*/
static inline
inline static
void functor_propagate(vvp_ipoint_t ptr, bool push=true)
{
functor_t fp = functor_index(ptr);
fp->propagate(push);
}
// Special infrastructure functor types
// The extra_outputs_functor_s class is for devices that require
// multiple inputs and outputs.
// ->set redirects the job to the base_, who knows what shall be done.
struct extra_outputs_functor_s: public functor_s {
extra_outputs_functor_s(vvp_ipoint_t b = 0) : base_(b) {}
virtual ~extra_outputs_functor_s();
virtual void set(vvp_ipoint_t i, bool push, unsigned val, unsigned str);
unsigned base_;
@ -365,6 +335,7 @@ struct extra_outputs_functor_s: public functor_s {
struct extra_ports_functor_s : public extra_outputs_functor_s
{
extra_ports_functor_s(vvp_ipoint_t b = 0) : extra_outputs_functor_s(b) {}
virtual ~extra_ports_functor_s();
virtual void set(vvp_ipoint_t i, bool push, unsigned val, unsigned str);
};
@ -374,6 +345,7 @@ struct extra_ports_functor_s : public extra_outputs_functor_s
struct extra_inputs_functor_s: public functor_s {
extra_inputs_functor_s(vvp_ipoint_t b = 0) { out = b; }
virtual ~extra_inputs_functor_s();
virtual void set(vvp_ipoint_t i, bool push, unsigned val, unsigned str);
};
@ -383,77 +355,10 @@ struct extra_inputs_functor_s: public functor_s {
struct edge_inputs_functor_s: public extra_inputs_functor_s
{
edge_inputs_functor_s() : old_ival(2) {}
virtual ~edge_inputs_functor_s();
unsigned char old_ival;
};
/*
* Table driven functor. oval = table[ival];
*/
struct table_functor_s: public functor_s {
typedef const unsigned char *truth_t;
explicit table_functor_s(truth_t t) : table(t) {}
virtual void set(vvp_ipoint_t i, bool push, unsigned val, unsigned str);
truth_t table;
};
// table functor types
extern const unsigned char ft_AND[];
extern const unsigned char ft_BUF[];
extern const unsigned char ft_BUFIF0[];
extern const unsigned char ft_BUFIF1[];
extern const unsigned char ft_PMOS[];
extern const unsigned char ft_NMOS[];
extern const unsigned char ft_MUXZ[];
extern const unsigned char ft_EEQ[];
extern const unsigned char ft_NAND[];
extern const unsigned char ft_NOR[];
extern const unsigned char ft_NOT[];
extern const unsigned char ft_OR[];
extern const unsigned char ft_XNOR[];
extern const unsigned char ft_XOR[];
extern const unsigned char ft_var[];
/*
* Event / edge detection functors
*/
struct event_functor_s: public edge_inputs_functor_s {
typedef unsigned short edge_t;
explicit event_functor_s(edge_t e) : edge(e), threads(0) {}
virtual void set(vvp_ipoint_t i, bool push, unsigned val, unsigned str);
edge_t edge;
vthread_t threads;
};
#define VVP_EDGE(a,b) (1<<(((a)<<2)|(b)))
const event_functor_s::edge_t vvp_edge_posedge
= VVP_EDGE(0,1)
| VVP_EDGE(0,2)
| VVP_EDGE(0,3)
| VVP_EDGE(2,1)
| VVP_EDGE(3,1)
;
const event_functor_s::edge_t vvp_edge_negedge
= VVP_EDGE(1,0)
| VVP_EDGE(1,2)
| VVP_EDGE(1,3)
| VVP_EDGE(2,0)
| VVP_EDGE(3,0)
;
const event_functor_s::edge_t vvp_edge_anyedge = 0x7bde;
const event_functor_s::edge_t vvp_edge_none = 0;
/*
* Callback functors.
*/
struct callback_functor_s *vvp_fvector_make_callback
(vvp_fvector_t, event_functor_s::edge_t = vvp_edge_none);
/*
* Vectors of functors
*/
@ -468,6 +373,9 @@ extern vvp_fvector_t vvp_fvector_continuous_new(unsigned size, vvp_ipoint_t p);
/*
* $Log: functor.h,v $
* Revision 1.37 2001/11/06 03:07:22 steve
* Code rearrange. (Stephan Boettcher)
*
* Revision 1.36 2001/11/01 03:00:19 steve
* Add force/cassign/release/deassign support. (Stephan Boettcher)
*

143
vvp/logic.cc Normal file
View File

@ -0,0 +1,143 @@
/*
* Copyright (c) 2001 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)
#ident "$Id: logic.cc,v 1.1 2001/11/06 03:07:22 steve Exp $"
#endif
# include "logic.h"
# include "compile.h"
# include "bufif.h"
# include "npmos.h"
# include <string.h>
# include <assert.h>
#ifdef HAVE_MALLOC_H
# include <malloc.h>
#endif
/*
* Implementation of the table functor, which provides logic with up
* to 4 inputs.
*/
inline table_functor_s::table_functor_s(truth_t t)
: table(t)
{}
table_functor_s::~table_functor_s()
{}
void table_functor_s::set(vvp_ipoint_t ptr, bool push, unsigned v, unsigned)
{
put(ptr, v);
/* Locate the new output value in the table. */
unsigned char val = table[ival >> 2];
val >>= 2 * (ival&0x03);
val &= 0x03;
put_oval(ptr, push, val);
}
/*
* The parser calls this function to create a logic functor. I allocate a
* functor, and map the name to the vvp_ipoint_t address for the
* functor. Also resolve the inputs to the functor.
*/
void compile_functor(char*label, char*type, unsigned argc, struct symb_s*argv)
{
functor_t obj;
if (strcmp(type, "OR") == 0) {
obj = new table_functor_s(ft_OR);
} else if (strcmp(type, "AND") == 0) {
obj = new table_functor_s(ft_AND);
} else if (strcmp(type, "BUF") == 0) {
obj = new table_functor_s(ft_BUF);
} else if (strcmp(type, "BUFIF0") == 0) {
obj = new vvp_bufif0_s;
} else if (strcmp(type, "BUFIF1") == 0) {
obj = new vvp_bufif1_s;
} else if (strcmp(type, "PMOS") == 0) {
obj = new vvp_pmos_s;
} else if (strcmp(type, "NMOS") == 0) {
obj= new vvp_nmos_s;
} else if (strcmp(type, "RPMOS") == 0) {
obj = new vvp_rpmos_s;
} else if (strcmp(type, "RNMOS") == 0) {
obj = new vvp_rnmos_s;
} else if (strcmp(type, "MUXZ") == 0) {
obj = new table_functor_s(ft_MUXZ);
} else if (strcmp(type, "EEQ") == 0) {
obj = new table_functor_s(ft_EEQ);
} else if (strcmp(type, "NAND") == 0) {
obj = new table_functor_s(ft_NAND);
} else if (strcmp(type, "NOR") == 0) {
obj = new table_functor_s(ft_NOR);
} else if (strcmp(type, "NOT") == 0) {
obj = new table_functor_s(ft_NOT);
} else if (strcmp(type, "XNOR") == 0) {
obj = new table_functor_s(ft_XNOR);
} else if (strcmp(type, "XOR") == 0) {
obj = new table_functor_s(ft_XOR);
} else {
yyerror("invalid functor type.");
free(type);
free(argv);
free(label);
return;
}
free(type);
assert(argc <= 4);
vvp_ipoint_t fdx = functor_allocate(1);
functor_define(fdx, obj);
define_functor_symbol(label, fdx);
free(label);
inputs_connect(fdx, argc, argv);
free(argv);
}
/*
* $Log: logic.cc,v $
* Revision 1.1 2001/11/06 03:07:22 steve
* Code rearrange. (Stephan Boettcher)
*
*/

63
vvp/logic.h Normal file
View File

@ -0,0 +1,63 @@
#ifndef __logic_H
#define __logic_H
/*
* 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)
#ident "$Id: logic.h,v 1.1 2001/11/06 03:07:22 steve Exp $"
#endif
# include "functor.h"
/*
* Table driven functor. oval = table[ival];
*/
struct table_functor_s: public functor_s {
typedef const unsigned char *truth_t;
explicit table_functor_s(truth_t t);
virtual ~table_functor_s();
virtual void set(vvp_ipoint_t i, bool push, unsigned val, unsigned str);
truth_t table;
};
// table functor types
extern const unsigned char ft_AND[];
extern const unsigned char ft_BUF[];
extern const unsigned char ft_BUFIF0[];
extern const unsigned char ft_BUFIF1[];
extern const unsigned char ft_PMOS[];
extern const unsigned char ft_NMOS[];
extern const unsigned char ft_MUXZ[];
extern const unsigned char ft_EEQ[];
extern const unsigned char ft_NAND[];
extern const unsigned char ft_NOR[];
extern const unsigned char ft_NOT[];
extern const unsigned char ft_OR[];
extern const unsigned char ft_XNOR[];
extern const unsigned char ft_XOR[];
extern const unsigned char ft_var[];
/*
* $Log: logic.h,v $
* Revision 1.1 2001/11/06 03:07:22 steve
* Code rearrange. (Stephan Boettcher)
*
*/
#endif // __logic_H

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: vpi_callback.cc,v 1.9 2001/10/31 04:27:47 steve Exp $"
#ident "$Id: vpi_callback.cc,v 1.10 2001/11/06 03:07:22 steve Exp $"
#endif
/*
@ -31,6 +31,7 @@
# include "vpi_priv.h"
# include "schedule.h"
# include "functor.h"
# include "event.h"
# include <stdio.h>
# include <assert.h>
#ifdef HAVE_MALLOC_H
@ -100,12 +101,20 @@ inline static void free_vpi_callback(struct __vpiCallback* obj)
*/
struct callback_functor_s: public functor_s {
callback_functor_s() : permanent(0) {}
callback_functor_s();
virtual ~callback_functor_s();
virtual void set(vvp_ipoint_t i, bool push, unsigned val, unsigned str);
struct __vpiCallback *cb_handle;
unsigned permanent : 1;
};
inline callback_functor_s::callback_functor_s()
: permanent(0)
{}
callback_functor_s::~callback_functor_s()
{}
struct callback_functor_s *vvp_fvector_make_callback(vvp_fvector_t vec,
event_functor_s::edge_t edge)
{
@ -300,6 +309,9 @@ void vpip_trip_monitor_callbacks(void)
/*
* $Log: vpi_callback.cc,v $
* Revision 1.10 2001/11/06 03:07:22 steve
* Code rearrange. (Stephan Boettcher)
*
* Revision 1.9 2001/10/31 04:27:47 steve
* Rewrite the functor type to have fewer functor modes,
* and use objects to manage the different types.

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: vthread.cc,v 1.63 2001/11/01 03:00:20 steve Exp $"
#ident "$Id: vthread.cc,v 1.64 2001/11/06 03:07:22 steve Exp $"
#endif
# include "vthread.h"
@ -25,6 +25,7 @@
# include "debug.h"
# include "schedule.h"
# include "functor.h"
# include "event.h"
# include "vpi_priv.h"
#ifdef HAVE_MALLOC_H
# include <malloc.h>
@ -1671,6 +1672,9 @@ bool of_ZOMBIE(vthread_t thr, vvp_code_t)
/*
* $Log: vthread.cc,v $
* Revision 1.64 2001/11/06 03:07:22 steve
* Code rearrange. (Stephan Boettcher)
*
* Revision 1.63 2001/11/01 03:00:20 steve
* Add force/cassign/release/deassign support. (Stephan Boettcher)
*