// File: /workspace/github_cpp_makefile_star2_O2/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 $0x40, %rsp
movq %rsi, %rbx
movl 0x8(%rdi), %eax
cmpq $0x4, %rax
ja 0xd45a
movq %rdi, %r14
leaq 0x124ed(%rip), %rcx     # 0x1f67c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq -0x38(%rbp), %rdi
xorps %xmm0, %xmm0
callq 0x177d4
movq 0x10(%r14), %rax
testq %rax, %rax
je 0xd4a9
movq (%rax), %rax
movq -0x8(%rax), %rsi
leaq 0x21a09(%rip), %rdi     # 0x2ebc8
callq 0x76ba
testb %al, %al
jne 0xd54b
pushq $0x10
popq %rdi
callq 0x61d0
movq %rax, %r15
leaq 0x18(%rbx), %r12
movq 0x10(%r14), %rdi
leaq 0x2184a(%rip), %rsi     # 0x2ea30
leaq 0x219db(%rip), %rdx     # 0x2ebc8
xorl %ecx, %ecx
callq 0x6230
leaq 0x21915(%rip), %rcx     # 0x2eb10
addq $0x10, %rcx
movq %rcx, (%r15)
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0x8(%r15)
leaq -0x58(%rbp), %rsi
movq %r15, (%rsi)
movq %r12, %rdi
callq 0x99a0
leaq -0x38(%rbp), %rdi
callq 0x17802
jmp 0xd45a
leaq -0x38(%rbp), %rdi
xorl %esi, %esi
callq 0x1704c
movq 0x10(%r14), %rax
testq %rax, %rax
je 0xd49a
movq (%rax), %rax
movq -0x8(%rax), %rsi
leaq 0x21710(%rip), %rdi     # 0x2e960
callq 0x76ba
testb %al, %al
jne 0xd4b3
pushq $0x10
popq %rdi
callq 0x61d0
movq %rax, %r15
leaq 0x18(%rbx), %r12
movq 0x10(%r14), %rdi
leaq 0x217b9(%rip), %rsi     # 0x2ea30
leaq 0x216e2(%rip), %rdx     # 0x2e960
xorl %ecx, %ecx
callq 0x6230
leaq 0x2161c(%rip), %rcx     # 0x2e8a8
addq $0x10, %rcx
movq %rcx, (%r15)
movl 0x8(%rax), %eax
movl %eax, 0x8(%r15)
leaq -0x58(%rbp), %rsi
movq %r15, (%rsi)
movq %r12, %rdi
callq 0x99a0
leaq -0x38(%rbp), %rdi
callq 0x17070
jmp 0xd45a
leaq -0x38(%rbp), %rdi
xorl %esi, %esi
callq 0x17a18
movq 0x10(%r14), %rax
testq %rax, %rax
je 0xd49f
movq (%rax), %rax
movq -0x8(%rax), %rsi
leaq 0x219bb(%rip), %rdi     # 0x2ec98
callq 0x76ba
testb %al, %al
jne 0xd4ff
pushq $0x10
popq %rdi
callq 0x61d0
movq %rax, %r15
leaq 0x18(%rbx), %r12
movq 0x10(%r14), %rdi
leaq 0x2172c(%rip), %rsi     # 0x2ea30
leaq 0x2198d(%rip), %rdx     # 0x2ec98
xorl %ecx, %ecx
callq 0x6230
leaq 0x218c7(%rip), %rcx     # 0x2ebe0
addq $0x10, %rcx
movq %rcx, (%r15)
movl 0x8(%rax), %eax
movl %eax, 0x8(%r15)
leaq -0x58(%rbp), %rsi
movq %r15, (%rsi)
movq %r12, %rdi
callq 0x99a0
leaq -0x38(%rbp), %rdi
callq 0x17a3c
jmp 0xd45a
leaq -0x38(%rbp), %rdi
pushq $0x61
popq %rsi
callq 0x17c08
movq 0x10(%r14), %rax
testq %rax, %rax
je 0xd4a4
movq (%rax), %rax
movq -0x8(%rax), %rsi
leaq 0x219fd(%rip), %rdi     # 0x2ed68
callq 0x76ba
testb %al, %al
jne 0xd597
pushq $0x10
popq %rdi
callq 0x61d0
movq %rax, %r15
leaq 0x18(%rbx), %r12
movq 0x10(%r14), %rdi
leaq 0x2169e(%rip), %rsi     # 0x2ea30
leaq 0x219cf(%rip), %rdx     # 0x2ed68
xorl %ecx, %ecx
callq 0x6230
leaq 0x21909(%rip), %rcx     # 0x2ecb0
addq $0x10, %rcx
movq %rcx, (%r15)
movb 0x8(%rax), %al
movb %al, 0x8(%r15)
leaq -0x58(%rbp), %rsi
movq %r15, (%rsi)
movq %r12, %rdi
callq 0x99a0
leaq -0x38(%rbp), %rdi
callq 0x17c2c
jmp 0xd45a
leaq -0x38(%rbp), %rdi
xorl %esi, %esi
callq 0x175ac
movq 0x10(%r14), %rax
testq %rax, %rax
je 0xd4ae
movq (%rax), %rax
movq -0x8(%rax), %rsi
leaq 0x21700(%rip), %rdi     # 0x2eaf8
callq 0x76ba
testb %al, %al
jne 0xd5e0
pushq $0x10
popq %rdi
callq 0x61d0
movq %rax, %r15
leaq 0x18(%rbx), %r12
movq 0x10(%r14), %rdi
leaq 0x21611(%rip), %rsi     # 0x2ea30
leaq 0x216d2(%rip), %rdx     # 0x2eaf8
xorl %ecx, %ecx
callq 0x6230
leaq 0x2160c(%rip), %rcx     # 0x2ea40
addq $0x10, %rcx
movq %rcx, (%r15)
movl 0x8(%rax), %eax
movl %eax, 0x8(%r15)
leaq -0x58(%rbp), %rsi
movq %r15, (%rsi)
movq %r12, %rdi
callq 0x99a0
leaq -0x38(%rbp), %rdi
callq 0x175d0
incl 0xb4(%rbx)
leaq 0x1234f(%rip), %rsi     # 0x1f7b6
leaq -0x58(%rbp), %rdi
leaq -0x38(%rbp), %rdx
callq 0x72a6
addq $0x78, %rbx
leaq -0x58(%rbp), %rsi
movq %rbx, %rdi
callq 0x1925e
leaq -0x58(%rbp), %rdi
callq 0x60d0
addq $0x40, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
callq 0x6220
callq 0x6220
callq 0x6220
callq 0x6220
callq 0x6220
pushq $0x20
popq %rdi
callq 0x60f0
movq %rax, %r14
leaq 0x122b7(%rip), %rsi     # 0x1f77c
leaq -0x58(%rbp), %rdi
leaq -0x21(%rbp), %rdx
callq 0x72a6
movb $0x1, %r15b
leaq -0x58(%rbp), %rsi
movq %r14, %rdi
callq 0x17d10
xorl %r15d, %r15d
leaq 0x2059d(%rip), %rsi     # 0x2da88
leaq 0xa828(%rip), %rdx      # 0x17d1a
movq %r14, %rdi
callq 0x63c0
jmp 0xd627
pushq $0x20
popq %rdi
callq 0x60f0
movq %rax, %r14
leaq 0x121f5(%rip), %rsi     # 0x1f706
leaq -0x58(%rbp), %rdi
leaq -0x21(%rbp), %rdx
callq 0x72a6
movb $0x1, %r15b
leaq -0x58(%rbp), %rsi
movq %r14, %rdi
callq 0x17d10
xorl %r15d, %r15d
leaq 0x20551(%rip), %rsi     # 0x2da88
leaq 0xa7dc(%rip), %rdx      # 0x17d1a
movq %r14, %rdi
callq 0x63c0
jmp 0xd627
pushq $0x20
popq %rdi
callq 0x60f0
movq %rax, %r14
leaq 0x12172(%rip), %rsi     # 0x1f6cf
leaq -0x58(%rbp), %rdi
leaq -0x21(%rbp), %rdx
callq 0x72a6
movb $0x1, %r15b
leaq -0x58(%rbp), %rsi
movq %r14, %rdi
callq 0x17d10
xorl %r15d, %r15d
leaq 0x20505(%rip), %rsi     # 0x2da88
leaq 0xa790(%rip), %rdx      # 0x17d1a
movq %r14, %rdi
callq 0x63c0
jmp 0xd627
pushq $0x20
popq %rdi
callq 0x60f0
movq %rax, %r14
leaq 0x12197(%rip), %rsi     # 0x1f740
leaq -0x58(%rbp), %rdi
leaq -0x21(%rbp), %rdx
callq 0x72a6
movb $0x1, %r15b
leaq -0x58(%rbp), %rsi
movq %r14, %rdi
callq 0x17d10
xorl %r15d, %r15d
leaq 0x204b9(%rip), %rsi     # 0x2da88
leaq 0xa744(%rip), %rdx      # 0x17d1a
movq %r14, %rdi
callq 0x63c0
jmp 0xd627
pushq $0x20
popq %rdi
callq 0x60f0
movq %rax, %r14
leaq 0x120a3(%rip), %rsi     # 0x1f695
leaq -0x58(%rbp), %rdi
leaq -0x21(%rbp), %rdx
callq 0x72a6
movb $0x1, %r15b
leaq -0x58(%rbp), %rsi
movq %r14, %rdi
callq 0x17d10
xorl %r15d, %r15d
leaq 0x20470(%rip), %rsi     # 0x2da88
leaq 0xa6fb(%rip), %rdx      # 0x17d1a
movq %r14, %rdi
callq 0x63c0
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
callq 0x60d0
testb %r15b, %r15b
jne 0xd640
jmp 0xd6e0
movq %rax, %rbx
movq %r14, %rdi
callq 0x6150
jmp 0xd6e0
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
callq 0x60d0
testb %r15b, %r15b
jne 0xd666
jmp 0xd6fc
movq %rax, %rbx
movq %r14, %rdi
callq 0x6150
jmp 0xd6fc
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
callq 0x60d0
testb %r15b, %r15b
jne 0xd689
jmp 0xd6ee
movq %rax, %rbx
movq %r14, %rdi
callq 0x6150
jmp 0xd6ee
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
callq 0x60d0
testb %r15b, %r15b
jne 0xd6a9
jmp 0xd70a
movq %rax, %rbx
movq %r14, %rdi
callq 0x6150
jmp 0xd70a
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
callq 0x60d0
testb %r15b, %r15b
jne 0xd6c9
jmp 0xd718
movq %rax, %rbx
movq %r14, %rdi
callq 0x6150
jmp 0xd718
jmp 0xd6dd
jmp 0xd6eb
jmp 0xd6f9
jmp 0xd707
jmp 0xd715
movq %rax, %rbx
leaq -0x38(%rbp), %rdi
callq 0x175d0
jmp 0xd734
movq %rax, %rbx
leaq -0x38(%rbp), %rdi
callq 0x17802
jmp 0xd734
movq %rax, %rbx
leaq -0x38(%rbp), %rdi
callq 0x17c2c
jmp 0xd734
movq %rax, %rbx
leaq -0x38(%rbp), %rdi
callq 0x17a3c
jmp 0xd734
movq %rax, %rbx
leaq -0x38(%rbp), %rdi
callq 0x17070
jmp 0xd734
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
callq 0x60d0
jmp 0xd734
movq %rax, %rbx
movq %rbx, %rdi
callq 0x63f0