Skip to content

Commit 1d1c780

Browse files
committed
Add standard error handling to yuldiff main
1 parent de86faa commit 1d1c780

1 file changed

Lines changed: 60 additions & 31 deletions

File tree

tools/yuldiff/main.cpp

Lines changed: 60 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
#include <libyul/ObjectParser.h>
2828
#include <libyul/backends/evm/EVMDialect.h>
2929

30+
#include <libsmtutil/Exceptions.h>
31+
3032
#include <libsolutil/CommonIO.h>
3133

3234
#include <liblangutil/CharStream.h>
@@ -60,46 +62,73 @@ static std::shared_ptr<Object> parseYulFile(std::string_view const _path)
6062

6163
int main(int argc, char* argv[])
6264
{
63-
if (argc != 3)
65+
try
6466
{
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]);
6875

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+
}
7188

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)
73111
{
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;
76115
}
77-
78-
Dialect const* dialect = objA->dialect();
79-
if (!dialect)
116+
catch (InternalCompilerError const& _exception)
80117
{
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;
83121
}
84-
85-
tools::cmpast::ASTComparator cmp(*dialect);
86-
auto const result = cmp.compareObjects(*objA, *objB);
87-
if (result)
122+
catch (YulAssertion const& _exception)
88123
{
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;
91127
}
92-
else
128+
catch (...)
93129
{
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;
104133
}
105134
}

0 commit comments

Comments
 (0)