ocarina.py 2.48 KB
Newer Older
yoogx's avatar
yoogx committed
1
#! /usr/bin/python
2
3
4
5
6
7
8
9
10
11
'''
:mod:`ocarina` -- Python binding to the Ocarina AADL processor
==============================================================

.. moduleauthor:: Jerome Hugues

This module provides direct access to top-level functions of Ocarina
to load, parse, instantiate AADL models, and to invoke backends.

'''
yoogx's avatar
yoogx committed
12
13
14
15

################################################################################
import libocarina_python; # Ocarina bindings

yoogx's avatar
yoogx committed
16
17
class Enum(tuple): __getattr__ = tuple.index

yoogx's avatar
yoogx committed
18
19
20
21
22
23
24
25
26
27
################################################################################
def version ():
    '''Print Ocarina version'''
    libocarina_python.version();

################################################################################
def status ():
    '''Print Ocarina status'''
    libocarina_python.status();

28
29
################################################################################
def reset ():
yoogx's avatar
yoogx committed
30
31
32
33
34
    '''Reset Ocarina internal state

    **Note:** this function must be called before processing a new set of models.
    '''

35
36
    libocarina_python.reset();

yoogx's avatar
yoogx committed
37
38
################################################################################
def load (filename):
yoogx's avatar
yoogx committed
39
40
41
42
43
44
45
46
47
48
    '''Load a file

    :param filename: name of the file to be loaded, following Ocarina search path
    :type filename: string

    E.g. to load "foo.aadl":

    >>> load("foo.aadl");

    '''
yoogx's avatar
yoogx committed
49
50
51
52
53
54
55
56
57
    libocarina_python.load (filename);

################################################################################
def analyze ():
    '''Analyze models'''
    libocarina_python.analyze ();

################################################################################
def instantiate (root_system):
58
59
60
61
62
63
    '''Instantiate model, starting from root_system

    :param root_system: name of the root system to instantiate
    :type root_system: string

    '''
yoogx's avatar
yoogx committed
64
65
66
    libocarina_python.instantiate (root_system);

################################################################################
yoogx's avatar
yoogx committed
67
Backends = Enum ([ "polyorb_hi_ada", "polyorb_hi_c"]);
yoogx's avatar
yoogx committed
68
69
'''List of supported backends, used by :data:`generate`'''
# Note, this list should match backend names as specified by Ocarina CLI
yoogx's avatar
yoogx committed
70

yoogx's avatar
yoogx committed
71
def generate (generator):
yoogx's avatar
yoogx committed
72
    '''Generate code
yoogx's avatar
yoogx committed
73

yoogx's avatar
yoogx committed
74
75
76
    :param generator: one supported backends, from :data:`Backends`

    For instance, to use the PolyORB-HI/Ada backend, you may use the following
yoogx's avatar
yoogx committed
77

yoogx's avatar
yoogx committed
78
79
80
    >>> generate (Backends.polyorb_hi_ada);
    '''
    libocarina_python.generate (Backends[generator]);
yoogx's avatar
yoogx committed
81
82
83

################################################################################