ocaml_如何获取由ocamlopt生成的OCaml代码的汇编代码?

ocaml

How to get the native assembly code (e.g. x86-64 asm) for OCaml code generated by the native ocamlopt compiler?

如何获取本机ocamlopt编译器生成的OCaml代码的本机汇编代码(例如x86-64 asm)?

To get the assembly code for an OCaml program, add these parameters to ocamlopt:

要获取OCaml程序的汇编代码,请将这些参数添加到ocamlopt

-S -inline 20 -nodynlink

An example is as follows.

一个例子如下。

The OCaml program:

OCaml程序:

$ cat not.ml 
let not x = 
    ((x - 1) lxor (x land (x - 1))) lsr 62
;;

not 0;;

not 1;;

not (-1);;

not (1 lsl 62);;

Compile the code:

编译代码:

$ ocamlopt -S -inline 20 -nodynlink not.ml -o not.opt

The assembly code generated:

生成的汇编代码:

$ cat not.s 
	.data
	.globl	camlNot__data_begin
camlNot__data_begin:
	.text
	.globl	camlNot__code_begin
camlNot__code_begin:
	.data
	.quad	1024
	.globl	camlNot
camlNot:
	.space	8
	.data
	.quad	2295
camlNot__1:
	.quad	camlNot__not_1008
	.quad	3
	.text
	.align	16
	.globl	camlNot__not_1008
camlNot__not_1008:
	.cfi_startproc
.L100:
	movq	%rax, %rdi
	addq	$-2, %rdi
	movq	%rax, %rbx
	andq	%rdi, %rbx
	addq	$-2, %rax
	xorq	%rbx, %rax
	orq	$1, %rax
	shrq	$62, %rax
	orq	$1, %rax
	ret
	.cfi_endproc
	.type	camlNot__not_1008,@function
	.size	camlNot__not_1008,.-camlNot__not_1008
	.text
	.align	16
	.globl	camlNot__entry
camlNot__entry:
	.cfi_startproc
.L101:
	leaq	camlNot__1(%rip), %rax
	movq	%rax, camlNot(%rip)
	movq	$3, %rax
	movq	$1, %rax
	movq	$1, %rax
	movq	$1, %rax
	movq	$1, %rax
	ret
	.cfi_endproc
	.type	camlNot__entry,@function
	.size	camlNot__entry,.-camlNot__entry
	.data
	.text
	.globl	camlNot__code_end
camlNot__code_end:
	.data
	.globl	camlNot__data_end
camlNot__data_end:
	.long	0
	.globl	camlNot__frametable
camlNot__frametable:
	.quad	0
	.section .note.GNU-stack,"",%progbits

Here, camlNot__not_1008 is the assembly for the function not. caml is the prefix. Not is the module/file name.

在这里, camlNot__not_1008是该函数的组件notcaml是前缀。 Not模块/文件名。

Answered by anonymous.
匿名回答。

翻译自: https://www.systutorials.com/how-to-get-the-assembly-code-for-ocaml-code-generated-by-ocamlopt/

ocaml

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值