// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x228, %rsp            # imm = 0x228
movq %rdx, %rbx
movq %rsi, 0x8(%rsp)
movq %rdi, %r13
andq $0x0, 0x30(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movq 0x8(%rdx), %r15
movq 0x10(%rdx), %r12
leaq 0x2a8b5(%rip), %rsi     # 0x576fa
leaq 0x90(%rsp), %rdi
leaq 0xb0(%rsp), %rdx
callq 0x10c3a
movq 0x20(%rbx), %rax
movq %rbx, 0x88(%rsp)
subq 0x18(%rbx), %rax
leaq 0x258(%r13), %rcx
movq %rcx, 0x80(%rsp)
shrq $0x4, %rax
movslq %eax, %rbx
pushq $-0x1
popq %rbp
leaq 0x40(%rsp), %r14
movq %r13, 0x18(%rsp)
leaq 0xc0(%rsp), %rax
movq %rax, 0xb0(%rsp)
andq $0x0, 0xb8(%rsp)
movb $0x0, 0xc0(%rsp)
movq %r14, %rdi
movq %r12, %rdx
callq 0x2a9f4
leaq 0xb0(%rsp), %rdi
movq %r14, %rsi
callq 0xf470
movq %r14, %rdi
callq 0xf1a0
cmpq $0x0, 0xb8(%rsp)
jne 0x2cffd
movq %r13, %rdi
movq %r15, %rsi
movq 0x80(%rsp), %rdx
callq 0x2cc58
testb %al, %al
jne 0x2cf23
movq %r14, %rdi
leaq 0x90(%rsp), %rsi
leaq 0x2a803(%rip), %rdx     # 0x5770c
callq 0x2ebc0
leaq 0x20(%rsp), %rdi
movq %r14, %rsi
callq 0x148f8
movq %r14, %rdi
callq 0xf1a0
xorps %xmm0, %xmm0
movaps %xmm0, 0x60(%rsp)
andq $0x0, 0x70(%rsp)
movq 0x8(%rsp), %rdi
leaq 0x60(%rsp), %r13
movq %r13, %rsi
callq 0x44660
movq 0x18(%rsp), %rax
movq 0x98(%rax), %rdx
movq %r15, %rdi
movq %r13, %rsi
callq 0x225d0
cmpl $0x2, %eax
je 0x2cf8a
cmpl $0x1, %eax
jne 0x2cfb6
movq %r14, %rdi
leaq 0x90(%rsp), %rsi
leaq 0x2a7ae(%rip), %rdx     # 0x57724
callq 0x2ebc0
leaq 0x20(%rsp), %rdi
movq %r14, %rsi
callq 0x148f8
jmp 0x2cfae
movq %r14, %rdi
leaq 0x90(%rsp), %rsi
leaq 0x2a7a3(%rip), %rdx     # 0x5773f
callq 0x2ebc0
leaq 0x20(%rsp), %rdi
movq %r14, %rsi
callq 0x148f8
movq %r14, %rdi
callq 0xf1a0
movq %r15, %rdi
callq 0x1c61e
testb %al, %al
movq 0x18(%rsp), %r13
jne 0x2cff3
movq %r14, %rdi
leaq 0x90(%rsp), %rsi
leaq 0x29011(%rip), %rdx     # 0x55fea
callq 0x2ebc0
leaq 0x20(%rsp), %rdi
movq %r14, %rsi
callq 0x148f8
movq %r14, %rdi
callq 0xf1a0
leaq 0x60(%rsp), %rdi
callq 0x30138
testl %ebp, %ebp
js 0x2d171
movl (%r15), %eax
testl %eax, %eax
je 0x2d08a
movq 0x190(%r13), %rcx
movq 0x8(%rsp), %rdx
cmpq 0x8(%rdx), %rcx
je 0x2d07a
movq %r14, %rdi
leaq 0x2a785(%rip), %rsi     # 0x577ad
leaq 0x60(%rsp), %rdx
callq 0x10c3a
movq %r13, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x2a3a2
movq %r14, %rdi
callq 0xf1a0
movq 0x5afa2(%rip), %rdi     # 0x87ff0
leaq 0x32092(%rip), %rsi     # 0x5f0e7
callq 0xf350
movq 0x8(%rsp), %rdi
movq 0x5af8a(%rip), %rsi     # 0x87ff0
callq 0x45ae2
movq 0x5af7e(%rip), %rdi     # 0x87ff0
callq 0xf1c0
movl (%r15), %eax
cmpl 0x1d0(%r13), %eax
jbe 0x2d08a
movl %eax, 0x1d0(%r13)
movslq %ebp, %r13
incl %ebp
movq %r13, %rax
shlq $0x20, %rax
movq %r13, %rcx
shlq $0x4, %rcx
addq $0x18, %rcx
movl %ebp, %edx
movl %edx, %ebp
incq %r13
cmpq %rbx, %r13
jge 0x2d14c
leal 0x1(%rbp), %edx
movabsq $0x100000000, %rsi      # imm = 0x100000000
addq %rsi, %rax
movq 0x88(%rsp), %rsi
movq 0x18(%rsi), %rsi
movq -0x8(%rsi,%rcx), %r14
movq (%rsi,%rcx), %r12
addq $0x10, %rcx
movl $0x0, %r15d
testq %r14, %r14
je 0x2d0a3
movq 0x18(%rsp), %rcx
movq 0x2a0(%rcx), %rcx
sarq $0x1d, %rax
movq (%rcx,%rax), %rdx
addq $0x8, %rdx
leaq 0x60(%rsp), %rdi
leaq 0x31fde(%rip), %rsi     # 0x5f0e7
callq 0x10cd1
leaq 0x40(%rsp), %r15
movq %r15, %rdi
leaq 0x60(%rsp), %rsi
leaq 0x2a5df(%rip), %rdx     # 0x57701
callq 0x2eb71
leaq 0x90(%rsp), %rdi
movq %r15, %rsi
callq 0xf470
movq %r15, %rdi
callq 0xf1a0
leaq 0x60(%rsp), %rdi
callq 0xf1a0
movq %r14, %r15
leaq 0xb0(%rsp), %rdi
callq 0xf1a0
cmpq %rbx, %r13
movq 0x18(%rsp), %r13
leaq 0x40(%rsp), %r14
jl 0x2ce8d
jmp 0x2d284
movq 0x20(%r15), %rcx
testq %rcx, %rcx
je 0x2d005
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rax
cmpq 0x190(%r13), %rax
je 0x2d233
movq %rcx, 0x10(%rsp)
leaq 0x40(%rcx), %rdi
callq 0x20e34
testb %al, %al
movq 0x10(%rsp), %rdi
je 0x2d1de
cmpl $0x0, 0x80(%rdi)
jne 0x2d1de
cmpq $0x0, 0x90(%rdi)
jne 0x2d1de
addq $0x60, %rdi
movq %r15, %rsi
callq 0x2e95e
testq %rax, %rax
je 0x2d256
movq 0x10(%rsp), %rcx
subq $-0x80, %rcx
jmp 0x2d21f
callq 0x20e34
testb %al, %al
movq 0x10(%rsp), %rax
je 0x2d005
cmpl $0x0, 0x20(%rax)
jne 0x2d005
cmpq $0x0, 0x30(%rax)
jne 0x2d005
leaq 0x60(%rax), %rdi
movq %r15, %rsi
callq 0x2e95e
testq %rax, %rax
je 0x2d256
movq 0x10(%rsp), %rcx
addq $0x20, %rcx
movups 0x40(%rax), %xmm0
movups 0x4c(%rax), %xmm1
movups %xmm1, 0xc(%rcx)
movups %xmm0, (%rcx)
jmp 0x2d005
movq %r14, %rdi
leaq 0x2a51f(%rip), %rsi     # 0x5775c
leaq 0x60(%rsp), %rdx
callq 0x10c3a
leaq 0x20(%rsp), %rdi
movq %r14, %rsi
callq 0x148f8
jmp 0x2d277
movq %r14, %rdi
leaq 0x2a530(%rip), %rsi     # 0x57790
leaq 0x60(%rsp), %rdx
callq 0x10c3a
leaq 0x20(%rsp), %rdi
movq %r14, %rsi
callq 0x148f8
movq %r14, %rdi
callq 0xf1a0
jmp 0x2d005
movq 0x20(%rsp), %r14
movq 0x28(%rsp), %r15
cmpq %r15, %r14
je 0x2d341
leaq 0xb0(%rsp), %rdi
callq 0xf520
leaq 0x2a96e(%rip), %rsi     # 0x57c19
leaq 0xb0(%rsp), %rdi
callq 0xf350
leaq 0xb0(%rsp), %rsi
movq 0x8(%rsp), %rdi
callq 0x45ae2
leaq 0xb8(%rsp), %rsi
leaq 0x40(%rsp), %rdi
callq 0xf610
leaq 0x40(%rsp), %rsi
movq %r13, %rdi
xorl %edx, %edx
callq 0x292f0
leaq 0x40(%rsp), %rdi
callq 0xf1a0
xorl %r12d, %r12d
movq 0x5acf1(%rip), %rbx     # 0x87ff0
xorl %r13d, %r13d
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rax
subq %rsi, %rax
sarq $0x5, %rax
cmpq %r13, %rax
jbe 0x2d334
addq %r12, %rsi
movq %rbx, %rdi
callq 0xf320
movq %rax, %rdi
callq 0xf1c0
incq %r13
addq $0x20, %r12
jmp 0x2d302
leaq 0xb0(%rsp), %rdi
callq 0xf0e0
cmpq %r15, %r14
sete %bl
leaq 0x90(%rsp), %rdi
callq 0xf1a0
leaq 0x20(%rsp), %rdi
callq 0x12d80
movl %ebx, %eax
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0xf1a0
jmp 0x2d3ed
jmp 0x2d3ea
movq %rax, %rbx
jmp 0x2d40c
jmp 0x2d3be
jmp 0x2d3fc
movq %rax, %rbx
jmp 0x2d419
jmp 0x2d3ea
jmp 0x2d3be
jmp 0x2d3fc
jmp 0x2d3ab
jmp 0x2d3d9
jmp 0x2d3ab
jmp 0x2d3d9
jmp 0x2d3d9
jmp 0x2d3be
jmp 0x2d3fc
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0xf1a0
jmp 0x2d3dc
jmp 0x2d3d9
jmp 0x2d3fc
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
jmp 0x2d3d2
jmp 0x2d3fc
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0xf1a0
jmp 0x2d3ff
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x30138
jmp 0x2d3ff
jmp 0x2d3fc
movq %rax, %rbx
leaq 0xb0(%rsp), %rdi
callq 0xf0e0
jmp 0x2d40c
movq %rax, %rbx
leaq 0xb0(%rsp), %rdi
callq 0xf1a0
leaq 0x90(%rsp), %rdi
callq 0xf1a0
leaq 0x20(%rsp), %rdi
callq 0x12d80
movq %rbx, %rdi
callq 0xf6e0
nop