From e5693328e2a9880e7b127c53d072bd08fff7afc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophile=20Bastian?= Date: Fri, 19 Jul 2019 00:32:42 +0200 Subject: [PATCH] DwAsm: check global bounds --- src/FactoredSwitchCompiler.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/FactoredSwitchCompiler.cpp b/src/FactoredSwitchCompiler.cpp index 9fd66cc..2c41f90 100644 --- a/src/FactoredSwitchCompiler.cpp +++ b/src/FactoredSwitchCompiler.cpp @@ -22,9 +22,20 @@ void FactoredSwitchCompiler::to_stream( } JumpPointMap jump_points; + uintptr_t low_bound = sw.cases.front().low_bound, + high_bound = sw.cases.back().high_bound; + + os << indent() << "if(" + << "0x" << hex << low_bound << " <= " << sw.switch_var + << " && " << sw.switch_var << " <= 0x" << high_bound << dec << ") {\n"; + indent_count++; + gen_binsearch_tree(os, jump_points, sw.switch_var, sw.cases.begin(), sw.cases.end(), - make_pair(sw.cases.front().low_bound, sw.cases.back().high_bound)); + make_pair(low_bound, high_bound)); + + indent_count--; + os << indent() << "}\n"; os << indent() << "_factor_default:\n" << indent_str(sw.default_case) << "\n"