// File: /workspace/github_cpp_makefile_star2_O1/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 0xa213
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 0xa213
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 0xa236
cmpl $0x1, %ecx
je 0xa224
testl %ecx, %ecx
jne 0xa24c
movq 0x110(%rdi), %rcx
incl (%rcx,%rax,4)
movq 0x30(%rdi), %rcx
movl $0x1, (%rcx,%rax,4)
jmp 0xa380
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 0xa23c
incl 0x28c(%rdi)
movq 0x30(%rdi), %rcx
movl $0x4, (%rcx,%rax,4)
jmp 0xa380
movq 0xed9d(%rip), %r14      # 0x18ff0
leaq 0x8f1e(%rip), %rsi      # 0x13178
movl $0x8, %edx
movq %r14, %rdi
callq 0x3200
leaq 0x992f(%rip), %r12      # 0x13b9d
movl $0xe, %edx
movq %r14, %rdi
movq %r12, %rsi
callq 0x3200
leaq 0x8e9c(%rip), %r13      # 0x13121
movl $0x1, %edx
movq %r14, %rdi
movq %r13, %rsi
callq 0x3200
movq %r14, %rdi
movl $0x14b, %esi            # imm = 0x14B
callq 0x3330
movq %rax, %r15
leaq 0x8edd(%rip), %rbp      # 0x13189
movl $0x4, %edx
movq %rax, %rdi
movq %rbp, %rsi
callq 0x3200
leaq 0x9926(%rip), %rsi      # 0x13be9
movl $0x15, %edx
movq %r15, %rdi
callq 0x3200
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x31b0
movsbl %al, %esi
movq %r15, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3130
movl $0x8, %edx
movq %r14, %rdi
leaq 0x8e72(%rip), %rsi      # 0x13178
callq 0x3200
movl $0xe, %edx
movq %r14, %rdi
movq %r12, %rsi
callq 0x3200
movl $0x1, %edx
movq %r14, %rdi
movq %r13, %rsi
callq 0x3200
movq %r14, %rdi
movl $0x14c, %esi            # imm = 0x14C
callq 0x3330
movq %rax, %r14
movl $0x4, %edx
movq %rax, %rdi
movq %rbp, %rsi
callq 0x3200
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3150
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x31b0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3130
movb $0x1, %al
jmp 0xa215
nop