Commit 59a470e6 authored by Michael Büsch's avatar Michael Büsch

Add library block loading interface

Signed-off-by: Michael Büsch's avatarMichael Buesch <m@bues.ch>
parent cedfdb97
......@@ -169,12 +169,12 @@ def run(inputFile):
writeStdout("Parsing code...\n")
parseTrees = []
for awlSrc in project.awlSources:
for awlSrc in project.getAwlSources():
p = AwlParser()
p.parseSource(awlSrc)
parseTrees.append(p.getParseTree())
symTables = []
for symTabSrc in project.symTabSources:
for symTabSrc in project.getSymTabSources():
mnemonics = project.cpuSpecs.getConfiguredMnemonics()
if opt_mnemonics is not None:
mnemonics = opt_mnemonics
......@@ -207,6 +207,8 @@ def run(inputFile):
s.loadSymbolTable(symTable)
for parseTree in parseTrees:
s.load(parseTree)
for libSel in project.getLibSelections():
s.loadLibraryBlock(libSel)
s.startup()
writeStdout("[Initialization finished - CPU is executing user code]\n")
try:
......@@ -299,10 +301,12 @@ def runWithServerBackend(inputFile):
# Fire up the core
writeStdout("Initializing CPU...\n")
for symTabSrc in project.symTabSources:
for symTabSrc in project.getSymTabSources():
client.loadSymbolTable(symTabSrc)
for awlSrc in project.awlSources:
for awlSrc in project.getAwlSources():
client.loadCode(awlSrc)
for libSel in project.getLibSelections():
client.loadLibraryBlock(libSel)
client.setRunState(True)
# Run the client-side event loop
......
......@@ -144,6 +144,18 @@ class AwlSim(object):
if self.__profileLevel >= 2:
self.__profileStop()
def loadLibraryBlock(self, libSelection):
if self.__profileLevel >= 2:
self.__profileStart()
try:
self.cpu.loadLibraryBlock(libSelection)
except AwlSimError as e:
self.__handleSimException(e)
if self.__profileLevel >= 2:
self.__profileStop()
def startup(self):
if self.__profileLevel >= 2:
self.__profileStart()
......
......@@ -316,6 +316,12 @@ class AwlSimClient(object):
if status != AwlSimMessage_REPLY.STAT_OK:
raise AwlSimError("AwlSimClient: Failed to load symbol table")
def loadLibraryBlock(self, libSelection):
msg = AwlSimMessage_LOAD_LIB(libSelection)
status = self.__sendAndWaitFor_REPLY(msg)
if status != AwlSimMessage_REPLY.STAT_OK:
raise AwlSimError("AwlSimClient: Failed to load library block")
def loadHardwareModule(self, name, parameters={}):
if not self.transceiver:
return False
......
......@@ -69,6 +69,7 @@ class AwlSimMessage(object):
MSG_ID_MEMORY = EnumGen.item
MSG_ID_INSNSTATE = EnumGen.item
MSG_ID_INSNSTATE_CONFIG = EnumGen.item
MSG_ID_LOAD_LIB = EnumGen.item
EnumGen.end
_bytesLenStruct = struct.Struct(str(">I"))
......@@ -298,6 +299,43 @@ class AwlSimMessage_LOAD_HW(AwlSimMessage):
raise TransferError("LOAD_HW: Invalid data format")
return cls(name = name, paramDict = paramDict)
class AwlSimMessage_LOAD_LIB(AwlSimMessage):
plStruct = struct.Struct(str(">Hii"))
def __init__(self, libSelection):
AwlSimMessage.__init__(self, AwlSimMessage.MSG_ID_LOAD_LIB)
self.libSelection = libSelection
def toBytes(self):
payload = b""
try:
payload += self.packString(self.libSelection.getLibName())
payload += self.plStruct.pack(self.libSelection.getEntryType(),
self.libSelection.getEntryIndex(),
self.libSelection.getEffectiveEntryIndex())
return AwlSimMessage.toBytes(self, len(payload)) + payload
except (ValueError) as e:
raise TransferError("LOAD_LIB: Invalid data format")
@classmethod
def fromBytes(cls, payload):
libSelection = AwlLibEntrySelection()
offset = 0
try:
libName, count = cls.unpackString(payload, offset)
offset += count
eType, eIndex, effIndex =\
cls.plStruct.unpack_from(payload, offset)
offset += cls.plStruct.size
libSelection = AwlLibEntrySelection(
libName = libName,
entryType = eType,
entryIndex = eIndex,
effectiveEntryIndex = effIndex)
except (ValueError, AwlSimError) as e:
raise TransferError("LOAD_LIB: Invalid data format")
return cls(libSelection = libSelection)
class AwlSimMessage_SET_OPT(AwlSimMessage):
def __init__(self, name, value):
AwlSimMessage.__init__(self, AwlSimMessage.MSG_ID_SET_OPT)
......@@ -654,6 +692,7 @@ class AwlSimMessageTransceiver(object):
AwlSimMessage.MSG_ID_MEMORY : AwlSimMessage_MEMORY,
AwlSimMessage.MSG_ID_INSNSTATE : AwlSimMessage_INSNSTATE,
AwlSimMessage.MSG_ID_INSNSTATE_CONFIG : AwlSimMessage_INSNSTATE_CONFIG,
AwlSimMessage.MSG_ID_LOAD_LIB : AwlSimMessage_LOAD_LIB,
}
def __init__(self, sock, peerInfoString):
......
......@@ -361,6 +361,12 @@ class AwlSimServer(object):
parameters = msg.paramDict)
client.transceiver.send(AwlSimMessage_REPLY.make(msg, status))
def __rx_LOAD_LIB(self, client, msg):
status = AwlSimMessage_REPLY.STAT_OK
self.__setRunState(self.STATE_INIT)
self.sim.loadLibraryBlock(msg.libSelection)
client.transceiver.send(AwlSimMessage_REPLY.make(msg, status))
def __rx_SET_OPT(self, client, msg):
status = AwlSimMessage_REPLY.STAT_OK
......@@ -449,6 +455,7 @@ class AwlSimServer(object):
AwlSimMessage.MSG_ID_REQ_MEMORY : __rx_REQ_MEMORY,
AwlSimMessage.MSG_ID_MEMORY : __rx_MEMORY,
AwlSimMessage.MSG_ID_INSNSTATE_CONFIG : __rx_INSNSTATE_CONFIG,
AwlSimMessage.MSG_ID_LOAD_LIB : __rx_LOAD_LIB,
}
def __handleClientComm(self, client):
......
......@@ -229,6 +229,7 @@ class CpuWidget(QWidget):
project = self.mainWidget.getProject()
awlSources = self.mainWidget.projectWidget.getAwlSources()
symTabSources = self.mainWidget.projectWidget.getSymTabSources()
libSelections = self.mainWidget.projectWidget.getLibSelections()
if not all(awlSources) or not all(symTabSources):
self.stop()
return
......@@ -279,6 +280,8 @@ class CpuWidget(QWidget):
client.loadSymbolTable(symTabSource)
for awlSource in awlSources:
client.loadCode(awlSource)
for libSel in libSelections:
client.loadLibraryBlock(libSel)
client.setRunState(True)
except AwlParserError as e:
self.__setState(self.STATE_EXCEPTION)
......
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