Create a gist now

Instantly share code, notes, and snippets.

Translate to Scheme from LLVM-IR code
;; simple loop program for Gauche
;; --- library
(define (icmp-slt a b)
(< a b))
;; --- target program
(define (main argv)
;; %1
;; %total
;; %i
(let
((current 'label-0)
(%1* 0)
(%total* 0)
(%i* 0)
(%1 0) (%2 0) (%3 0) (%4 0) (%5 0) (%6 0) (%7 0) (%8 0) (%9 0) (%10 0)
(%11 0) (%12 0) (%13 0) (%14 0) (%15 0) (%16 0) (%17 0) (%18 0) (%19 0) (%20 0)
(%return 0))
(while (not (eq? current 'end))
(cond
((eq? current 'label-0)
;;(message "label 0")
(set! %1* 0)
(set! %total* 0)
(set! %i* 0)
(set! current 'label-2))
((eq? current 'label-2)
;;(message "<label>:2")
(set! %3 %i*)
(set! %4 (icmp-slt %3 (* 1000000 10)))
(when %4 (set! current 'label-5)) ;; label 5
(when (not %4) (set! current 'label-13)) ;; lable 13
)
((eq? current 'label-5)
;;(message "<label>:5")
(set! %6 %i*)
(set! %7 (+ %6 1))
(set! %8 %total*)
(set! %9 (+ %8 %7))
(set! %total* %9)
(set! current 'label-10))
((eq? current 'label-10)
;;(message "<label>:10")
(set! %11 %i*)
(set! %12 (+ %11 1))
(set! %i* %12)
(set! current 'label-2))
((eq? current 'label-13)
;;(message "<label>:13")
(set! %14 %total*)
(display (format "total = ~d" %14)) (newline)
(set! %return 0)
(set! current 'end)) ;; END
))
%return))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment