| 4256 | } |
| 4257 | |
| 4258 | std::string YulUtilFunctions::negateNumberCheckedFunction(Type const& _type) |
| 4259 | { |
| 4260 | solAssert(_type.category() == Type::Category::Integer, ""); |
| 4261 | IntegerType const& type = dynamic_cast<IntegerType const&>(_type); |
| 4262 | solAssert(type.isSigned(), "Expected signed type!"); |
| 4263 | |
| 4264 | std::string const functionName = "negate_" + _type.identifier(); |
| 4265 | return m_functionCollector.createFunction(functionName, [&]() { |
| 4266 | return Whiskers(R"( |
| 4267 | function <functionName>(value) -> ret { |
| 4268 | value := <cleanupFunction>(value) |
| 4269 | if eq(value, <minval>) { <panic>() } |
| 4270 | ret := sub(0, value) |
| 4271 | } |
| 4272 | )") |
| 4273 | ("functionName", functionName) |
| 4274 | ("minval", toCompactHexWithPrefix(type.min())) |
| 4275 | ("cleanupFunction", cleanupFunction(_type)) |
| 4276 | ("panic", panicFunction(PanicCode::UnderOverflow)) |
| 4277 | .render(); |
| 4278 | }); |
| 4279 | } |
| 4280 | |
| 4281 | std::string YulUtilFunctions::negateNumberWrappingFunction(Type const& _type) |
| 4282 | { |
no test coverage detected