From 3f7e05f44f86776ea01b28b176116730d94a9354 Mon Sep 17 00:00:00 2001 From: Lukas Einhaus Date: Mon, 4 Sep 2023 20:06:33 +0200 Subject: [PATCH] feat: parse ghdl output --- .../nn/fixed_point/mac/ghdl_report_parsing.py | 9 +++++++ .../mac/ghdl_report_parsing_test.py | 27 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 elasticai/creator/nn/fixed_point/mac/ghdl_report_parsing.py create mode 100644 elasticai/creator/nn/fixed_point/mac/ghdl_report_parsing_test.py diff --git a/elasticai/creator/nn/fixed_point/mac/ghdl_report_parsing.py b/elasticai/creator/nn/fixed_point/mac/ghdl_report_parsing.py new file mode 100644 index 00000000..d4dae037 --- /dev/null +++ b/elasticai/creator/nn/fixed_point/mac/ghdl_report_parsing.py @@ -0,0 +1,9 @@ +def parse(text): + separated = text.split(":") + fields = ("source", "line", "column", "time", "type", "content") + parsed = dict(zip(fields, separated)) + parsed["type"] = parsed["type"][1:-1] + parsed["time"] = parsed["time"][1:] + parsed["line"] = int(parsed["line"]) + parsed["column"] = int(parsed["column"]) + return parsed diff --git a/elasticai/creator/nn/fixed_point/mac/ghdl_report_parsing_test.py b/elasticai/creator/nn/fixed_point/mac/ghdl_report_parsing_test.py new file mode 100644 index 00000000..cf701c6a --- /dev/null +++ b/elasticai/creator/nn/fixed_point/mac/ghdl_report_parsing_test.py @@ -0,0 +1,27 @@ +from .ghdl_report_parsing import parse + + +def test_parse_ghdl_simulation_results_one_liner(): + simulation_output = "my_test_bench.vhd:64:17:@4ps:(report note):my report message" + expected = { + "source": "my_test_bench.vhd", + "line": 64, + "column": 17, + "time": "4ps", + "type": "report note", + "content": "my report message", + } + assert expected == parse(simulation_output) + + +def test_parse_ghdl_another_line(): + simulation_output = "A:1:2:@B:(C):D" + expected = { + "source": "A", + "line": 1, + "column": 2, + "time": "B", + "type": "C", + "content": "D", + } + assert expected == parse(simulation_output)