Method for generating source code
A block diagram includes at least three blocks, including a source block emitting a first composite signal, a passing block receiving the first composite signal and emitting a second composite signal with the same dimensions, and a filter block receiving the second composite signal and discarding at least one component of the second composite signal. A method for generating source code from one or more blocks of the block diagram includes: transforming the block diagram into an intermediate representation, including transforming the at least three blocks; applying at least one optimization to the intermediate representation, including determining whether a memory condition is fulfilled; based on the memory condition being fulfilled, replacing an output variable of the passing block with an auxiliary variable of smaller dimension; and translating the optimized intermediate representation into source code.
1 . A method for generating source code from one or more blocks of a block diagram, the method comprising:
transforming the block diagram into an intermediate representation, wherein the block diagram comprises at least three blocks, wherein the at least three blocks include a source block emitting a first composite signal corresponding to a multi-component variable, a passing block receiving the first composite signal and emitting a second composite signal with the same dimensions, and a filter block receiving the second composite signal and discarding at least one component of the second composite signal, and wherein transforming the block diagram into the intermediate representation comprises transforming the at least three blocks;
applying at least one optimization to the intermediate representation, wherein applying the at least one optimization comprises:
determining whether a memory condition is fulfilled, wherein determining whether a memory condition is fulfilled comprises: determining whether at least one component discarded in the filter block is of bigger dimension than a first predefined threshold, and determining whether the dimension of the remaining components emitted by the filter block is lower than a second predefined threshold; and
based on the at least one component discarded in the filter block being of bigger dimension than the first predefined threshold or based on the dimension of the remaining components emitted by the filter block being lower than the second predefined threshold the memory condition being fulfilled, replacing an output variable of the passing block with one or more auxiliary variables of smaller dimension; and
translating the optimized intermediate representation into source code.
2 . The method of claim 1 , wherein the first composite signal is a bus.
3 . The method of claim 1 , wherein the multi-component variable is a structure comprising multiple components of different data types.
4 . The method of claim 1 , wherein the multi-component variable is a vector comprising multiple components of the same data type.
5 . The method of claim 1 , wherein the passing block is a selection block receiving the first composite signal and a third composite signal of the same dimension, wherein the selection block transmits either the first composite signal or the third composite signal.
6 . The method of claim 1 , wherein the passing block is a calculation block that performs elementwise calculation on the first composite signal.
7 . The method of claim 1 , wherein the passing block is a delay block that emits received signals after one or more periods.
8 . The method of claim 1 , wherein applying the at least one optimization further comprises replacing the output variable of at least one block directly upstream of the passing block with one or more auxiliary variables of smaller dimension based on a memory condition being fulfilled.
9 . The method of claim 1 , further comprising:
compiling the source code for at least one arithmetic logic unit of a control unit to generate an executable code;
transmitting the executable code to the control unit; and
storing the executable code on a non-volatile memory of the control unit and/or executing the executable code by the at least one arithmetic logic unit of the control unit.
10 . A method for generating source code from one or more blocks of a block diagram, the method comprising:
transforming the block diagram into an intermediate representation, wherein the block diagram comprises at least three blocks, wherein the at least three blocks include a source block emitting a first composite signal corresponding to a multi-component variable, a passing block receiving the first composite signal and emitting a second composite signal with the same dimensions, and a filter block receiving the second composite signal and discarding at least one component of the second composite signal, and wherein transforming the block diagram into the intermediate representation comprises transforming the at least three blocks; and
applying at least one optimization to the intermediate representation, wherein applying the at least one optimization comprises:
determining whether a memory condition is fulfilled;
based on the memory condition not being fulfilled, determining whether a cost condition is fulfilled, wherein the cost condition is fulfilled based on the execution time for the partial assignment being lower than a predefined threshold; and
based on the cost condition being fulfilled, replacing an assignment of the entire multi-component variable by a partial assignment pertaining to one or more components of the multi-component variable, wherein replacing an assignment of the entire multi-component variable by a partial assignment pertaining to one or more components of the multi-component variable further comprises replacing an assignment of the entire multi-component variable by a partial assignment pertaining to one or more components of the multi-component variable of at least one block directly upstream of the passing block.
11 . A non-transitory computer-readable medium having processor-executable instructions stored thereon for generating source code from one or more blocks of a block diagram, wherein the processor-executable instructions, when executed, facilitate:
transforming the block diagram into an intermediate representation, wherein the block diagram comprises at least three blocks, wherein the at least three blocks include a source block emitting a first composite signal corresponding to a multi-component variable, a passing block receiving the first composite signal and emitting a second composite signal with the same dimensions, and a filter block receiving the second composite signal and discarding at least one component of the second composite signal, and wherein transforming the block diagram into the intermediate representation comprises transforming the at least three blocks;
applying at least one optimization to the intermediate representation, wherein applying the at least one optimization comprises:
determining whether a memory condition is fulfilled, wherein determining whether a memory condition is fulfilled comprises: determining whether at least one component discarded in the filter block is of bigger dimension than a first predefined threshold, and determining whether the dimension of the remaining components emitted by the filter block is lower than a second predefined threshold; and
based on the at least one component discarded in the filter block being of bigger dimension than the first predefined threshold or based on the dimension of the remaining components emitted by the filter block being lower than the second predefined threshold the memory condition being fulfilled, replacing an output variable of the passing block with one or more auxiliary variables of smaller dimension; and
translating the optimized intermediate representation into source code.