Shop OBEX P1 Docs P2 Docs Learn Events
spin2cpp version 1.94 released — Parallax Forums

spin2cpp version 1.94 released

ersmithersmith Posts: 5,914
edited 2016-01-07 21:04 in Propeller 1
I've posted release 1.94 of spin2cpp, the Spin to C/C++ converter, to https://github.com/totalspectrum/spin2cpp/releases/tag/v1.94.

I had hoped to achieve 100% implementation of Spin with this release, but COGNEW/COGINIT of Spin methods is not finished yet (COGNEW/COGINIT of Pasm has worked for a long time, and is the most common use case). There were enough bug fixes and new features that I thought a release was warranted.

If you haven't used it, spin2cpp is a compiler for Spin. It can output C or C++, and it can optionally invoke PropGCC to produce binary output, so you can compile Spin to LMM or CMM code directly if you have both spin2cpp and PropGCC installed. Spin code compiled with spin2cpp ends up being substantially faster than "standard" Spin (2x - 20x faster, depending on options), at the cost of using more space (1.2x - 4x times bigger code, again depending on options).

At present spin2cpp is a command line only tool. At some point I'd like to integrate it into a GUI; it should be straightforward to use it in the same was as openspin in many cases (the command line parameters are a bit different, but it has very similar functionality). It complements openspin by providing a different size/speed tradeoff; if you need minimum code size use openspin, if you need faster Spin code use spin2cpp.

Some sample use cases:
spin2cpp test.spin
produces "test.cpp" and "test.h", C++ code and a header file. I've tried to make the output code "natural" with preserved comments and reasonable structure, but it is of course machine generated so there are some things that will look a bit strange.
spin2cpp --binary -Os -mcmm demo.spin
will produce "demo.binary", a ready to run executable.
spin2cpp --ccode demo2.spin
will produce "demo2.c" and "demo2.h". This is plain C code, for the most part (there are a few GCC extensions used for some Spin constructs, but in many cases the output could be compiled with Catalina or other compilers).
spin2cpp --gas demo3.spin
The --gas flag says to convert the PASM code into inline assembly instead of inline hex codes. This is still experimental, but makes for more readable code. Unfortunately there's a bug which causes this not to work together with --ccode. This will be fixed in the next version of spin2cpp.

[ Edited to note the --gas --ccode conflict ]

Comments

  • dgatelydgately Posts: 1,621
    edited 2016-01-07 18:29
    Not sure if this is new to v1.94... Not able to compile the --ccode --gas variants of the demos with gcc version 4.6.1 that is in SimpleIDE v1.0.2 (RC2)

    Note: I built spin2cpp v1.94 on Mac OS X 10.11.2 (El Capitan)
    $ spin2cpp -v
    Spin to C++ converter version 1.94
    Usage: spin2cpp [options] file.spin
    ...
    
    Demo]$ make
    spin2cpp --ccode --gas --elf -Os -o fibo.elf Fibo.spin
    Fibo.c:62:9: error: expected '(' before 'volatile'
    Fibo.c:63:9: error: expected '(' before 'volatile'
    Fibo.c:64:9: error: expected '(' before 'volatile'
    Fibo.c:65:9: error: expected '(' before 'volatile'
    make: *** [fibo.elf] Error 1
    
    The 'offending lines of code':
      __asm__ volatile( "    .global __clkfreqval\n" );
      __asm__ volatile( "    __clkfreqval = 0x4c4b400\n" );
      __asm__ volatile( "    .global __clkmodeval\n" );
      __asm__ volatile( "    __clkmodeval = 0x6f\n" );
    

    propeller-elf-gcc version info:
    $ /Applications/MCU\ Apps/SimpleIDE.app/Contents/propeller-gcc/bn/propeller-elf-gcc -v
    Using built-in specs.
    COLLECT_GCC=/Applications/MCU Apps/SimpleIDE.app/Contents/propeller-gcc/bin/propeller-elf-gcc
    COLLECT_LTO_WRAPPER=/Applications/MCU Apps/SimpleIDE.app/Contents/propeller-gcc/bin/../libexec/gcc/propeller-elf/4.6.1/lto-wrapper
    Target: propeller-elf
    Configured with: ../../propgcc/gcc/configure --target=propeller-elf --prefix=/opt/parallax --disable-nls --disable-libssp --disable-lto --disable-shared --with-pkgversion=propellergcc_v1_0_0_2435 --with-bugurl=http://code.google.com/p/propgcc/issues
    Thread model: single
    gcc version 4.6.1 (propellergcc_v1_0_0_2435) 
    

    Oh... I am able to build Hello.cpp with propeller-elf-gcc, so it's something about the --ccode variant.

    dgately
  • That's a weird one... gcc's C++ parser accepts "__asm__ volatile" at top level, but its C parser does not. It is documented that the volatile is optional, but apparently in C it's actually forbidden. I couldn't find any discussion about this online, which is curious.

    I've modified the spin2cpp source code to leave off the volatile, so if you're able to build it yourself you can pull the current git version and it should be fixed.

    I guess I haven't been using --ccode and --gas together much lately. Thanks for the bug report!
  • DavidZemonDavidZemon Posts: 2,973
    edited 2016-01-07 21:11
    I'm afraid I can't build Mac binaries, but Windows and Linux are available here, including your latest commit: http://david.zemon.name:8111/project.html?projectId=Spin2Cpp&guest=1
  • Thanks David!
  • ersmith wrote: »
    I've modified the spin2cpp source code to leave off the volatile, so if you're able to build it yourself you can pull the current git version and it should be fixed.

    Yes, spin2cpp v1.95 built and is working with this fix!

    Thanks,
    dgately

  • I've released an official version of 1.95 to https://github.com/totalspectrum/spin2cpp/releases/tag/v1.95. Besides the fixes above there is a preliminary implementation of coginit for Spin methods, and improved detection of static member functions.
  • ersmithersmith Posts: 5,914
    edited 2016-02-08 19:29
    spin2cpp has been updated again (see https://github.com/totalspectrum/spin2cpp/releases/tag/v1.96). It's now able to compile the Spin standard library, and its C/C++ output is getting neater (for example, functions that don't explicitly return any value are now declared as "void").
  • Thank you for the ongoing work on spin2cpp. I hope to be able to use it myself very soon.
  • Hey! Have you considered moving your project to the Parallax GitHub?

    It's hip, it's happenin', it's where all kinds of fun stuff is happening!
    https://github.com/parallaxinc

    After that, we can get your project set up on the official Parallax developer site.
    http://developer.parallax.com/
  • Brett Weir wrote: »
    It's hip, it's happenin', it's where all kinds of fun stuff is happening!
    https://github.com/parallaxinc

    Who could say no to that?!? :D
  • Brett Weir wrote: »
    Hey! Have you considered moving your project to the Parallax GitHub?
    I'm not a Parallax employee, and spin2cpp is not in any way sponsored by or affiliated with Parallax (it isn't their fault if something breaks :)). It's an open source project, and I'd be happy to see it forked, if someone wants to do that. Frankly I've never heard anything from Parallax about spin2cpp. I guess they have a lot of other things on their plate.

  • ersmith wrote: »
    Brett Weir wrote: »
    Hey! Have you considered moving your project to the Parallax GitHub?
    I'm not a Parallax employee, and spin2cpp is not in any way sponsored by or affiliated with Parallax (it isn't their fault if something breaks :)). It's an open source project, and I'd be happy to see it forked, if someone wants to do that. Frankly I've never heard anything from Parallax about spin2cpp. I guess they have a lot of other things on their plate.

    Yea... it's a bit odd... but they appear to be attempting to turn the ParallaxInc org into a GitHub-driven Obex. At least, that's my personal impression. Parallax want community-driven projects to be stored in one place for everyone to find. That's how PropWare ended up there, even though it "is not in any way sponsored by or affiliated with Parallax."
Sign In or Register to comment.