Beispiel #1
0
    def create_component_functions(self, port):
        function = FunctionImplementation(port.functions['run'])

        for arg in function.arguments:
            function.mark_argument_used(arg)

        return {'run': function}
Beispiel #2
0
    def _create_function(self, port):
        function = FunctionImplementation(port.functions['read'])

        data_type = self._types.get(port['data_type'])
        if data_type.passed_by() == TypeCollection.PASS_BY_POINTER:
            function.add_input_assert('value', 'value != NULL')

        return function
Beispiel #3
0
    def create_runtime_functions(self, port):
        declared_functions = port.functions

        call_fn = FunctionImplementation(declared_functions['async_call'])
        result_fn = FunctionImplementation(declared_functions['get_result'])
        cancel_fn = FunctionImplementation(declared_functions['cancel'])

        return {'async_call': call_fn, 'get_result': result_fn, 'cancel': cancel_fn}
Beispiel #4
0
    def create_component_functions(self, port):
        function = FunctionImplementation(port.functions['run'])
        function.attributes.add('weak')

        if function.return_type != 'void':
            function_return_type = self._types.get(function.return_type)
            return_value = function_return_type.render_value(
                port['return_value'])
            function.set_return_statement(return_value)

        return {'run': function}
Beispiel #5
0
    def create_component_functions(self, port):
        declared_functions = port.functions

        call_fn = FunctionImplementation(declared_functions['async_call'])
        call_fn.attributes.add('weak')
        call_fn.set_return_statement('AsyncState_Busy')

        result_fn = FunctionImplementation(declared_functions['get_result'])
        result_fn.attributes.add('weak')
        result_fn.set_return_statement('AsyncState_Busy')

        cancel_fn = FunctionImplementation(declared_functions['cancel'])
        cancel_fn.attributes.add('weak')

        return {'async_call': call_fn, 'get_result': result_fn, 'cancel': cancel_fn}
Beispiel #6
0
    def create_component_functions(self, port):
        prototype = port.functions['constant']
        data_type = self._types.get(port['data_type'])

        function = FunctionImplementation(prototype)

        constant_value = data_type.render_value(port['value'])
        if data_type.passed_by() == TypeCollection.PASS_BY_VALUE:
            function.set_return_statement(constant_value)
        else:
            function.add_input_assert('value', 'value != NULL')
            function.add_body(f'*value = {constant_value};')

        return {'constant': function}
Beispiel #7
0
    def create_runtime_functions(self, port):
        function = FunctionImplementation(port.functions['run'])

        return {'run': function}
Beispiel #8
0
    def create_component_functions(self, port):
        function = FunctionImplementation(port.functions['run'])
        function.attributes.add('weak')

        return {'run': function}
Beispiel #9
0
    def _create_function(port):
        function = FunctionImplementation(port.functions['read'])
        function.add_input_assert('value', 'value != NULL')

        return function
Beispiel #10
0
    def create_component_functions(self, port):
        prototype = port.functions['constant']
        data_type = self._types.get(port['data_type'])

        function = FunctionImplementation(prototype)
        function.add_input_assert('index', f'index < {port["count"]}')

        constant_value = ',\n'.join(map(data_type.render_value, port['value']))
        function.add_body(
            f'static const {data_type.name} constant[{port["count"]}] = {{\n'
            f'{indent(constant_value)}\n'
            f'}};')
        if data_type.passed_by() == TypeCollection.PASS_BY_VALUE:
            function.set_return_statement('constant[index]')
        else:
            function.add_input_assert('value', 'value != NULL')
            function.add_body('*value = constant[index];')

        return {'constant': function}
Beispiel #11
0
def add_sections_to_function(function: FunctionImplementation, name):
    secname = name + ' Start'
    function.prepend_body(create_section(secname, ''))

    secname = name + ' End'
    function.add_body(create_section(secname, ''))
Beispiel #12
0
    def create_component_functions(self, port):
        function = FunctionImplementation(port.functions['async_run'])

        return {'async_run': function}
Beispiel #13
0
    def create(self, context: RuntimeGeneratorContext, connection: SignalConnection):
        port = context.get_port(connection.provider)

        provider_instance = context.get_component_instance(connection.provider)

        # updater function is unique for each signal, no need for instance argument
        update_function = FunctionImplementation(FunctionPrototype(connection.name + '_Update', 'void'))

        # create updater function
        context['functions'][connection.provider] = {'update': update_function}

        stored_arguments = []
        callee_arguments = {}

        indentation = ' ' * 12
        arg_prefix = '\n' + indentation

        port_args = port['arguments'].copy()
        if port_component_is_instanced(provider_instance):
            callee_arguments['instance'] = arg_prefix + '&' + provider_instance.instance_var_name
            del port_args['instance']
            context['used_types'].append(provider_instance.component.instance_type)

        for name, arg_data in port_args.items():
            if type(arg_data) is str:
                arg_dir = 'in'
                arg_type = context.types.get(arg_data)
            else:
                arg_dir = arg_data['direction']
                arg_type = context.types.get(arg_data['data_type'])

            stored_arguments.append({'name': name, 'type': arg_type.name})

            if arg_dir == 'out' or arg_type.passed_by() == TypeCollection.PASS_BY_POINTER:
                callee_arguments[name] = f'{arg_prefix}&{connection.name}_argument_{name}'
            else:
                callee_arguments[name] = f'{arg_prefix}{connection.name}_argument_{name}'

        context['declarations'].append(chevron.render(**{
            'template':
                '\n/* {{ signal_name }} */\n'
                'static AsyncOperationState_t {{ signal_name }}_state = AsyncState_Idle;\n'
                'static AsyncCommand_t {{ signal_name }}_command = AsyncCommand_None;\n'
                '{{# arguments }}'
                'static {{ type }} {{ signal_name }}_argument_{{ name }};\n'
                '{{/ arguments }}'
                'static {{ updater_header }};',
            'data': {
                'signal_name': connection.name,
                'arguments': stored_arguments,
                'updater_header': update_function.get_header()
            }
        }))
        context['used_types'].append('AsyncOperationState_t')
        context['used_types'].append('AsyncCommand_t')

        # generate the updater function
        if 'run' in port.functions:
            self._generate_sync_updater_impl(callee_arguments, connection, port, update_function)

        elif 'async_run' in port.functions:
            self._generate_async_updater_impl(callee_arguments, connection, port, update_function)
        else:
            raise NotImplementedError