// File: /workspace/github_c_makefile_star2_O0/ejunjsh[P]mycc/expr.c
// Function: primary
static struct ASTnode *primary(int ptp) {
  struct ASTnode *n;
  struct symtable *enumptr;
  struct symtable *varptr;
  int id;
  int type = 0;
  int size, class;
  struct symtable *ctype;

  switch (Token.token) {
  case T_STATIC:
  case T_EXTERN:
    fatal("Compiler doesn't support static or extern local declarations");
  case T_SIZEOF:
    // 跳过T_SIZEOF和保证我们有个左括号
    scan(&Token);
    if (Token.token != T_LPAREN)
      fatal("Left parenthesis expected after sizeof");
    scan(&Token);

    // 获取括号中的类型
    type = parse_stars(parse_type(&ctype, &class));

    // 获取类型大小
    size = typesize(type, ctype);
    rparen();

    // 创建一个叶子节点，整型字面量，值为类型大小
    return (mkastleaf(A_INTLIT, P_INT, NULL, NULL, size));

  case T_INTLIT:
    // 对于INTLIT， 直接创建个叶子节点
    // 如果在字符的范围，那就令它为P_CHAR
    if (Token.intvalue >= 0 && Token.intvalue < 256)
      n = mkastleaf(A_INTLIT, P_CHAR, NULL, NULL, Token.intvalue);
    else
      n = mkastleaf(A_INTLIT, P_INT, NULL, NULL, Token.intvalue);
    break;

  case T_STRLIT:
    // 对于STRLIT，生成汇编给它
    id = genglobstr(Text, 0);

    // 对于后面还有STRLIT，直接加在后面
    while (1) {
      scan(&Peektoken);
      if (Peektoken.token != T_STRLIT) break;
      genglobstr(Text, 1);
      scan(&Token);	// 跳过，才能偷窥下一个
    }

    // 现在建一个叶子节点，id就是字符的标签号
    genglobstrend();
    n = mkastleaf(A_STRLIT, pointer_to(P_CHAR), NULL, NULL, id);
    break;

  case T_IDENT:
    // 如果标识符是个枚举值
    // 返回一个A_INTLIT节点
    if ((enumptr = findenumval(Text)) != NULL) {
      n = mkastleaf(A_INTLIT, P_INT, NULL, NULL, enumptr->stu.st_posn);
      break;
    }

    // 检查标识符是否存在在符号表里面。如果是数组，设置rvalue为1
    if ((varptr = findsymbol(Text)) == NULL)
      fatals("Unknown variable or function", Text);
    switch (varptr->stype) {
    case S_VARIABLE:
      n = mkastleaf(A_IDENT, varptr->type, varptr->ctype, varptr, 0);
      break;
    case S_ARRAY:
      n = mkastleaf(A_ADDR, varptr->type, varptr->ctype, varptr, 0);
      n->rvalue = 1;
      break;
    case S_FUNCTION:
      // 函数调用，检查下个token是不是个左括号
      scan(&Token);
      if (Token.token != T_LPAREN)
	      fatals("Function name used without parentheses", Text);
      return (funccall());
    default:
      fatals("Identifier not a scalar or array variable", Text);
    }

    break;

  case T_LPAREN:
    return (paren_expression(ptp));

  default:
    fatals("Expecting a primary expression, got token", Token.tokstr);
  }

  // 扫描下一个token，返回叶子节点
  scan(&Token);
  return (n);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movl %edi, -0xc(%rbp)
movl $0x0, -0x30(%rbp)
leaq 0xc437(%rip), %rax      # 0x12530
movl (%rax), %eax
addl $-0x2b, %eax
movl %eax, %ecx
movq %rcx, -0x48(%rbp)
subl $0xe, %eax
ja 0x63ce
movq -0x48(%rbp), %rax
leaq 0x6d58(%rip), %rcx      # 0xce70
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x6eea(%rip), %rdi      # 0xd012
callq 0x8110
leaq 0xc3fc(%rip), %rdi      # 0x12530
callq 0x84c0
leaq 0xc3f0(%rip), %rax      # 0x12530
cmpl $0x39, (%rax)
je 0x6151
leaq 0x6f03(%rip), %rdi      # 0xd04f
callq 0x8110
leaq 0xc3d8(%rip), %rdi      # 0x12530
callq 0x84c0
leaq -0x40(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x42d0
movl %eax, %edi
callq 0x4a40
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %edi
movq -0x40(%rbp), %rsi
callq 0xb7c0
movl %eax, -0x34(%rbp)
callq 0x80b0
movl -0x34(%rbp), %r8d
movl $0x1a, %edi
movl $0x30, %esi
xorl %eax, %eax
movl %eax, %ecx
movq %rcx, %rdx
callq 0xad50
movq %rax, -0x8(%rbp)
jmp 0x63f9
leaq 0xc37e(%rip), %rax      # 0x12530
cmpl $0x0, 0x10(%rax)
jl 0x61ef
leaq 0xc371(%rip), %rax      # 0x12530
cmpl $0x100, 0x10(%rax)      # imm = 0x100
jge 0x61ef
leaq 0xc361(%rip), %rax      # 0x12530
movl 0x10(%rax), %r8d
movl $0x1a, %edi
movl $0x20, %esi
xorl %eax, %eax
movl %eax, %ecx
movq %rcx, %rdx
callq 0xad50
movq %rax, -0x18(%rbp)
jmp 0x6214
leaq 0xc33a(%rip), %rax      # 0x12530
movl 0x10(%rax), %r8d
movl $0x1a, %edi
movl $0x30, %esi
xorl %eax, %eax
movl %eax, %ecx
movq %rcx, %rdx
callq 0xad50
movq %rax, -0x18(%rbp)
jmp 0x63e5
leaq 0xc340(%rip), %rdi      # 0x12560
xorl %esi, %esi
callq 0x7590
movl %eax, -0x2c(%rbp)
leaq 0xc317(%rip), %rdi      # 0x12548
callq 0x84c0
leaq 0xc30b(%rip), %rax      # 0x12548
cmpl $0x34, (%rax)
je 0x6244
jmp 0x6263
leaq 0xc315(%rip), %rdi      # 0x12560
movl $0x1, %esi
callq 0x7590
leaq 0xc2d4(%rip), %rdi      # 0x12530
callq 0x84c0
jmp 0x622a
callq 0x75c0
movl $0x20, %edi
callq 0xb740
movl %eax, %esi
movl -0x2c(%rbp), %r8d
movl $0x1b, %edi
xorl %eax, %eax
movl %eax, %ecx
movq %rcx, %rdx
callq 0xad50
movq %rax, -0x18(%rbp)
jmp 0x63e5
leaq 0xc2c7(%rip), %rdi      # 0x12560
callq 0xa570
movq %rax, -0x20(%rbp)
cmpq $0x0, %rax
je 0x62ce
movq -0x20(%rbp), %rax
movl (%rax), %r8d
movl $0x1a, %edi
movl $0x30, %esi
xorl %eax, %eax
movl %eax, %ecx
movq %rcx, %rdx
callq 0xad50
movq %rax, -0x18(%rbp)
jmp 0x63e5
leaq 0xc28b(%rip), %rdi      # 0x12560
callq 0xa410
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
jne 0x62f7
leaq 0x6d8b(%rip), %rdi      # 0xd076
leaq 0xc26e(%rip), %rsi      # 0x12560
callq 0x7fc0
movq -0x28(%rbp), %rax
movl 0x20(%rax), %eax
movl %eax, -0x4c(%rbp)
testl %eax, %eax
je 0x631e
jmp 0x6307
movl -0x4c(%rbp), %eax
subl $0x1, %eax
je 0x6375
jmp 0x6311
movl -0x4c(%rbp), %eax
subl $0x2, %eax
je 0x6344
jmp 0x63ab
movq -0x28(%rbp), %rax
movl 0x10(%rax), %esi
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rdx
movq -0x28(%rbp), %rcx
movl $0x1c, %edi
xorl %r8d, %r8d
callq 0xad50
movq %rax, -0x18(%rbp)
jmp 0x63be
movq -0x28(%rbp), %rax
movl 0x10(%rax), %esi
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rdx
movq -0x28(%rbp), %rcx
movl $0x25, %edi
xorl %r8d, %r8d
callq 0xad50
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movl $0x1, 0x18(%rax)
jmp 0x63be
leaq 0xc1b4(%rip), %rdi      # 0x12530
callq 0x84c0
leaq 0xc1a8(%rip), %rax      # 0x12530
cmpl $0x39, (%rax)
je 0x63a0
leaq 0x6cff(%rip), %rdi      # 0xd093
leaq 0xc1c5(%rip), %rsi      # 0x12560
callq 0x7fc0
callq 0x66d0
movq %rax, -0x8(%rbp)
jmp 0x63f9
leaq 0x6d08(%rip), %rdi      # 0xd0ba
leaq 0xc1a7(%rip), %rsi      # 0x12560
callq 0x7fc0
jmp 0x63e5
movl -0xc(%rbp), %edi
callq 0x6760
movq %rax, -0x8(%rbp)
jmp 0x63f9
leaq 0xc15b(%rip), %rax      # 0x12530
movq 0x8(%rax), %rsi
leaq 0x6d04(%rip), %rdi      # 0xd0e4
callq 0x7fc0
leaq 0xc144(%rip), %rdi      # 0x12530
callq 0x84c0
movq -0x18(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)