MCPcopy Create free account
hub / github.com/avast/retdec / getStackVariable

Method getStackVariable

src/bin2llvmir/utils/ir_modifier.cpp:544–576  ·  view source on GitHub ↗

* Get or create&get stack variable. * @param fnc Function owning the stack variable. * @param offset Stack varibale's offset. * @param type Stack varibale's type. * @param name Stack varibale's name in IR. If not set default name is used. * Offset is always appended to this name. If you want to get * this name to output C, set it as a real name to returned

Source from the content-addressed store, hash-verified

542 * stack var.
543 */
544IrModifier::StackPair IrModifier::getStackVariable(
545 llvm::Function* fnc,
546 int offset,
547 llvm::Type* type,
548 const std::string& name,
549 const std::string& realName,
550 bool fromDebug)
551{
552 if (!PointerType::isValidElementType(type) || !type->isSized())
553 {
554 type = Abi::getDefaultType(fnc->getParent());
555 }
556
557 std::string n = names::generateStackVarName(offset, name);
558
559 AllocaInst* ret = _config->getLlvmStackVariable(fnc, offset);
560 if (ret)
561 {
562 auto* csv = _config->getConfigStackVariable(ret);
563 assert(csv);
564 return {ret, csv};
565 }
566
567 ret = new AllocaInst(type, Abi::DEFAULT_ADDR_SPACE, n);
568
569 auto it = inst_begin(fnc);
570 assert(it != inst_end(fnc)); // -> create bb, insert alloca.
571 ret->insertBefore(&*it);
572
573 auto* csv = _config->insertStackVariable(ret, offset, fromDebug, realName);
574
575 return {ret, csv};
576}
577
578/**
579 * Get global variable from the given address @a addr in @a objf input file.

Callers 1

handleInstructionMethod · 0.80

Calls 5

generateStackVarNameFunction · 0.85
getLlvmStackVariableMethod · 0.80
insertStackVariableMethod · 0.80
getParentMethod · 0.45

Tested by

no test coverage detected