// File: jstaursky[P]hutch/src/Sleigh/sleigh.cc
// Function: Sleigh::resolveHandles(ParserContext&) const
void Sleigh::resolveHandles (ParserContext& pos) const

{ // Resolve handles (assuming Constructors already resolved)
    TripleSymbol* triple;
    Constructor* ct;
    int4 oper, numoper;

    ParserWalker walker (&pos);
    walker.baseState ();
    while (walker.isState ()) {
        ct = walker.getConstructor ();
        oper = walker.getOperand ();
        numoper = ct->getNumOperands ();
        while (oper < numoper) {
            OperandSymbol* sym = ct->getOperand (oper);
            walker.pushOperand (oper); // Descend into node
            triple = sym->getDefiningSymbol ();
            if (triple != (TripleSymbol*)0) {
                if (triple->getType () == SleighSymbol::subtable_symbol)
                    break;
                else // Some other kind of symbol as an operand
                    triple->getFixedHandle (walker.getParentHandle (), walker);
            } else { // Must be an expression
                PatternExpression* patexp = sym->getDefiningExpression ();
                intb res = patexp->getValue (walker);
                FixedHandle& hand (walker.getParentHandle ());
                // Result of expression is a constant
                hand.space = pos.getConstSpace ();
                hand.offset_space = (AddrSpace*)0;
                hand.offset_offset = (uintb)res;
                hand.size = 0;  // This size should not get used
            }
            walker.popOperand ();
            oper += 1;
        }
        if (oper >= numoper) { // Finished processing constructor
            ConstructTpl* templ = ct->getTempl ();
            if (templ != (ConstructTpl*)0) {
                HandleTpl* res = templ->getResult ();
                // Pop up handle to containing operand
                if (res != (HandleTpl*)0) 
                    res->fix (walker.getParentHandle (), walker);
                // If we need an indicator that the constructor exports nothing try
                // else
                //   walker.getParentHandle().setInvalid();
            }
            walker.popOperand ();
        }
    }
    pos.setParserState (ParserContext::pcode);
}

// Assembly:
subq $0x108, %rsp            # imm = 0x108
movq %rdi, 0x100(%rsp)
movq %rsi, 0xf8(%rsp)
movq 0xf8(%rsp), %rsi
leaq 0x40(%rsp), %rdi
callq 0xd7160
leaq 0x40(%rsp), %rdi
callq 0xe07e0
leaq 0x40(%rsp), %rdi
callq 0xd0910
testb $0x1, %al
jne 0x11c8a6
jmp 0x11ca84
leaq 0x40(%rsp), %rdi
callq 0xd81d0
movq %rax, 0xe8(%rsp)
leaq 0x40(%rsp), %rdi
callq 0xd9aa0
movl %eax, 0xe4(%rsp)
movq 0xe8(%rsp), %rdi
callq 0xd0880
movl %eax, 0xe0(%rsp)
movl 0xe4(%rsp), %eax
cmpl 0xe0(%rsp), %eax
jge 0x11ca0e
movq 0xe8(%rsp), %rdi
movl 0xe4(%rsp), %esi
callq 0xd3060
movq %rax, 0x38(%rsp)
movl 0xe4(%rsp), %esi
leaq 0x40(%rsp), %rdi
callq 0xcf7d0
movq 0x38(%rsp), %rdi
callq 0xdf550
movq %rax, 0xf0(%rsp)
cmpq $0x0, 0xf0(%rsp)
je 0x11c97c
movq 0xf0(%rsp), %rdi
movq (%rdi), %rax
callq *0x10(%rax)
cmpl $0xb, %eax
jne 0x11c950
jmp 0x11ca0e
movq 0xf0(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq 0x40(%rsp), %rdi
callq 0xd16a0
movq 0x8(%rsp), %rdi
movq %rax, %rsi
movq (%rdi), %rax
leaq 0x40(%rsp), %rdx
callq *0x40(%rax)
jmp 0x11c9ee
movq 0x38(%rsp), %rdi
callq 0xd7220
movq %rax, 0x30(%rsp)
movq 0x30(%rsp), %rdi
movq (%rdi), %rax
leaq 0x40(%rsp), %rsi
callq *0x10(%rax)
movq %rax, 0x28(%rsp)
leaq 0x40(%rsp), %rdi
callq 0xd16a0
movq %rax, 0x20(%rsp)
movq 0xf8(%rsp), %rdi
callq 0xdf100
movq %rax, %rcx
movq 0x20(%rsp), %rax
movq %rcx, (%rax)
movq 0x20(%rsp), %rax
movq $0x0, 0x10(%rax)
movq 0x28(%rsp), %rcx
movq 0x20(%rsp), %rax
movq %rcx, 0x18(%rax)
movq 0x20(%rsp), %rax
movl $0x0, 0x8(%rax)
leaq 0x40(%rsp), %rdi
callq 0xceb70
movl 0xe4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xe4(%rsp)
jmp 0x11c8dd
movl 0xe4(%rsp), %eax
cmpl 0xe0(%rsp), %eax
jl 0x11ca7f
movq 0xe8(%rsp), %rdi
callq 0xd87a0
movq %rax, 0x18(%rsp)
cmpq $0x0, 0x18(%rsp)
je 0x11ca75
movq 0x18(%rsp), %rdi
callq 0xcf9d0
movq %rax, 0x10(%rsp)
cmpq $0x0, 0x10(%rsp)
je 0x11ca73
movq 0x10(%rsp), %rax
movq %rax, (%rsp)
leaq 0x40(%rsp), %rdi
callq 0xd16a0
movq (%rsp), %rdi
movq %rax, %rsi
leaq 0x40(%rsp), %rdx
callq 0xd9080
jmp 0x11ca75
leaq 0x40(%rsp), %rdi
callq 0xceb70
jmp 0x11c893
movq 0xf8(%rsp), %rdi
movl $0x2, %esi
callq 0xd58a0
addq $0x108, %rsp            # imm = 0x108
retq
nop