Previous Up Next

Chapter 7  Example 7: source code associated with an operation

7.1  Definition of the source code into the code editor window

In the previous Example 6, we have learnt that a m4 file, called with the name of the application plus the m4x extension, must be manually written. It contains all the source code associated with all operations present in a SynDEx application. For example, in the example6 application, the conv function increments of one the value of the input and stores the result in the output. Thus example6.m4x file contains:

    MGC,‘LOOP’,‘$2[0] = $1[0] + 1;’,

where $1 and $2 correspond respectively to the input port named i and the output port named o of the conv function.

You may read the comments written in the example6.m4x.

Handwriting this kind of code is not very easy, for several reasons:

It should be more convenient to write @OUT(o)[0] = @IN(i)[0] + @PARAM(P) and let SynDEx interpret it and generate the associated m4x file than to write the specification with the m4 syntax. SynDEx (version ≥ 7.0.0) is able to do that thanks the code editor which is a tool integrated in the graphical user interface (GUI). In the following example, we will show how to use this tool.

7.1.1  To add parameters to an already defined operation

In this example, we show how to modify some functions by adding parameters in order to expand parameters into m4 arguments.

Open the example6.sdx application:

Add parameters to the conv function:

Verify that the parameters have been stored in the function

We have two solutions:

7.1.2  To edit the code associated with an operation

In the case of a generic processor

In the case of an architecture with heterogeneous processors

Sometimes it is interesting for an operation to have different source codes depending on the type of processor. For example, a given processor type X may only offer assembly language as a programming interface. In such case, we must be able to provide (for example) C code for processors that support it, and assembly language for the X processor type. To support heterogeneous architecture, the code editor associates code to a triplet (phase, processor, operation). A special processor type Default is provided for processors that have not been associated with dedicated code. Its use allows to share a code between different processor types.

Learn the macros of the code editor

The code editor comes with a set of predefined macros that alleviate the user from knowing the black magic of m4 processing.

The more useful ones are names translation macros. These macros translate port and parameter names to their internal representation as m4 parameters. We have already encountered such macros in what we have just done: @IN, @OUT and @INOUT are port name translation macros, and @PARAM is the parameter name translation macro. As a rule of thumb, you should use @PARAM(x) when you want to refer to a parameter x and @IN(i) (resp. @OUT(o) / @INOUT(io)) when you refer to an input port i (resp. output port o / input-output port io).

The code editor recognizes three more macros: @NAME, @QUOTE and @TEXT. These advanced macros are not used in this tutorial and the reader is refered to SynDEx user manual to learn more about it.

7.1.3  To generate m4x files

Before performing the code generation we have to perform the adequation:

Two cases are possible:

These two files constitute the Applicative kernel:

The example7_sdc.m4x file contains the following code:

    # (c)INRIA 2001-2009

    MGC,‘INIT’, “/* Hi, I am $0 function, in init phase for C40 processor */”,
    MGC,‘LOOP’,“$2[0] = $1[0]; /* Hi, I am $0 function, in loop phase for C40 processor */”,
    MGC,‘END’, “/* Bye, I am $0 function, in end phase for C40 processor */”)’)’)
    MGC,‘INIT’,“/* Hi, I am $0 function, in init phase for U processor */”,
    MGC,‘LOOP’,“$2[0] = $1[0] * 42; /* Hi, I am $0 function, in loop phase for U processor */”,
    MGC,‘END’, “/* Bye, I am $0 function, in end phase for U processor */”)’,

    MGC,‘INIT’,“printf("Init phase of function $0 for default processor.\n");”,
     printf("Loop phase of function $0 for default processor =%i.\n", $4[0]);”,
    MGC,‘END’,“printf("End phase of function $0 for default processor.\n");”)’)’)

If the example7.m4x file did not exist at code generation time then it will contain the following code:

    # (c)INRIA 2001-2009

    define(‘dnldnl’,“// ”)


    #include <stdio.h> /* for printf */

Deeper insights about the m4 macro language can be found in SynDEx user manual and GNU M4 manual.

Notice that:

From the principal window, choose File / Close. In the dialog window, click on the Save button.

Macros of the code editor as @IN, @OUT, @PARAM, … are explained in the User Manual.

Previous Up Next