|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectmapss.dif.softsyn.c.DIFtoC
public class DIFtoC
DIF-to-C code generation (software synthesis) supports: SDF, hierarchical scheduling (with flatten option), semi-circular buffering, read/write pointers with modulo operation -- SAS and MAS.
1. Buffer declaration for an edge uses edge's name as buffer variable.
2. Read and write pointers for an edge buffer have suffix "r" and "w". Note that this may cause naming ambiguity.
3. Subhierarchy is generated as a subroutine (C function). Subroutine parameter types use ports' DIFAttributeType.datatype parameters. Subroutine parameter id use ports' name.
4. Actor attribute types, INPUT, OUTPUT, and PARAMETER, are usually associated when attribute's value is Edge or Port object. However, it is not necessary to specify INPUT, OUTPUT, and PARAMETER for software synthesis (code generation). But they may be useful in exporting, importing, and porting.
5. In DIF specification, the first attribute of an actor is its computation. The following actor attributes must match the function's parameter order defined in function prototype.
6. In dif specification, each graph must have a unique name. Several supernodes based on the same subgraph functionality still have different sub-routine functions for them. The derived class may improve it. Be aware of local variable that may need to be static.
7. Datatype of edges and ports are int, float, double, short, or static int, static float, ... Do not add '*' in datatype specification in DIF. The derived class may parse the datatype String for more complicated declaration.
8. User-defined attribute datatype is preserved to specify the datatype of an edge. 9. Source and sink of an edge must produces and consumes data in the same type. There is no way in C to cast an array to another type. 10. Sub-routine (function) parameters corresponding to ports are always pointer types. This class will automatically add '*'.
11. Array and matrix must set as a parameter in DIF instead of directly used in attribute value.
12. I/O parameters of functions are assumed to have types matching the connected edges' types. In this case, it is not necessary to specify the datatype fields of actor attributes. The derived class can add methods to check the consistency of edges' datatypes and I/O parameters' datatypes.
13. String in DIF value will be directly generated as its content instead of "...".
14. Adjusting read and write pointers performs modulo operation.
15. Semi-circular buffering: Buffer size for an edge e is maxTokne(e,S) + max(prd(e), cns(e)) -1 for the worst case MAS or delay situation in wrap around access.
16. Semi-circular buffering: If at certain instance, the actor consumes or produces tokens circled around the circular buffer, a necessary amount of tokens are copied from front to the extra space for being consumed before function call or a necessary amount of tokens are copied from the extra space to front after the function call.
17. User-defined attribute: include, priorExpression, and postExpression can be used in DIF specification to specify include files, expression before the main execution, and expression after the main execution (ex: file close).
| Field Summary | |
|---|---|
protected boolean |
_ansic
|
protected java.util.Map |
_buffers
|
protected CGenerator |
_generator
|
protected DIFHierarchy |
_hierarchy
|
protected java.lang.String |
_IDX
|
protected java.lang.String |
_INT
|
protected int |
_level
|
protected java.lang.String |
_RP
|
protected Scheduler |
_scheduler
|
protected java.util.HashMap |
_subSchedules
|
protected java.lang.String |
_TEMPIDX
|
protected java.lang.String |
_WP
|
| Constructor Summary | |
|---|---|
DIFtoC(DIFHierarchy hierarchy,
Scheduler scheduler,
java.lang.String cFile)
Constructor. |
|
| Method Summary | |
|---|---|
protected void |
_calculateBuffers(DIFHierarchy hierarchy,
mocgraph.sched.Schedule schedule)
Calculate buffer memory requirements by SynthesisUtilities.simulateBuffer(mapss.dif.csdf.sdf.SDFGraph, mocgraph.sched.Schedule) for all eges in
hierarchy.getGraph() given the schedule. |
protected void |
_generateBuffers(DIFHierarchy hierarchy,
mocgraph.sched.Schedule schedule)
This method declaress buffers, such as: int e1[6], for all edges according to the results computed by _calculateBuffers. |
protected void |
_generateFiring(DIFHierarchy hierarchy,
mocgraph.sched.Firing firing)
Generate function call for an actor firing. |
protected void |
_generateFunctionCall(DIFHierarchy hierarchy,
mocgraph.sched.Firing firing)
Generate function call for an actor whose computation is a library function. |
protected void |
_generateHierarchy(DIFHierarchy hierarchy)
Generate C sub-routine for hierarchy. |
protected void |
_generateIndices(DIFHierarchy hierarchy,
mocgraph.sched.Schedule schedule)
Generate indices of for-loops for all subschedules in schedule. |
protected void |
_generateIOParam(DIFGraph graph,
mocgraph.Edge edge,
mocgraph.sched.Firing firing,
java.util.List params,
java.util.List priorExps,
java.util.List postExps)
Generate I/O parameter for function call. |
protected void |
_generateIOParam(DIFHierarchy hierarchy,
Port port,
mocgraph.sched.Firing firing,
java.util.List params,
java.util.List priorExps,
java.util.List postExps)
Generate I/O parameter for function call. |
protected void |
_generateMain(DIFHierarchy hierarchy,
mocgraph.sched.Schedule schedule)
Generate main(). |
protected void |
_generateParameters(DIFHierarchy hierarchy)
Generate C variable or array for DIFParameter contained in the graph of hierarchy. |
protected void |
_generatePortAccess(DIFHierarchy hierarchy)
For all ports in hierarchy, generate read or write pointer for port according to its direction. |
protected void |
_generatePostExpression(DIFHierarchy hierarchy)
Generate post expressions before the end of main or subroutine according to the user-defined attribute "postExpression". |
protected void |
_generatePriorExpression(DIFHierarchy hierarchy)
Generate prior expressions before the major for loop in main or subroutine according to the user-defined attribute "priorExpression". |
protected void |
_generatePrologInclude()
Generate prolog (copyright, author, version) and include according to the user-defined attribute "include". |
protected void |
_generateSchedule(DIFHierarchy hierarchy,
mocgraph.sched.Schedule schedule)
Generate codes for schedule or subschedule, schedule, of hierarchy. |
protected void |
_generateSubroutineParams(DIFHierarchy hierarchy,
java.util.List types,
java.util.List params)
Generate subroutine parameters and parameters' types. |
protected void |
_generateSupernodeFiring(DIFHierarchy hierarchy,
mocgraph.sched.Firing firing)
Generate subroutine function call for firing whose firing element is a supernode. |
protected void |
_generateVariable(java.lang.String name,
java.lang.String dataType,
java.lang.Object value)
Generate variable name, with datatype and value. |
protected boolean |
_isTypeMatch(DIFGraph graph,
mocgraph.Edge edge,
DIFHierarchy subHierarchy,
Port subPort)
Check whether the datatype of edge is equal to the datatype of subPort. |
protected boolean |
_isTypeMatch(DIFHierarchy hierarchy,
Port port,
DIFHierarchy subHierarchy,
Port subPort)
Check whether the datatype of port is equal to the datatype of subPort. |
void |
generate()
Generate the c code implementing the input hierarchy. |
void |
setANSIC(boolean ansic)
If ansic is true, all variables will be declared before any functional expression. |
void |
setFlatten(boolean flag)
|
void |
setIteration(int iteration)
Set the number of iteration for the whole schedule. |
void |
setYear(java.lang.String year)
Set the copyright year. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected CGenerator _generator
protected DIFHierarchy _hierarchy
protected java.util.HashMap _subSchedules
protected Scheduler _scheduler
protected java.util.Map _buffers
protected int _level
protected java.lang.String _WP
protected java.lang.String _RP
protected java.lang.String _IDX
protected java.lang.String _INT
protected java.lang.String _TEMPIDX
protected boolean _ansic
| Constructor Detail |
|---|
public DIFtoC(DIFHierarchy hierarchy,
Scheduler scheduler,
java.lang.String cFile)
throws java.io.IOException
hierarchy - scheduler - The SDFScheduler.cFile - The c file name to be generated.
java.io.IOException| Method Detail |
|---|
public void generate()
_generateMain(mapss.dif.DIFHierarchy, mocgraph.sched.Schedule). For each sub-hierarchy,
_generateHierarchy(mapss.dif.DIFHierarchy) is invoked.
public void setANSIC(boolean ansic)
public void setYear(java.lang.String year)
year - public void setIteration(int iteration)
iteration - public void setFlatten(boolean flag)
protected void _calculateBuffers(DIFHierarchy hierarchy,
mocgraph.sched.Schedule schedule)
SynthesisUtilities.simulateBuffer(mapss.dif.csdf.sdf.SDFGraph, mocgraph.sched.Schedule) for all eges in
hierarchy.getGraph() given the schedule.
The results will be set to a private Map _buffers
containing all edges in the graph. The key of the Map is
Edge object, the entry is Integer buffer size.
The derived class can override this class to perform other buffer
calculation and put their own entry into the Map.
hierarchy - schedule -
protected void _generateBuffers(DIFHierarchy hierarchy,
mocgraph.sched.Schedule schedule)
_calculateBuffers.
The buffer size is extended for accommodating circulation for
delays and MASs.
It also declares read and write pointers for all buffers.
A read pointer is named by edge name + _RP and a write pointer is
named by edge name + _WP. All read pointers are initialized to 0.
If edges have initial delays, the corresponding write pointers are set
accordingly.
hierarchy - schedule -
protected void _generateFiring(DIFHierarchy hierarchy,
mocgraph.sched.Firing firing)
_generateSupernodeFiring(mapss.dif.DIFHierarchy, mocgraph.sched.Firing). If the node of firing is
an actor, it calls _generateFunctionCall(mapss.dif.DIFHierarchy, mocgraph.sched.Firing).
hierarchy - firing -
protected void _generateFunctionCall(DIFHierarchy hierarchy,
mocgraph.sched.Firing firing)
_generateIOParam(mapss.dif.DIFGraph, mocgraph.Edge, mocgraph.sched.Firing, java.util.List, java.util.List, java.util.List).
graph - firing - protected void _generateHierarchy(DIFHierarchy hierarchy)
_generateSubroutineParams(mapss.dif.DIFHierarchy, java.util.List, java.util.List). Port access
pointers are generated by _generatePortAccess(mapss.dif.DIFHierarchy).
Edge buffer information is calculate by #calculateBuffers.
Which can be overrided to perform various computation such as
buffer memory requirement, lifetime analysis.
Edge buffers are generated by _generateBuffers(mapss.dif.DIFHierarchy, mocgraph.sched.Schedule). Parameters
are generated by _generateParameters(mapss.dif.DIFHierarchy). Indices of for loops
are generated by _generateIndices(mapss.dif.DIFHierarchy, mocgraph.sched.Schedule). Code implementing the
schedule of this hierarchy is generated by
_generateSchedule(mapss.dif.DIFHierarchy, mocgraph.sched.Schedule).
protected void _generateIndices(DIFHierarchy hierarchy,
mocgraph.sched.Schedule schedule)
hierarchy - schedule -
protected void _generateIOParam(DIFGraph graph,
mocgraph.Edge edge,
mocgraph.sched.Firing firing,
java.util.List params,
java.util.List priorExps,
java.util.List postExps)
graph - The graph contains edge.edge - The edge to which the parameter refers.firing - params - The parameter list of the function call.priorExps - The expresions before firing.postExps - The expresions after firing, e.g., the pointer adjust
expressions of the function call.
protected void _generateIOParam(DIFHierarchy hierarchy,
Port port,
mocgraph.sched.Firing firing,
java.util.List params,
java.util.List priorExps,
java.util.List postExps)
hierarchy - The hierarchy contains port.port - The port to which the parameter refers.firing - params - The parameter list of the function call.priorExps - The expresions before firing.postExps - The expresions after firing, e.g., the pointer adjust
expressions of the function call.
protected void _generateMain(DIFHierarchy hierarchy,
mocgraph.sched.Schedule schedule)
_generatePrologInclude(). Edge buffers of the top level graph
are generated by _generateBuffers(mapss.dif.DIFHierarchy, mocgraph.sched.Schedule). Parameters are
generated by _generateParameters(mapss.dif.DIFHierarchy). Indices of for loops are
generated by _generateIndices(mapss.dif.DIFHierarchy, mocgraph.sched.Schedule). The most outer for loops to
iterate schedule is generated according to
setIteration(int). Code implementing the schedule of the top level
hierarchy is generated by _generateSchedule(mapss.dif.DIFHierarchy, mocgraph.sched.Schedule).
A fcloseall() may be generated according to
#setAutoFileClose.
hierarchy - The top level hierarchy corresponding to main().schedule - The schedule of hierarchy.protected void _generateParameters(DIFHierarchy hierarchy)
hierarchy - protected void _generatePortAccess(DIFHierarchy hierarchy)
hierarchy - protected void _generatePostExpression(DIFHierarchy hierarchy)
attribute postExpression { = "xxx"; } or
attribute postExpression { = ("xxx", ..., "xxx"); }
hierarchy - protected void _generatePriorExpression(DIFHierarchy hierarchy)
attribute priorExpression { = "xxx"; } or
attribute priorExpression { = ("xxx", ..., "xxx"); }
hierarchy - protected void _generatePrologInclude()
attribute include { = "xxx"; } or
attribute include { = ("xxx", ..., "xxx"); }
protected void _generateSchedule(DIFHierarchy hierarchy,
mocgraph.sched.Schedule schedule)
_generateFiring(mapss.dif.DIFHierarchy, mocgraph.sched.Firing) is invoked; if it is a sub-schedule,
_generateSchedule(mapss.dif.DIFHierarchy, mocgraph.sched.Schedule) is invoked recursively.
hierarchy - schedule -
protected void _generateSubroutineParams(DIFHierarchy hierarchy,
java.util.List types,
java.util.List params)
hierarchy - types - LinkedList of String containing typeparams - LinkedList of String containing parameter
protected void _generateSupernodeFiring(DIFHierarchy hierarchy,
mocgraph.sched.Firing firing)
_generateHierarchy(mapss.dif.DIFHierarchy), which is independent of this method.
The for loop to iterate firing is generated first, and then
the subroutine function call. I/O parameters of the function call
and the adjusting expression is handled by _generateIOParam(mapss.dif.DIFGraph, mocgraph.Edge, mocgraph.sched.Firing, java.util.List, java.util.List, java.util.List).
hierarchy - firing -
protected void _generateVariable(java.lang.String name,
java.lang.String dataType,
java.lang.Object value)
name - datatype - value -
protected boolean _isTypeMatch(DIFGraph graph,
mocgraph.Edge edge,
DIFHierarchy subHierarchy,
Port subPort)
graph - edge - subHierarchy - subPort -
protected boolean _isTypeMatch(DIFHierarchy hierarchy,
Port port,
DIFHierarchy subHierarchy,
Port subPort)
hierarchy - port - subHierarchy - subPort -
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||