// File: /workspace/github_cpp_makefile_star2_O2/dramninjasUMD[P]BOBSim/BOBWrapper.cpp
// Function: BOBSim::BOBWrapper::AddTransaction(BOBSim::Transaction*, unsigned int)
bool BOBWrapper::AddTransaction(Transaction* trans, unsigned port)
{
	if(inFlightRequestCounter[port]==0 &&
	        bob->ports[port].inputBuffer.size()<PORT_QUEUE_DEPTH)
	{
		trans->fullStartTime = currentClockCycle;
		requestCounterPerPort[port]++;

		inFlightRequest[port] = trans;
		inFlightRequest[port]->portID = port;
		inFlightRequest[port]->cyclesReqPort = currentClockCycle;

		inFlightRequestHeaderCounter[port] = 1;

		switch(trans->transactionType)
		{
		case DATA_READ:
			readsPerPort[port]++;
			inFlightRequestCounter[port] = 1;
			break;
		case DATA_WRITE:
			issuedWrites++;
			writesPerPort[port]++;
			inFlightRequestCounter[port] = TRANSACTION_SIZE / PORT_WIDTH;
			break;
		case LOGIC_OPERATION:
			issuedLogicOperations++;
			inFlightRequestCounter[port] = TRANSACTION_SIZE / PORT_WIDTH;
			break;
		default:
			ERROR(" = Error - wrong type");
			ERROR(trans);
			break;
		}

		if(DEBUG_PORTS) DEBUG(" = Putting transaction on port "<<port<<" - "<<*inFlightRequest[port]<<" for "<<inFlightRequestCounter[port]<<" CPU cycles");

		return true;
	}
	else
	{
		if(DEBUG_PORTS) DEBUG(" = Port Busy or Full");

		return false; //port busy
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edx, %eax
movq 0x30(%rdi), %rcx
cmpl $0x0, (%rcx,%rax,4)
jne 0x7929
movq %rsi, %rbx
movq 0x10(%rdi), %rcx
movq 0x10(%rcx), %rcx
movq %rax, %rsi
shlq $0x6, %rsi
movq 0x18(%rcx,%rsi), %r8
subq 0x10(%rcx,%rsi), %r8
cmpq $0x3f, %r8
ja 0x7929
movq 0x8(%rdi), %rcx
movq %rcx, 0x60(%rbx)
movq 0xf8(%rdi), %rsi
incl (%rsi,%rax,4)
movq 0x18(%rdi), %rsi
movq %rbx, (%rsi,%rax,8)
movq 0x18(%rdi), %rsi
movq (%rsi,%rax,8), %rsi
movl %edx, 0x1c(%rsi)
movq %rcx, 0x38(%rsi)
movq 0x48(%rdi), %rcx
movl $0x1, (%rcx,%rax,4)
movl (%rbx), %ecx
cmpl $0x3, %ecx
je 0x794c
cmpl $0x1, %ecx
je 0x793a
testl %ecx, %ecx
jne 0x7962
movq 0x110(%rdi), %rcx
incl (%rcx,%rax,4)
movq 0x30(%rdi), %rcx
movl $0x1, (%rcx,%rax,4)
jmp 0x7a21
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
incl 0x290(%rdi)
movq 0x128(%rdi), %rcx
incl (%rcx,%rax,4)
jmp 0x7952
incl 0x28c(%rdi)
movq 0x30(%rdi), %rcx
movl $0x4, (%rcx,%rax,4)
jmp 0x7a21
movq 0xe687(%rip), %r14      # 0x15ff0
leaq 0x7810(%rip), %r15      # 0xf180
movq %r14, %rdi
movq %r15, %rsi
callq 0x2180
leaq 0x822b(%rip), %r12      # 0xfbad
movq %rax, %rdi
movq %r12, %rsi
callq 0x2180
leaq 0x7795(%rip), %r13      # 0xf129
movq %rax, %rdi
movq %r13, %rsi
callq 0x2180
movq %rax, %rdi
movl $0x14b, %esi            # imm = 0x14B
callq 0x22e0
leaq 0x77de(%rip), %rbp      # 0xf191
movq %rax, %rdi
movq %rbp, %rsi
callq 0x2180
leaq 0x8234(%rip), %rsi      # 0xfbf9
movq %rax, %rdi
callq 0x2180
movq %rax, %rdi
callq 0x20b0
movq %r14, %rdi
movq %r15, %rsi
callq 0x2180
movq %rax, %rdi
movq %r12, %rsi
callq 0x2180
movq %rax, %rdi
movq %r13, %rsi
callq 0x2180
movq %rax, %rdi
movl $0x14c, %esi            # imm = 0x14C
callq 0x22e0
movq %rax, %rdi
movq %rbp, %rsi
callq 0x2180
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2130
movq %rax, %rdi
callq 0x20b0
movb $0x1, %al
jmp 0x792b