-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add a tool for generate .pub file #1008
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1008 +/- ##
=======================================
Coverage 89.27% 89.27%
=======================================
Files 27 27
Lines 6958 6958
=======================================
Hits 6212 6212
Misses 708 708
Partials 38 38 ☔ View full report in Codecov by Sentry. |
9d5c973
to
911c761
Compare
c/c.pub
Outdated
unsafe.Pointer Pointer | ||
*FILE FilePtr | ||
FILE FILE | ||
uintptr SizeT | ||
uintptr IntptrT | ||
uintptr UintptrT | ||
int8 Int8T | ||
int16 Int16T | ||
int32 Int32T | ||
int64 Int64T | ||
uint8 Uint8T | ||
uint16 Uint16T | ||
uint32 Uint32T | ||
uint64 Uint64T | ||
LongLong IntmaxT | ||
UlongLong UintmaxT | ||
Option Option |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
llcppg.pub
file stores mappings from original C names to public Go names, not mappings from Go's typedef underlying types to typedef names"
Lines 39 to 41 in 9edaa8e
type FILE struct { | |
Unused [8]byte | |
} |
Lines 58 to 65 in 9edaa8e
type SizeT = uintptr | |
type IntptrT = uintptr | |
type UintptrT = uintptr | |
type Int8T = int8 | |
type Int16T = int16 | |
type Int32T = int32 | |
type Int64T = int64 |
For example, it would map something like:
llcppg.pub
FILE
size_t SizeT
intptr_t IntptrT
int8_t Int8T
int16_t Int16T
int32_t Int32T
int64_t Int64T
The left side shows the original type names in C language, while the right side shows the corresponding Go names after conversion. By reading this mapping, we can know what public Go name corresponds to each original C name.
When the C name and Go name are identical,like FILE
,only the C name is listed - no need for a second column
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
以后添加新类型必须写上c原始映射类型到注释,这个工作量太大。
type Int8T = int8 //cname:int8_t
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
对于llgo编译器来说,是否引入这个标识是仍然需要讨论的。
//cname:int8_t
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
也可以不加,但是那样的话需要做添加类型后,在c标准库的llcppg.pub上添加。添加//cname:注释可以提高代码可读性。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果添加上又2个好处,提高可读性和方便自动生成.pub文件。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
认同可以增加可读性,这里这个设计也就是会期望一个转换完成的Go包,会存在一个内含类型映射描述的Go文件,同时为了llcppg读取还会再存在一个llcppg.pub文件么。
如果是这样,那么在一个包中再存放额外一份映射信息会有一定的冗余。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
目前就是这样设计。独立一个pub文件是为了方便处理,为了独立性。否则处理导入的时候,要读取每个.go文件。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
目前就是这样设计。独立一个pub文件是为了方便处理,为了独立性。否则处理导入的时候,要读取每个.go文件。
@xushiwei 是否需要引入这个设计还是需要对齐一下的,这对于llgo来说会是新的规则,这里我认为存在两个相同的映射信息在同一个包中会存在冗余。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
目前就是这样设计。独立一个pub文件是为了方便处理,为了独立性。否则处理导入的时候,要读取每个.go文件。
@xushiwei 是否需要引入这个设计还是需要对齐一下的,这对于llgo来说会是新的规则,这里我认为存在两个相同的映射信息在同一个包中会存在冗余。
有些事情是不需要讨论的。如果卡的太死,就没有创新了。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the third-party library llcppg.pub, it will be automatically generated by llcppg
Therefore, we should not, nor can we, implement an automated tool to extract the original C source names to Go names into llcppg.pub from this converted Go file. (We cannot obtain the original C type names from this Go file, nor can we determine which types in the current Go file have corresponding types in the C language.) |
c/c.pub
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This mapping table from C source names to Go names should be 'llcppg.pub', not 'pkgname.pub',like this c.pub
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
最后会合并,然后删除临时的pub
b7a01ba
to
dd67aee
Compare
这里你可能误解我的意思了,我的意思是标准库的llcppg.pub的生成,是会由自动化工具来完成的(很有可能直接就由llcppg来支持了),但是当前这个PR实现的这个工具是无法满足这个自动化需求的,因为这个工具的输入是Go文件,其本身并不包含c语言的源信息,无法建立这个映射。 |
我并没有认为这里不需要自动化工具来转换标准库,只是现在标准库中的已经转换的类型并不多,为了目前的llcppg的进度推进可以先手动去创建系统库是llcppg.pub。 |
5dfc830
to
3da7a6f
Compare
你不是说查找所有c头文件,然后手工写入go对应的类型。然后再手工写pub文件?这个工具目的是为了减少手工工作。你不会连这个都反对。那你去尝试一下全部手工。 |
知道,这个工具不是还没有写完吗?为了实现递归生成临时生成。 |
工具不可能完美,为了减少手工工作。否则打开文件,第一个眼睛就晕了。 |
我没有认为标准库的类型都会由手动来进行转换并填入llcppg.pub。 |
c/c.go
Outdated
type SizeT = uintptr //cname:size_t | ||
|
||
type IntptrT = uintptr | ||
type IntptrT = uintptr //cname:intptr_t |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里你可能误解我的意思了,我的意思是标准库的llcppg.pub的生成,是会由自动化工具来完成的(很有可能直接就由llcppg来支持了),但是当前这个PR实现的这个工具是无法满足这个自动化需求的,因为这个工具的输入是Go文件,其本身并不包含c语言的源信息,无法建立这个映射。
工具不可能完美,为了减少手工工作。否则打开文件,第一个眼睛就晕了。
我并没有认为不需要自动化来处理标准库的类型转换和映射信息生成。
我有疑问的仅是这个Pr实现的工具最初的策略是输入为一个已经转换完成的Go文件,其本身不包含c语言原本文件的信息,无法构建这个映射信息(llcppg.pub)。
在当前这个更新中,我看到预期的输入是一个转换完毕的Go文件,并在对应类型末尾增加规定的注释来表明当前类型的来源,那么这个注释和类型就已经表示了映射信息,而这个映射信息在对应的自动化工具(比如llcppg)中是能获取并且输出的,也就能完成llcppg.pub文件的输出,无需再规定一个接口,让llcppg输出符合这个接口规定的类型和注释,再通过这个工具来提取出llcppg.pub。
这里如果我存在误解的话,可以同步一下当前工具的输入输出。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这工具不是针对llcppg已经生成的产物。针对无法用llcppg生成的c标准库。
98bb388
to
e055633
Compare
55033ff
to
9a95ffd
Compare
.pub 文件是哪里使用的?为什么需要这个? |
llcppg.pub 是用于 llcppg https://github.com/goplus/llcppg 进行依赖处理的,其描述了C的原始名称及对应的Go名称,在llcppg的转换中,声明了对应的dep llgo package,即会去对应Package中寻找对应的lccpg.pub并读取该文件,并对其对应的类型进行引用。 比如在某个转换工程中,声明依赖了 {
"deps":["github/goplus/llgo/c"]
} 那么就会寻找对应Package下的llcppg.pub文件,注册对应的类型映射 Lines 1 to 4 in 22524b0
那么对于C头文件中有使用FILE,size_t,intptr_t 等类型时,就可以通过这个保存的映射关系,找到实际引用的转换完成的Go类型 #include <stdio.h>
typedef struct Stream
{
FILE *f;
CallBack cb;
} Stream; import (
"github.com/goplus/llgo/c"
"unsafe"
)
type Stream struct {
F *c.FILE
Cb unsafe.Pointer
} |
…merge all llcppg.pub for subdirs to merge.llcppg.pub
.pub文件导出llpkg的c类型到go类型的映射关系,目的是为了llcppg转换的时候,在包的作用域内注入第三方包或标准库的类型信息。 |
605a39d
to
9ecfa16
Compare
No description provided.