// File: jstaursky[P]hutch/src/Sleigh/sleighbase.cc
// Function: SleighBase::buildXrefs()
void SleighBase::buildXrefs(void)

{
  SymbolScope *glb = symtab.getGlobalScope();
  SymbolTree::const_iterator iter;
  SleighSymbol *sym;
  int4 errors = 0;
  ostringstream s;

  for(iter=glb->begin();iter!=glb->end();++iter) {
    sym = *iter;
    if (sym->getType() == SleighSymbol::varnode_symbol) {
      pair<VarnodeData,string> ins(((VarnodeSymbol *)sym)->getFixedVarnode(),sym->getName());
      pair<map<VarnodeData,string>::iterator,bool> res = varnode_xref.insert(ins);
      if (!res.second) {
	s << "Duplicate (offset,size) pair for registers: ";
	s << sym->getName() << " and " << (*(res.first)).second << '\n';
	errors += 1;
      }
    }
    else if (sym->getType() == SleighSymbol::userop_symbol) {
      int4 index = ((UserOpSymbol *)sym)->getIndex();
      while(userop.size() <= index)
	userop.push_back("");
      userop[index] = sym->getName();
    }
    else if (sym->getType() == SleighSymbol::context_symbol) {
      ContextSymbol *csym = (ContextSymbol *)sym;
      ContextField *field = (ContextField *)csym->getPatternValue();
      int4 startbit = field->getStartBit();
      int4 endbit = field->getEndBit();
      registerContext(csym->getName(),startbit,endbit);
    }
  }
  if (errors > 0)
    throw SleighError(s.str());
}

// Assembly:
subq $0x338, %rsp            # imm = 0x338
movq %rdi, 0x330(%rsp)
movq 0x330(%rsp), %rdi
movq %rdi, 0xa0(%rsp)
addq $0x198, %rdi            # imm = 0x198
callq 0xd7210
movq %rax, 0x328(%rsp)
leaq 0x320(%rsp), %rdi
callq 0xd3950
movl $0x0, 0x314(%rsp)
leaq 0x198(%rsp), %rdi
callq 0xdbe90
movq 0x328(%rsp), %rdi
callq 0xd71f0
movq %rax, 0xa8(%rsp)
jmp 0x120e1f
movq 0xa8(%rsp), %rax
movq %rax, 0x190(%rsp)
movq 0x190(%rsp), %rax
movq %rax, 0x320(%rsp)
movq 0x328(%rsp), %rdi
callq 0xd9490
movq %rax, 0x98(%rsp)
jmp 0x120e56
movq 0x98(%rsp), %rax
movq %rax, 0x178(%rsp)
leaq 0x320(%rsp), %rdi
leaq 0x178(%rsp), %rsi
callq 0xd8da0
testb $0x1, %al
jne 0x120e84
jmp 0x1212c3
leaq 0x320(%rsp), %rdi
callq 0xe1aa0
movq (%rax), %rax
movq %rax, 0x318(%rsp)
movq 0x318(%rsp), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
movl %eax, 0x94(%rsp)
jmp 0x120eb6
movl 0x94(%rsp), %eax
cmpl $0x6, %eax
jne 0x121073
movq 0x318(%rsp), %rdi
callq 0xd0730
movq %rax, 0x88(%rsp)
jmp 0x120edd
movq 0x318(%rsp), %rdi
callq 0xd1f90
movq %rax, 0x80(%rsp)
jmp 0x120ef4
movq 0x80(%rsp), %rdx
movq 0x88(%rsp), %rsi
leaq 0x140(%rsp), %rdi
callq 0xd4ca0
jmp 0x120f13
movq 0xa0(%rsp), %rdi
addq $0x160, %rdi            # imm = 0x160
leaq 0x140(%rsp), %rsi
callq 0xd3df0
movb %dl, 0x77(%rsp)
movq %rax, 0x78(%rsp)
jmp 0x120f3a
movb 0x77(%rsp), %al
movq 0x78(%rsp), %rcx
movq %rcx, 0x120(%rsp)
movb %al, 0x128(%rsp)
movq 0x120(%rsp), %rax
movq %rax, 0x130(%rsp)
movb 0x128(%rsp), %al
movb %al, 0x138(%rsp)
testb $0x1, 0x138(%rsp)
jne 0x121061
leaq 0x675fc(%rip), %rsi     # 0x188581
leaq 0x198(%rsp), %rdi
callq 0xd8300
jmp 0x120f94
movq 0x318(%rsp), %rdi
callq 0xd1f90
movq %rax, 0x68(%rsp)
jmp 0x120fa8
movq 0x68(%rsp), %rsi
leaq 0x198(%rsp), %rdi
callq 0xd7350
movq %rax, 0x60(%rsp)
jmp 0x120fc1
movq 0x60(%rsp), %rdi
leaq 0x675e1(%rip), %rsi     # 0x1885ae
callq 0xd8300
movq %rax, 0x58(%rsp)
jmp 0x120fd9
leaq 0x130(%rsp), %rdi
callq 0xd3420
movq 0x58(%rsp), %rdi
movq %rax, %rsi
addq $0x18, %rsi
callq 0xd7350
movq %rax, 0x50(%rsp)
jmp 0x120ffe
movq 0x50(%rsp), %rdi
movl $0xa, %esi
callq 0xda0c0
jmp 0x12100f
movl 0x314(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x314(%rsp)
jmp 0x121061
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x188(%rsp)
movl %eax, 0x184(%rsp)
jmp 0x121399
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x188(%rsp)
movl %eax, 0x184(%rsp)
leaq 0x140(%rsp), %rdi
callq 0xd82f0
jmp 0x121399
leaq 0x140(%rsp), %rdi
callq 0xd82f0
jmp 0x1212af
movq 0x318(%rsp), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
movl %eax, 0x4c(%rsp)
jmp 0x12108a
movl 0x4c(%rsp), %eax
cmpl $0x2, %eax
jne 0x1211da
movq 0x318(%rsp), %rdi
callq 0xd6ea0
movl %eax, 0x48(%rsp)
jmp 0x1210aa
movl 0x48(%rsp), %eax
movl %eax, 0x11c(%rsp)
movq 0xa0(%rsp), %rdi
addq $0x148, %rdi            # imm = 0x148
callq 0xe1670
movslq 0x11c(%rsp), %rcx
cmpq %rcx, %rax
ja 0x121196
movq 0xa0(%rsp), %rax
addq $0x148, %rax            # imm = 0x148
movq %rax, 0x38(%rsp)
leaq 0xf7(%rsp), %rdi
movq %rdi, 0x40(%rsp)
callq 0xe0c80
movq 0x40(%rsp), %rdx
leaq 0x67f85(%rip), %rsi     # 0x189090
leaq 0xf8(%rsp), %rdi
callq 0xe00a0
jmp 0x12111a
movq 0x38(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
callq 0xd5950
jmp 0x12112e
leaq 0xf8(%rsp), %rdi
callq 0xd4550
leaq 0xf7(%rsp), %rdi
callq 0xd8ec0
jmp 0x1210b5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x188(%rsp)
movl %eax, 0x184(%rsp)
jmp 0x121184
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x188(%rsp)
movl %eax, 0x184(%rsp)
leaq 0xf8(%rsp), %rdi
callq 0xd4550
leaq 0xf7(%rsp), %rdi
callq 0xd8ec0
jmp 0x121399
movq 0x318(%rsp), %rdi
callq 0xd1f90
movq %rax, 0x30(%rsp)
jmp 0x1211aa
movq 0xa0(%rsp), %rdi
addq $0x148, %rdi            # imm = 0x148
movslq 0x11c(%rsp), %rsi
callq 0xe1770
movq 0x30(%rsp), %rsi
movq %rax, %rdi
callq 0xce450
jmp 0x1211d5
jmp 0x1212ad
movq 0x318(%rsp), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
movl %eax, 0x2c(%rsp)
jmp 0x1211f1
movl 0x2c(%rsp), %eax
cmpl $0xf, %eax
jne 0x1212ab
movq 0x318(%rsp), %rax
movq %rax, 0xe8(%rsp)
movq 0xe8(%rsp), %rdi
movq (%rdi), %rax
movq 0x60(%rax), %rax
callq *%rax
movq %rax, 0x20(%rsp)
jmp 0x121226
movq 0x20(%rsp), %rax
movq %rax, 0xe0(%rsp)
movq 0xe0(%rsp), %rdi
callq 0xd3490
movl %eax, 0x1c(%rsp)
jmp 0x121246
movl 0x1c(%rsp), %eax
movl %eax, 0xdc(%rsp)
movq 0xe0(%rsp), %rdi
callq 0xd5620
movl %eax, 0x18(%rsp)
jmp 0x121264
movl 0x18(%rsp), %eax
movl %eax, 0xd8(%rsp)
movq 0xe8(%rsp), %rdi
callq 0xd1f90
movq %rax, 0x10(%rsp)
jmp 0x121283
movq 0x10(%rsp), %rsi
movq 0xa0(%rsp), %rdi
movl 0xdc(%rsp), %edx
movl 0xd8(%rsp), %ecx
movq (%rdi), %rax
movq 0x18(%rax), %rax
callq *%rax
jmp 0x1212a9
jmp 0x1212ab
jmp 0x1212ad
jmp 0x1212af
jmp 0x1212b1
leaq 0x320(%rsp), %rdi
callq 0xdcc00
jmp 0x120e3f
cmpl $0x0, 0x314(%rsp)
jle 0x121384
movb $0x1, 0xb7(%rsp)
movl $0x20, %edi
callq 0xd2b40
movq %rax, 0x8(%rsp)
leaq 0xb8(%rsp), %rdi
leaq 0x198(%rsp), %rsi
callq 0xd8840
jmp 0x1212ff
movq 0x8(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
callq 0xd06e0
jmp 0x121313
movq 0x8(%rsp), %rdi
movb $0x0, 0xb7(%rsp)
movq 0xa6b41(%rip), %rsi     # 0x1c7e68
movq 0xa66f2(%rip), %rdx     # 0x1c7a20
callq 0xe01f0
jmp 0x1213b3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x188(%rsp)
movl %eax, 0x184(%rsp)
jmp 0x12136c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x188(%rsp)
movl %eax, 0x184(%rsp)
leaq 0xb8(%rsp), %rdi
callq 0xd4550
testb $0x1, 0xb7(%rsp)
jne 0x121378
jmp 0x121382
movq 0x8(%rsp), %rdi
callq 0xd5400
jmp 0x121399
leaq 0x198(%rsp), %rdi
callq 0xd0160
addq $0x338, %rsp            # imm = 0x338
retq
leaq 0x198(%rsp), %rdi
callq 0xd0160
movq 0x188(%rsp), %rdi
callq 0xe0be0
nopw %cs:(%rax,%rax)