Example #1
0
    def add(self, connector_name, path, template):
        '''Add a template to the lookup dictionary. Note that this function is
        intentionally implemented in such a way to allow you to overwrite
        default templates. This assumes you are adding a template related to a
        connector.'''

        # Create a mock connection and then try to locate an existing matching
        # key. We do this to allow the caller to replace one of the built-in
        # templates.
        class FakeConnection(Connection):
            def __init__(self):
                self.type = collections.namedtuple('Type',
                                                   'name')(connector_name)

        fc = FakeConnection()
        for key in self.base:
            if isinstance(key, Guard) and key(fc):
                k = key
                break
        else:
            # We didn't find an existing key (expected case) so we need to make
            # a new one.
            k = Guard(lambda x, name=connector_name: isinstance(x, Connection) \
                and x.type.name == name)
            self.base[k] = {}

        # Add the given template.
        d = self.base
        prev = k
        for p in path.split('.'):
            if p not in d[prev]:
                d[prev][p] = {}
            d = d[prev]
            prev = p
        d[prev] = template
Example #2
0
    def add(self, connector, connection):
        '''Add connector-based templates to the lookup dictionary. Note that
        this function is intentionally implemented in such a way to allow you
        to overwrite default templates. This assumes you are adding a template
        related to a connector.'''

        # Short circuit the whole process if the caller gave us no templates.
        if connector.from_template is None and connector.to_template is None:
            return set()

        # Use the provided connection to try to locate an existing matching
        # key. We do this to allow the caller to replace one of the built-in
        # templates.
        for key in self.base:
            if isinstance(key, Guard) and key(connection):
                k = key
                break
        else:
            # We didn't find an existing key (expected case) so we need to make
            # a new one.
            k = Guard(lambda x, name=connector.name: isinstance(x, Connection)
                      and x.type.name == name)
            self.base[k] = {}

        dependencies = set()

        # Add the given template(s).
        intermediate = self.base[k]
        if connector.from_template is not None:
            if 'from' not in intermediate:
                intermediate['from'] = {}
            intermediate['from']['source'] = connector.from_template
            dependencies |= get_dependencies(self.roots,
                                             connector.from_template)
        if connector.to_template is not None:
            if 'to' not in intermediate:
                intermediate['to'] = {}
            intermediate['to']['source'] = connector.to_template
            dependencies |= get_dependencies(self.roots, connector.to_template)

        return dependencies
Example #3
0
from camkes.internal.seven import cmp, filter, map, zip

from camkes.ast import Instance, Connection
from camkes.internal.dictutils import Guard
from .exception import TemplateError
import collections, os, re, six

# Base dictionary of templates for instantiation. Note that the top-level keys
# must be strings, while the following levels are either Guards or strings. A
# guard is essentially a parameterised key in the dictionary that is expecting
# to be passed an AST entity.
TEMPLATES = {
    # Platform
    'seL4':{
        # Type
        Guard(lambda x: isinstance(x, Instance)):{
            'source':'component.template.c',
            'header':'component.template.h',
            'simple':'component.simple.c',
            'rumprun':'component.rumprun.c',
            'debug':'component.debug.c',
            'linker':'linker.lds',
        },
        Guard(lambda x: isinstance(x, Connection) and x.type.name == 'seL4RPC'):{
            # Direction
            'from':{
                # Item
                'source':'seL4RPC-from.template.c',
            },
            'to':{
                'source':'seL4RPC-to.template.c',