// File: /workspace/github_cpp_makefile_star2_O3/zerolfx[P]P-Machine/ldc.cpp
// Function: Ldc::execute(StackMachine*)
void Ldc::execute(StackMachine *stack)
{
	switch(fType)
	{
		case integer:
		{
			StackInteger p1;

			// check if constant is of type integer
			if(typeid(p1) != typeid(*fConstant))
			{
				throw ExecutionError("instruction ldc: type of constant is not of type integer.");
			}
			else
			{
				stack->fStore.push_back(new StackInteger(*(dynamic_cast<StackInteger*>(fConstant))));
			}
				
			break;
		}	
		case real:
		{
			StackReal p1;
			// check if constant is of type real
			if(typeid(p1) != typeid(*fConstant))
			{
				throw ExecutionError("instruction ldc: type of constant is not of type real.");
			}
			else
			{
				stack->fStore.push_back(new StackReal(*(dynamic_cast<StackReal*>(fConstant))));
			}

			break;
		}
		case boolean:
		{
			StackBoolean p1;
			
			// check if constant is of type boolean
			if(typeid(p1) != typeid(*fConstant))
			{
				throw ExecutionError("instruction ldc: type of constant is not of type boolean.");
			}
			else
			{
				stack->fStore.push_back(new StackBoolean(*(dynamic_cast<StackBoolean*>(fConstant))));
			}

			break;
		}
		case character:
		{
			StackCharacter p1;
			
			// check if constant is of type character
			if(typeid(p1) != typeid(*fConstant))
			{
				throw ExecutionError("instruction ldc: type of constant is not of type character.");
			}
			else
			{
				stack->fStore.push_back(new StackCharacter(*(dynamic_cast<StackCharacter*>(fConstant))));
			}

			break;
		}
		case address:
		{
			StackAddress p1;

			// check if constant is of type address
			
			if(typeid(p1) != typeid(*fConstant))
			{
				throw ExecutionError("instruction ldc: type of constant is not of type address.");
			}
			else
			{
				stack->fStore.push_back(new StackAddress(*(dynamic_cast<StackAddress*>(fConstant))));
			}

			break;
		}
	}
	
	// fSP = fSP + 1
	++stack->fSP;
	
	// adding cost of this instruction
	stack->fTime.count("ldc");

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x30, %rsp
movq %rsi, %rbx
movl 0x8(%rdi), %eax
cmpq $0x4, %rax
ja 0xe893
movq %rdi, %r14
leaq 0x16129(%rip), %rcx     # 0x2467c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq -0x50(%rbp), %rdi
xorps %xmm0, %xmm0
callq 0x1abfc
movq 0x10(%r14), %r14
testq %r14, %r14
je 0xeaae
movq (%r14), %rax
movq -0x8(%rax), %rax
leaq 0x25645(%rip), %rcx     # 0x33bc8
movq 0x8(%rcx), %rdi
movq 0x8(%rax), %rsi
cmpq %rsi, %rdi
je 0xe5a6
cmpb $0x2a, (%rdi)
je 0xe9f5
callq 0x6310
testl %eax, %eax
jne 0xe9f5
movl $0x10, %edi
callq 0x6200
movq %rax, %r15
leaq 0x18(%rbx), %r12
leaq 0x25472(%rip), %rsi     # 0x33a30
leaq 0x25603(%rip), %rdx     # 0x33bc8
movq %r14, %rdi
xorl %ecx, %ecx
callq 0x6260
leaq 0x2553a(%rip), %rcx     # 0x33b10
addq $0x10, %rcx
movq %rcx, (%r15)
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0x8(%r15)
leaq -0x40(%rbp), %rsi
movq %r15, (%rsi)
movq %r12, %rdi
callq 0xa334
leaq -0x50(%rbp), %rdi
callq 0x1ac2a
jmp 0xe893
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
callq 0x1a104
movq 0x10(%r14), %r14
testq %r14, %r14
je 0xea9f
movq (%r14), %rax
movq -0x8(%rax), %rax
leaq 0x25335(%rip), %rcx     # 0x33960
movq 0x8(%rcx), %rdi
movq 0x8(%rax), %rsi
cmpq %rsi, %rdi
je 0xe64e
cmpb $0x2a, (%rdi)
je 0xe8ea
callq 0x6310
testl %eax, %eax
jne 0xe8ea
movl $0x10, %edi
callq 0x6200
movq %rax, %r15
leaq 0x18(%rbx), %r12
leaq 0x253ca(%rip), %rsi     # 0x33a30
leaq 0x252f3(%rip), %rdx     # 0x33960
movq %r14, %rdi
xorl %ecx, %ecx
callq 0x6260
leaq 0x2522a(%rip), %rcx     # 0x338a8
addq $0x10, %rcx
movq %rcx, (%r15)
movl 0x8(%rax), %eax
movl %eax, 0x8(%r15)
leaq -0x40(%rbp), %rsi
movq %r15, (%rsi)
movq %r12, %rdi
callq 0xa334
leaq -0x50(%rbp), %rdi
callq 0x1a128
jmp 0xe893
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
callq 0x1ae40
movq 0x10(%r14), %r14
testq %r14, %r14
je 0xeaa4
movq (%r14), %rax
movq -0x8(%rax), %rax
leaq 0x255c9(%rip), %rcx     # 0x33c98
movq 0x8(%rcx), %rdi
movq 0x8(%rax), %rsi
cmpq %rsi, %rdi
je 0xe6f2
cmpb $0x2a, (%rdi)
je 0xe943
callq 0x6310
testl %eax, %eax
jne 0xe943
movl $0x10, %edi
callq 0x6200
movq %rax, %r15
leaq 0x18(%rbx), %r12
leaq 0x25326(%rip), %rsi     # 0x33a30
leaq 0x25587(%rip), %rdx     # 0x33c98
movq %r14, %rdi
xorl %ecx, %ecx
callq 0x6260
leaq 0x254be(%rip), %rcx     # 0x33be0
addq $0x10, %rcx
movq %rcx, (%r15)
movl 0x8(%rax), %eax
movl %eax, 0x8(%r15)
leaq -0x40(%rbp), %rsi
movq %r15, (%rsi)
movq %r12, %rdi
callq 0xa334
leaq -0x50(%rbp), %rdi
callq 0x1ae64
jmp 0xe893
leaq -0x50(%rbp), %rdi
movl $0x61, %esi
callq 0x1b03c
movq 0x10(%r14), %r14
testq %r14, %r14
je 0xeaa9
movq (%r14), %rax
movq -0x8(%rax), %rax
leaq 0x255f2(%rip), %rcx     # 0x33d68
movq 0x8(%rcx), %rdi
movq 0x8(%rax), %rsi
cmpq %rsi, %rdi
je 0xe799
cmpb $0x2a, (%rdi)
je 0xe99c
callq 0x6310
testl %eax, %eax
jne 0xe99c
movl $0x10, %edi
callq 0x6200
movq %rax, %r15
leaq 0x18(%rbx), %r12
leaq 0x2527f(%rip), %rsi     # 0x33a30
leaq 0x255b0(%rip), %rdx     # 0x33d68
movq %r14, %rdi
xorl %ecx, %ecx
callq 0x6260
leaq 0x254e7(%rip), %rcx     # 0x33cb0
addq $0x10, %rcx
movq %rcx, (%r15)
movb 0x8(%rax), %al
movb %al, 0x8(%r15)
leaq -0x40(%rbp), %rsi
movq %r15, (%rsi)
movq %r12, %rdi
callq 0xa334
leaq -0x50(%rbp), %rdi
callq 0x1b060
jmp 0xe893
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
callq 0x1a9d4
movq 0x10(%r14), %r14
testq %r14, %r14
je 0xeab3
movq (%r14), %rax
movq -0x8(%rax), %rax
leaq 0x252de(%rip), %rcx     # 0x33af8
movq 0x8(%rcx), %rdi
movq 0x8(%rax), %rsi
cmpq %rsi, %rdi
je 0xe83d
cmpb $0x2a, (%rdi)
je 0xea4b
callq 0x6310
testl %eax, %eax
jne 0xea4b
movl $0x10, %edi
callq 0x6200
movq %rax, %r15
leaq 0x18(%rbx), %r12
leaq 0x251db(%rip), %rsi     # 0x33a30
leaq 0x2529c(%rip), %rdx     # 0x33af8
movq %r14, %rdi
xorl %ecx, %ecx
callq 0x6260
leaq 0x251d3(%rip), %rcx     # 0x33a40
addq $0x10, %rcx
movq %rcx, (%r15)
movl 0x8(%rax), %eax
movl %eax, 0x8(%r15)
leaq -0x40(%rbp), %rsi
movq %r15, (%rsi)
movq %r12, %rdi
callq 0xa334
leaq -0x50(%rbp), %rdi
callq 0x1a9f8
incl 0xb4(%rbx)
leaq -0x30(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x15f0e(%rip), %rsi     # 0x247b6
leaq 0x15f0a(%rip), %rdx     # 0x247b9
leaq -0x40(%rbp), %rdi
callq 0x746c
addq $0x78, %rbx
leaq -0x40(%rbp), %rsi
movq %rbx, %rdi
callq 0x1cbc8
movq -0x40(%rbp), %rdi
cmpq %r14, %rdi
je 0xe8dd
movq -0x30(%rbp), %rsi
incq %rsi
callq 0x6210
addq $0x30, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movl $0x20, %edi
callq 0x6100
movq %rax, %r14
leaq -0x30(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x15e76(%rip), %rsi     # 0x2477c
leaq 0x15ea8(%rip), %rdx     # 0x247b5
leaq -0x40(%rbp), %rdi
callq 0x746c
movb $0x1, %r12b
leaq -0x40(%rbp), %rsi
movq %r14, %rdi
callq 0x1b14c
xorl %r12d, %r12d
leaq 0x24159(%rip), %rsi     # 0x32a88
leaq 0xc834(%rip), %rdx      # 0x1b16a
movq %r14, %rdi
callq 0x63e0
jmp 0xea9f
movl $0x20, %edi
callq 0x6100
movq %rax, %r14
leaq -0x30(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x15da7(%rip), %rsi     # 0x24706
leaq 0x15dd9(%rip), %rdx     # 0x2473f
leaq -0x40(%rbp), %rdi
callq 0x746c
movb $0x1, %r12b
leaq -0x40(%rbp), %rsi
movq %r14, %rdi
callq 0x1b14c
xorl %r12d, %r12d
leaq 0x24100(%rip), %rsi     # 0x32a88
leaq 0xc7db(%rip), %rdx      # 0x1b16a
movq %r14, %rdi
callq 0x63e0
jmp 0xea9f
movl $0x20, %edi
callq 0x6100
movq %rax, %r14
leaq -0x30(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x15d88(%rip), %rsi     # 0x24740
leaq 0x15dbc(%rip), %rdx     # 0x2477b
leaq -0x40(%rbp), %rdi
callq 0x746c
movb $0x1, %r12b
leaq -0x40(%rbp), %rsi
movq %r14, %rdi
callq 0x1b14c
xorl %r12d, %r12d
leaq 0x240a7(%rip), %rsi     # 0x32a88
leaq 0xc782(%rip), %rdx      # 0x1b16a
movq %r14, %rdi
callq 0x63e0
jmp 0xea9f
movl $0x20, %edi
callq 0x6100
movq %rax, %r14
leaq -0x30(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x15cbe(%rip), %rsi     # 0x246cf
leaq 0x15ced(%rip), %rdx     # 0x24705
leaq -0x40(%rbp), %rdi
callq 0x746c
movb $0x1, %r12b
leaq -0x40(%rbp), %rsi
movq %r14, %rdi
callq 0x1b14c
xorl %r12d, %r12d
leaq 0x2404e(%rip), %rsi     # 0x32a88
leaq 0xc729(%rip), %rdx      # 0x1b16a
movq %r14, %rdi
callq 0x63e0
jmp 0xea9f
movl $0x20, %edi
callq 0x6100
movq %rax, %r14
leaq -0x30(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x15c2e(%rip), %rsi     # 0x24695
leaq 0x15c60(%rip), %rdx     # 0x246ce
leaq -0x40(%rbp), %rdi
callq 0x746c
movb $0x1, %r12b
leaq -0x40(%rbp), %rsi
movq %r14, %rdi
callq 0x1b14c
xorl %r12d, %r12d
leaq 0x23ff8(%rip), %rsi     # 0x32a88
leaq 0xc6d3(%rip), %rdx      # 0x1b16a
movq %r14, %rdi
callq 0x63e0
callq 0x6250
callq 0x6250
callq 0x6250
callq 0x6250
callq 0x6250
movq %rax, %rbx
movq -0x40(%rbp), %rdi
cmpq %r15, %rdi
je 0xead0
movq -0x30(%rbp), %rsi
incq %rsi
callq 0x6210
testb %r12b, %r12b
jne 0xeaff
jmp 0xebb3
movq %rax, %rbx
movq -0x40(%rbp), %rdi
cmpq %r15, %rdi
je 0xeaf2
movq -0x30(%rbp), %rsi
incq %rsi
callq 0x6210
testb %r12b, %r12b
jne 0xeb0f
jmp 0xebc1
movq %rax, %rbx
movq %r14, %rdi
callq 0x6170
jmp 0xebb3
movq %rax, %rbx
movq %r14, %rdi
callq 0x6170
jmp 0xebc1
movq %rax, %rbx
movq -0x40(%rbp), %rdi
cmpq %r15, %rdi
je 0xeb34
movq -0x30(%rbp), %rsi
incq %rsi
callq 0x6210
testb %r12b, %r12b
jne 0xeb41
jmp 0xebcf
movq %rax, %rbx
movq %r14, %rdi
callq 0x6170
jmp 0xebcf
movq %rax, %rbx
movq -0x40(%rbp), %rdi
cmpq %r15, %rdi
je 0xeb66
movq -0x30(%rbp), %rsi
incq %rsi
callq 0x6210
testb %r12b, %r12b
jne 0xeb70
jmp 0xebdd
movq %rax, %rbx
movq %r14, %rdi
callq 0x6170
jmp 0xebdd
movq %rax, %rbx
movq -0x40(%rbp), %rdi
cmpq %r15, %rdi
je 0xeb92
movq -0x30(%rbp), %rsi
incq %rsi
callq 0x6210
testb %r12b, %r12b
jne 0xeb9c
jmp 0xebeb
movq %rax, %rbx
movq %r14, %rdi
callq 0x6170
jmp 0xebeb
jmp 0xebb0
jmp 0xebbe
jmp 0xebcc
jmp 0xebda
jmp 0xebe8
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x1a9f8
jmp 0xec13
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x1ac2a
jmp 0xec13
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x1b060
jmp 0xec13
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x1ae64
jmp 0xec13
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x1a128
jmp 0xec13
movq %rax, %rbx
movq -0x40(%rbp), %rdi
cmpq %r14, %rdi
je 0xec13
movq -0x30(%rbp), %rsi
incq %rsi
callq 0x6210
jmp 0xec13
movq %rax, %rbx
movq %rbx, %rdi
callq 0x6410
nop