Shop OBEX P1 Docs P2 Docs Learn Events
CSPIN - A C-to-Spin Converter - Page 3 — Parallax Forums

CSPIN - A C-to-Spin Converter

13»

Comments

  • Dave HeinDave Hein Posts: 6,347
    edited 2014-05-29 15:51
    I had thought about porting cspin to the Prop, but I knew there were a few issues with doing that. Hub RAM is one of the biggest problems. cspin uses a number of buffers, and it generates several linked lists.

    I haven't thought about the issue of circular references, but I can see how even just 2 files could have circular references. In my own Spin code I get around circular references by creating duplicate copies of methods. This works OK if the methods are small. Larger methods should probably be moved to a separate object. It's probably best to do this at the C source level.

    It's interesting that it compiles under PropGCC, and even more amazing that it works. It may be able to convert small C files. I'll have to give that a try.
  • AntoineDoinelAntoineDoinel Posts: 312
    edited 2014-05-29 16:08
    Dave Hein wrote: »
    I had thought about porting cspin to the Prop, but I knew there were a few issues with doing that. Hub RAM is one of the biggest problems. cspin uses a number of buffers, and it generates several linked lists.

    I haven't thought about the issue of circular references, but I can see how even just 2 files could have circular references. In my own Spin code I get around circular references by creating duplicate copies of methods. This works OK if the methods are small. Larger methods should probably be moved to a separate object. It's probably best to do this at the C source level.

    It's interesting that it compiles under PropGCC, and even more amazing that it works. It may be able to convert small C files. I'll have to give that a try.

    It only needed an #include <stdint.h> (for uint8_t), and the device initialization structure (for SD card) added to cspin.c
    XMMC has too small data, needs xmm-single or xmm-split.
  • Dave HeinDave Hein Posts: 6,347
    edited 2014-06-20 12:12
    cspin 0.82

    This version contains the following changes and fixes:
    - Fixed problem with multi-line array initialization using "strings"
    - Fixed problem with /=
    - Fixed problem declaring a variable with FILE *
    - Fixed problem with case x: { ... break; } generating a quit
    - Fixed problem with dereferencing and array with *array_name
    - Now only print cspin_initialize routine if using function pointers or main
    - Fixed problem with dereferencing a pointer to a pointer using pptr[0]
    - Now handle having volatile in the C source
    - Ignore comments in include files
    - Added buildit.bat to build cspin using the Watcom compiler
  • jazzedjazzed Posts: 11,803
    edited 2014-06-20 13:58
    Hi Dave,

    I've been wanting to use this as a library in another effort for a while, but the "interactive nature" of the program gets in the way.

    Is it possible to create a library function (callable from a program where the library is linked) that takes an input file name (*.c), an options string, and an output filename (*.spin)?

    Thanks for your consideration.

    Dave Hein wrote: »
    cspin 0.82

    This version contains the following changes and fixes:
    - Fixed problem with multi-line array initialization using "strings"
    - Fixed problem with /=
    - Fixed problem declaring a variable with FILE *
    - Fixed problem with case x: { ... break; } generating a quit
    - Fixed problem with dereferencing and array with *array_name
    - Now only print cspin_initialize routine if using function pointers or main
    - Fixed problem with dereferencing a pointer to a pointer using pptr[0]
    - Now handle having volatile in the C source
    - Ignore comments in include files
    - Added buildit.bat to build cspin using the Watcom compiler
  • Dave HeinDave Hein Posts: 6,347
    edited 2014-06-20 14:45
    jazzed wrote: »
    Is it possible to create a library function (callable from a program where the library is linked) that takes an input file name (*.c), an options string, and an output filename (*.spin)?
    You can comment out the main routine and call ParseCommandLine directly. It uses the same argc and argv parameters that are passed to main, so you could construct your own argc and argv parameters and pass it to ParseCommandLine. So your program would look something like this.
    int main()
    {
        int num = 3;
        char *parms[] = {"dummy", "-m", "testfile.c"};
    
        ParseCommandLine(num, parms);
        return 0;
    }
    
    There's currently no way to specify an output file name. This example will generate testfile.spin.

    EDIT: Another way to do this is to just set the options flags yourself since they are all globals, and then call ConvertFileToSpin where you just pass the a string containing the input file name.
  • jazzedjazzed Posts: 11,803
    edited 2014-06-20 14:57
    Thanks Dave,

    I'll try that. Is it possible to redirect all output to an arbitrary file name?

    I've used this approach with a modified version of OpenSpin, and it works nicely.

    The only problem with adding bits and pieces independently is program maintenance whenever nice updates (like today's) show up.

    Cheers.
  • Dave HeinDave Hein Posts: 6,347
    edited 2014-06-20 15:55
    There is currently no way to redirect the output to an arbitrary file name. I can add an option to specify an output file name without too much trouble.
  • Jim EdwardsJim Edwards Posts: 54
    edited 2015-06-26 07:35
    Hi,
    I am trying to use cspin082 to convert a C library for an LCD. I am running into issues with typedefs for structures. I do not see anything in the readme that says it can't handle them but it seems to cause the converter to hiccup by generating a long spin comment. I extracted a small portion of my .H and .C file in the attached and put in a test structure that will cause the hiccup. Is this a known bug and is there a workaround? Thanks.
    JimE

    test.spintest.htest.c
  • Dave HeinDave Hein Posts: 6,347
    edited 2015-06-26 08:38
    The problem is with
    typedef struct {
            unsigned int test;
    } TEST;
    
    cspin requires a name after the struct keyword. I could fix it by generating a dummy struct name, but it currently doesn't do that. Change the typedef to something like this
    typedef struct TEST_struct {
            unsigned int test;
    } TEST;
    
    I also noticed that the #ifndef isn't terminated with a #endif. You should add a #endif at the end of the file.
  • Jim EdwardsJim Edwards Posts: 54
    edited 2015-06-26 08:41
    Dave Hein wrote: »
    The problem is with
    typedef struct {
            unsigned int test;
    } TEST;
    
    cspin requires a name after the struct keyword. I could fix it by generating a dummy struct name, but it currently doesn't do that. Change the typedef to something like this
    typedef struct TEST_struct {
            unsigned int test;
    } TEST;
    
    I also noticed that the #ifndef isn't terminated with a #endif. You should add a #endif at the end of the file.

    Thank you, thank you, thank you for the quick response!
  • Hello Dave, if this will run - respect, excellent work! I will try this tool. For the new OLED display there is only C code available. Parallax cannot help currently (they try their best) but I do not get any SPIN code right now. Can your tool convert this code into the SPIN format really? Had you ever tried this?
  • I needed cspin to attempt to convert the lsm9ds1 library to SPIN this weekend and realized converting C's '0b' to SPIN's '%' binary number identifier hadn't been implemented.
    There may be a good reason why Dave didn't add it, but I added it and fixed the buildit.sh build script (linking with the libm math library wasn't part of the command line).
    Attached is a zip of the two udiff patchfiles as well as a small sh script to actually perform the patching. To do it manually, unzip the files in the cspin root directory, and patch both files with:
    patch -p0 --verbose <buildit.sh.patch
    patch -p0 --verbose <spinit.c.patch
    

    Thanks Dave for cspin!

    Cheers,
    Jesse
  • avsa242, thanks for adding that to cspin. When I get some time I'll make a new update to cspin that will include your addition. I haven't worked on cspin for 3 years, but I do have an updated version sitting on my computer with the struct change that was discussed 2 years ago. I'll also incorporate jazzed's suggestion about specifying the output file name. I hope cspin is working fine for you.
  • Dave,

    No problem. I didn't expect that you were still working on it as I haven't seen any activity in awhile but I find a use for it here and there and figured, if nothing else, someone else may benefit from it. :smile:
    Though the transpiled code needs quite a bit of work to make it functional, for sure, it still did a mammoth amount of work that would've otherwise been a lot of man-hours, so thanks again!

  • Dave HeinDave Hein Posts: 6,347
    edited 2017-07-11 23:42
    Duplicate post removed.
  • I've incorporated the suggested changes given in this thread since the last update. I've also fixed a couple of outher issues involving structs. The latest version is in the attached zip file.
  • I downloaded the latest cspin zip file and tried running the 'buildit.sh' script in my cygwin installation on my Win7 64bit laptop. I get the following error and no finished executable:

    (1449) unknown dependency file type (ang-c).

    I also tried my Git-bash installation and get the same error.

    What am I missing?
  • Can you try running this script file and see where the error is generated? Download test.txt and run it as follows:

    bash -x test.txt
  • It turned out that my 'cygwin' gcc installation wasn't completely setup.

    Once I got the gcc installation setup I was able to compile 'cspin'.

    Thanks for the help and for creating 'cspin'...
Sign In or Register to comment.