// File: navrajsaini[P]PL_Compiler_design_project/plc.cpp
// Function: main
int main ()
{
   // variables for file names
   /*remove testLang.txt when project complete*/
   string codeFileName /*= "testLang.txt"*/, tokenFileName /* = "tokenFile"*/;
   //string codeFileName = "./testfiles/testLang.txt",
   //      tokenFileName  = "./testfiles/tokenFile";
   //get the file name for input and then declare and open file
   cout<<"Welcome to compiler4600, please enter your code input file name: ";
   cin>>codeFileName;
   //get the file name for output and then declare and open file
   cout<<endl<< "Now, please enter your scanner output file: ";
   cin>>tokenFileName;
   
   remove(tokenFileName.c_str()); 

   cout<<endl;
   
   //creating a scanner 
   Scanner scan(codeFileName, tokenFileName);

   //run the compiler
   Admin compiler(codeFileName, tokenFileName, scan);

   //calls the scanner function.
   int stat = compiler.scan();
   char answer;
   //result msg
   if(stat == 1)
   {
	cout<< "Scan Complete" << endl;
	cout<<"would you like us to output the completed syboltable?";
	cout<<endl<<"Y(y)/N(n): ";
	cin>>answer;

	if(answer=='y'||answer=='Y')
	   compiler.print();//printing token list
   }
   else
      cout << "Scan errors have occoured" <<endl;
   
   //Time to parse
   compiler.parse();
   if (compiler.ctd)
   {
      //--------------------------assembler-------------------
      //open the psudogen and create the output file for the interpreter
      ifstream infile;//psudogen is given to the assembler
      infile.open ("psudogen");

      //psudogen.Out file is given to the assember then passed to the interpreter
      ofstream outfile;
      outfile.open ("psudogen.Out");
   
      Assembler assemble(infile, outfile);

      cout << "Assembler first pass: "<<endl;
      assemble.firstPass();

      infile.close();
      infile.open ("psudogen");

      cout << "Assembler second pass: " << endl;
      assemble.secondPass();
      cout << "Assembler output file is: psudogen.Out. This will be passed"
	   << " to the interpreter now." << endl;
      Interpreter interp("psudogen.Out", true);
   }
   return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x4c60, %rsp           # imm = 0x4C60
movl $0x0, -0x4(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x22a0
leaq -0x48(%rbp), %rdi
callq 0x22a0
movq 0x21d3d(%rip), %rdi     # 0x26fc8
leaq 0x19e00(%rip), %rsi     # 0x1f092
callq 0x21b0
jmp 0x5299
movq 0x21d38(%rip), %rdi     # 0x26fd8
leaq -0x28(%rbp), %rsi
callq 0x2250
jmp 0x52ab
movq 0x21d16(%rip), %rdi     # 0x26fc8
movq 0x21cff(%rip), %rsi     # 0x26fb8
callq 0x21d0
movq %rax, -0x4c18(%rbp)
jmp 0x52c7
movq -0x4c18(%rbp), %rdi
leaq 0x19dff(%rip), %rsi     # 0x1f0d4
callq 0x21b0
jmp 0x52dc
movq 0x21cf5(%rip), %rdi     # 0x26fd8
leaq -0x48(%rbp), %rsi
callq 0x2250
jmp 0x52ee
leaq -0x48(%rbp), %rdi
callq 0x20c0
movq %rax, %rdi
callq 0x2360
movq 0x21cc2(%rip), %rdi     # 0x26fc8
movq 0x21cab(%rip), %rsi     # 0x26fb8
callq 0x21d0
jmp 0x5314
leaq -0xee8(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x20d0
jmp 0x5326
leaq -0xf08(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x20d0
jmp 0x5338
leaq -0xec8(%rbp), %rdi
leaq -0xee8(%rbp), %rsi
leaq -0xf08(%rbp), %rdx
callq 0x13690
jmp 0x5354
leaq -0xf08(%rbp), %rdi
callq 0x2130
leaq -0xee8(%rbp), %rdi
callq 0x2130
leaq -0x3018(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x20d0
jmp 0x537e
leaq -0x3038(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x20d0
jmp 0x5390
leaq -0x2ff8(%rbp), %rdi
leaq -0x3018(%rbp), %rsi
leaq -0x3038(%rbp), %rdx
leaq -0xec8(%rbp), %rcx
callq 0x124b0
jmp 0x53b3
leaq -0x3038(%rbp), %rdi
callq 0x2130
leaq -0x3018(%rbp), %rdi
callq 0x2130
leaq -0x2ff8(%rbp), %rdi
callq 0x12820
movl %eax, -0x4c1c(%rbp)
jmp 0x53df
movl -0x4c1c(%rbp), %eax
movl %eax, -0x303c(%rbp)
cmpl $0x1, -0x303c(%rbp)
jne 0x5556
movq 0x21bc9(%rip), %rdi     # 0x26fc8
leaq 0x19cfb(%rip), %rsi     # 0x1f101
callq 0x21b0
movq %rax, -0x4c28(%rbp)
jmp 0x5414
movq -0x4c28(%rbp), %rdi
movq 0x21b96(%rip), %rsi     # 0x26fb8
callq 0x21d0
jmp 0x5429
movq 0x21b98(%rip), %rdi     # 0x26fc8
leaq 0x19cd8(%rip), %rsi     # 0x1f10f
callq 0x21b0
jmp 0x543e
movq 0x21b83(%rip), %rdi     # 0x26fc8
movq 0x21b6c(%rip), %rsi     # 0x26fb8
callq 0x21d0
movq %rax, -0x4c30(%rbp)
jmp 0x545a
movq -0x4c30(%rbp), %rdi
leaq 0x19cdd(%rip), %rsi     # 0x1f145
callq 0x21b0
jmp 0x546f
movq 0x21b62(%rip), %rdi     # 0x26fd8
leaq -0x303d(%rbp), %rsi
callq 0x2270
jmp 0x5484
movsbl -0x303d(%rbp), %eax
cmpl $0x79, %eax
je 0x54a0
movsbl -0x303d(%rbp), %eax
cmpl $0x59, %eax
jne 0x5554
leaq -0x2ff8(%rbp), %rdi
callq 0x127f0
jmp 0x54ae
jmp 0x5554
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x5864
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x54ea
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xf08(%rbp), %rdi
callq 0x2130
leaq -0xee8(%rbp), %rdi
callq 0x2130
jmp 0x5864
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x5858
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x5532
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x3038(%rbp), %rdi
callq 0x2130
leaq -0x3018(%rbp), %rdi
callq 0x2130
jmp 0x5858
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x584c
jmp 0x5589
movq 0x21a6b(%rip), %rdi     # 0x26fc8
leaq 0x19bed(%rip), %rsi     # 0x1f151
callq 0x21b0
movq %rax, -0x4c38(%rbp)
jmp 0x5572
movq -0x4c38(%rbp), %rdi
movq 0x21a38(%rip), %rsi     # 0x26fb8
callq 0x21d0
jmp 0x5587
jmp 0x5589
leaq -0x2ff8(%rbp), %rdi
callq 0x129d0
jmp 0x5597
testb $0x1, -0x2ff7(%rbp)
je 0x580f
leaq -0x3248(%rbp), %rdi
callq 0x2200
jmp 0x55b2
leaq 0x19bb2(%rip), %rsi     # 0x1f16b
leaq -0x3248(%rbp), %rdi
movl $0x8, %edx
callq 0x2140
jmp 0x55cc
leaq -0x3448(%rbp), %rdi
callq 0x2310
jmp 0x55da
leaq 0x19b93(%rip), %rsi     # 0x1f174
leaq -0x3448(%rbp), %rdi
movl $0x10, %edx
callq 0x2040
jmp 0x55f4
leaq -0x3c30(%rbp), %rdi
leaq -0x3248(%rbp), %rsi
leaq -0x3448(%rbp), %rdx
callq 0x1bb80
jmp 0x5610
movq 0x219b1(%rip), %rdi     # 0x26fc8
leaq 0x19b63(%rip), %rsi     # 0x1f181
callq 0x21b0
movq %rax, -0x4c40(%rbp)
jmp 0x562c
movq -0x4c40(%rbp), %rdi
movq 0x2197e(%rip), %rsi     # 0x26fb8
callq 0x21d0
jmp 0x5641
leaq -0x3c30(%rbp), %rdi
callq 0x1bc00
jmp 0x564f
leaq -0x3248(%rbp), %rdi
callq 0x2050
jmp 0x565d
leaq 0x19b07(%rip), %rsi     # 0x1f16b
leaq -0x3248(%rbp), %rdi
movl $0x8, %edx
callq 0x2140
jmp 0x5677
movq 0x2194a(%rip), %rdi     # 0x26fc8
leaq 0x19b13(%rip), %rsi     # 0x1f198
callq 0x21b0
movq %rax, -0x4c48(%rbp)
jmp 0x5693
movq -0x4c48(%rbp), %rdi
movq 0x21917(%rip), %rsi     # 0x26fb8
callq 0x21d0
jmp 0x56a8
leaq -0x3c30(%rbp), %rdi
callq 0x1bfa0
jmp 0x56b6
movq 0x2190b(%rip), %rdi     # 0x26fc8
leaq 0x19aec(%rip), %rsi     # 0x1f1b0
callq 0x21b0
movq %rax, -0x4c50(%rbp)
jmp 0x56d2
movq -0x4c50(%rbp), %rdi
leaq 0x19b0c(%rip), %rsi     # 0x1f1ec
callq 0x21b0
movq %rax, -0x4c58(%rbp)
jmp 0x56ee
movq -0x4c58(%rbp), %rdi
movq 0x218bc(%rip), %rsi     # 0x26fb8
callq 0x21d0
jmp 0x5703
leaq -0x4c09(%rbp), %rdi
movq %rdi, -0x4c60(%rbp)
callq 0x2350
movq -0x4c60(%rbp), %rdx
leaq 0x19a50(%rip), %rsi     # 0x1f174
leaq -0x4c08(%rbp), %rdi
callq 0x2290
jmp 0x5732
leaq -0x4be8(%rbp), %rdi
leaq -0x4c08(%rbp), %rsi
movl $0x1, %edx
callq 0x1d1d0
jmp 0x574c
leaq -0x4c08(%rbp), %rdi
callq 0x2130
leaq -0x4c09(%rbp), %rdi
callq 0x21e0
leaq -0x3c30(%rbp), %rdi
callq 0x1bbf0
leaq -0x3448(%rbp), %rdi
callq 0x22d0
leaq -0x3248(%rbp), %rdi
callq 0x2060
jmp 0x580f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x5801
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x57f5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x57e9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x57dd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x4c08(%rbp), %rdi
callq 0x2130
leaq -0x4c09(%rbp), %rdi
callq 0x21e0
leaq -0x3c30(%rbp), %rdi
callq 0x1bbf0
leaq -0x3448(%rbp), %rdi
callq 0x22d0
leaq -0x3248(%rbp), %rdi
callq 0x2060
jmp 0x584c
movl $0x0, -0x4(%rbp)
leaq -0x2ff8(%rbp), %rdi
callq 0x5880
leaq -0xec8(%rbp), %rdi
callq 0x5910
leaq -0x48(%rbp), %rdi
callq 0x2130
leaq -0x28(%rbp), %rdi
callq 0x2130
movl -0x4(%rbp), %eax
addq $0x4c60, %rsp           # imm = 0x4C60
popq %rbp
retq
leaq -0x2ff8(%rbp), %rdi
callq 0x5880
leaq -0xec8(%rbp), %rdi
callq 0x5910
leaq -0x48(%rbp), %rdi
callq 0x2130
leaq -0x28(%rbp), %rdi
callq 0x2130
movq -0x50(%rbp), %rdi
callq 0x2340
nop