File size: 1,499 Bytes
684db41
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <gtest/gtest.h>
#include "passes/techmap/libparse.h"

YOSYS_NAMESPACE_BEGIN

namespace RTLIL {

	class TechmapLibparseTest : public testing::Test {
	protected:
		TechmapLibparseTest() {
			if (logger().empty()) logger().add_sink<ConsoleLogSink>();
		}
		void checkAll(std::initializer_list<std::string> expressions, std::string expected) {
			for (const auto& e : expressions) {
				auto helper = LibertyExpression::Lexer(e);
				auto tree_s = LibertyExpression::parse(helper).sexpr_str();
				EXPECT_EQ(tree_s, expected);
			}
		}
	};
	TEST_F(TechmapLibparseTest, LibertyExpressionSpace)
	{
		checkAll({
			"x",
			"x ",
			" x",
			" x ",
			"  x ",
		}, "(pin \"x\")");

		checkAll({
			"x y",
			" x y ",
			"x (y)",
			" x (y) ",
			"(x) y",
			" (x) y ",

			"x & y",
			"x&y",
			"x &y",
			"x& y",
			" x&y ",
			"x & (y)",
			"x&(y)",
			"x &(y)",
			"x& (y)",
			" x&(y) ",
			"(x) & y",
			"(x)&y",
			"(x) &y",
			"(x)& y",
			" (x)&y ",
		}, "(and (pin \"x\")\n"
		   "     (pin \"y\"))"
		);

		checkAll({
			"x ^ y",
			"x^y",
			"x ^y",
			"x^ y",
			" x^y ",
		}, "(xor (pin \"x\")\n"
		   "     (pin \"y\"))"
		);
		checkAll({
			"x !y",
			" x !y ",
			"x & !y",
			"x&!y",
			"x &!y",
			"x& !y",
			" x&!y ",
			"x y'",
			" x y' ",
			"x & y'",
			"x&y'",
			"x &y'",
			"x& y'",
			" x&y' ",
		}, "(and (pin \"x\")\n"
		   "     (not (pin \"y\")))"
		);
		checkAll({
			"( D & EN )",
		}, "(and (pin \"D\")\n"
		   "     (pin \"EN\"))"
		);
	}
}

YOSYS_NAMESPACE_END