Recent

Author Topic: H2Pas can't handle EXP CALL from C header  (Read 3068 times)

Dibo

  • Hero Member
  • *****
  • Posts: 1057
H2Pas can't handle EXP CALL from C header
« on: January 14, 2025, 10:16:41 pm »
Hi,
Is there any special switch / param for H2Pas which can handle this declaration in C header:

Code: Pascal  [Select][+][-]
  1. EXP ryzen_access CALL init_ryzenadj();
  2.  
  3. EXP void CALL cleanup_ryzenadj(ryzen_access ry);
  4.  
  5. EXP enum ryzen_family get_cpu_family(ryzen_access ry);
  6. EXP int get_bios_if_ver(ryzen_access ry);
  7.  
  8. EXP int CALL init_table(ryzen_access ry);
  9. EXP uint32_t CALL get_table_ver(ryzen_access ry);
  10. EXP size_t CALL get_table_size(ryzen_access ry);
  11. EXP float* CALL get_table_values(ryzen_access ry);
  12. EXP int CALL refresh_table(ryzen_access ry);

I'm getting this output with commented lines:
Code: Pascal  [Select][+][-]
  1. (* error
  2. EXP ryzen_access CALL init_ryzenadj();
  3.  in declarator_list *)
  4. (* error
  5. EXP void CALL cleanup_ryzenadj(ryzen_access ry);
  6. in declaration at line 67 *)
  7. (* error
  8. EXP enum ryzen_family get_cpu_family(ryzen_access ry);
  9. in declaration at line 69 *)
  10. (* error
  11. EXP int get_bios_if_ver(ryzen_access ry);
  12. in declaration at line 70 *)
  13. (* error
  14. EXP int CALL init_table(ryzen_access ry);
  15. in declaration at line 72 *)
  16. (* error
  17. EXP uint32_t CALL get_table_ver(ryzen_access ry);
  18.  in declarator_list *)

AFIK h2pas is quite old tool, I'm using the one from FPC installator. Is there anything updated or similar? I'm familiar with C lang and can convert it manually but there is a lot of methods

DragoRosso

  • Guest
Re: H2Pas can't handle EXP CALL from C header
« Reply #1 on: January 14, 2025, 10:24:02 pm »
You can try CHET: https://github.com/neslib/Chet

I use it with several project in C and it gives good results.

It was write about Delphi, but I think that works also for Lazarus.

Dibo

  • Hero Member
  • *****
  • Posts: 1057
Re: H2Pas can't handle EXP CALL from C header
« Reply #2 on: January 14, 2025, 10:30:23 pm »
Thanks! I'm currently on linux machine and can't test it because I see it use some libclang.dll and other windows runtime library but I'll check this tomorrow on some window machine

Thaddy

  • Hero Member
  • *****
  • Posts: 18712
  • To Europe: simply sell USA bonds: dollar collapses
Re: H2Pas can't handle EXP CALL from C header
« Reply #3 on: January 15, 2025, 06:09:54 am »
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

Seenkao

  • Hero Member
  • *****
  • Posts: 718
    • New ZenGL.
Re: H2Pas can't handle EXP CALL from C header
« Reply #4 on: January 15, 2025, 10:30:21 am »
Посмотрите видео. Извиняюсь что на русском. Перематывайте видео вперёд (начало примерно на 3-й минуте), потому что делал видео на скорую руку.
По вашему коду, попробуйте убрать "EXP".

Google translate:
Watch video. Sorry it's in Russian. Fast forward the video (starts at about 3 minutes), because I made the video in a hurry.
According to your code, try removing "EXP".
Rus: Стремлюсь к созданию минимальных и достаточно быстрых приложений.

Eng: I strive to create applications that are minimal and reasonably fast.
Working on ZenGL

Thaddy

  • Hero Member
  • *****
  • Posts: 18712
  • To Europe: simply sell USA bonds: dollar collapses
Re: H2Pas can't handle EXP CALL from C header
« Reply #5 on: January 15, 2025, 05:39:12 pm »
EXP is in this case just one of those do nothing thingies that C is famous for?
You can safely remove it using search and replace with '' ?
(btw, I can read Russian, even understand it ;) , and can reply in Russian but it would be a better idea to present the English language version first.)
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12601
  • FPC developer.
Re: H2Pas can't handle EXP CALL from C header
« Reply #6 on: January 15, 2025, 05:49:48 pm »
EXP is probably some macro that combines some directives (like "export this function", akin to the Pascal "exports" reserved word) and the calling convention. Quite often ifdefed in a platform specific matter (e.g. _cdecl for *nix and _stdcall for Windows).


Dibo

  • Hero Member
  • *****
  • Posts: 1057
Re: H2Pas can't handle EXP CALL from C header
« Reply #7 on: January 15, 2025, 07:24:46 pm »
You can try CHET: https://github.com/neslib/Chet

I use it with several project in C and it gives good results.

It was write about Delphi, but I think that works also for Lazarus.
I get multiple outputs that it can't recognize uint32_t type and convertion was aborted. I could not find any option for this. But this tool looks very interesting and I'll be keep it in my mind in future. Thanks a lot!

@Seenkao, @Thaddy, @marcov: Indeed it was such simple (I also had to remove CALL clause). Everything converted except this one:
Code: Pascal  [Select][+][-]
  1.     var
  2.       init_ryzenadj : function:Tryzen_access;cdecl;
  3.       cleanup_ryzenadj : procedure(ry:Tryzen_access);cdecl;
  4. (* error
  5. enum ryzen_family get_cpu_family(ryzen_access ry);
  6. in declaration at line 69 *)
  7.       get_bios_if_ver : function(ry:Tryzen_access):Tcint;cdecl;
  8.       init_table : function(ry:Tryzen_access):Tcint;cdecl;  
     
But that is a peanut, everything else converted even into dynamic loading as I wanted. Thank you guys
« Last Edit: January 15, 2025, 07:30:53 pm by Dibo »

DragoRosso

  • Guest
Re: H2Pas can't handle EXP CALL from C header
« Reply #8 on: January 15, 2025, 09:43:25 pm »
I get multiple outputs that it can't recognize uint32_t type and convertion was aborted. I could not find any option for this. But this tool looks very interesting and I'll be keep it in my mind in future. Thanks a lot!

In my projects, in  the include files where is present "uint32_t" I have at least this declaration:

Code: Pascal  [Select][+][-]
  1. typedef unsigned __int32 uint32_t

Dibo

  • Hero Member
  • *****
  • Posts: 1057
Re: H2Pas can't handle EXP CALL from C header
« Reply #9 on: January 15, 2025, 10:01:03 pm »
Indeed, I could force that with typedef. I will try it next time. Anyway thanks for CHET, google evend didn't show it in results (instead AI sites)

Thaddy

  • Hero Member
  • *****
  • Posts: 18712
  • To Europe: simply sell USA bonds: dollar collapses
Re: H2Pas can't handle EXP CALL from C header
« Reply #10 on: January 16, 2025, 05:46:45 am »
uint32_t should be in the unit ctypes but isn't.
Almost all *_t types seem misssing.
« Last Edit: January 16, 2025, 05:52:43 am by Thaddy »
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

TRon

  • Hero Member
  • *****
  • Posts: 4377
Re: H2Pas can't handle EXP CALL from C header
« Reply #11 on: January 16, 2025, 06:08:24 am »
uint32_t should be in the unit ctypes but isn't.
Almost all *_t types seem misssing.
replace with cuintXX and cintXX. There are still missing such as size_t and offset_t though size_t can be found in unix, baseunix or unixtypes while offset_t seems mia.
« Last Edit: January 16, 2025, 06:13:28 am by TRon »
Today is tomorrow's yesterday.

Thaddy

  • Hero Member
  • *****
  • Posts: 18712
  • To Europe: simply sell USA bonds: dollar collapses
Re: H2Pas can't handle EXP CALL from C header
« Reply #12 on: January 16, 2025, 06:19:06 am »
size_t and offset_t though size_t can be found in unix, baseunix or unixtypes while offset_t seems mia.
So is there any relation to unix ?(answer: not at all)
I see what you mean and that is the wrong place.
These should all be in a unit like ctypes, since it is notational related to the programming language C and not any OS.
« Last Edit: January 16, 2025, 06:23:23 am by Thaddy »
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

TRon

  • Hero Member
  • *****
  • Posts: 4377
Re: H2Pas can't handle EXP CALL from C header
« Reply #13 on: January 16, 2025, 06:20:17 am »
No argument from me there Thaddy as I completely agree.
Today is tomorrow's yesterday.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12601
  • FPC developer.
Re: H2Pas can't handle EXP CALL from C header
« Reply #14 on: January 16, 2025, 10:14:58 am »
size_t and offset_t though size_t can be found in unix, baseunix or unixtypes while offset_t seems mia.
So is there any relation to unix ?(answer: not at all)

size_t is C (stddef.h), but offset_t is to my best knowledge a POSIX type, so platform dependent.

 

TinyPortal © 2005-2018