009-call.scm (1117B)
1 ;; tests/cc-cg/09-call.scm — direct call to an in-TU function. 2 ;; Models: int triple(int x) { return x + x + x; } 3 ;; int main(void) { return triple(3); } 4 ;; Exercises cg-call's direct-label path (%call(&cc__triple)) and the 5 ;; one-arg ABI (a0 register-passed). 6 7 (let* ((cg (cg-init)) 8 (triple-fnty (%ctype 'fn 8 8 9 (cons %t-i32 (cons (list %t-i32) #f)))) 10 (triple-sym (%sym "triple" 'fn 'extern triple-fnty #f))) 11 ;; int triple(int x) { return x + x + x; } 12 (let* ((params (cg-fn-begin cg "triple" 13 (list (cons "x" %t-i32)) 14 %t-i32)) 15 (x* (cdr (car params)))) 16 (cg-push-sym cg x*) (cg-load cg) 17 (cg-push-sym cg x*) (cg-load cg) 18 (cg-binop cg 'add) 19 (cg-push-sym cg x*) (cg-load cg) 20 (cg-binop cg 'add) 21 (cg-return cg) 22 (cg-fn-end cg)) 23 ;; int main(void) { return triple(3); } 24 (cg-fn-begin cg "main" '() %t-i32) 25 (cg-push-sym cg triple-sym) 26 (cg-push-imm cg %t-i32 3) 27 (cg-call cg 1 #t) 28 (cg-return cg) 29 (cg-fn-end cg) 30 (write-bv-fd 1 (cg-finish cg)))