|
27 | 27 | #include <libyul/ObjectParser.h> |
28 | 28 | #include <libyul/backends/evm/EVMDialect.h> |
29 | 29 |
|
| 30 | +#include <libsmtutil/Exceptions.h> |
| 31 | + |
30 | 32 | #include <libsolutil/CommonIO.h> |
31 | 33 |
|
32 | 34 | #include <liblangutil/CharStream.h> |
@@ -60,46 +62,73 @@ static std::shared_ptr<Object> parseYulFile(std::string_view const _path) |
60 | 62 |
|
61 | 63 | int main(int argc, char* argv[]) |
62 | 64 | { |
63 | | - if (argc != 3) |
| 65 | + try |
64 | 66 | { |
65 | | - std::cerr << "Usage: yulASTComparator <file1.yul> <file2.yul>\n"; |
66 | | - return EXIT_FAILURE; |
67 | | - } |
| 67 | + if (argc != 3) |
| 68 | + { |
| 69 | + std::cerr << "Usage: yulASTComparator <file1.yul> <file2.yul>\n"; |
| 70 | + return EXIT_FAILURE; |
| 71 | + } |
| 72 | + |
| 73 | + auto objA = parseYulFile(argv[1]); |
| 74 | + auto objB = parseYulFile(argv[2]); |
68 | 75 |
|
69 | | - auto objA = parseYulFile(argv[1]); |
70 | | - auto objB = parseYulFile(argv[2]); |
| 76 | + if (!objA || !objB) |
| 77 | + { |
| 78 | + std::cerr << "Aborting due to parse errors.\n"; |
| 79 | + return EXIT_FAILURE; |
| 80 | + } |
| 81 | + |
| 82 | + Dialect const* dialect = objA->dialect(); |
| 83 | + if (!dialect) |
| 84 | + { |
| 85 | + std::cerr << "No dialect available.\n"; |
| 86 | + return EXIT_FAILURE; |
| 87 | + } |
71 | 88 |
|
72 | | - if (!objA || !objB) |
| 89 | + tools::cmpast::ASTComparator cmp(*dialect); |
| 90 | + auto const result = cmp.compareObjects(*objA, *objB); |
| 91 | + if (result) |
| 92 | + { |
| 93 | + std::cout << "EQUIVALENT\n"; |
| 94 | + return EXIT_SUCCESS; |
| 95 | + } |
| 96 | + else |
| 97 | + { |
| 98 | + auto const& mm = result.mismatch(); |
| 99 | + std::cout << "MISMATCH\n"; |
| 100 | + std::cout << " at: " << mm.path << "\n"; |
| 101 | + std::cout << " reason: " << mm.reason << "\n"; |
| 102 | + if (!mm.lhs.empty()) |
| 103 | + { |
| 104 | + std::cout << "\n --- LHS ---\n" << mm.lhs << "\n"; |
| 105 | + std::cout << "\n --- RHS ---\n" << mm.rhs << "\n"; |
| 106 | + } |
| 107 | + return EXIT_FAILURE; |
| 108 | + } |
| 109 | + } |
| 110 | + catch (smtutil::SMTLogicError const& _exception) |
73 | 111 | { |
74 | | - std::cerr << "Aborting due to parse errors.\n"; |
75 | | - return EXIT_FAILURE; |
| 112 | + std::cerr << "SMT logic error:" << std::endl; |
| 113 | + std::cerr << boost::diagnostic_information(_exception); |
| 114 | + return 2; |
76 | 115 | } |
77 | | - |
78 | | - Dialect const* dialect = objA->dialect(); |
79 | | - if (!dialect) |
| 116 | + catch (InternalCompilerError const& _exception) |
80 | 117 | { |
81 | | - std::cerr << "No dialect available.\n"; |
82 | | - return EXIT_FAILURE; |
| 118 | + std::cerr << "Internal compiler error:" << std::endl; |
| 119 | + std::cerr << boost::diagnostic_information(_exception); |
| 120 | + return 2; |
83 | 121 | } |
84 | | - |
85 | | - tools::cmpast::ASTComparator cmp(*dialect); |
86 | | - auto const result = cmp.compareObjects(*objA, *objB); |
87 | | - if (result) |
| 122 | + catch (YulAssertion const& _exception) |
88 | 123 | { |
89 | | - std::cout << "EQUIVALENT\n"; |
90 | | - return EXIT_SUCCESS; |
| 124 | + std::cerr << "Yul assertion failed:" << std::endl; |
| 125 | + std::cerr << boost::diagnostic_information(_exception); |
| 126 | + return 2; |
91 | 127 | } |
92 | | - else |
| 128 | + catch (...) |
93 | 129 | { |
94 | | - auto const& mm = result.mismatch(); |
95 | | - std::cout << "MISMATCH\n"; |
96 | | - std::cout << " at: " << mm.path << "\n"; |
97 | | - std::cout << " reason: " << mm.reason << "\n"; |
98 | | - if (!mm.lhs.empty()) |
99 | | - { |
100 | | - std::cout << "\n --- LHS ---\n" << mm.lhs << "\n"; |
101 | | - std::cout << "\n --- RHS ---\n" << mm.rhs << "\n"; |
102 | | - } |
103 | | - return EXIT_FAILURE; |
| 130 | + std::cerr << "Uncaught exception:" << std::endl; |
| 131 | + std::cerr << boost::current_exception_diagnostic_information() << std::endl; |
| 132 | + return 2; |
104 | 133 | } |
105 | 134 | } |
0 commit comments