Skip to content

Instantly share code, notes, and snippets.

@agrif
Created December 15, 2013 14:11
Show Gist options
  • Select an option

  • Save agrif/7973490 to your computer and use it in GitHub Desktop.

Select an option

Save agrif/7973490 to your computer and use it in GitHub Desktop.
a quick llvm-backed compiled lisp
; lisp source file
(defun incr (x)
(+ x 1))
(defun main ()
(incr 42))
; LLVM IR
; ModuleID = 'test'
define i32 @incr(i32 %x) {
entry:
%0 = add i32 %x, 1
ret i32 %0
}
define i32 @main() {
entry:
%0 = call i32 @incr(i32 42)
ret i32 %0
}
# GNU AS source (from llc)
.file "<stdin>"
.text
.globl incr
.align 16, 0x90
.type incr,@function
incr: # @incr
.cfi_startproc
# BB#0: # %entry
leal 1(%rdi), %eax
ret
.Ltmp0:
.size incr, .Ltmp0-incr
.cfi_endproc
.globl main
.align 16, 0x90
.type main,@function
main: # @main
.cfi_startproc
# BB#0: # %entry
pushq %rax
.Ltmp2:
.cfi_def_cfa_offset 16
movl $42, %edi
callq incr
popq %rdx
ret
.Ltmp3:
.size main, .Ltmp3-main
.cfi_endproc
.section ".note.GNU-stack","",@progbits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment