c2v icon indicating copy to clipboard operation
c2v copied to clipboard

Cannot convert C file to V

Open Unicorn7141 opened this issue 1 year ago • 8 comments

I tried following the demo, and copied the primes.c file to a file called main.c which has the following code:

#include <stdio.h>
#include <stdbool.h>

_Bool is_prime(int num) {
    for (int i = 2; i <= num / 2; i++) {
        if (num % i == 0) return false;
    }

    return true;
}

int main() {
    for (int i = 1; i < 100; i++) {
        if (is_prime(i)) {
            printf("%i\n", i);
        }
    }

    return 0;
}

I validated the code is working by running

gcc main.c -o run.exe
run

and it worked as exxpected.

Then I tried running v translate main.c and got the following error:

C to V translator 0.3.1
  translating main.c          ... 
The file main.c could not be parsed as a C source file.
C2V command: "C:\Users\Unicorn\.vmodules\c2v\c2v.exe" "main.c"
C2V failed to translate the C files. Please report it via GitHub.

Unicorn7141 avatar Apr 14 '23 21:04 Unicorn7141

I don't know if this is Windows specific, the version of clang you have, or what, but it works correctly here, on Linux, using V 0.3.3 2179db3 and clang version 15.0.7:

$ vi main.c
[jalon@7950x ~]$ gcc main.c -o run
[jalon@7950x ~]$ ./run
1
2
3
5
7
11
13
17
19
23
29
31
37
41
43
47
53
59
61
67
71
73
79
83
89
97
[jalon@7950x ~]$ v translate main.c
C to V translator 0.3.1
  translating main.c          ... No more children
No more children
Reformatted file: /home/jalon/main.v
 took   406 ms ; output .v file: main.v
Translated   1 files in   406 ms.
[jalon@7950x ~]$ v run main.v
1
2
3
5
7
11
13
17
19
23
29
31
37
41
43
47
53
59
61
67
71
73
79
83
89
97
[jalon@7950x ~]$

So... which version of clang do you have? If you don't have the one from https:\\winlibs.com, I recommend uninstalling what you have now, and getting that one.

JalonSolov avatar Apr 14 '23 23:04 JalonSolov

I don't know if this is Windows specific, the version of clang you have, or what, but it works correctly here, on Linux, using V 0.3.3 2179db3 and clang version 15.0.7:

$ vi main.c
[jalon@7950x ~]$ gcc main.c -o run
[jalon@7950x ~]$ ./run
1
2
3
5
7
11
13
17
19
23
29
31
37
41
43
47
53
59
61
67
71
73
79
83
89
97
[jalon@7950x ~]$ v translate main.c
C to V translator 0.3.1
  translating main.c          ... No more children
No more children
Reformatted file: /home/jalon/main.v
 took   406 ms ; output .v file: main.v
Translated   1 files in   406 ms.
[jalon@7950x ~]$ v run main.v
1
2
3
5
7
11
13
17
19
23
29
31
37
41
43
47
53
59
61
67
71
73
79
83
89
97
[jalon@7950x ~]$

So... which version of clang do you have? If you don't have the one from https:\\winlibs.com, I recommend uninstalling what you have now, and getting that one.

I downloaded MinGW64 and it came with clang...

Unicorn7141 avatar Apr 15 '23 06:04 Unicorn7141

Everyone using V on Windows has had much better luck with the gcc/clang package from https://winlibs.com - it is a much more up-to-date package than the one from mingw, usually.

JalonSolov avatar Apr 15 '23 12:04 JalonSolov

Everyone using V on Windows has had much better luck with the gcc/clang package from https://winlibs.com - it is a much more up-to-date package than the one from mingw, usually.

This is exactly what I downloaded.... image

Unicorn7141 avatar Apr 15 '23 14:04 Unicorn7141

I faced the same issue on Windows 10 trying to run v translate on an example from the docs. I already had gcc from MinGW package that works ok with compiling C files, but not with c2v. Then I installed clang with llvm package, and now c2v works without errors.

ArturM94 avatar May 08 '23 14:05 ArturM94

Same issue, also on Windows. By the way I also downloaded clang from winlibs.

TimmieTudor avatar May 29 '23 16:05 TimmieTudor

clang with llvm package

Could you share the link for this, please?

JohnClaw avatar May 25 '24 22:05 JohnClaw

Look on https://winlibs.com - you have a choice of downloading gcc either WITH, or WITHOUT clang/llvm/ldb/lldb

Just choose one of the links to the left, instead of the right (after the text about "without...").

Up to version 14.1.0 there, now.

JalonSolov avatar May 25 '24 22:05 JalonSolov