Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Translate to Elisp from LLVM-IR code
;; loop1.el
;; --- library
(defun icmp-slt(a b)
(< a b))
;; --- target program
(defun %main()
;; %1
;; %total
;; %i
(let
((current 'label-0))
(while (not (eq current 'end))
(cond
((eq current 'label-0)
;;(message "label 0")
(setq %1* 0)
(setq %total* 0)
(setq %i* 0)
(setq current 'label-2))
((eq current 'label-2)
;;(message "<label>:2")
(setq %3 %i*)
(setq %4 (icmp-slt %3 1000000))
(when %4 (setq current 'label-5)) ;; label 5
(when (not %4) (setq current 'label-13)) ;; lable 13
)
((eq current 'label-5)
;;(message "<label>:5")
(setq %6 %i*)
(setq %7 (+ %6 1))
(setq %8 %total*)
(setq %9 (+ %8 %7))
(setq %total* %9)
(setq current 'label-10))
((eq current 'label-10)
;;(message "<label>:10")
(setq %11 %i*)
(setq %12 (+ %11 1))
(setq %i* %12)
(setq current 'label-2))
((eq current 'label-13)
;;(message "<label>:13")
(setq %14 %total*)
(message (format "total = %d" %14))
(setq %return 0)
(setq current 'end)) ;; END
))))
(%main)
;; loop2.el
;; --- library
(defun icmp-slt(a b)
(< a b))
;; --- target program
(defun %main()
;; %1
;; %total
;; %i
(let
((current 'label-0))
(while (not (eq current 'end))
(cond
((eq current 'label-0)
;;(message "label 0")
(setq %1* 0)
(setq %total* 0)
(setq %i* 0)
(setq current 'label-2))
((eq current 'label-2)
;;(message "<label>:2")
(setq %3 %i*)
(setq %4 (icmp-slt %3 1000000))
(when %4 (setq current 'label-5)) ;; label 5
(when (not %4) (setq current 'label-13)) ;; lable 13
)
((eq current 'label-5)
;;(message "<label>:5")
(setq %total* (+ (+ %i* 1) %total*))
(setq current 'label-10))
((eq current 'label-10)
;;(message "<label>:10")
(setq %i* (+ %i* 1))
(setq current 'label-2))
((eq current 'label-13)
;;(message "<label>:13")
(setq %14 %total*)
(message (format "total = %d" %14))
(setq %return 0)
(setq current 'end)) ;; END
))))
(%main)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment