MCPcopy Create free account
hub / github.com/Vector35/binaryninja-api / AppendTwoOperand

Method AppendTwoOperand

lang/rust/pseudorust.cpp:273–362  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

271
272
273void PseudoRustFunction::AppendTwoOperand(const string& operand, const HighLevelILInstruction& instr,
274 HighLevelILTokenEmitter& emitter, DisassemblySettings* settings, BNOperatorPrecedence precedence,
275 std::optional<bool> signedHint)
276{
277 const auto& twoOperand = instr.AsTwoOperand();
278 const auto leftExpr = twoOperand.GetLeftExpr();
279 const auto rightExpr = twoOperand.GetRightExpr();
280 BNOperatorPrecedence leftPrecedence = precedence;
281 switch (precedence)
282 {
283 case SubOperatorPrecedence:
284 // Treat left side of subtraction as same level as addition. This lets
285 // (a - b) - c be represented as a - b - c, but a - (b - c) does not
286 // simplify at rendering
287 leftPrecedence = AddOperatorPrecedence;
288 break;
289 case DivideOperatorPrecedence:
290 // Treat left side of divison as same level as multiplication. This lets
291 // (a / b) / c be represented as a / b / c, but a / (b / c) does not
292 // simplify at rendering
293 leftPrecedence = MultiplyOperatorPrecedence;
294 break;
295 default:
296 break;
297 }
298
299 if (leftExpr.operation == HLIL_SPLIT)
300 {
301 const auto low = leftExpr.GetLowExpr();
302 const auto high = leftExpr.GetHighExpr();
303
304 emitter.Append(OperationToken, "COMBINE");
305 emitter.AppendOpenParen();
306 GetExprText(high, emitter, settings);
307 emitter.Append(TextToken, ", ");
308 GetExprText(low, emitter, settings);
309 emitter.AppendCloseParen();
310 }
311
312 if (operand == " + " || operand == " - ")
313 {
314 const auto exprType = leftExpr.GetType();
315 if (exprType && exprType->IsPointer())
316 {
317 GetExprText(leftExpr, emitter, settings, MemberAndFunctionOperatorPrecedence);
318 emitter.Append(TextToken, ".");
319 emitter.Append(OperationToken, "byte_offset");
320 emitter.AppendOpenParen();
321 if (operand == " - ")
322 {
323 emitter.Append(OperationToken, "-");
324 GetExprText(rightExpr, emitter, settings, UnaryOperatorPrecedence);
325 }
326 else
327 {
328 GetExprText(rightExpr, emitter, settings);
329 }
330 emitter.AppendCloseParen();

Callers

nothing calls this directly

Calls 10

AppendOpenParenMethod · 0.80
AppendCloseParenMethod · 0.80
GetLeftExprMethod · 0.45
GetRightExprMethod · 0.45
GetLowExprMethod · 0.45
GetHighExprMethod · 0.45
AppendMethod · 0.45
GetTypeMethod · 0.45
IsPointerMethod · 0.45

Tested by

no test coverage detected