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

Add container type for memory objects

Signed-off-by: Michael Büsch's avatarMichael Buesch <m@bues.ch>
parent ac73741e
......@@ -203,6 +203,8 @@ class AwlTranslator(object):
# dataType: The AwlDataType for this field.
# initBytes: The initialization bytes for this field, or None.
def rawFieldTranslate(self, rawField):
#@cy cdef AwlMemoryObject memObj
# Get the field name
name = rawField.getIdentString()
# Get the field data type
......@@ -230,7 +232,6 @@ class AwlTranslator(object):
# Translate the initialization values and
# put them into a bytearray.
initMem = AwlMemory(intDivRoundUp(dataType.width, 8))
initBytes = initMem.dataBytes
AwlDataType = _getAwlDataTypeClass()
if dataType.type == AwlDataType.TYPE_ARRAY:
for rawDataInit in rawField.defaultInits:
......@@ -240,29 +241,44 @@ class AwlTranslator(object):
offset = make_AwlOffset_fromLongBitOffset(
linArrayIndex *
dataType.arrayElementType.width)
memObj = make_AwlMemoryObject_fromGeneric(
value,
dataType.arrayElementType.width)
try:
initMem.store(offset, dataType.arrayElementType.width,
value)
initMem.store(offset, memObj)
except AwlSimError as e:
raise AwlSimError("Data field '%s' initialization "
"is out of range." % str(rawField))
else:
assert(len(rawField.defaultInits) == 1)
value = dataType.parseMatchingImmediate(rawField.defaultInits[0].valueTokens)
memObj = make_AwlMemoryObject_fromGeneric(
value, dataType.width)
try:
initMem.store(make_AwlOffset(0, 0), dataType.width, value)
initMem.store(make_AwlOffset(0, 0), memObj)
except AwlSimError as e:
raise AwlSimError("Data field '%s' initialization "
"is out of range." % str(rawField))
initBytes = initMem.getDataBytes()
else:
initBytes = None
return name, dataType, initBytes
# Initialize a DB (global or instance) data field from a raw data-init.
def __initDBField(self, db, dataType, rawDataInit):
#@cy cdef AwlStructInstance structInstance
#@cy cdef AwlMemoryObject memObj
fieldName = rawDataInit.getIdentString()
value = dataType.parseMatchingImmediate(rawDataInit.valueTokens)
db.structInstance.setFieldDataByName(fieldName, value)
if dataType.type == dataType.TYPE_ARRAY:
# This is a single-array-element initializer.
width = dataType.arrayElementType.width
else:
width = dataType.width
memObj = make_AwlMemoryObject_fromGeneric(value, width)
structInstance = db.structInstance
structInstance.setFieldDataByName(fieldName, memObj)
# Create a DB data field.
def __createDBField(self, db, rawDataField):
......
......@@ -173,7 +173,7 @@ class CallStackElem(object): #+cdef
else:
dbNumber = rvalueOp.offset.dbNumber
cpu.store(storeOper,
max(0, dbNumber),
make_AwlMemoryObject_fromScalar(max(0, dbNumber), 16),
widthMaskAll)
storeOper.offset = loffset.addInt(2, 0)
storeOper.width = 32
......@@ -189,7 +189,7 @@ class CallStackElem(object): #+cdef
raise AwlSimBug("FC_trans_dbpointerInVL: Invalid rValueOp area. "
"(area=%d, operType=%d)" % (area, rvalueOp.operType))
cpu.store(storeOper,
area | rvalueOp.offset.toPointerValue(),
make_AwlMemoryObject_fromScalar(area | rvalueOp.offset.toPointerValue(), 32),
widthMaskAll)
# Return the operator for the DB pointer.
return make_AwlOperator(AwlOperatorTypes.MEM_VL,
......@@ -485,6 +485,7 @@ def make_CallStackElem(cpu, #@nocy
#@cy cdef AwlStructField structField
#@cy cdef AwlStructInstance structInstance
#@cy cdef uint32_t widthMaskAll
#@cy cdef AwlMemoryObject memObj
cse = CallStackElem()
......@@ -528,8 +529,9 @@ def make_CallStackElem(cpu, #@nocy
structField.compound:
# Compound data type with IN_OUT decl.
# Make a DB-ptr to the actual data.
data = cse._FB_trans_dbpointer(
param, param.rvalueOp)
memObj = make_AwlMemoryObject_fromBytes(
cse._FB_trans_dbpointer(param, param.rvalueOp),
48)
# Get the DB-ptr struct field.
structField = structField.finalOverride
else:
......@@ -539,12 +541,14 @@ def make_CallStackElem(cpu, #@nocy
if structField.callByRef:
# Do not fetch. Type is passed 'by reference'.
# This is for TIMER, COUNTER, etc...
data = param.rvalueOp.resolve(True).offset.byteOffset
memObj = make_AwlMemoryObject_fromScalar(
param.rvalueOp.resolve(True).offset.byteOffset,
16)
else:
data = cpu.fetch(param.rvalueOp, widthMaskAll)
memObj = cpu.fetch(param.rvalueOp, widthMaskAll)
# Transfer data into DBI.
structInstance.setFieldData(structField,
data,
memObj,
instanceBaseOffset)
cse._interfRefs = None
else:
......
......@@ -101,56 +101,56 @@ cdef class S7CPU(object):
cdef mcrStackAppend(self, S7StatusWord statusWord)
cdef mcrStackPop(self)
cpdef object fetch(self, AwlOperator operator, uint32_t allowedWidths)
cdef object __fetchIMM(self, AwlOperator operator, uint32_t allowedWidths)
cdef object __fetchIMM_DT(self, AwlOperator operator, uint32_t allowedWidths)
cdef object __fetchIMM_PTR(self, AwlOperator operator, uint32_t allowedWidths)
cdef object __fetchIMM_STR(self, AwlOperator operator, uint32_t allowedWidths)
cdef object __fetchDBLG(self, AwlOperator operator, uint32_t allowedWidths)
cdef object __fetchDBNO(self, AwlOperator operator, uint32_t allowedWidths)
cdef object __fetchDILG(self, AwlOperator operator, uint32_t allowedWidths)
cdef object __fetchDINO(self, AwlOperator operator, uint32_t allowedWidths)
cdef object __fetchAR2(self, AwlOperator operator, uint32_t allowedWidths)
cdef object __fetchSTW(self, AwlOperator operator, uint32_t allowedWidths)
cdef object __fetchSTW_Z(self, AwlOperator operator, uint32_t allowedWidths)
cdef object __fetchSTW_NZ(self, AwlOperator operator, uint32_t allowedWidths)
cdef object __fetchSTW_POS(self, AwlOperator operator, uint32_t allowedWidths)
cdef object __fetchSTW_NEG(self, AwlOperator operator, uint32_t allowedWidths)
cdef object __fetchSTW_POSZ(self, AwlOperator operator, uint32_t allowedWidths)
cdef object __fetchSTW_NEGZ(self, AwlOperator operator, uint32_t allowedWidths)
cdef object __fetchSTW_UO(self, AwlOperator operator, uint32_t allowedWidths)
cdef object __fetchE(self, AwlOperator operator, uint32_t allowedWidths)
cdef object __fetchA(self, AwlOperator operator, uint32_t allowedWidths)
cdef object __fetchM(self, AwlOperator operator, uint32_t allowedWidths)
cdef object __fetchL(self, AwlOperator operator, uint32_t allowedWidths)
cdef object __fetchVL(self, AwlOperator operator, uint32_t allowedWidths)
cdef object __fetchDB(self, AwlOperator operator, uint32_t allowedWidths)
cdef object __fetchDI(self, AwlOperator operator, uint32_t allowedWidths)
cdef object __fetchPE(self, AwlOperator operator, uint32_t allowedWidths)
cdef object __fetchT(self, AwlOperator operator, uint32_t allowedWidths)
cdef object __fetchZ(self, AwlOperator operator, uint32_t allowedWidths)
cdef object __fetchNAMED_LOCAL(self, AwlOperator operator, uint32_t allowedWidths)
cdef object __fetchNAMED_LOCAL_PTR(self, AwlOperator operator, uint32_t allowedWidths)
cdef object __fetchNAMED_DBVAR(self, AwlOperator operator, uint32_t allowedWidths)
cdef object __fetchINDIRECT(self, AwlOperator operator, uint32_t allowedWidths)
cdef object __fetchVirtACCU(self, AwlOperator operator, uint32_t allowedWidths)
cdef object __fetchVirtAR(self, AwlOperator operator, uint32_t allowedWidths)
cdef object __fetchVirtDBR(self, AwlOperator operator, uint32_t allowedWidths)
cpdef store(self, AwlOperator operator, object value, uint32_t allowedWidths)
cdef __storeE(self, AwlOperator operator, object value, uint32_t allowedWidths)
cdef __storeA(self, AwlOperator operator, object value, uint32_t allowedWidths)
cdef __storeM(self, AwlOperator operator, object value, uint32_t allowedWidths)
cdef __storeL(self, AwlOperator operator, object value, uint32_t allowedWidths)
cdef __storeVL(self, AwlOperator operator, object value, uint32_t allowedWidths)
cdef __storeDB(self, AwlOperator operator, object value, uint32_t allowedWidths)
cdef __storeDI(self, AwlOperator operator, object value, uint32_t allowedWidths)
cdef __storePA(self, AwlOperator operator, object value, uint32_t allowedWidths)
cdef __storeAR2(self, AwlOperator operator, object value, uint32_t allowedWidths)
cdef __storeSTW(self, AwlOperator operator, object value, uint32_t allowedWidths)
cdef __storeNAMED_LOCAL(self, AwlOperator operator, object value, uint32_t allowedWidths)
cdef __storeNAMED_DBVAR(self, AwlOperator operator, object value, uint32_t allowedWidths)
cdef __storeINDIRECT(self, AwlOperator operator, object value, uint32_t allowedWidths)
cdef AwlMemoryObject fetch(self, AwlOperator operator, uint32_t allowedWidths) except NULL
cdef AwlMemoryObject __fetchIMM(self, AwlOperator operator, uint32_t allowedWidths) except NULL
cdef AwlMemoryObject __fetchIMM_DT(self, AwlOperator operator, uint32_t allowedWidths) except NULL
cdef AwlMemoryObject __fetchIMM_PTR(self, AwlOperator operator, uint32_t allowedWidths) except NULL
cdef AwlMemoryObject __fetchIMM_STR(self, AwlOperator operator, uint32_t allowedWidths) except NULL
cdef AwlMemoryObject __fetchDBLG(self, AwlOperator operator, uint32_t allowedWidths) except NULL
cdef AwlMemoryObject __fetchDBNO(self, AwlOperator operator, uint32_t allowedWidths) except NULL
cdef AwlMemoryObject __fetchDILG(self, AwlOperator operator, uint32_t allowedWidths) except NULL
cdef AwlMemoryObject __fetchDINO(self, AwlOperator operator, uint32_t allowedWidths) except NULL
cdef AwlMemoryObject __fetchAR2(self, AwlOperator operator, uint32_t allowedWidths) except NULL
cdef AwlMemoryObject __fetchSTW(self, AwlOperator operator, uint32_t allowedWidths) except NULL
cdef AwlMemoryObject __fetchSTW_Z(self, AwlOperator operator, uint32_t allowedWidths) except NULL
cdef AwlMemoryObject __fetchSTW_NZ(self, AwlOperator operator, uint32_t allowedWidths) except NULL
cdef AwlMemoryObject __fetchSTW_POS(self, AwlOperator operator, uint32_t allowedWidths) except NULL
cdef AwlMemoryObject __fetchSTW_NEG(self, AwlOperator operator, uint32_t allowedWidths) except NULL
cdef AwlMemoryObject __fetchSTW_POSZ(self, AwlOperator operator, uint32_t allowedWidths) except NULL
cdef AwlMemoryObject __fetchSTW_NEGZ(self, AwlOperator operator, uint32_t allowedWidths) except NULL
cdef AwlMemoryObject __fetchSTW_UO(self, AwlOperator operator, uint32_t allowedWidths) except NULL
cdef AwlMemoryObject __fetchE(self, AwlOperator operator, uint32_t allowedWidths) except NULL
cdef AwlMemoryObject __fetchA(self, AwlOperator operator, uint32_t allowedWidths) except NULL
cdef AwlMemoryObject __fetchM(self, AwlOperator operator, uint32_t allowedWidths) except NULL
cdef AwlMemoryObject __fetchL(self, AwlOperator operator, uint32_t allowedWidths) except NULL
cdef AwlMemoryObject __fetchVL(self, AwlOperator operator, uint32_t allowedWidths) except NULL
cdef AwlMemoryObject __fetchDB(self, AwlOperator operator, uint32_t allowedWidths) except NULL
cdef AwlMemoryObject __fetchDI(self, AwlOperator operator, uint32_t allowedWidths) except NULL
cdef AwlMemoryObject __fetchPE(self, AwlOperator operator, uint32_t allowedWidths) except NULL
cdef AwlMemoryObject __fetchT(self, AwlOperator operator, uint32_t allowedWidths) except NULL
cdef AwlMemoryObject __fetchZ(self, AwlOperator operator, uint32_t allowedWidths) except NULL
cdef AwlMemoryObject __fetchNAMED_LOCAL(self, AwlOperator operator, uint32_t allowedWidths) except NULL
cdef AwlMemoryObject __fetchNAMED_LOCAL_PTR(self, AwlOperator operator, uint32_t allowedWidths) except NULL
cdef AwlMemoryObject __fetchNAMED_DBVAR(self, AwlOperator operator, uint32_t allowedWidths) except NULL
cdef AwlMemoryObject __fetchINDIRECT(self, AwlOperator operator, uint32_t allowedWidths) except NULL
cdef AwlMemoryObject __fetchVirtACCU(self, AwlOperator operator, uint32_t allowedWidths) except NULL
cdef AwlMemoryObject __fetchVirtAR(self, AwlOperator operator, uint32_t allowedWidths) except NULL
cdef AwlMemoryObject __fetchVirtDBR(self, AwlOperator operator, uint32_t allowedWidths) except NULL
cdef store(self, AwlOperator operator, AwlMemoryObject memObj, uint32_t allowedWidths)
cdef __storeE(self, AwlOperator operator, AwlMemoryObject memObj, uint32_t allowedWidths)
cdef __storeA(self, AwlOperator operator, AwlMemoryObject memObj, uint32_t allowedWidths)
cdef __storeM(self, AwlOperator operator, AwlMemoryObject memObj, uint32_t allowedWidths)
cdef __storeL(self, AwlOperator operator, AwlMemoryObject memObj, uint32_t allowedWidths)
cdef __storeVL(self, AwlOperator operator, AwlMemoryObject memObj, uint32_t allowedWidths)
cdef __storeDB(self, AwlOperator operator, AwlMemoryObject memObj, uint32_t allowedWidths)
cdef __storeDI(self, AwlOperator operator, AwlMemoryObject memObj, uint32_t allowedWidths)
cdef __storePA(self, AwlOperator operator, AwlMemoryObject memObj, uint32_t allowedWidths)
cdef __storeAR2(self, AwlOperator operator, AwlMemoryObject memObj, uint32_t allowedWidths)
cdef __storeSTW(self, AwlOperator operator, AwlMemoryObject memObj, uint32_t allowedWidths)
cdef __storeNAMED_LOCAL(self, AwlOperator operator, AwlMemoryObject memObj, uint32_t allowedWidths)
cdef __storeNAMED_DBVAR(self, AwlOperator operator, AwlMemoryObject memObj, uint32_t allowedWidths)
cdef __storeINDIRECT(self, AwlOperator operator, AwlMemoryObject memObj, uint32_t allowedWidths)
cpdef bytearray fetchOutputRange(self, uint32_t byteOffset, uint32_t byteCount)
cpdef bytearray fetchInputRange(self, uint32_t byteOffset, uint32_t byteCount)
......@@ -191,6 +191,6 @@ cdef class S7CPU(object):
cdef AwlOperator __translateFCNamedLocalOper(self, AwlOperator operator, _Bool store)
cdef makeCurrentDateAndTime(self, bytearray byteArray, uint32_t offset)
cdef makeCurrentDateAndTime(self, uint8_t *byteArray, uint32_t offset)
cdef __dumpLStackFrame(self, prefix, LStackFrame *frame)
This diff is collapsed.
......@@ -13,5 +13,5 @@ cdef class DB(Block):
cdef public AwlStruct __struct
cdef public AwlStructInstance structInstance
cdef object fetch(self, AwlOperator operator, AwlOffset baseOffset)
cdef store(self, AwlOperator operator, object value, AwlOffset baseOffset)
cdef AwlMemoryObject fetch(self, AwlOperator operator, AwlOffset baseOffset) except NULL
cdef store(self, AwlOperator operator, AwlMemoryObject memObj, AwlOffset baseOffset)
......@@ -74,7 +74,7 @@ class DB(Block): #+cdef
self.structInstance = AwlStructInstance(self.struct)
def fetch(self, operator, baseOffset): #@nocy
#@cy cdef object fetch(self, AwlOperator operator, AwlOffset baseOffset):
#@cy cdef AwlMemoryObject fetch(self, AwlOperator operator, AwlOffset baseOffset) except NULL:
if self.permissions & self._PERM_READ:
if baseOffset is None:
return self.structInstance.memory.fetch(
......@@ -86,19 +86,18 @@ class DB(Block): #+cdef
operator.width)
raise AwlSimError("Fetch from read protected DB %d" % self.index)
def store(self, operator, value, baseOffset): #@nocy
#@cy cdef store(self, AwlOperator operator, object value, AwlOffset baseOffset):
def store(self, operator, memObj, baseOffset): #@nocy
#@cy cdef store(self, AwlOperator operator, AwlMemoryObject memObj, AwlOffset baseOffset):
if self.permissions & self._PERM_WRITE:
AwlMemoryObject_assertWidth(memObj, operator.width)
if baseOffset is None:
self.structInstance.memory.store(
operator.offset,
operator.width,
value)
memObj)
else:
self.structInstance.memory.store(
baseOffset.add(operator.offset),
operator.width,
value)
memObj)
else:
raise AwlSimError("Store to write protected DB %d" % self.index)
......
......@@ -26,5 +26,8 @@ cdef class AwlStructInstance(object):
cdef public AwlStruct _struct
cdef public AwlMemory memory
cdef object getFieldData(self, AwlStructField field, AwlOffset baseOffset)
cdef setFieldData(self, AwlStructField field, object value, AwlOffset baseOffset)
cdef AwlMemoryObject getFieldData(self, AwlStructField field, AwlOffset baseOffset) except NULL
cdef setFieldData(self, AwlStructField field, AwlMemoryObject memObj, AwlOffset baseOffset)
cdef AwlMemoryObject getFieldDataByName(self, object name) except NULL
cdef setFieldDataByName(self, object name, AwlMemoryObject memObj)
......@@ -284,10 +284,10 @@ class AwlStruct(object): #+cdef
if not initBytes:
raise ValueError
fieldInitMem = AwlMemory(intDivRoundUp(childType.width, 8))
fieldInitData = fieldInitMem.dataBytes
fieldInitMem.store(make_AwlOffset(0, 0), childType.width,
initMem.fetch(initOffset,
childType.width))
fieldInitMem.store(make_AwlOffset(0, 0),
initMem.fetch(initOffset,
childType.width))
fieldInitData = fieldInitMem.getDataBytes()
except (AwlSimError, ValueError) as e:
fieldInitData = None
self.addField(cpu, str(childIdent), childType,
......@@ -365,30 +365,32 @@ class AwlStructInstance(object): #+cdef
if not field.initBytes:
continue
try:
self.memory.store(field.offset, field.bitSize,
field.initBytes)
self.memory.store(field.offset,
make_AwlMemoryObject_fromBytes(field.initBytes,
field.bitSize))
except AwlSimError as e:
raise AwlSimError("Data structure field '%s' "
"initialization is out of range." %\
str(field))
def getFieldData(self, field, baseOffset): #@nocy
#@cy cdef object getFieldData(self, AwlStructField field, AwlOffset baseOffset):
#@cy cdef AwlMemoryObject getFieldData(self, AwlStructField field, AwlOffset baseOffset) except NULL:
if baseOffset is None:
return self.memory.fetch(field.offset, field.bitSize)
return self.memory.fetch(baseOffset.add(field.offset), field.bitSize)
def setFieldData(self, field, value, baseOffset): #@nocy
#@cy cdef setFieldData(self, AwlStructField field, object value, AwlOffset baseOffset):
def setFieldData(self, field, memObj, baseOffset): #@nocy
#@cy cdef setFieldData(self, AwlStructField field, AwlMemoryObject memObj, AwlOffset baseOffset):
AwlMemoryObject_assertWidth(memObj, field.bitSize)
if baseOffset is None:
self.memory.store(field.offset,
field.bitSize, value)
self.memory.store(field.offset, memObj)
else:
self.memory.store(baseOffset.add(field.offset),
field.bitSize, value)
self.memory.store(baseOffset.add(field.offset), memObj)
def getFieldDataByName(self, name):
def getFieldDataByName(self, name): #@nocy
#@cy cdef AwlMemoryObject getFieldDataByName(self, object name) except NULL:
return self.getFieldData(self._struct.getField(name), None)
def setFieldDataByName(self, name, value):
self.setFieldData(self._struct.getField(name), value, None)
def setFieldDataByName(self, name, memObj): #@nocy
#@cy cdef setFieldDataByName(self, object name, AwlMemoryObject memObj):
self.setFieldData(self._struct.getField(name), memObj, None)
......@@ -2,7 +2,7 @@
#
# AWL simulator - instructions
#
# Copyright 2012-2017 Michael Buesch <m@bues.ch>
# Copyright 2012-2018 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
......@@ -40,10 +40,19 @@ class AwlInsn_ASSERT_EQ(AwlInsn): #+cdef
def run(self): #+cdef
#@cy cdef S7StatusWord s
#@cy cdef AwlMemoryObject memObj0
#@cy cdef AwlMemoryObject memObj1
s = self.cpu.statusWord
val0 = self.cpu.fetch(self.op0, self._widths_all)
val1 = self.cpu.fetch(self.op1, self._widths_all)
memObj0 = self.cpu.fetch(self.op0, self._widths_all)
memObj1 = self.cpu.fetch(self.op1, self._widths_all)
if memObj0.width <= 32 and memObj1.width <= 32:
val0 = AwlMemoryObject_asScalar(memObj0)
val1 = AwlMemoryObject_asScalar(memObj1)
else:
val0 = AwlMemoryObject_asBytes(memObj0)
val1 = AwlMemoryObject_asBytes(memObj1)
if not (val0 == val1):
raise AwlSimError("Assertion failed")
s.NER = 0
......@@ -2,7 +2,7 @@
#
# AWL simulator - instructions
#
# Copyright 2012-2017 Michael Buesch <m@bues.ch>
# Copyright 2012-2018 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
......@@ -41,10 +41,15 @@ class AwlInsn_ASSERT_EQ_R(AwlInsn): #+cdef
def run(self): #+cdef
#@cy cdef S7StatusWord s
#@cy cdef AwlMemoryObject memObj0
#@cy cdef AwlMemoryObject memObj1
s = self.cpu.statusWord
val0 = self.cpu.fetch(self.op0, self._widths_32)
val1 = self.cpu.fetch(self.op1, self._widths_32)
memObj0 = self.cpu.fetch(self.op0, self._widths_all)
memObj1 = self.cpu.fetch(self.op1, self._widths_all)
val0 = AwlMemoryObject_asScalar(memObj0)
val1 = AwlMemoryObject_asScalar(memObj1)
if not floatEqual(val0, val1):
raise AwlSimError("Assertion failed")
s.NER = 0
......@@ -2,7 +2,7 @@
#
# AWL simulator - instructions
#
# Copyright 2012-2017 Michael Buesch <m@bues.ch>
# Copyright 2012-2018 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
......@@ -40,10 +40,19 @@ class AwlInsn_ASSERT_GE(AwlInsn): #+cdef
def run(self): #+cdef
#@cy cdef S7StatusWord s
#@cy cdef AwlMemoryObject memObj0
#@cy cdef AwlMemoryObject memObj1
s = self.cpu.statusWord
val0 = self.cpu.fetch(self.op0, self._widths_all)
val1 = self.cpu.fetch(self.op1, self._widths_all)
memObj0 = self.cpu.fetch(self.op0, self._widths_all)
memObj1 = self.cpu.fetch(self.op1, self._widths_all)
if memObj0.width <= 32 and memObj1.width <= 32:
val0 = AwlMemoryObject_asScalar(memObj0)
val1 = AwlMemoryObject_asScalar(memObj1)
else:
val0 = AwlMemoryObject_asBytes(memObj0)
val1 = AwlMemoryObject_asBytes(memObj1)
if not (val0 >= val1):
raise AwlSimError("Assertion failed")
s.NER = 0
......@@ -2,7 +2,7 @@
#
# AWL simulator - instructions
#
# Copyright 2012-2017 Michael Buesch <m@bues.ch>
# Copyright 2012-2018 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
......@@ -40,10 +40,19 @@ class AwlInsn_ASSERT_GT(AwlInsn): #+cdef
def run(self): #+cdef
#@cy cdef S7StatusWord s
#@cy cdef AwlMemoryObject memObj0
#@cy cdef AwlMemoryObject memObj1
s = self.cpu.statusWord
val0 = self.cpu.fetch(self.op0, self._widths_all)
val1 = self.cpu.fetch(self.op1, self._widths_all)
memObj0 = self.cpu.fetch(self.op0, self._widths_all)
memObj1 = self.cpu.fetch(self.op1, self._widths_all)
if memObj0.width <= 32 and memObj1.width <= 32:
val0 = AwlMemoryObject_asScalar(memObj0)
val1 = AwlMemoryObject_asScalar(memObj1)
else:
val0 = AwlMemoryObject_asBytes(memObj0)
val1 = AwlMemoryObject_asBytes(memObj1)
if not (val0 > val1):
raise AwlSimError("Assertion failed")
s.NER = 0
......@@ -2,7 +2,7 @@
#
# AWL simulator - instructions
#
# Copyright 2012-2017 Michael Buesch <m@bues.ch>
# Copyright 2012-2018 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
......@@ -40,10 +40,19 @@ class AwlInsn_ASSERT_LE(AwlInsn): #+cdef
def run(self): #+cdef
#@cy cdef S7StatusWord s
#@cy cdef AwlMemoryObject memObj0
#@cy cdef AwlMemoryObject memObj1
s = self.cpu.statusWord
val0 = self.cpu.fetch(self.op0, self._widths_all)
val1 = self.cpu.fetch(self.op1, self._widths_all)
memObj0 = self.cpu.fetch(self.op0, self._widths_all)
memObj1 = self.cpu.fetch(self.op1, self._widths_all)
if memObj0.width <= 32 and memObj1.width <= 32:
val0 = AwlMemoryObject_asScalar(memObj0)
val1 = AwlMemoryObject_asScalar(memObj1)
else:
val0 = AwlMemoryObject_asBytes(memObj0)
val1 = AwlMemoryObject_asBytes(memObj1)
if not (val0 <= val1):
raise AwlSimError("Assertion failed")
s.NER = 0
......@@ -2,7 +2,7 @@
#
# AWL simulator - instructions
#
# Copyright 2012-2017 Michael Buesch <m@bues.ch>
# Copyright 2012-2018 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
......@@ -40,10 +40,19 @@ class AwlInsn_ASSERT_LT(AwlInsn): #+cdef
def run(self): #+cdef
#@cy cdef S7StatusWord s
#@cy cdef AwlMemoryObject memObj0
#@cy cdef AwlMemoryObject memObj1
s = self.cpu.statusWord
val0 = self.cpu.fetch(self.op0, self._widths_all)
val1 = self.cpu.fetch(self.op1, self._widths_all)
memObj0 = self.cpu.fetch(self.op0, self._widths_all)
memObj1 = self.cpu.fetch(self.op1, self._widths_all)
if memObj0.width <= 32 and memObj1.width <= 32:
val0 = AwlMemoryObject_asScalar(memObj0)
val1 = AwlMemoryObject_asScalar(memObj1)
else:
val0 = AwlMemoryObject_asBytes(memObj0)
val1 = AwlMemoryObject_asBytes(memObj1)
if not (val0 < val1):
raise AwlSimError("Assertion failed")
s.NER = 0
......@@ -2,7 +2,7 @@
#
# AWL simulator - instructions
#
# Copyright 2012-2017 Michael Buesch <m@bues.ch>
# Copyright 2012-2018 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
......@@ -40,10 +40,19 @@ class AwlInsn_ASSERT_NE(AwlInsn): #+cdef
def run(self): #+cdef
#@cy cdef S7StatusWord s
#@cy cdef AwlMemoryObject memObj0
#@cy cdef AwlMemoryObject memObj1
s = self.cpu.statusWord
val0 = self.cpu.fetch(self.op0, self._widths_all)
val1 = self.cpu.fetch(self.op1, self._widths_all)
memObj0 = self.cpu.fetch(self.op0, self._widths_all)
memObj1 = self.cpu.fetch(self.op1, self._widths_all)
if memObj0.width <= 32 and memObj1.width <= 32:
val0 = AwlMemoryObject_asScalar(memObj0)
val1 = AwlMemoryObject_asScalar(memObj1)
else:
val0 = AwlMemoryObject_asBytes(memObj0)
val1 = AwlMemoryObject_asBytes(memObj1)
if not (val0 != val1):
raise AwlSimError("Assertion failed")
s.NER = 0
......@@ -2,7 +2,7 @@
#
# AWL simulator - instructions
#
# Copyright 2012-2017 Michael Buesch <m@bues.ch>
# Copyright 2012-2018 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
......@@ -48,4 +48,6 @@ class AwlInsn_ASSIGN(AwlInsn): #+cdef
s.OR, s.STA, s.NER = 0, 0, 0
else:
s.OR, s.STA, s.NER = 0, s.VKE, 0
cpu.store(self.op0, s.STA, self._widths_1)
cpu.store(self.op0,
make_AwlMemoryObject_fromScalar(s.STA, 1),
self._widths_1)
......@@ -2,7 +2,7 @@
#
# AWL simulator - instructions
#
# Copyright 2012-2017 Michael Buesch <m@bues.ch>
# Copyright 2012-2018 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
......@@ -39,10 +39,12 @@ class AwlInsn_FEATURE(AwlInsn): #+cdef
self.assertOpCount((1, 2))
def run(self): #+cdef
target = self.cpu.fetch(self.op0, self._widths_scalar)
target = AwlMemoryObject_asScalar(self.cpu.fetch(self.op0,
self._widths_scalar))
value = None
if self.opCount >= 2:
value = self.cpu.fetch(self.op1, self._widths_scalar)
value = AwlMemoryObject_asScalar(self.cpu.fetch(self.op1,
self._widths_scalar))
if target == 0:
# Set/get the number of accumulator registers.
......
......@@ -2,7 +2,7 @@
#
# AWL simulator - instructions
#
# Copyright 2012-2017 Michael Buesch <m@bues.ch>
# Copyright 2012-2018 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
......@@ -43,7 +43,10 @@ class AwlInsn_FN(AwlInsn): #+cdef
#@cy cdef _Bool fm
s = self.cpu.statusWord
fm = self.cpu.fetch(self.op0, self._widths_1)
self.cpu.store(self.op0, s.VKE, self._widths_1)
fm = AwlMemoryObject_asScalar(self.cpu.fetch(self.op0,
self._widths_1))
self.cpu.store(self.op0,
make_AwlMemoryObject_fromScalar(s.VKE, 1),
self._widths_1)
s.OR, s.STA, s.NER = 0, s.VKE, 1
s.VKE = (s.VKE ^ 1) & fm
......@@ -2,7 +2,7 @@
#
# AWL simulator - instructions
#
# Copyright 2012-2017 Michael Buesch <m@bues.ch>
# Copyright 2012-2018 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
......@@ -43,7 +43,10 @@ class AwlInsn_FP(AwlInsn): #+cdef
#@cy cdef _Bool fm
s = self.cpu.statusWord
fm = self.cpu.fetch(self.op0, self._widths_1)
self.cpu.store(self.op0, s.VKE, self._widths_1)
fm = AwlMemoryObject_asScalar(self.cpu.fetch(self.op0,
self._widths_1))
self.cpu.store(self.op0,
make_AwlMemoryObject_fromScalar(s.VKE, 1),
self._widths_1)
s.OR, s.STA, s.NER = 0, s.VKE, 1
s.VKE = s.VKE & (fm ^ 1)
......@@ -2,7 +2,7 @@
#
# AWL simulator - instructions
#
# Copyright 2012-2017 Michael Buesch <m@bues.ch>
# Copyright 2012-2018 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
......@@ -39,7 +39,7 @@ class AwlInsn_L(AwlInsn): #+cdef
self.assertOpCount(1)
def run(self): #+cdef
#@cy cdef S7StatusWord s
self.cpu.accu2.copyFrom(self.cpu.accu1)
self.cpu.accu1.set(self.cpu.fetch(self.op0, self._widths_8_16_32))
self.cpu.accu1.set(
AwlMemoryObject_asScalar(self.cpu.fetch(self.op0,
self._widths_8_16_32)))
......@@ -2,7 +2,7 @@
#
# AWL simulator - instructions
#
# Copyright 2012-2017 Michael Buesch <m@bues.ch>
# Copyright 2012-2018 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
......@@ -39,9 +39,9 @@ class AwlInsn_LAR1(AwlInsn): #+cdef
self.assertOpCount((0, 1))
def run(self): #+cdef
#@cy cdef S7StatusWord s
if self.opCount:
self.cpu.ar1.set(self.cpu.fetch(self.op0, self._widths_32))
self.cpu.ar1.set(
AwlMemoryObject_asScalar(self.cpu.fetch(self.op0,
self._widths_32)))
else:
self.cpu.ar1.set(self.cpu.accu1.get())
......@@ -2,7 +2,7 @@
#
# AWL simulator - instructions
#
# Copyright 2012-2017 Michael Buesch <m@bues.ch>
# Copyright 2012-2018 Michael Buesch <m@bues.ch>
#
# This program is free software; you can redistribute it and/or modify