boolean addReference(CodeUnit fromCodeUnit, int opIndex, Address toAddr, boolean isOffsetRef,
			long offset, RefType refType) {

		Address fromAddr = fromCodeUnit.getMinAddress();
		Reference[] refs =
			fromCodeUnit.getProgram().getReferenceManager().getReferencesFrom(fromAddr, opIndex);

		if (refs.length != 0 && !refs[0].isMemoryReference() &&
			!confirmPossibleReferenceRemoval(fromCodeUnit, opIndex, refs[0])) {
			return false;
		}

		Command<Program> cmd;
		if (isOffsetRef) {
			cmd = new AddOffsetMemRefCmd(fromAddr, toAddr, false, refType, SourceType.USER_DEFINED,
				opIndex, offset);
		}
		else {
			cmd = new AddMemRefCmd(fromAddr, toAddr, refType, SourceType.USER_DEFINED, opIndex);
		}
		return tool.execute(cmd, fromCodeUnit.getProgram());
	}
Add memory reference

@param fromCodeUnit
@param opIndex
@param toAddr
@param isOffsetRef
@param offset
@param refType
@return true if add was successful
Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/references/ReferencesPlugin.java