a toy c compiler for macOS(m1) written in go.
macOS向け9ccのc実装(未完成)のgo再実装
参考:
- 低レイヤを知りたい人のためのCコンパイラ作成入門
- Jun's Homepage
- arm developer
- Overview of ARM64 ABI conventions
- modexp
- https://stackoverflow.com/questions/66098678/understanding-aarch64-assembly-function-call-how-is-stack-operated
memo:
- Zero Flag (Z)
- Carry Flag (C)
- Negative Flag (N)
- Overflow Flag (V)
program = toplevel*
toplevel = ident "(" (ident ","?)* ")" stmt
stmt = expr ";"
| "return" expr ";"
| "if" "(" expr ")" stmt ("else" stmt)?
| "while "(" expr ")" stmt
| "for" "(" expr? ";" expr? ";" expr? ")" stmt
| "{" stmt* "}"
expr = assign
assign = andor ("=" assign)?
andor = equality ("&&" equality | "||" equality)*
equality = relational ("==" relational | "!=" relational)*
relational = add ("<" add | "<=" add | ">" add | ">=" add)*
add = mul ("+" mul | "-" mul)*
mul = unary ("*" unary | "/" unary)*
unary = ("+" | "-")? primary
primary = num
| ident ("(" (expr ","?)* ")")?
| "(" expr ")"
| """ ascii* """
ascii = (0x21 - 0x7E)