// File: 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:
subq $0xa8, %rsp
movq %rdi, 0xa0(%rsp)
movq 0xa0(%rsp), %rax
movq %rax, 0x40(%rsp)
movl $0x0, 0x94(%rsp)
movq 0x40(%rsp), %rdi
movslq 0x94(%rsp), %rax
movq %rax, 0x38(%rsp)
callq 0xd6170
movq %rax, %rcx
movq 0x38(%rsp), %rax
cmpq %rcx, %rax
jae 0x13f8a7
movq 0x40(%rsp), %rdi
movslq 0x94(%rsp), %rsi
callq 0xd7fa0
movq (%rax), %rax
movq %rax, 0x98(%rsp)
cmpq $0x0, 0x98(%rsp)
jne 0x13f5bc
jmp 0x13f891
movq 0x98(%rsp), %rax
cmpl $0x0, 0x2c(%rax)
je 0x13f5e7
movq 0x98(%rsp), %rdi
movq (%rdi), %rax
callq *0x10(%rax)
cmpl $0x8, %eax
jne 0x13f5e2
jmp 0x13f891
jmp 0x13f82d
movq 0x98(%rsp), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
movl %eax, %ecx
movl %ecx, 0x34(%rsp)
subl $0x2, %eax
jb 0x13f639
jmp 0x13f605
movl 0x34(%rsp), %eax
subl $0xb, %eax
je 0x13f710
jmp 0x13f614
movl 0x34(%rsp), %eax
subl $0xc, %eax
je 0x13f63e
jmp 0x13f61f
movl 0x34(%rsp), %eax
subl $0xd, %eax
je 0x13f639
jmp 0x13f62a
movl 0x34(%rsp), %eax
subl $0x10, %eax
jne 0x13f829
jmp 0x13f639
jmp 0x13f82b
movq 0x98(%rsp), %rax
movq %rax, 0x88(%rsp)
movl $0x0, 0x84(%rsp)
movl 0x84(%rsp), %eax
movl %eax, 0x30(%rsp)
movq 0x88(%rsp), %rdi
callq 0xdc3c0
movl %eax, %ecx
movl 0x30(%rsp), %eax
cmpl %ecx, %eax
jge 0x13f70b
movq 0x88(%rsp), %rdi
movl 0x84(%rsp), %esi
callq 0xdbcf0
movq 0x40(%rsp), %rdi
movq %rax, 0x78(%rsp)
addq $0x18, %rdi
movq 0x78(%rsp), %rax
movl 0x2c(%rax), %eax
movl %eax, %esi
callq 0xe19d0
movq (%rax), %rdi
movq 0x78(%rsp), %rsi
callq 0xd3230
movq 0x40(%rsp), %rdi
movq 0x78(%rsp), %rax
movl 0x28(%rax), %eax
movl %eax, %esi
callq 0xd7fa0
movq $0x0, (%rax)
movq 0x78(%rsp), %rax
movq %rax, 0x28(%rsp)
cmpq $0x0, %rax
je 0x13f6f3
movq 0x28(%rsp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0x13f6f5
movl 0x84(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x84(%rsp)
jmp 0x13f659
jmp 0x13f82b
movq 0x98(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0x70(%rsp), %rdi
callq 0xe3100
cmpq $0x0, %rax
je 0x13f732
jmp 0x13f891
movl $0x0, 0x6c(%rsp)
movl 0x6c(%rsp), %eax
movl %eax, 0x24(%rsp)
movq 0x70(%rsp), %rdi
callq 0xcf8c0
movl %eax, %ecx
movl 0x24(%rsp), %eax
cmpl %ecx, %eax
jge 0x13f827
movq 0x70(%rsp), %rdi
movl 0x6c(%rsp), %esi
callq 0xd3c10
movq %rax, 0x60(%rsp)
movl $0x0, 0x5c(%rsp)
movl 0x5c(%rsp), %eax
movl %eax, 0x20(%rsp)
movq 0x60(%rsp), %rdi
callq 0xd0880
movl %eax, %ecx
movl 0x20(%rsp), %eax
cmpl %ecx, %eax
jge 0x13f815
movq 0x60(%rsp), %rdi
movl 0x5c(%rsp), %esi
callq 0xd3060
movq 0x40(%rsp), %rdi
movq %rax, 0x50(%rsp)
addq $0x18, %rdi
movq 0x50(%rsp), %rax
movl 0x2c(%rax), %eax
movl %eax, %esi
callq 0xe19d0
movq (%rax), %rdi
movq 0x50(%rsp), %rsi
callq 0xd3230
movq 0x40(%rsp), %rdi
movq 0x50(%rsp), %rax
movl 0x28(%rax), %eax
movl %eax, %esi
callq 0xd7fa0
movq $0x0, (%rax)
movq 0x50(%rsp), %rax
movq %rax, 0x18(%rsp)
cmpq $0x0, %rax
je 0x13f803
movq 0x18(%rsp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0x13f805
movl 0x5c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x5c(%rsp)
jmp 0x13f775
jmp 0x13f817
movl 0x6c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x6c(%rsp)
jmp 0x13f73a
jmp 0x13f82b
jmp 0x13f891
jmp 0x13f82d
movq 0x40(%rsp), %rdi
addq $0x18, %rdi
movq 0x98(%rsp), %rax
movl 0x2c(%rax), %eax
movl %eax, %esi
callq 0xe19d0
movq (%rax), %rdi
movq 0x98(%rsp), %rsi
callq 0xd3230
movq 0x40(%rsp), %rdi
movslq 0x94(%rsp), %rsi
callq 0xd7fa0
movq $0x0, (%rax)
movq 0x98(%rsp), %rax
movq %rax, 0x10(%rsp)
cmpq $0x0, %rax
je 0x13f88f
movq 0x10(%rsp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0x13f891
movl 0x94(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x94(%rsp)
jmp 0x13f567
movl $0x1, 0x4c(%rsp)
movq 0x40(%rsp), %rdi
movslq 0x4c(%rsp), %rax
movq %rax, 0x8(%rsp)
addq $0x18, %rdi
callq 0xdd9b0
movq %rax, %rcx
movq 0x8(%rsp), %rax
cmpq %rcx, %rax
jae 0x13f960
movq 0x40(%rsp), %rdi
addq $0x18, %rdi
movslq 0x4c(%rsp), %rsi
callq 0xe19d0
movq (%rax), %rdi
addq $0x8, %rdi
callq 0xce6c0
testb $0x1, %al
jne 0x13f8fd
jmp 0x13f94e
movq 0x40(%rsp), %rdi
addq $0x18, %rdi
movslq 0x4c(%rsp), %rsi
callq 0xe19d0
movq (%rax), %rax
movq %rax, (%rsp)
cmpq $0x0, %rax
je 0x13f934
movq (%rsp), %rdi
callq 0xdfe20
movq (%rsp), %rdi
movl $0x40, %esi
callq 0xd8620
movq 0x40(%rsp), %rdi
addq $0x18, %rdi
movslq 0x4c(%rsp), %rsi
callq 0xe19d0
movq $0x0, (%rax)
jmp 0x13f950
movl 0x4c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4c(%rsp)
jmp 0x13f8af
movq 0x40(%rsp), %rdi
callq 0xdc590
addq $0xa8, %rsp
retq
nopw %cs:(%rax,%rax)