| |
| Posted by Dario in reply to Walter | PermalinkReply |
|
Dario
Posted in reply to Walter
| module test;
void loop(int[] a, int function(int) f)
{
for(uint i=0; i<a.length; i++)
a[i] = f(a[i]);
}
void main()
{
int[] a = new int[10];
loop(a, function int(int b) { return b+1; });
return 0;
}
_________________________________________
dmd -c -release -inline -O test.d
obj2asm test.obj
_________________________________________
_TEXT segment dword use32 public 'CODE' ;size is 0
_TEXT ends
_DATA segment para use32 public 'DATA' ;size is 0
_DATA ends
CONST segment para use32 public 'CONST' ;size is 0
CONST ends
_BSS segment para use32 public 'BSS' ;size is 0
_BSS ends
FLAT group
extrn _Dtest_loop_FAiPFiZiZv
includelib phobos.lib
extrn _main
extrn __acrtused_con
extrn __Dmain
extrn _Dtest_main__FiZi
extrn __d_new
_Dtest_loop_FAiPFiZiZv COMDAT flags=x0 attr=x0 align=x0
__Dmain COMDAT flags=x0 attr=x0 align=x0
_Dtest_main__FiZi COMDAT flags=x0 attr=x0 align=x0
_TEXT segment
assume CS:_TEXT
_TEXT ends
_DATA segment
_DATA ends
CONST segment
CONST ends
_BSS segment
_BSS ends
_Dtest_loop_FAiPFiZiZv comdat
assume CS:_Dtest_loop_FAiPFiZiZv
push EAX
push EAX
push EBX
xor EBX,EBX
push ESI
push EDI
;move function pointer in EDI
mov EDI,EAX
cmp 018h[ESP],EBX
je L30
mov 010h[ESP],EBX
mov EDX,01Ch[ESP]
mov EBX,018h[ESP]
mov ESI,EDX
mov EBX,010h[ESP]
L21: mov EAX,[EBX*4][ESI]
;call function (it's not inlined)
call EDI
mov [EBX*4][ESI],EAX
inc EBX
cmp EBX,018h[ESP]
jb L21
L30: pop EDI
pop ESI
pop EBX
add ESP,8
ret 8
_Dtest_loop_FAiPFiZiZv ends
__Dmain comdat
assume CS:__Dmain
L0: push EAX
push 4
push 0Ah
call near ptr __d_new
add ESP,8
push EDX
push EAX
;pass function pointer
mov EAX,offset FLAT:_Dtest_main__FiZi
;call function (it's not inlined)
call near ptr _Dtest_loop_FAiPFiZiZv
xor EAX,EAX
pop ECX
ret
__Dmain ends
_Dtest_main__FiZi comdat
assume CS:_Dtest_main__FiZi
inc EAX
ret
_Dtest_main__FiZi ends
end
|