// File: /workspace/github_cpp_makefile_star2_O2/jstaursky[P]hutch/src/Sleigh/slghsymbol.cc
// Function: SymbolTable::purge()
void SymbolTable::purge(void)

{				// Get rid of unsavable symbols and scopes
  SleighSymbol *sym;
  for(int4 i=0;i<symbollist.size();++i) {
    sym = symbollist[i];
    if (sym == (SleighSymbol *)0) continue;
    if (sym->scopeid != 0) { // Not in global scope
      if (sym->getType() == SleighSymbol::operand_symbol) continue;
    }
    else {
      switch(sym->getType()) {
      case SleighSymbol::space_symbol:
      case SleighSymbol::token_symbol:
      case SleighSymbol::epsilon_symbol:
      case SleighSymbol::section_symbol:
	break;
      case SleighSymbol::macro_symbol:
	{			// Delete macro's local symbols
	  MacroSymbol *macro = (MacroSymbol *)sym;
	  for(int4 i=0;i<macro->getNumOperands();++i) {
	    SleighSymbol *opersym = macro->getOperand(i);
	    table[opersym->scopeid]->removeSymbol(opersym);
	    symbollist[opersym->id] = (SleighSymbol *)0;
	    delete opersym;
	  }
	  break;
	}
      case SleighSymbol::subtable_symbol:
	{			// Delete unused subtables
	  SubtableSymbol *subsym = (SubtableSymbol *)sym;
	  if (subsym->getPattern() != (TokenPattern *)0) continue;
	  for(int4 i=0;i<subsym->getNumConstructors();++i) { // Go thru each constructor
	    Constructor *con = subsym->getConstructor(i);
	    for(int4 j=0;j<con->getNumOperands();++j) { // Go thru each operand
	      OperandSymbol *oper = con->getOperand(j);
	      table[oper->scopeid]->removeSymbol(oper);
	      symbollist[oper->id] = (SleighSymbol *)0;
	      delete oper;
	    }
	  }
	  break;		// Remove the subtable symbol itself
	}
      default:
	continue;
      }
    }
    table[sym->scopeid]->removeSymbol(sym); // Remove the symbol
    symbollist[i] = (SleighSymbol *)0;
    delete sym;
  }
  for(int4 i=1;i<table.size();++i) { // Remove any empty scopes
    if (table[i]->tree.empty()) {
      delete table[i];
      table[i] = (SymbolScope *)0;
    }
  }
  renumber();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
xorl %r12d, %r12d
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %r12, %rcx
jbe 0x6fa0e
movq (%rax,%r12,8), %r14
testq %r14, %r14
je 0x6f9ba
movl 0x2c(%r14), %ebp
movq (%r14), %rax
movq %r14, %rdi
callq *0x10(%rax)
testl %ebp, %ebp
je 0x6f8f4
cmpl $0x8, %eax
jne 0x6f995
jmp 0x6f9ba
leal -0xb(%rax), %ecx
cmpl $0x5, %ecx
ja 0x6f990
leaq 0x185cd(%rip), %rdx     # 0x87ed4
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
jmpq *%rax
cmpq $0x0, 0x30(%r14)
jne 0x6f9ba
xorl %edx, %edx
movq 0x40(%r14), %rax
movq 0x48(%r14), %rcx
subq %rax, %rcx
shrq $0x3, %rcx
movslq %ecx, %rcx
cmpq %rcx, %rdx
jge 0x6f995
movq %rdx, (%rsp)
movq (%rax,%rdx,8), %r13
xorl %ebp, %ebp
movq 0x18(%r13), %rax
movq 0x20(%r13), %rcx
subq %rax, %rcx
shrq $0x3, %rcx
movslq %ecx, %rcx
cmpq %rcx, %rbp
jge 0x6f987
movq (%rax,%rbp,8), %r15
movl 0x2c(%r15), %eax
movq 0x18(%rbx), %rcx
movq (%rcx,%rax,8), %rdi
movq %r15, %rsi
callq 0x4e350
movl 0x28(%r15), %eax
movq (%rbx), %rcx
andq $0x0, (%rcx,%rax,8)
movq (%r15), %rax
movq %r15, %rdi
callq *0x8(%rax)
incq %rbp
jmp 0x6f93e
movq (%rsp), %rdx
incq %rdx
jmp 0x6f91d
cmpl $0x2, %eax
jae 0x6f9ba
movl 0x2c(%r14), %eax
movq 0x18(%rbx), %rcx
movq (%rcx,%rax,8), %rdi
movq %r14, %rsi
callq 0x4e350
movq (%rbx), %rax
andq $0x0, (%rax,%r12,8)
movq (%r14), %rax
movq %r14, %rdi
callq *0x8(%rax)
incq %r12
jmp 0x6f8b1
xorl %r13d, %r13d
movq 0x40(%r14), %rax
movq 0x48(%r14), %rcx
subq %rax, %rcx
shrq $0x3, %rcx
movslq %ecx, %rcx
cmpq %rcx, %r13
jge 0x6f995
movq (%rax,%r13,8), %r15
movl 0x2c(%r15), %eax
movq 0x18(%rbx), %rcx
movq (%rcx,%rax,8), %rdi
movq %r15, %rsi
callq 0x4e350
movl 0x28(%r15), %eax
movq (%rbx), %rcx
andq $0x0, (%rcx,%rax,8)
movq (%r15), %rax
movq %r15, %rdi
callq *0x8(%rax)
incq %r13
jmp 0x6f9c5
pushq $0x1
popq %r12
pushq $0x40
popq %r14
movq 0x18(%rbx), %rax
movq 0x20(%rbx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %r12, %rcx
jbe 0x6fa57
movq (%rax,%r12,8), %r15
cmpq $0x0, 0x30(%r15)
jne 0x6fa52
leaq 0x8(%r15), %rdi
callq 0x4f510
movq %r15, %rdi
movq %r14, %rsi
callq 0x4f670
movq 0x18(%rbx), %rax
andq $0x0, (%rax,%r12,8)
incq %r12
jmp 0x6fa16
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x50660
nop