private Object getMemoryReferenceLabel(CodeUnit fromCodeUnit, Reference ref) {

		Program program = fromCodeUnit.getProgram();
		Address toAddress = ref.getToAddress();

		boolean withBlockName = false;
		MemoryBlock refBlock = null;

		if (toAddress.isMemoryAddress()) {
			Memory mem = program.getMemory();
			refBlock = mem.getBlock(toAddress);
			if (options.showBlockName == ShowBlockName.ALWAYS) {
				withBlockName = true;
			}
			else if (options.showBlockName == ShowBlockName.NON_LOCAL) {
				MemoryBlock block = mem.getBlock(fromCodeUnit.getMinAddress());
				withBlockName = (block != refBlock);
			}
		}

		String result;
		Symbol toSymbol = program.getSymbolTable().getSymbol(ref);
		if (toSymbol != null) {
			result = getSymbolLabelString(program, toSymbol, fromCodeUnit.getMinAddress());
		}
		else {
			result = toAddress.toString();
		}

		result = addBlockName(program, toAddress, result, refBlock, withBlockName);
		LabelType labelType = (toSymbol != null && toSymbol.isExternal()) ? LabelString.EXTERNAL
				: LabelString.CODE_LABEL;
		LabelString label = new LabelString(result, labelType);

		// Apply extended pointer markup if needed
		RefType referenceType = ref.getReferenceType();
		if (options.followReferencedPointers &&
			(referenceType.isIndirect() || ref.getReferenceType() == RefType.READ)) {
			LabelString extLabel = getExtendedPointerReferenceMarkup(program, ref);
			if (extLabel != null) {
				OperandRepresentationList list = new OperandRepresentationList();
				//list.add(label);
				list.add(EXTENDED_INDIRECT_REFERENCE_DELIMITER);
				list.add(extLabel);
				return list;
			}
		}

		return label;
	}
Get a LabelString object which corresponds to the specified memory
reference from the specified code unit. Format options are considered
when generating label.

@param fromCodeUnit code unit
@param ref memory reference
@return LabelString representation object
Ghidra/Features/Base/src/main/java/ghidra/program/model/listing/CodeUnitFormat.java