Skip to content

Commit d156846

Browse files
authored
Merge pull request #5 from deckamil/dev
Delivery into 0.3.0-alpha release milestone
2 parents 510fbe7 + fe79327 commit d156846

File tree

7 files changed

+121
-56
lines changed

7 files changed

+121
-56
lines changed

MCG/MCG_CC/mcg_cc_file_checker.py

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# responsible for checking of model module content from .exml file.
66
#
77
# COPYRIGHT: Copyright (C) 2021-2023 Kamil Deć github.com/deckamil
8-
# DATE: 7 JUN 2023
8+
# DATE: 23 JUN 2023
99
#
1010
# LICENSE:
1111
# This file is part of Mod Code Generator (MCG).
@@ -39,12 +39,14 @@
3939
class FileChecker(object):
4040

4141
# list of actions types
42-
action_type_list = ["ADD", "SUB", "MUL", "DIV"]
42+
action_3letter_type_list = ["ADD", "SUB", "MUL", "DIV", "AND", "NOT"]
43+
action_2letter_type_list = ["OR", "EQ", "NE", "GT", "LT", "GE", "LE"]
4344

4445
# list of interface element types
4546
interface_element_type_list = ["INT8", "INT16", "INT32", "INT64",
4647
"UINT8", "UINT16", "UINT32", "UINT64",
47-
"FLOAT32", "FLOAT64"]
48+
"FLOAT32", "FLOAT64",
49+
"BOOL"]
4850

4951
# Description:
5052
# This is class constructor.
@@ -93,14 +95,27 @@ def check_action_type(action_type_ref):
9395
# result flag
9496
action_type_valid = False
9597

96-
# for all possible action types
97-
for action_type in FileChecker.action_type_list:
98-
# if action type is the same as in reference
99-
if action_type == action_type_ref[0:3]:
100-
# set flag
101-
action_type_valid = True
102-
# exit loop
103-
break
98+
# is valid type is not found
99+
if not action_type_valid:
100+
# check all possible 3-letter action types
101+
for action_type in FileChecker.action_3letter_type_list:
102+
# if action type is the same as in reference
103+
if action_type == action_type_ref[0:3]:
104+
# set flag
105+
action_type_valid = True
106+
# exit loop
107+
break
108+
109+
# is valid types is not found
110+
if not action_type_valid:
111+
# check 2-letter action types
112+
for action_type in FileChecker.action_2letter_type_list:
113+
# if action type is the same as in reference
114+
if action_type == action_type_ref[0:2]:
115+
# set flag
116+
action_type_valid = True
117+
# exit loop
118+
break
104119

105120
# return flag
106121
return action_type_valid

MCG/MCG_CC/mcg_cc_file_reader.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# responsible for reading of module content from .exml file.
66
#
77
# COPYRIGHT: Copyright (C) 2021-2023 Kamil Deć github.com/deckamil
8-
# DATE: 21 JAN 2023
8+
# DATE: 24 JUN 2023
99
#
1010
# LICENSE:
1111
# This file is part of Mod Code Generator (MCG).
@@ -388,8 +388,18 @@ def read_interaction_targets(self):
388388
Logger.save_in_log_file("FileReader", "Have found " + str(connection) + " connection",
389389
False)
390390

391-
# if end of target section if found
392-
if "</COMP>" in self.activity_file[j]:
391+
# if end of action target section is found
392+
if "</COMP>" in self.activity_file[j] and \
393+
source_interaction_type == Connection.ACTION:
394+
# exit "for j in range" loop
395+
break
396+
397+
# if end of operation target section is found
398+
if "</COMP>" in self.activity_file[j] and \
399+
"</DEPENDENCIES>" in self.activity_file[j+1] and \
400+
"</OBJECT>" in self.activity_file[j+2] and \
401+
"</COMP>" in self.activity_file[j+3] and \
402+
source_interaction_type == Connection.OPERATION:
393403
# exit "for j in range" loop
394404
break
395405

MCG/MCG_CC/mcg_cc_main.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# file.
88
#
99
# COPYRIGHT: Copyright (C) 2021-2023 Kamil Deć github.com/deckamil
10-
# DATE: 10 JUN 2023
10+
# DATE: 25 JUN 2023
1111
#
1212
# LICENSE:
1313
# This file is part of Mod Code Generator (MCG).
@@ -55,7 +55,7 @@ class Main(object):
5555
OUTPUT_DIR_PATH_INDEX = 2
5656

5757
# MCG CC version
58-
MCG_CC_VERSION = "v0.2.0-alpha"
58+
MCG_CC_VERSION = "v0.3.0-alpha"
5959

6060
# Description:
6161
# This is main method, which display short notice and start conversion process.
@@ -142,15 +142,15 @@ def convert_model():
142142
# check errors
143143
ErrorHandler.check_errors()
144144

145-
# initialize sorter
145+
# initialize module sorter
146146
module_sorter = ModuleSorter(file_reader_list)
147147
# sort module content
148148
module_sorter_list = module_sorter.sort_module()
149149

150150
# check errors
151151
ErrorHandler.check_errors()
152152

153-
# initialize converter
153+
# initialize module converter
154154
module_converter = ModuleConverter(file_finder_list, file_reader_list, module_sorter_list)
155155
# convert module content
156156
module_converter.convert_module()

MCG/MCG_CC/mcg_cc_module_converter.py

Lines changed: 56 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# for conversion of module content into configuration file format.
66
#
77
# COPYRIGHT: Copyright (C) 2021-2023 Kamil Deć github.com/deckamil
8-
# DATE: 28 MAY 2023
8+
# DATE: 23 JUN 2023
99
#
1010
# LICENSE:
1111
# This file is part of Mod Code Generator (MCG).
@@ -240,8 +240,8 @@ def convert_operation_node(self, sorted_node):
240240
Logger.save_in_log_file("ModuleConverter", "Have converted to " + str(conversion_line) + " line", False)
241241

242242
# Description:
243-
# This method converts module specific action node into configuration file.
244-
def convert_specific_action_node(self, sorted_node, math_symbol):
243+
# This method converts module specific action node with n-argument operator into configuration file.
244+
def convert_specific_action_node_arity_n(self, sorted_node, operator):
245245

246246
# get output link
247247
output_link = sorted_node.output_data_list[0]
@@ -254,40 +254,78 @@ def convert_specific_action_node(self, sorted_node, math_symbol):
254254
input_data_name = input_link[Node.DATA_NAME_INDEX]
255255
# append input data element to conversion line
256256
conversion_line = conversion_line + str(input_data_name)
257-
# append math symbol to conversion line
258-
conversion_line = conversion_line + str(" ") + str(math_symbol) + str(" ")
257+
# append operator to conversion line
258+
conversion_line = conversion_line + str(" ") + str(operator) + str(" ")
259259

260-
# remove spare math symbol and whitespace
260+
# remove spare operator and whitespace
261261
conversion_line = conversion_line[0:len(conversion_line) - 3]
262262
# append conversion line to configuration file
263263
self.configuration_file.append(conversion_line)
264264

265265
# record info
266266
Logger.save_in_log_file("ModuleConverter", "Have converted to " + str(conversion_line) + " line", False)
267267

268+
# Description:
269+
# This method converts module specific action node with 1-argument operator into configuration file.
270+
def convert_specific_action_node_arity_1(self, sorted_node, operator):
271+
272+
# get input link
273+
input_link = sorted_node.input_data_list[0]
274+
# get output link
275+
output_link = sorted_node.output_data_list[0]
276+
# set beginning of action interaction to conversion line
277+
conversion_line = str("$INS ") + str(output_link[Node.DATA_NAME_INDEX]) + str(" = ") + \
278+
str(operator) + str(input_link[Node.DATA_NAME_INDEX])
279+
280+
# append conversion line to configuration file
281+
self.configuration_file.append(conversion_line)
282+
283+
# record info
284+
Logger.save_in_log_file("ModuleConverter", "Have converted to " + str(conversion_line) + " line", False)
285+
268286
# Description:
269287
# This method converts module action node into configuration file.
270288
def convert_action_node(self, sorted_node):
271289

272-
# if sorted node contains ADD action
290+
# depending on the type of action, covert module node into configuration file.
273291
if sorted_node.name[0:3] == "ADD":
274-
# convert ADD action
275-
self.convert_specific_action_node(sorted_node, "+")
292+
self.convert_specific_action_node_arity_n(sorted_node, "+")
276293

277-
# if sorted node contains SUB action
278294
elif sorted_node.name[0:3] == "SUB":
279-
# convert SUB action
280-
self.convert_specific_action_node(sorted_node, "-")
295+
self.convert_specific_action_node_arity_n(sorted_node, "-")
281296

282-
# if sorted node contains MUL action
283297
elif sorted_node.name[0:3] == "MUL":
284-
# convert MUL action
285-
self.convert_specific_action_node(sorted_node, "*")
298+
self.convert_specific_action_node_arity_n(sorted_node, "*")
286299

287-
# if sorted node contains DIV action
288300
elif sorted_node.name[0:3] == "DIV":
289-
# convert DIV action
290-
self.convert_specific_action_node(sorted_node, "/")
301+
self.convert_specific_action_node_arity_n(sorted_node, "/")
302+
303+
elif sorted_node.name[0:3] == "AND":
304+
self.convert_specific_action_node_arity_n(sorted_node, "&&")
305+
306+
elif sorted_node.name[0:3] == "NOT":
307+
self.convert_specific_action_node_arity_1(sorted_node, "!")
308+
309+
elif sorted_node.name[0:2] == "OR":
310+
self.convert_specific_action_node_arity_n(sorted_node, "||")
311+
312+
elif sorted_node.name[0:2] == "EQ":
313+
self.convert_specific_action_node_arity_n(sorted_node, "==")
314+
315+
elif sorted_node.name[0:2] == "NE":
316+
self.convert_specific_action_node_arity_n(sorted_node, "!=")
317+
318+
elif sorted_node.name[0:2] == "GT":
319+
self.convert_specific_action_node_arity_n(sorted_node, ">")
320+
321+
elif sorted_node.name[0:2] == "LT":
322+
self.convert_specific_action_node_arity_n(sorted_node, "LT")
323+
324+
elif sorted_node.name[0:2] == "GE":
325+
self.convert_specific_action_node_arity_n(sorted_node, ">=")
326+
327+
elif sorted_node.name[0:2] == "LE":
328+
self.convert_specific_action_node_arity_n(sorted_node, "<=")
291329

292330
# Description:
293331
# This method converts module data node into configuration file.

MCG/MCG_CC/mcg_cc_module_sorter.py

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# for finding and sorting of module nodes.
66
#
77
# COPYRIGHT: Copyright (C) 2021-2023 Kamil Deć github.com/deckamil
8-
# DATE: 25 MAR 2023
8+
# DATE: 24 JUN 2023
99
#
1010
# LICENSE:
1111
# This file is part of Mod Code Generator (MCG).
@@ -42,7 +42,7 @@ class ModuleSorter(object):
4242
SORTED_NODE_LIST_INDEX = 0
4343

4444
# list of action interaction that require to distinguish main data input
45-
input_sensitivity_action_list = ["SUB", "DIV"]
45+
input_sensitive_action_list = ["SUB", "DIV", "GT", "LT", "GE", "LE"]
4646

4747
# Description:
4848
# This is class constructor.
@@ -248,10 +248,8 @@ def sort_nodes(self):
248248
self.sorted_node_list.append(dependency[0])
249249
# remove dependency sublist from dependency list
250250
self.dependency_list.remove(dependency)
251-
# get output link
252-
output_link = dependency[0].output_data_list[0]
253-
# get output data name
254-
output_data_name = output_link[Node.DATA_NAME_INDEX]
251+
# get output data list
252+
output_data_list = dependency[0].output_data_list
255253
# recalculate number of nodes to sort, i.e. length of dependency list
256254
dependency_list_length = len(self.dependency_list)
257255

@@ -267,15 +265,18 @@ def sort_nodes(self):
267265
for k in range(index, len(dependency)):
268266
# if given node consumes local data elements, which comes from node, which
269267
# was appended above to sorted node list
270-
if output_data_name == dependency[index]:
271-
# remove local data element from dependency sublist
272-
dependency.remove(dependency[index])
273-
# decrement index for next iteration, as one dependence was removed
274-
# therefore all next dependencies in dependency sublist were pushed by
275-
# one position towards beginning of the sublist, e.g. [...,A,B,C] -> [...,B,C];
276-
# A was removed and now B is under previous position of A so at next
277-
# iteration the same index need to be checked to examine B;
278-
index = index - 1
268+
for output_link in output_data_list:
269+
if output_link[Node.DATA_NAME_INDEX] == dependency[index]:
270+
# remove local data element from dependency sublist
271+
dependency.remove(dependency[index])
272+
# decrement index for next iteration, as one dependence was removed
273+
# therefore all next dependencies in dependency sublist were pushed by
274+
# one position towards beginning of the sublist, e.g. [...,A,B,C] -> [...,B,C];
275+
# A was removed and now B is under previous position of A so at next
276+
# iteration the same index need to be checked to examine B;
277+
index = index - 1
278+
# exit "for output_link in" loop
279+
break
279280
index = index + 1
280281

281282
# exit "for i in range" loop
@@ -311,8 +312,9 @@ def sort_input_data_list(self):
311312
if sorted_node.type == Node.ACTION:
312313

313314
# and if action is input sensitive, i.e. requires to distinguish main input data
314-
for input_sensitivity_action in ModuleSorter.input_sensitivity_action_list:
315-
if sorted_node.name[0:3] == input_sensitivity_action:
315+
for input_sensitive_action in ModuleSorter.input_sensitive_action_list:
316+
if (sorted_node.name[0:3] == input_sensitive_action) or \
317+
(sorted_node.name[0:2] == input_sensitive_action):
316318

317319
# get marker position
318320
marker_position = sorted_node.name.find("+")
@@ -335,7 +337,7 @@ def sort_input_data_list(self):
335337
# record info
336338
Logger.save_in_log_file("ModuleSorter", "Have sorted " + str(sorted_node) + " node",
337339
False)
338-
# exit "for input_data in" loop
340+
# exit "for input_link in" loop
339341
break
340342

341343
# Description:

MCG/MCG_CGC/mcg_cgc_main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# to generate C code from the configuration file.
77
#
88
# COPYRIGHT: Copyright (C) 2022-2023 Kamil Deć github.com/deckamil
9-
# DATE: 10 JUN 2023
9+
# DATE: 25 JUN 2023
1010
#
1111
# LICENSE:
1212
# This file is part of Mod Code Generator (MCG).
@@ -51,7 +51,7 @@ class Main(object):
5151
OUTPUT_DIR_PATH_INDEX = 2
5252

5353
# MCG CGC version
54-
MCG_CGC_VERSION = "v0.2.0-alpha"
54+
MCG_CGC_VERSION = "v0.3.0-alpha"
5555

5656
# Description:
5757
# This is main method, which display short notice and start code generation process.

Mod Code Generator Manual.pdf

452 KB
Binary file not shown.

0 commit comments

Comments
 (0)