Commit c16b29b7 authored by Michael Büsch's avatar Michael Büsch

AwlOffset: Use DynAttrs

Signed-off-by: Michael Büsch's avatarMichael Buesch <[email protected]>
parent 902feacf
......@@ -22,22 +22,28 @@
from __future__ import division, absolute_import, print_function, unicode_literals
from awlsim.core.compat import *
from awlsim.core.dynattrs import *
from awlsim.core.util import *
from awlsim.core.timers import *
from awlsim.core.datatypehelpers import *
class AwlOffset(object):
class AwlOffset(DynAttrs):
"Memory area offset"
def __init__(self, byteOffset, bitOffset=0, dbNumber=None):
self.byteOffset, self.bitOffset, self.dbNumber =\
byteOffset, bitOffset, dbNumber
dynAttrs = {
"dbNumber" : None,
}
def __init__(self, byteOffset, bitOffset=0):
self.byteOffset, self.bitOffset =\
byteOffset, bitOffset
def dup(self):
return AwlOffset(self.byteOffset,
self.bitOffset,
self.dbNumber)
offset = AwlOffset(self.byteOffset,
self.bitOffset)
offset.dbNumber = self.dbNumber
return offset
@classmethod
def fromPointerValue(cls, value):
......
......@@ -400,6 +400,7 @@ class AwlOpTranslator(object):
rawOps[0][3:]), 1)
# Symbolic name
if token0.startswith('"') and token0.endswith('"'):
#TODO symbolic fully qualified access
return OpDescriptor(AwlOperator(AwlOperator.SYMBOLIC, 0,
rawOps[0][1:-1]), 1)
# Immediate boolean
......@@ -490,7 +491,7 @@ class AwlOpTranslator(object):
if immediate is not None:
return OpDescriptor(AwlOperator(AwlOperator.IMM, 32,
immediate), 1)
# DBx.DB[XBWD] addressing
# DBx.DBX/B/W/D addressing
match = re.match(r'^DB(\d+)\.DB([XBWD])$', rawOps[0])
if match:
dbNumber = int(match.group(1))
......@@ -500,10 +501,20 @@ class AwlOpTranslator(object):
"W" : 16,
"D" : 32,
}[match.group(2)]
offset = AwlOffset(-1, -1 if (width == 1) else 0,
dbNumber = dbNumber)
offset = AwlOffset(-1, -1 if (width == 1) else 0)
offset.dbNumber = dbNumber
return OpDescriptor(AwlOperator(AwlOperator.MEM_DB, width,
offset), 2)
# DBx.VARIABLE adressing
match = re.match(r'^DB(\d+)\.(.+)$', rawOps[0])
if match:
if len(rawOps) == 1:
# DBx.VARIABLE adressing
pass#TODO
elif len(rawOps) >= 4 and\
rawOps[1] == '[' and rawOps[-1] == ']':
# DBx.ARRAY[x, y, z] adressing
pass#TODO
raise AwlSimError("Cannot parse operand: " +\
str(rawOps[0]))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment