starClass
argument in its constructor specifies what type. A Universe or InterpUniverse is run by executing its Target. Targets have Schedulers, which as a rule control order of execution, but it is the Target that is in control. A Target can have children that are other Targets; this is used, for example, to represent multi-processor systems for which code is being generated (the parent target represents the system as a whole, and child targets represent each processor).
Target(const char* name, const char* starClass,const char* desc = "");This is the signature of the Target constructor.
name
specifies the name of the Target and desc
specifies its descriptor (these fields end up filling in the corresponding NamedObj fields). The starClass
argument specifies the class of stars that can be executed by the Target. For example, specifying DataFlowStar
for this argument means that the Target can run any type of star of this class or a class derived from it. The isA
function is used to perform the check. See the description of auxStarClass
below.
const char* starType() const;Return the supported star class (the
starClass
argument from the constructor).
Scheduler* scheduler() const;Return a pointer to my scheduler.
Target* cloneTarget() const;This simply returns the result of the
clone
function as a Target. It is used by the KnownTarget class, for example to create a Target object corresponding to a name specified from a user interface.
virtual StringList displaySchedule();The default implementation simply passes this call along to the scheduler; derived classes may modify this.
virtual StringList pragma () const;A Target may understand certain annotations associated with Blocks called pragmas. For example, an annotation may specify how many times a particular Star should fire. Or it could specify that a particular Block should be mapped onto a particular processor. Or it could specify that a particular State of a particular Block should be settable on the command line that invokes a generated program. The above method returns the list of named pragmas that a particular target understands (e.g.
firingsPerIteration
or processorNumber
). In derived classes, each item in the list is a three part string, "name type value
", separated by spaces. The value
will be a default value. The implementation in class Target returns a StringList with only a single zero-length string in it. The type
can be any type used in states.
virtual StringList pragma (const char* parentname,To determine the value of all pragmas that have been specified for a particular block, call this method. In derived classes, it returns a list of "
const char* blockname) const;
name value
" pairs, separated by spaces. In the base class, it returns an empty string. The parentname
is the name of the parent class (universe or galaxy master name).
virtual StringList pragma (const char* parentname,To determine the value of a pragma of a particular type that has been specified for a particular block, call this method. In derived classes, it returns a value. In the base class, it returns a zero-length string.
const char* blockname,
const char* pragmaname) const;
virtual StringList pragma (const char* parentname,To specify a pragma to a target, call this method. The implementation in the base class "Target" does nothing. In derived classes, the pragma will be registered in some way. The return value is always a zero-length string.
const char* blockname,
const char* pragmaname,
const char* value) const;
Target* child(int n);Return the
nth
child Target, null if no children or if n
exceeds the number of children.
Target* proc(int n);This is the same as
child
if there are children. If there are no children, an argument of 0 will return a pointer to the object on which it is called, otherwise a null pointer is returned.
int nProcs() const;Return the number of processors (1 if no children, otherwise the number of children).
virtual int hasResourcesFor(Star& s,const char* extra=0);Determine whether this target has the necessary resources to run the given star. It is virtual in case this is necessary in child classes. The default implementation uses
resources
states of the target and the star.
virtual int childHasResources(Star& s,int childNum);Determine whether a particular child target has resources to run the given star. It is virtual in case later necessary.
virtual void setGalaxy(Galaxy& g);Associate a Galaxy with the Target. The default implementation just sets its galaxy pointer to point to
g.
virtual void setStopTime(double when);Set the stopping condition. The default implementation just passes this on to the scheduler.
virtual void resetStopTime(double when);Reset the stopping condition for the wormhole containing this Target. The default implementation just passes this on to the scheduler. In addition to the action performed by
setStopTime,
this function also does any synchronization required by wormholes.
virtual void setCurrentTime(double now);Set the current time to
now.
virtual int run();The following methods are provided for code generation; schedulers may call these. They may move to class CGTarget in a future Ptolemy release.
virtual void wrapup();
virtual void beginIteration(int repetitions, int depth);Function called to begin an iteration (default version does nothing).
virtual void endIteration(int repetitions, int depth);Function called to end an iteration (default version does nothing).
virtual void writeFiring(Star& s, int depth);Function called to generate code for the star, with any modifications required by this particular Target (the default version does nothing).
virtual void beginIf(PortHole& cond, int truthdir,
int depth, int haveElsePart);
virtual void beginElse(int depth);These above functions are used in code generation to generate conditionals. The default implementations do nothing.
virtual void endIf(int depth);
virtual void beginDoWhile(PortHole& cond, int truthdir, int depth);
virtual void endDoWhile(PortHole& cond);
virtual int commTime(int sender,int receiver,int nUnits, int type);Return the number of time units required to send
nUnits
units of data whose type is the code indicated by type
from the child Target numbered sender
to the child target numbered receiver.
The default implementation returns 0 regardless of the parameters. No meaning is specified at this level for the type codes, as different languages have different types; all that is required is that different types supported by a particular target map into distinct type codes.
Galaxy* galaxy();Return my galaxy pointer (0 if it has not been set).
virtual void setup();This is the main initialization function for the target. It is called by the
initialize
function, which by default initializes the Target states. The default implementation calls galaxySetup(),
and if it returns a nonzero value, then calls schedulerSetup().
virtual int galaxySetup();This method (and overloaded versions of it) is responsible for checking the galaxy belonging to the target. In the default implementation, each star is checked to see if its type is supported by the target (because the
isA
function reports that it is one of the supported star classes). If a star does not match this condition an error is reported. In addition, setTarget()
is called for each star with a pointer to the Target as an argument. If there are errors, 0 is returned, otherwise 1.
virtual int schedulerSetup();This method (and overloaded versions of it) are responsible for initializing an execution of the universe. The default implementation initializes the scheduler and calls
setup()
on it.
void setSched(Scheduler* sch);The target's scheduler is set to
sch,
which must either point to a scheduler on the heap or be a null pointer. Any preexisting scheduler is deleted. Also, the scheduler's setTarget
member is called, associating the Target with the Scheduler.
void delSched();This function deletes the target's scheduler and sets the scheduler pointer to null.
void addChild(Target& child);Add
child
as a child target.
void inheritChildren(Target* parent, int start, int stop);This method permits two different Target objects to share child Targets. The child targets numbered
start
through stop
of the Target pointed to by parent
become the children of this Target (the one on which this method is called). Its primary use is in multi-processor scheduling or code generation, in which some construct is assigned to a group of processors. It has a big disadvantage; the range of child targets must be continuous.
void remChildren();Remove the
children
list. This does not delete the child targets.
void deleteChildren();Delete all the
children
. This assumes that the child Targets were created with new.
virtual const char* auxStarClass() const;Auxiliary star class: permits a second type of star in addition to the supported star class (see
startType()
). The default implementation returns a null pointer, indicating no auxiliary star class. Sorry, there is no present way to support yet a third type.
const char* writeDirectoryName(const char* dirName = 0);This method returns a directory name that is intended for use in writing files, particularly for code generation targets. If the directory does not exist, it attempts to create it. Returns the fully expanded path name (which is saved by the target).
const char* workingDirectory() const;Return the directory name previously set by
writeDirectoryName.
char* writeFileName(const char* fileName = 0);Method to set a file name for writing.
writeFileName
prepends dirFullName
(which was set by writeDirectoryName)
to fileName
with "/
" between. Always returns a pointer to a string in new memory. It is up to the user to delete the memory when no longer needed. If dirFullName
or fileName
is NULL then it returns a pointer to a new copy of the string /dev/null
.