// File: jstaursky[P]hutch/src/Sleigh/semantics.cc
// Function: ConstTpl::fix(ParserWalker const&) const
uintb ConstTpl::fix(const ParserWalker &walker) const

{ // Get the value of the ConstTpl in context
  // NOTE: if the property is dynamic this returns the property
  // of the temporary storage
  switch(type) {
  case j_start:
    return walker.getAddr().getOffset(); // Fill in starting address placeholder with real address
  case j_next:
    return walker.getNaddr().getOffset(); // Fill in next address placeholder with real address
  case j_flowref:
    return walker.getRefAddr().getOffset();
  case j_flowref_size:
    return walker.getRefAddr().getAddrSize();
  case j_flowdest:
    return walker.getDestAddr().getOffset();
  case j_flowdest_size:
    return walker.getDestAddr().getAddrSize();
  case j_curspace_size:
    return walker.getCurSpace()->getAddrSize();
  case j_curspace:
    return (uintb)(uintp)walker.getCurSpace();
  case handle:
    {
      const FixedHandle &hand(walker.getFixedHandle(value.handle_index));
      switch(select) {
      case v_space:
	if (hand.offset_space == (AddrSpace *)0)
	  return (uintb)(uintp)hand.space;
	return (uintb)(uintp)hand.temp_space;
      case v_offset:
	if (hand.offset_space==(AddrSpace *)0)
	  return hand.offset_offset;
	return hand.temp_offset;
      case v_size:
	return hand.size;
      case v_offset_plus:
	if (hand.space != walker.getConstSpace()) { // If we are not a constant
	  if (hand.offset_space==(AddrSpace *)0)
	    return hand.offset_offset + (value_real&0xffff); // Adjust offset by truncation amount
	  return hand.temp_offset + (value_real&0xffff);
	}
	else {			// If we are a constant, we want to return a shifted value
	  uintb val;
	  if (hand.offset_space==(AddrSpace *)0)
	    val = hand.offset_offset;
	  else
	    val = hand.temp_offset;
	  val >>= 8 * (value_real>>16);
	  return val;
	}
      }
      break;
    }
  case j_relative:
  case real:
    return value_real;
  case spaceid:
    return (uintb)(uintp)value.spaceid;
  }
  return 0;			// Should never reach here
}

// Assembly:
subq $0x48, %rsp
movq %rdi, 0x38(%rsp)
movq %rsi, 0x30(%rsp)
movq 0x38(%rsp), %rax
movq %rax, 0x10(%rsp)
movl (%rax), %eax
movq %rax, 0x18(%rsp)
subq $0xb, %rax
ja 0x115114
movq 0x18(%rsp), %rax
leaq 0x7324f(%rip), %rcx     # 0x1880d4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x30(%rsp), %rdi
callq 0xcee30
movq %rax, %rdi
callq 0xe03b0
movq %rax, 0x40(%rsp)
jmp 0x11511d
movq 0x30(%rsp), %rdi
callq 0xdad30
movq %rax, %rdi
callq 0xe03b0
movq %rax, 0x40(%rsp)
jmp 0x11511d
movq 0x30(%rsp), %rdi
callq 0xd1300
movq %rax, %rdi
callq 0xe03b0
movq %rax, 0x40(%rsp)
jmp 0x11511d
movq 0x30(%rsp), %rdi
callq 0xd1300
movq %rax, %rdi
callq 0xdcb60
cltq
movq %rax, 0x40(%rsp)
jmp 0x11511d
movq 0x30(%rsp), %rdi
callq 0xd9090
movq %rax, %rdi
callq 0xe03b0
movq %rax, 0x40(%rsp)
jmp 0x11511d
movq 0x30(%rsp), %rdi
callq 0xd9090
movq %rax, %rdi
callq 0xdcb60
cltq
movq %rax, 0x40(%rsp)
jmp 0x11511d
movq 0x30(%rsp), %rdi
callq 0xdadc0
movq %rax, %rdi
callq 0xd7510
movl %eax, %eax
movq %rax, 0x40(%rsp)
jmp 0x11511d
movq 0x30(%rsp), %rdi
callq 0xdadc0
movq %rax, 0x40(%rsp)
jmp 0x11511d
movq 0x10(%rsp), %rax
movq 0x30(%rsp), %rdi
movl 0x8(%rax), %esi
callq 0xdb860
movq %rax, %rcx
movq 0x10(%rsp), %rax
movq %rcx, 0x28(%rsp)
movl 0x18(%rax), %eax
movq %rax, 0x8(%rsp)
subq $0x3, %rax
ja 0x1150f2
movq 0x8(%rsp), %rax
leaq 0x7315b(%rip), %rcx     # 0x188104
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x28(%rsp), %rax
cmpq $0x0, 0x10(%rax)
jne 0x114fd0
movq 0x28(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x40(%rsp)
jmp 0x11511d
movq 0x28(%rsp), %rax
movq 0x28(%rax), %rax
movq %rax, 0x40(%rsp)
jmp 0x11511d
movq 0x28(%rsp), %rax
cmpq $0x0, 0x10(%rax)
jne 0x115002
movq 0x28(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, 0x40(%rsp)
jmp 0x11511d
movq 0x28(%rsp), %rax
movq 0x30(%rax), %rax
movq %rax, 0x40(%rsp)
jmp 0x11511d
movq 0x28(%rsp), %rax
movl 0x8(%rax), %eax
movq %rax, 0x40(%rsp)
jmp 0x11511d
movq 0x28(%rsp), %rax
movq (%rax), %rax
movq %rax, (%rsp)
movq 0x30(%rsp), %rdi
callq 0xd04d0
movq %rax, %rcx
movq (%rsp), %rax
cmpq %rcx, %rax
je 0x11509e
movq 0x28(%rsp), %rax
cmpq $0x0, 0x10(%rax)
jne 0x11507b
movq 0x10(%rsp), %rcx
movq 0x28(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x10(%rcx), %rcx
andq $0xffff, %rcx           # imm = 0xFFFF
addq %rcx, %rax
movq %rax, 0x40(%rsp)
jmp 0x11511d
movq 0x10(%rsp), %rcx
movq 0x28(%rsp), %rax
movq 0x30(%rax), %rax
movq 0x10(%rcx), %rcx
andq $0xffff, %rcx           # imm = 0xFFFF
addq %rcx, %rax
movq %rax, 0x40(%rsp)
jmp 0x11511d
movq 0x28(%rsp), %rax
cmpq $0x0, 0x10(%rax)
jne 0x1150ba
movq 0x28(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, 0x20(%rsp)
jmp 0x1150c8
movq 0x28(%rsp), %rax
movq 0x30(%rax), %rax
movq %rax, 0x20(%rsp)
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rcx
shrq $0x10, %rcx
shlq $0x3, %rcx
movq 0x20(%rsp), %rax
shrq %cl, %rax
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rax
movq %rax, 0x40(%rsp)
jmp 0x11511d
jmp 0x115114
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rax
movq %rax, 0x40(%rsp)
jmp 0x11511d
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x40(%rsp)
jmp 0x11511d
movq $0x0, 0x40(%rsp)
movq 0x40(%rsp), %rax
addq $0x48, %rsp
retq
nopw (%rax,%rax)