Skip to content

Instantly share code, notes, and snippets.

@nomaddo
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nomaddo/ca27c49e0ad3c73df6e1 to your computer and use it in GitHub Desktop.
Save nomaddo/ca27c49e0ad3c73df6e1 to your computer and use it in GitHub Desktop.
機械語(一部)
/* fはloop1の内部でループしてる関数 */
camlExept2__f_1464:
.cfi_startproc
.L104:
/* クロージャの環境から定数を持ってきて */
movq 16(%rbx), %rdi
/* 比較 */
cmpq %rdi, %rax
/* 比較結果のフラグで分岐 */
jne .L103
/* もし成り立てば、今投げようとしてる例外の番号を取ってきてraxレジスタにコピー */
movq camlExept2@GOTPCREL(%rip), %rax
movq (%rax), %rax
/* r14レジスタ(おそらく直前の例外ハンドラの位置を覚えてるレジスタ)
の内容をレジスタスタックポインタにコピーしてretによりその場所に戻る */
movq %r14, %rsp
popq %r14
ret
.align 4
.L103:
/* 関数f1の引数に1たして、関数先頭にジャンプする
(末尾再帰最適化によりジャンプになってる) */
addq $2, %rax
jmp .L104
.cfi_endproc
.type camlExept2__f_1464,@function
.size camlExept2__f_1464,.-camlExept2__f_1464
.text
.align 16
.globl camlExept2__g_1468
/* gはloop2の内部でループしてる関数 */
camlExept2__g_1468:
.cfi_startproc
subq $8, %rsp
.cfi_adjust_cfa_offset 8
.L109:
/* クロージャの環境から定数を持ってきて */
movq 16(%rbx), %rdi
/* 比較 */
cmpq %rdi, %rax
/* 比較結果のフラグで分岐 */
jne .L108
/* もし成り立てば、今投げようとしてる例外の番号を取ってきてraxレジスタにコピー
おそらく例外を投げた時、その例外を区別するためのラベルをraxレジスタに覚えてる */
movq camlExept2@GOTPCREL(%rip), %rax
movq 8(%rax), %rax
/* r14レジスタ(おそらく直前の例外ハンドラの位置を覚えてるレジスタ)
の内容をレジスタスタックポインタにコピーしてretによりその場所に戻る */
movq %r14, %rsp
popq %r14
ret
.align 4
.L108:
/* try - withの中身の処理をする */
call .L106
/* raxレジスタをみてキャッチしたい例外の番号と一緒だったら */
movq camlExept2@GOTPCREL(%rip), %rbx
movq 8(%rbx), %rbx
cmpq %rbx, %rax
jne .L107
/* ユニット($1のこと)をraxレジスタにセットして戻る */
movq $1, %rax
addq $8, %rsp
.cfi_adjust_cfa_offset -8
ret
.cfi_adjust_cfa_offset 8
.align 4
.L107:
/* 番号が一緒でなければ更に前の例外ハンドラを遡るよ */
movq %r14, %rsp
popq %r14
ret
.align 4
.L106: ; try-withの中身の処理
.cfi_adjust_cfa_offset 8
pushq %r14 ; 前からあった内容をスタックに避難する
.cfi_adjust_cfa_offset 8
movq %rsp, %r14 ; 例外がキャッチされた時に戻る場所をr14に覚えておくよ
addq $2, %rax
call camlExept2__g_1468@PLT  ; 関数f1の引数に1たして、関数呼び出し
.L110:
popq %r14 ;try-withを抜けるときにスタックをpopして積んだものを除去
.cfi_adjust_cfa_offset -8
addq $8, %rsp
.cfi_adjust_cfa_offset -8
.L105:
addq $8, %rsp
.cfi_adjust_cfa_offset -8
ret
.cfi_adjust_cfa_offset 8
.cfi_endproc
.type camlExept2__g_1468,@function
.size camlExept2__g_1468,.-camlExept2__g_1468
.text
.align 16
.globl camlExept2__fun_2854
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment