// File: /workspace/github_cpp_makefile_star2_O1/navrajsaini[P]PL_Compiler_design_project/Assembler.cpp
// Function: Assembler::firstPass()
void Assembler::firstPass()
{
   // Start at address 0 (not 1 as I had previously thought)
   currentAddress = 0;
   string nextop;
   (*insource) >> nextop;
   // Loop until we find the ENDPROG operation.
   for (;;) {
      // Record the current address in the label table.
      if (nextop == "DEFADDR") {
	 int index;
	 (*insource) >> index;
	 labelTable[index] = currentAddress;
	 (*insource) >> nextop;
      }
      // Record the associated value in the label table.
      else if (nextop == "DEFARG") {
	 int index, value;
	 (*insource) >> index >> value;
	 labelTable[index] = value;
	 (*insource) >> nextop;
      }
      // Stop when we find ENDPROG.
      else if (nextop == "ENDPROG")
	 return;
      else if (nextop == "ARROW" || nextop == "ASSIGN" || nextop == "BAR" ||
	       nextop == "CONSTANT" || nextop == "FI" || nextop == "READ" ||
	       nextop == "WRITE") {
	 // Skip one machine words.
	 (*insource) >> nextop;
	 (*insource) >> nextop;
	 currentAddress += 2;
      }
      else if (nextop == "CALL" || nextop == "INDEX" || nextop == "PROC" ||
	       nextop == "PROG" || nextop == "VARIABLE") {
	 // Skip two machine words.
	 (*insource) >> nextop;
	 (*insource) >> nextop;
	 (*insource) >> nextop;
	 currentAddress += 3;
      }
      else {
	 // just get the next machine word.
	 (*insource) >> nextop;
	 currentAddress++;
      }
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
movl $0x0, 0x7d0(%rdi)
leaq -0x40(%rbp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq 0x7d8(%rdi), %rdi
leaq -0x50(%rbp), %rsi
callq 0x2250
leaq 0x29f5(%rip), %r14      # 0x136b3
leaq -0x50(%rbp), %r15
leaq -0x2c(%rbp), %r12
leaq 0x29df(%rip), %r13      # 0x136ac
movq %r15, %rdi
movq %r14, %rsi
callq 0x2080
testl %eax, %eax
je 0x10e38
movq %r15, %rdi
movq %r13, %rsi
callq 0x2080
testl %eax, %eax
je 0x10e92
movq %r15, %rdi
leaq 0x29a7(%rip), %rsi      # 0x136a4
callq 0x2080
testl %eax, %eax
je 0x10f04
movq %r15, %rdi
leaq 0x2b1e(%rip), %rsi      # 0x13832
callq 0x2080
testl %eax, %eax
je 0x10e68
movq %r15, %rdi
leaq 0x2abe(%rip), %rsi      # 0x137e9
callq 0x2080
testl %eax, %eax
je 0x10e68
movq %r15, %rdi
leaq 0x2af6(%rip), %rsi      # 0x13838
callq 0x2080
testl %eax, %eax
je 0x10e68
movq %r15, %rdi
leaq 0x2b3d(%rip), %rsi      # 0x13896
callq 0x2080
testl %eax, %eax
je 0x10e68
movq %r15, %rdi
leaq 0x2aad(%rip), %rsi      # 0x1381d
callq 0x2080
testl %eax, %eax
je 0x10e68
movq %r15, %rdi
leaq 0x2a41(%rip), %rsi      # 0x137c8
callq 0x2080
testl %eax, %eax
je 0x10e68
movq %r15, %rdi
leaq 0x2a3b(%rip), %rsi      # 0x137d9
callq 0x2080
testl %eax, %eax
je 0x10e68
movq %r15, %rdi
leaq 0x2a60(%rip), %rsi      # 0x13815
callq 0x2080
testl %eax, %eax
je 0x10ecb
movq %r15, %rdi
leaq 0x2b0c(%rip), %rsi      # 0x138d8
callq 0x2080
testl %eax, %eax
je 0x10ecb
movq %r15, %rdi
leaq 0x29da(%rip), %rsi      # 0x137bd
callq 0x2080
testl %eax, %eax
je 0x10ecb
movq %r15, %rdi
leaq 0x28ad(%rip), %rsi      # 0x136a7
callq 0x2080
testl %eax, %eax
je 0x10ecb
movq %r15, %rdi
leaq 0x2a9b(%rip), %rsi      # 0x138ac
callq 0x2080
testl %eax, %eax
je 0x10ecb
movq 0x7d8(%rbx), %rdi
movq %r15, %rsi
callq 0x2250
incl 0x7d0(%rbx)
jmp 0x10ccd
movq 0x7d8(%rbx), %rdi
movq %r12, %rsi
callq 0x2120
movl 0x7d0(%rbx), %eax
movslq -0x2c(%rbp), %rcx
movl %eax, (%rbx,%rcx,4)
movq 0x7d8(%rbx), %rdi
movq %r15, %rsi
callq 0x2250
jmp 0x10ccd
movq 0x7d8(%rbx), %rdi
movq %r15, %rsi
callq 0x2250
movq 0x7d8(%rbx), %rdi
movq %r15, %rsi
callq 0x2250
addl $0x2, 0x7d0(%rbx)
jmp 0x10ccd
movq 0x7d8(%rbx), %rdi
movq %r12, %rsi
callq 0x2120
movq %rax, %rdi
leaq -0x30(%rbp), %rsi
callq 0x2120
movl -0x30(%rbp), %eax
movslq -0x2c(%rbp), %rcx
movl %eax, (%rbx,%rcx,4)
movq 0x7d8(%rbx), %rdi
movq %r15, %rsi
callq 0x2250
jmp 0x10ccd
movq 0x7d8(%rbx), %rdi
movq %r15, %rsi
callq 0x2250
movq 0x7d8(%rbx), %rdi
movq %r15, %rsi
callq 0x2250
movq 0x7d8(%rbx), %rdi
movq %r15, %rsi
callq 0x2250
addl $0x3, 0x7d0(%rbx)
jmp 0x10ccd
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x10f16
callq 0x21b0
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x10f2b
jmp 0x10f2b
jmp 0x10f2b
movq %rax, %rbx
leaq -0x40(%rbp), %rax
movq -0x50(%rbp), %rdi
cmpq %rax, %rdi
je 0x10f40
callq 0x21b0
movq %rbx, %rdi
callq 0x2310