Guest User

two calls to external lib in one FFI call using NativeBoost

a guest
May 28th, 2012
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. test3
  2.  
  3. "__gmpz_add (mpz_t gmpz, mpz_t op1, mpz_t op2)"
  4. <primitive: #primitiveNativeCall module: #NativeBoostPlugin>
  5.  
  6. ^ NBFFICallout cdecl: #( void (mpz_t gmpz, mpz_t gmpz, mpz_t gmpz, ))
  7. emitCall: [:gen | | asm proxy gmpzAddFcnPtr sa sb sc|
  8. asm := gen asm.
  9. proxy := gen proxy.
  10.  
  11.  
  12. sa := gen reserveTemp.
  13. sb := gen reserveTemp.
  14. sc := gen reserveTemp.
  15.  
  16. "save args"
  17. asm
  18. mov: asm ESP ptr to: asm EAX;
  19. mov: asm EAX to: sa; "a -> sa "
  20. mov: asm ESP ptr + 4 to: asm EAX;
  21. mov: asm EAX to: sb; "b -> sb"
  22. mov: asm ESP ptr + 8 to: asm EAX;
  23. mov: asm EAX to: sc . "c -> sc"
  24.  
  25.  
  26. gmpzAddFcnPtr := self nbGetSymbolAddress: '__gmpz_add' module:self nbLibraryNameOrHandle.
  27. asm mov: gmpzAddFcnPtr asUImm to: asm EAX.
  28. asm call: asm EAX.
  29.  
  30. asm cdeclCall: [:call |
  31.  
  32. "push function arguments (note, cdecl push order is from right to left )"
  33. asm
  34. push: sc;
  35. push: sb;
  36. push: sa.
  37.  
  38.  
  39. "get a function addres"
  40. gmpzAddFcnPtr := self nbGetSymbolAddress: '__gmpz_add' module:self nbLibraryNameOrHandle.
  41.  
  42.  
  43. "put a function address into EAX, and call function"
  44.  
  45. asm mov: gmpzAddFcnPtr asUImm to: asm EAX.
  46. asm call: asm EAX.
  47.  
  48.  
  49. ] alignment: gen stackAlignment .
  50.  
  51. ]
Advertisement
Add Comment
Please, Sign In to add comment