1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
# -*- coding: utf-8 -*-
#
# AWL simulator - FUP compiler - Base object
#
# Copyright 2016 Michael Buesch <m@bues.ch>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
from __future__ import division, absolute_import, print_function, unicode_literals
from awlsim.common.compat import *
from awlsim.common.util import *
from awlsim.common.exceptions import *
class FupCompilerError(AwlSimError):
"""FUP compiler exception.
"""
def __init__(self, message, fupObj=None):
AwlSimError.__init__(self, message)
self.fupObj = fupObj
class FupCompiler_BaseObj(object):
"""FUP compiler base class.
"""
factory = None
# compileState values
EnumGen.start
NOT_COMPILED = EnumGen.item
COMPILE_RUNNING = EnumGen.item
COMPILE_DONE = EnumGen.item
EnumGen.end
# Allow certain state transitions?
allowTrans_done2Running = False # DONE -> RUNNING
allowTrans_2NotCompiled = False # any -> NOT_COMPILED
def __init__(self):
self.__compileState = self.NOT_COMPILED
@property
def compileState(self):
return self.__compileState
@compileState.setter
def compileState(self, state):
if state == self.NOT_COMPILED and\
not self.allowTrans_2NotCompiled:
raise FupCompilerError(
"Tried to set FBD/FUP object (%s) state to "
"NOT_COMPILED." % (
type(self).__name__), self)
elif state == self.COMPILE_RUNNING:
if self.__compileState == self.COMPILE_RUNNING:
raise FupCompilerError(
"Tried to set FBD/FUP object (%s) state to "
"COMPILE_RUNNING while already being in that state.\n"
"This most likely happened due to some dependency "
"loop in the FBD/FUP diagram.\n"
"Please check the diagram for signal loops." % (
type(self).__name__), self)
if self.__compileState == self.COMPILE_DONE and\
not self.allowTrans_done2Running:
raise FupCompilerError(
"Tried to set FBD/FUP object (%s) state to "
"COMPILE_RUNNING while being in state COMPILE_DONE." % (
type(self).__name__), self)
elif state == self.COMPILE_DONE:
if self.__compileState == self.COMPILE_DONE:
raise FupCompilerError(
"Tried to set FBD/FUP object (%s) state to "
"COMPILE_DONE while already being in that state." % (
type(self).__name__), self)
if self.__compileState == self.NOT_COMPILED:
raise FupCompilerError(
"Tried to set FBD/FUP object (%s) state to "
"COMPILE_DONE, but skipping COMPILE_RUNNING state." % (
type(self).__name__), self)
else:
assert(0)
self.__compileState = state
def __eq__(self, other):
return self is other
def __ne__(self, other):
return self is not other
def __hash__(self):
return id(self)
|