// File: jstaursky[P]hutch/src/Sleigh/slgh_compile.cc
// Function: SleighCompile::finalizeSections(Constructor*, SectionVector*)
bool SleighCompile::finalizeSections(Constructor *big,SectionVector *vec)

{ // Do all final checks, expansions, and linking for p-code sections
  vector<string> errors;

  RtlPair cur = vec->getMainPair();
  int4 i=-1;
  string sectionstring = "   Main section: ";
  int4 max = vec->getMaxId();
  for(;;) {
    string errstring;

    errstring = checkSymbols(cur.scope); // Check labels in the section's scope
    if (errstring.size()==0) {
      if (!expandMacros(cur.section,macrotable))
	errors.push_back(sectionstring + "Could not expand macros");
      vector<int4> check;
      big->markSubtableOperands(check);
      int4 res = cur.section->fillinBuild(check,getConstantSpace());
      if (res == 1)
	errors.push_back(sectionstring + "Duplicate BUILD statements");
      if (res == 2)
	errors.push_back(sectionstring + "Unnecessary BUILD statements");
  
      if (!PcodeCompile::propagateSize(cur.section))
	errors.push_back(sectionstring + "Could not resolve at least 1 variable size");
    }
    if (i < 0) {		// These potential errors only apply to main section
      if (cur.section->getResult() != (HandleTpl *)0) {	// If there is an export statement
	if (big->getParent()==root)
	  errors.push_back("   Cannot have export statement in root constructor");
	else if (!force_exportsize(cur.section))
	  errors.push_back("   Size of export is unknown");
      }
    }
    if (cur.section->delaySlot() != 0) { // Delay slot is present in this constructor
      if (root != big->getParent()) { // it is not in a root constructor
	reportWarning("Delay slot used in",false);
	cerr << "   ";
	big->printInfo(cerr);
	cerr << endl;
      }
      if (cur.section->delaySlot() > maxdelayslotbytes)	// Keep track of maximum delayslot parameter
	maxdelayslotbytes = cur.section->delaySlot();
    }
    do {
      i += 1;
      if (i >= max) break;
      cur = vec->getNamedPair(i);
    } while(cur.section == (ConstructTpl *)0);
      
    if (i >= max) break;
    SectionSymbol *sym = sections[i];
    sectionstring = "   " + sym->getName() + " section: ";
  }
  if (!errors.empty()) {
    ostringstream s;
    s << "in ";
    big->printInfo(s);
    reportError(s.str(),false);
    for(int4 j=0;j<errors.size();++j)
      cerr << errors[j] << endl;
    return false;
  }
  return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x4a0, %rsp            # imm = 0x4A0
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x3f0(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x1ba90
movq -0x20(%rbp), %rdi
callq 0x6c890
movq %rdx, -0x3e8(%rbp)
movq %rax, -0x3e0(%rbp)
jmp 0x66fb4
movq -0x3e8(%rbp), %rax
movq -0x3e0(%rbp), %rcx
movq %rcx, -0x48(%rbp)
movq %rax, -0x40(%rbp)
movl $0xffffffff, -0x58(%rbp) # imm = 0xFFFFFFFF
leaq -0x79(%rbp), %rdi
movq %rdi, -0x3f8(%rbp)
callq 0x118c0
movq -0x3f8(%rbp), %rdx
leaq 0x72903(%rip), %rsi     # 0xd98f2
leaq -0x78(%rbp), %rdi
callq 0x14430
jmp 0x66ffa
leaq -0x79(%rbp), %rdi
callq 0x114d0
movq -0x20(%rbp), %rdi
callq 0x6c8b0
movl %eax, -0x3fc(%rbp)
jmp 0x67014
movl -0x3fc(%rbp), %eax
movl %eax, -0x80(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x11700
movq -0x3f0(%rbp), %rsi
movq -0x40(%rbp), %rdx
leaq -0xc0(%rbp), %rdi
callq 0x62ef0
jmp 0x67042
leaq -0xa0(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x115c0
leaq -0xc0(%rbp), %rdi
callq 0x11300
leaq -0xa0(%rbp), %rdi
callq 0x11340
cmpq $0x0, %rax
jne 0x6731a
movq -0x3f0(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq %rdi, %rdx
addq $0x258, %rdx            # imm = 0x258
callq 0x66c50
movb %al, -0x3fd(%rbp)
jmp 0x67099
movb -0x3fd(%rbp), %al
testb $0x1, %al
jne 0x6714c
jmp 0x670a9
leaq 0x72854(%rip), %rdx     # 0xd9904
leaq -0xe0(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x151f0
jmp 0x670c2
leaq -0x38(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x22660
jmp 0x670d4
leaq -0xe0(%rbp), %rdi
callq 0x11300
jmp 0x6714c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x6792f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x79(%rbp), %rdi
callq 0x114d0
jmp 0x6792f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x67926
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x67797
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x11300
jmp 0x67797
leaq -0xf8(%rbp), %rdi
movq %rdi, -0x408(%rbp)
callq 0x6a7f0
movq -0x408(%rbp), %rsi
movq -0x18(%rbp), %rdi
callq 0xaad10
jmp 0x67171
movq -0x3f0(%rbp), %rdi
movq -0x48(%rbp), %rax
movq %rax, -0x418(%rbp)
callq 0x48150
movq %rax, -0x410(%rbp)
jmp 0x67191
movq -0x410(%rbp), %rdx
movq -0x418(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0x4cfb0
movl %eax, -0x41c(%rbp)
jmp 0x671b3
movl -0x41c(%rbp), %eax
movl %eax, -0xfc(%rbp)
cmpl $0x1, -0xfc(%rbp)
jne 0x6722f
leaq 0x7274d(%rip), %rdx     # 0xd991c
leaq -0x120(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x151f0
jmp 0x671e1
leaq -0x38(%rbp), %rdi
leaq -0x120(%rbp), %rsi
callq 0x22660
jmp 0x671f3
leaq -0x120(%rbp), %rdi
callq 0x11300
jmp 0x6722f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x67309
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x120(%rbp), %rdi
callq 0x11300
jmp 0x67309
cmpl $0x2, -0xfc(%rbp)
jne 0x6728b
leaq 0x726f8(%rip), %rdx     # 0xd9937
leaq -0x140(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x151f0
jmp 0x67251
leaq -0x38(%rbp), %rdi
leaq -0x140(%rbp), %rsi
callq 0x22660
jmp 0x67263
leaq -0x140(%rbp), %rdi
callq 0x11300
jmp 0x6728b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x140(%rbp), %rdi
callq 0x11300
jmp 0x67309
movq -0x48(%rbp), %rdi
callq 0x3c800
movb %al, -0x41d(%rbp)
jmp 0x6729c
movb -0x41d(%rbp), %al
testb $0x1, %al
jne 0x672fb
jmp 0x672a8
leaq 0x70f5b(%rip), %rdx     # 0xd820a
leaq -0x160(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x151f0
jmp 0x672c1
leaq -0x38(%rbp), %rdi
leaq -0x160(%rbp), %rsi
callq 0x22660
jmp 0x672d3
leaq -0x160(%rbp), %rdi
callq 0x11300
jmp 0x672fb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x160(%rbp), %rdi
callq 0x11300
jmp 0x67309
leaq -0xf8(%rbp), %rdi
callq 0x6a9d0
jmp 0x6731a
leaq -0xf8(%rbp), %rdi
callq 0x6a9d0
jmp 0x67797
cmpl $0x0, -0x58(%rbp)
jge 0x674c2
movq -0x48(%rbp), %rdi
callq 0x52ef0
movq %rax, -0x428(%rbp)
jmp 0x67336
movq -0x428(%rbp), %rax
cmpq $0x0, %rax
je 0x674c0
movq -0x18(%rbp), %rdi
callq 0x6a640
movq %rax, -0x430(%rbp)
jmp 0x67359
movq -0x430(%rbp), %rax
movq -0x3f0(%rbp), %rcx
cmpq 0x190(%rcx), %rax
jne 0x67409
leaq -0x181(%rbp), %rdi
movq %rdi, -0x438(%rbp)
callq 0x118c0
movq -0x438(%rbp), %rdx
leaq 0x725bf(%rip), %rsi     # 0xd9954
leaq -0x180(%rbp), %rdi
callq 0x14430
jmp 0x673a3
leaq -0x38(%rbp), %rdi
leaq -0x180(%rbp), %rsi
callq 0x22660
jmp 0x673b5
leaq -0x180(%rbp), %rdi
callq 0x11300
leaq -0x181(%rbp), %rdi
callq 0x114d0
jmp 0x674be
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x673f8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x180(%rbp), %rdi
callq 0x11300
leaq -0x181(%rbp), %rdi
callq 0x114d0
jmp 0x67797
movq -0x48(%rbp), %rdi
callq 0x67950
movb %al, -0x439(%rbp)
jmp 0x6741a
movb -0x439(%rbp), %al
testb $0x1, %al
jne 0x674bc
jmp 0x6742a
leaq -0x1a9(%rbp), %rdi
movq %rdi, -0x448(%rbp)
callq 0x118c0
movq -0x448(%rbp), %rdx
leaq 0x7253d(%rip), %rsi     # 0xd9988
leaq -0x1a8(%rbp), %rdi
callq 0x14430
jmp 0x67459
leaq -0x38(%rbp), %rdi
leaq -0x1a8(%rbp), %rsi
callq 0x22660
jmp 0x6746b
leaq -0x1a8(%rbp), %rdi
callq 0x11300
leaq -0x1a9(%rbp), %rdi
callq 0x114d0
jmp 0x674bc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x674ab
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x1a8(%rbp), %rdi
callq 0x11300
leaq -0x1a9(%rbp), %rdi
callq 0x114d0
jmp 0x67797
jmp 0x674be
jmp 0x674c0
jmp 0x674c2
movq -0x48(%rbp), %rdi
callq 0x52e70
movl %eax, -0x44c(%rbp)
jmp 0x674d3
movl -0x44c(%rbp), %eax
cmpl $0x0, %eax
je 0x6763f
movq -0x3f0(%rbp), %rax
movq 0x190(%rax), %rax
movq %rax, -0x460(%rbp)
movq -0x18(%rbp), %rdi
callq 0x6a640
movq %rax, -0x458(%rbp)
jmp 0x67509
movq -0x460(%rbp), %rax
movq -0x458(%rbp), %rcx
cmpq %rcx, %rax
je 0x675f3
leaq -0x1d1(%rbp), %rdi
movq %rdi, -0x468(%rbp)
callq 0x118c0
movq -0x468(%rbp), %rdx
leaq 0x72464(%rip), %rsi     # 0xd99a5
leaq -0x1d0(%rbp), %rdi
callq 0x14430
jmp 0x6754f
movq -0x3f0(%rbp), %rdi
leaq -0x1d0(%rbp), %rsi
xorl %edx, %edx
callq 0x62430
jmp 0x67566
leaq -0x1d0(%rbp), %rdi
callq 0x11300
leaq -0x1d1(%rbp), %rdi
callq 0x114d0
movq 0xcaa63(%rip), %rdi     # 0x131fe8
leaq 0x79edb(%rip), %rsi     # 0xe1467
callq 0x11420
jmp 0x67593
movq -0x18(%rbp), %rdi
movq 0xcaa4a(%rip), %rsi     # 0x131fe8
callq 0xadbf0
jmp 0x675a5
movq 0xcaa3c(%rip), %rdi     # 0x131fe8
movq 0xca9ed(%rip), %rsi     # 0x131fa0
callq 0x114a0
jmp 0x675ba
jmp 0x675f3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x675e2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x1d0(%rbp), %rdi
callq 0x11300
leaq -0x1d1(%rbp), %rdi
callq 0x114d0
jmp 0x67797
movq -0x48(%rbp), %rdi
callq 0x52e70
movl %eax, -0x46c(%rbp)
jmp 0x67604
movl -0x46c(%rbp), %eax
movq -0x3f0(%rbp), %rcx
cmpl 0x1d0(%rcx), %eax
jbe 0x6763d
movq -0x48(%rbp), %rdi
callq 0x52e70
movl %eax, -0x470(%rbp)
jmp 0x6762a
movq -0x3f0(%rbp), %rax
movl -0x470(%rbp), %ecx
movl %ecx, 0x1d0(%rax)
jmp 0x6763f
jmp 0x67641
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
movl -0x58(%rbp), %eax
cmpl -0x80(%rbp), %eax
jl 0x67654
jmp 0x676a9
movq -0x20(%rbp), %rdi
movl -0x58(%rbp), %esi
callq 0x6c8d0
movq %rdx, -0x480(%rbp)
movq %rax, -0x478(%rbp)
jmp 0x67670
movq -0x480(%rbp), %rax
movq -0x478(%rbp), %rcx
movq %rcx, -0x1e8(%rbp)
movq %rax, -0x1e0(%rbp)
movq -0x1e8(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x1e0(%rbp), %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x48(%rbp)
je 0x67641
movl -0x58(%rbp), %eax
cmpl -0x80(%rbp), %eax
jl 0x676c0
movl $0x2, -0x1ec(%rbp)
jmp 0x67760
movq -0x3f0(%rbp), %rdi
addq $0x2a0, %rdi            # imm = 0x2A0
movslq -0x58(%rbp), %rsi
callq 0x6c910
movq (%rax), %rax
movq %rax, -0x1f8(%rbp)
movq -0x1f8(%rbp), %rdi
callq 0x401a0
movq %rax, -0x488(%rbp)
jmp 0x676f6
movq -0x488(%rbp), %rdx
leaq 0x79d63(%rip), %rsi     # 0xe1467
leaq -0x238(%rbp), %rdi
callq 0x147f0
jmp 0x67712
leaq 0x721e0(%rip), %rdx     # 0xd98f9
leaq -0x218(%rbp), %rdi
leaq -0x238(%rbp), %rsi
callq 0x6b540
jmp 0x6772e
leaq -0x78(%rbp), %rdi
leaq -0x218(%rbp), %rsi
callq 0x115c0
leaq -0x218(%rbp), %rdi
callq 0x11300
leaq -0x238(%rbp), %rdi
callq 0x11300
movl $0x0, -0x1ec(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x11300
movl -0x1ec(%rbp), %eax
testl %eax, %eax
je 0x6777a
jmp 0x67778
jmp 0x677a8
jmp 0x6701d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x238(%rbp), %rdi
callq 0x11300
leaq -0xa0(%rbp), %rdi
callq 0x11300
jmp 0x67926
leaq -0x38(%rbp), %rdi
callq 0x6b990
testb $0x1, %al
jne 0x678f8
leaq -0x3b0(%rbp), %rdi
callq 0x116c0
jmp 0x677c7
leaq 0x72643(%rip), %rsi     # 0xd9e11
leaq -0x3b0(%rbp), %rdi
callq 0x11420
jmp 0x677dc
movq -0x18(%rbp), %rdi
leaq -0x3b0(%rbp), %rsi
callq 0xadbf0
jmp 0x677ee
leaq -0x3d0(%rbp), %rdi
leaq -0x3b0(%rbp), %rsi
callq 0x11460
jmp 0x67803
movq -0x3f0(%rbp), %rdi
leaq -0x3d0(%rbp), %rsi
xorl %edx, %edx
callq 0x603b0
jmp 0x6781a
leaq -0x3d0(%rbp), %rdi
callq 0x11300
movl $0x0, -0x3d4(%rbp)
movslq -0x3d4(%rbp), %rax
movq %rax, -0x490(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x15090
movq %rax, %rcx
movq -0x490(%rbp), %rax
cmpq %rcx, %rax
jae 0x678ce
movslq -0x3d4(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0x1bb40
movq %rax, %rsi
movq 0xca778(%rip), %rdi     # 0x131fe8
callq 0x113e0
movq %rax, -0x498(%rbp)
jmp 0x6787e
movq -0x498(%rbp), %rdi
movq 0xca714(%rip), %rsi     # 0x131fa0
callq 0x114a0
jmp 0x67893
jmp 0x67895
movl -0x3d4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3d4(%rbp)
jmp 0x67830
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x678ea
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x3d0(%rbp), %rdi
callq 0x11300
jmp 0x678ea
movb $0x0, -0x1(%rbp)
movl $0x1, -0x1ec(%rbp)
leaq -0x3b0(%rbp), %rdi
callq 0x11120
jmp 0x67906
leaq -0x3b0(%rbp), %rdi
callq 0x11120
jmp 0x67926
movb $0x1, -0x1(%rbp)
movl $0x1, -0x1ec(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x11300
leaq -0x38(%rbp), %rdi
callq 0x1bc40
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x4a0, %rsp            # imm = 0x4A0
popq %rbp
retq
leaq -0x78(%rbp), %rdi
callq 0x11300
leaq -0x38(%rbp), %rdi
callq 0x1bc40
movq -0x50(%rbp), %rdi
callq 0x118b0
nopw %cs:(%rax,%rax)