Skip to content
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

Failing to run c2go on kilo.c #25

Open
4 of 13 tasks
yml opened this issue Apr 14, 2017 · 7 comments
Open
4 of 13 tasks

Failing to run c2go on kilo.c #25

yml opened this issue Apr 14, 2017 · 7 comments

Comments

@yml
Copy link

yml commented Apr 14, 2017

While trying out this project I tried and fail to run it against kilo.c

c2go kilo.c 
panic: could not match regexp '(?P<address>[0-9a-fx]+) <(?P<position>.*)>(?P<position2> [^ ]+)?(?P<referenced> referenced)? (?P<name>\w+?) '(?P<type>.+?)'' with string 'FieldDecl 0x21391d8 <line:75:2, col:15> col:2 'unsigned int''

goroutine 1 [running]:
main.groupsFromRegex(0x5228cf, 0x6f, 0xc4203e35aa, 0x3c, 0x1)
	/home/yml/gopath/src/github.com/elliotchance/c2go/ast.go:150 +0x392
main.parseFieldDecl(0xc4203e35aa, 0x3c, 0x51aa8a)
	/home/yml/gopath/src/github.com/elliotchance/c2go/field_decl.go:26 +0x4e
main.Parse(0xc4203e35aa, 0x3c, 0x42, 0xc4200af6e0)
	/home/yml/gopath/src/github.com/elliotchance/c2go/ast.go:69 +0xb9c
main.convertLinesToNodes(0xc4200ba000, 0x2631, 0x2631, 0xc4200ba000, 0x2631, 0x2631)
	/home/yml/gopath/src/github.com/elliotchance/c2go/main.go:38 +0x1d8
main.Start(0xc420076080, 0x2, 0x2, 0x0, 0x0)
	/home/yml/gopath/src/github.com/elliotchance/c2go/main.go:143 +0x289
main.main()
	/home/yml/gopath/src/github.com/elliotchance/c2go/main.go:171 +0x49

I have close to no idea what I am doing and running c2go on this kind of project is may be out of scope. Thank you for opening up this project.

TODO:

  • <termios.h>
  • <stdlib.h>
  • <stdio.h>
  • <errno.h>
  • <string.h>
  • <stdlib.h>
  • <ctype.h>
  • <sys/types.h>
  • <sys/ioctl.h>
  • <sys/time.h>
  • <unistd.h>
  • <stdarg.h>
  • <fcntl.h>
@yml yml changed the title Failing to run on kilo.c Failing to run c2go on kilo.c Apr 14, 2017
@elliotchance
Copy link
Owner

Hi @yml that is a really good example to play with (I will definitely keep this in mind in the future), but unfortunately c2go does not have enough features to be able to process that codebase... at least not yet!

The AST (the structure that describes the C code) is ingested from the clang output. There are still particular lines, like this one from the error message...

FieldDecl 0x21391d8 <line:75:2, col:15> col:2 'unsigned int'

...that it cannot yet understand. Here are the test cases for FieldDecl. Once a new test case is added, and this regex is updated it should be able to understand this input.

Like I said, we are still far away from being able to compile kilo.c, but one step at a time...

@elliotchance
Copy link
Owner

I believe this is fixed with #31

@elliotchance elliotchance added this to the Future Release milestone Apr 23, 2017
@yml
Copy link
Author

yml commented Nov 17, 2017

There has been some progress on this front:

yml@kodi$ c2go transpile kilo.c
~/Devs/kilo master
yml@kodi$ ll
total 188
-rw-r--r-- 1 yml yml 40314 avril 14  2017 kilo.c
-rw-r--r-- 1 yml yml 57703 nov.  17 09:38 kilo.go
-rw-r--r-- 1 yml yml  1330 avril 14  2017 LICENSE
-rw-r--r-- 1 yml yml    91 avril 14  2017 Makefile
-rw-r--r-- 1 yml yml   828 avril 14  2017 README.md
-rw-r--r-- 1 yml yml   204 avril 14  2017 TODO
yml@kodi$ go run kilo.
kilo.c   kilo.go  
~/Devs/kilo master
yml@kodi$ go run kilo.go
# command-line-arguments
./kilo.go:1006:79: cannot use 0 (type int) as type []byte in array or slice literal
./kilo.go:1007: cannot use 0 (type int) as type []byte in array or slice literal
./kilo.go:1013:3: undefined: tcsetattr
./kilo.go:1025:19: undefined: isatty
./kilo.go:1028:2: undefined: atexit
./kilo.go:1029:5: undefined: tcgetattr
./kilo.go:1033:14: invalid operation: raw.c_iflag &= ^(2 | 256 | 16 | 32 | 1024) (mismatched types tcflag_t and int)
./kilo.go:1034:14: invalid operation: raw.c_oflag &= ^1 (mismatched types tcflag_t and int)
./kilo.go:1035:14: invalid operation: raw.c_cflag |= 48 (mismatched types tcflag_t and int)
./kilo.go:1036:14: invalid operation: raw.c_lflag &= ^(8 | 2 | 32768 | 1) (mismatched types tcflag_t and int)
./kilo.go:1036:14: too many errors

@elliotchance
Copy link
Owner

Thanks for the update @yml. There is still a lot of work to get kilo.c working, but we definitely are making progress 👍

@Konstantin8105
Copy link
Contributor

Konstantin8105 commented Dec 12, 2017

Warnings for present version:

// Warning (FieldDecl): 69: I couldn't find an appropriate Go type for the C type '(anonymous struct at /usr/include/x86_64-l
inux-gnu/bits/waitstatus.h:69:5)'.
// Warning (FieldDecl): 84: I couldn't find an appropriate Go type for the C type '(anonymous struct at /usr/include/x86_64-l
inux-gnu/bits/waitstatus.h:84:5)'.
// Warning (RecordDecl): 66: could not determine the size of type `union wait` for that reason: cannot determine size of: `st
ruct (anonymous struct at /usr/include/x86_64-linux-gnu/bits/waitstatus.h:84:5)`
// Warning (TransparentUnionAttr): 71: could not parse &{43525168 {/usr/include/stdlib.h 71 0 35 0 } []}
// Warning (FieldDecl): 141: I couldn't find an appropriate Go type for the C type '(anonymous struct at /usr/include/x86_64-
linux-gnu/bits/pthreadtypes.h:141:3)'.
// Warning (FieldDecl): 177: I couldn't find an appropriate Go type for the C type '(anonymous struct at /usr/include/x86_64-
linux-gnu/bits/pthreadtypes.h:177:3)'.
// Warning (TypedefDecl): 741: function pointers are not supported : 'int ( void *, void *)'
// Warning (TypedefDecl): 748: function pointers are not supported : 'int ( void *, void *, void *)'
// Warning (FieldDecl): 85: probably an incorrect type translation 3
// Warning (TypedefDecl): 333: function pointers are not supported : '__ssize_t (void *, char *, size_t)'
// Warning (TypedefDecl): 341: function pointers are not supported : '__ssize_t (void *, char *, size_t)'
// Warning (TypedefDecl): 350: function pointers are not supported : 'int (void *, __off64_t *, int)'
// Warning (TypedefDecl): 353: function pointers are not supported : 'int (void *)'
// Warning (EnumDecl): 46: Add support of continues counter for type : *ast.ParenExpr
// Warning (EnumDecl): 46: Add support of continues counter for type : *ast.ParenExpr
// Warning (EnumDecl): 46: Add support of continues counter for type : *ast.ParenExpr
// Warning (EnumDecl): 46: Add support of continues counter for type : *ast.ParenExpr
// Warning (EnumDecl): 46: Add support of continues counter for type : *ast.ParenExpr
// Warning (EnumDecl): 46: Add support of continues counter for type : *ast.ParenExpr
// Warning (EnumDecl): 46: Add support of continues counter for type : *ast.ParenExpr
// Warning (EnumDecl): 46: Add support of continues counter for type : *ast.ParenExpr
// Warning (EnumDecl): 46: Add support of continues counter for type : *ast.ParenExpr
// Warning (EnumDecl): 46: Add support of continues counter for type : *ast.ParenExpr
// Warning (EnumDecl): 46: Add support of continues counter for type : *ast.ParenExpr
// Warning (EnumDecl): 46: Add support of continues counter for type : *ast.ParenExpr
// Warning (EnumDecl): 71: Add support of continues counter for type : *ast.BinaryExpr
// Warning (EnumDecl): 533: Add support of continues counter for type : *ast.BasicLit
// Warning (EnumDecl): 533: Add support of continues counter for type : *ast.BasicLit
// Warning (CallExpr): 209: function pointers are not supported : 'void (void)'
// Warning (UnaryExprOrTypeTraitExpr): 522: cannot determine size of: `struct editorSyntax [1]`
// Warning (UnaryExprOrTypeTraitExpr): 522: cannot determine size of: `struct editorSyntax':'struct editorSyntax`
// Warning (UnaryExprOrTypeTraitExpr): 572: cannot determine size of: `erow`
// Warning (UnaryExprOrTypeTraitExpr): 572: cannot determine size of: `erow`
// Error (BinaryOperator): 572: cannot determine size of: `erow`
// Warning (UnaryExprOrTypeTraitExpr): 574: cannot determine size of: `erow':'struct erow`
// Warning (UnaryExprOrTypeTraitExpr): 605: cannot determine size of: `erow':'struct erow`
// Warning (BinaryOperator): 909: int
// Warning (CallExpr): 980: Cannot resolve function : I couldn't find an appropriate Go type for the C type '...'.
// Error (CallExpr): 980: I couldn't find an appropriate Go type for the C type '...'.
// Warning (CallExpr): 982: I couldn't find an appropriate Go type for the C type '[]__va_list_tag'.
// Warning (BinaryOperator): 1017: int
// Warning (BinaryOperator): 1029: int
// Warning (BinaryOperator): 1034: int

@Konstantin8105
Copy link
Contributor

After #469:

// Warning (FieldDecl): 69: I couldn't find an appropriate Go type for the C type '(anonymous struct at /usr/include/x86_64-linux-gnu/bits/waitstatus.h:69:5)'.
// Warning (FieldDecl): 84: I couldn't find an appropriate Go type for the C type '(anonymous struct at /usr/include/x86_64-linux-gnu/bits/waitstatus.h:84:5)'.
// Warning (RecordDecl): 66: could not determine the size of type `union wait` for that reason: cannot determine size of: ``
// Warning (TransparentUnionAttr): 71: could not parse &{32060464 {/usr/include/stdlib.h 71 0 35 0 } []}
// Warning (FieldDecl): 141: I couldn't find an appropriate Go type for the C type '(anonymous struct at /usr/include/x86_64-linux-gnu/bits/pthreadtypes.h:141:3)'.
// Warning (FieldDecl): 177: I couldn't find an appropriate Go type for the C type '(anonymous struct at /usr/include/x86_64-linux-gnu/bits/pthreadtypes.h:177:3)'.
// Warning (TypedefDecl): 741: function pointers are not supported [1] : 'int (*)( void *, void *)'
// Warning (TypedefDecl): 748: function pointers are not supported [1] : 'int (*)( void *, void *, void *)'
// Warning (FieldDecl): 85: probably an incorrect type translation 3
// Warning (TypedefDecl): 333: function pointers are not supported [2] : '__ssize_t (void *, char *, size_t)'
// Warning (TypedefDecl): 341: function pointers are not supported [2] : '__ssize_t (void *, char *, size_t)'
// Warning (TypedefDecl): 350: function pointers are not supported [2] : 'int (void *, __off64_t *, int)'
// Warning (TypedefDecl): 353: function pointers are not supported [2] : 'int (void *)'
// Warning (EnumDecl): 46: Add support of continues counter for type : *ast.ParenExpr
// Warning (EnumDecl): 71: Add support of continues counter for type : *ast.BinaryExpr
// Warning (CallExpr): 209: function pointers are not supported [2] : 'void (void)'
// Warning (UnaryExprOrTypeTraitExpr): 522: cannot determine size of: `struct editorSyntax [1]`
// Error (CallExpr): 547: Cannot found goast.Ident in operation <ToVoid> or function free
// Warning (UnaryExprOrTypeTraitExpr): 572: cannot determine size of: `erow`
// Error (BinaryOperator): 572: Cannot transpile BinaryOperator : result type = {unknown63}. Error: cannot determine size of: `erow`
// Warning (UnaryExprOrTypeTraitExpr): 574: cannot determine size of: `erow`
// Error (CallExpr): 592: Cannot found goast.Ident in operation <ToVoid> or function free
// Error (CallExpr): 593: Cannot found goast.Ident in operation <ToVoid> or function free
// Error (CallExpr): 594: Cannot found goast.Ident in operation <ToVoid> or function free
// Warning (UnaryExprOrTypeTraitExpr): 605: cannot determine size of: `erow`
// Error (CallExpr): 779: Cannot found goast.Ident in operation <ToVoid> or function free
// Error (CallExpr): 853: Cannot found goast.Ident in operation <ToVoid> or function free
// Warning (BinaryOperator): 909: int
// Warning (CallExpr): 980: I couldn't find an appropriate Go type for the C type '...'.
// Warning (BinaryOperator): 1017: int
// Warning (ParenExpr): 0: Cannot transpile ParenExpr. err = probably an incorrect type translation 1
// Warning (UnaryOperator): 0: Cannot transpile UnaryOperator: err = Cannot transpile ParenExpr. err = probably an incorrect type translation 1
// Error (IfStmt): 0: Cannot transpile UnaryOperator: err = Cannot transpile ParenExpr. err = probably an incorrect type translation 1
// Warning (BinaryOperator): 1029: int
// Warning (BinaryOperator): 1034: int
// Warning (ParenExpr): 0: Cannot transpile ParenExpr. err = probably an incorrect type translation 1
// Warning (UnaryOperator): 0: Cannot transpile UnaryOperator: err = Cannot transpile ParenExpr. err = probably an incorrect type translation 1
// Error (IfStmt): 0: Cannot transpile UnaryOperator: err = Cannot transpile ParenExpr. err = probably an incorrect type translation 1

@Konstantin8105
Copy link
Contributor

result of go build:

± |master ?:1 ✗| → go build kilo.go
# command-line-arguments
./kilo.go:820:6: __itimer_which_t redeclared in this block
	previous declaration at ./kilo.go:816:6
./kilo.go:1327:3: undefined: tcsetattr
./kilo.go:1347:19: undefined: isatty
./kilo.go:1350:2: undefined: atexit
./kilo.go:1351:5: undefined: tcgetattr
./kilo.go:1355:23: constant -1331 overflows uint32
./kilo.go:1356:23: constant -2 overflows uint32
./kilo.go:1358:23: constant -32780 overflows uint32
./kilo.go:1361:5: undefined: tcsetattr
./kilo.go:1368:3: undefined: __errno_location
./kilo.go:1368:3: too many errors

Warning maybe from user source:

// Warning (ParenExpr):  :0 : Cannot transpile ParenExpr. err = Cannot casting {int -> }. err = Cannot resolve type '' : probably an incorrect type translation 1
// Warning (UnaryOperator):  :0 : Cannot transpile UnaryOperator: err = Cannot transpileToExpr. err = Cannot transpile ParenExpr. err = Cannot casting {int -> }. err = Cannot resolve type '' : probably an incorrect type translation 1
// Warning (ParenExpr):  :0 : Cannot transpile ParenExpr. err = Cannot casting {int -> }. err = Cannot resolve type '' : probably an incorrect type translation 1
// Warning (UnaryOperator):  :0 : Cannot transpile UnaryOperator: err = Cannot transpileToExpr. err = Cannot transpile ParenExpr. err = Cannot casting {int -> }. err = Cannot resolve type '' : probably an incorrect type translation 1

So, now problem of kilo is unsupported C libraries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants