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

spin2cpp version 1.01

ersmithersmith Posts: 6,092
edited 2012-12-16 20:49 in Propeller 1
There's a new version of spin2cpp, the Spin to C/C++ converter, available from http://code.google.com/p/spin2cpp. Version 1.01 fixes a few bugs (like the missing <= and =<= operators) and also has slightly cleaner C/C++ output: constants are now output as the constant name rather than a literal value.

Eric

Comments

  • Dr_AculaDr_Acula Posts: 5,484
    edited 2012-11-28 16:38
    Nice work - I've been using Spin2cpp in the last few days and it is working very well. Keep up the good work!
  • RaymanRayman Posts: 14,826
    edited 2012-11-30 06:41
    Eric, thanks again for this code. Really makes transition from Spin to Catalina or GCC painless.

    Out of curiousity, is this going to be part of PropGCC? Or, are you keeping it seperate?
  • TinkersALotTinkersALot Posts: 535
    edited 2012-12-01 08:57
    errors converting femtobasic (from obex).

    ran this command line:
    C:\testing>spin2cpp --main --ccode --files femtobasic.spin

    this was returned:
    vga_Drive.spin:284: syntax error
    1 errors
  • ersmithersmith Posts: 6,092
    edited 2012-12-03 05:01
    errors converting femtobasic (from obex).

    ran this command line:
    C:\testing>spin2cpp --main --ccode --files femtobasic.spin

    this was returned:
    vga_Drive.spin:284: syntax error
    1 errors

    Thanks for the bug report -- it'll be fixed in the next version of spin2cpp. In the meantime you can change lines like:
    CON
      #1, scanbuff[128], scancode[128*2-1+3], maincode
    
    into the equivalent
      CON
        scanbuff=1
        scancode=128+scanbuff
        maincode=scancode+(128*2-1+3)
    
    which spin2cpp does understand.

    Eric
  • SRLMSRLM Posts: 5,045
    edited 2012-12-05 22:18
    I tried running spin2cpp with --elf, and I got the following error message:
    $>spin2cpp.linux --main --elf --gas main.spin
    /tmp/ccWSWTTM.s: Assembler messages:
    /tmp/ccWSWTTM.s:163: Warning: zero assumed for missing expression
    /tmp/ccWSWTTM.s:165: Warning: zero assumed for missing expression
    /tmp/ccWSWTTM.s:167: Warning: zero assumed for missing expression
    /tmp/ccWSWTTM.s:169: Warning: zero assumed for missing expression
    /tmp/ccWSWTTM.s:171: Warning: zero assumed for missing expression
    /opt/parallax/lib/gcc/propeller-elf/4.6.1/../../../../propeller-elf/bin/ld: address 0x18a0 of a.out section `.FullDuplexSerialPlus.cog' is not within region `coguser'
    /opt/parallax/lib/gcc/propeller-elf/4.6.1/../../../../propeller-elf/bin/ld: address 0x18a0 of a.out section `.FullDuplexSerialPlus.cog' is not within region `coguser'
    collect2: ld returned 1 exit status
    

    I've attached the code to this post.

    Edit: it works if I remove the --gas option.

    Edit2: It also works (with the --gas option, but without the --elf option) with this makefile:
    ifndef MODEL
    MODEL = lmm
    endif
    
    SRCS=$(wildcard *.cpp)
    OBJS=$(subst .cpp,.o,$(SRCS))
    
    CXX = propeller-elf-g++
    CLD = propeller-elf-ld
    CXXFLAGS = -m${MODEL} -Wall -Os -m32bit-doubles -mfcache -fno-exceptions -fno-rtti -fpermissive -ffunction-sections -fno-strict-aliasing
    
    Debug: cleanDebug ${OBJS}
    	${CXX} ${CXXFLAGS} -o main.elf ${OBJS}
    
    depend: .depend
    
    .depend: ${SRCS}
    	rm -f ./.depend
    	${CXX} ${CXXFLAGS} --MM $^>>./.depend;
    
    cleanDebug:
    	${RM} *.o *.elf .depend *.map *.rawmap a.out
    	
    clean: cleanDebug
    
    include .depend
    

    I suspect it's because I compile each into a .o file, and then link them? I get the same error as above (not within region) if I try the propeller-elf-gcc with the three .cpp filenames.

    Also, I learned that propeller-elf-gcc *.cpp will match all the cpp files. I didn't know that GCC does wildcard matching.
  • SRLMSRLM Posts: 5,045
    edited 2012-12-10 02:21
    I found a segfault bug in spin2cpp v1.01. This is a minor bug.

    The following Spin code (except, full source attached to post), when run through spin2cpp, causes a segfault.
    pub go | x
       maxdur := 2 ' the max duration in seconds; keep below 10sec to avoid clock wrap
       maxdur *= clkfreq
       x := \start
       term.str(string("Erroneously returned from start!", 10, 13))
       term.dec(x)
       term.tx(10)
       term.tx(13)
    pub start_block_layer : retval | i
      retval := \block.start_explicit(term#sd_DO, term#sd_CLK, term#sd_DI, term#sd_CS)
      if retval < 0
        term.str( string(10,  13, "Mount failed spectacularly!",10,  13, "Command => Response", 10, 13 ) )
        {
        i := block.get_log_pointer
        repeat while byte[i] <> 0
          term.dec( byte[i++] & 63 )
          term.str( string( " => "  ) )
          term.dec( byte[i++] )
          term.tx( 13 )
        }
        abort( retval )
    pub stop_block_layer
       block.stop
    pub start
       term.start
       repeat
          sr := 0
          term.str(string(10, 13, "Waiting for key press to start tests",10,  13))
          term.rx
          ' if these fail, comment out the next line
          mounttests
          rawspeed
          fsrwspeed
          sdfat.unmount
          term.str(string("Repeating all the speed results:",10,  13))
          showallspeed
          term.str(string("All done!", 10, 13))
    

    The GDB of the core dump is:
    warning: Can't read pathname for load map: Input/output error.
    Core was generated by `spin2cpp.linux --main test_nl.spin'.
    Program terminated with signal 11, Segmentation fault.
    #0  ScanFunctionBody (fdef=0x99428c8, body=0x8458b0c) at functions.c:91
    91	functions.c: No such file or directory.
    

    The problem is the \ in line 4 of the except above (line 31 of test_nl.spin, which is the top level file). When this is removed spin2cpp seems to function correctly.

    Interestingly, the only other \ in the program doesn't cause spin2cpp to crash, one way or the other.
  • SRLMSRLM Posts: 5,045
    edited 2012-12-10 02:32
    I found another bug. I think I may have seen this mentioned somewhere else, but I'll put it here just in case.

    spin2cpp does not seem to recognize the array indicator ( [ n ] ) for objects. It simply drops the array index in the generated code.

    I have attached the problem code, both the .spin source and the spin2cpp generated files. Here is the compiler output (the errors are near the bottom).
    propeller-elf-g++ -mlmm -Wall -Os -m32bit-doubles -mfcache -fno-exceptions -fno-rtti -fpermissive -ffunction-sections -fno-strict-aliasing --MM fsrw.cpp FullDuplexSerial.cpp safe_spi.cpp sysdep.cpp test_nl.cpp>>./.depend;
    fsrw.cpp: In member function 'int32_t fsrwSpin::Brword(int32_t)':
    fsrw.cpp:108:11: warning: unused variable 'result' [-Wunused-variable]
    fsrw.cpp: In member function 'int32_t fsrwSpin::Brlong(int32_t)':
    fsrw.cpp:114:11: warning: unused variable 'result' [-Wunused-variable]
    fsrw.cpp: In member function 'int32_t fsrwSpin::Brclust(int32_t)':
    fsrw.cpp:120:11: warning: unused variable 'result' [-Wunused-variable]
    fsrw.cpp: In member function 'int32_t fsrwSpin::Mount(int32_t)':
    fsrw.cpp:255:11: warning: unused variable 'Start' [-Wunused-variable]
    fsrw.cpp:255:18: warning: unused variable 'Sectorspercluster' [-Wunused-variable]
    fsrw.cpp:255:37: warning: unused variable 'Reserved' [-Wunused-variable]
    fsrw.cpp:255:47: warning: unused variable 'Rootentries' [-Wunused-variable]
    fsrw.cpp:255:60: warning: unused variable 'Sectors' [-Wunused-variable]
    fsrw.cpp:256:11: warning: unused variable 'R' [-Wunused-variable]
    fsrw.cpp: In member function 'int32_t fsrwSpin::Readbytec(int32_t)':
    fsrw.cpp:262:11: warning: unused variable 'result' [-Wunused-variable]
    fsrw.cpp: In member function 'int32_t fsrwSpin::Readfat(int32_t)':
    fsrw.cpp:269:11: warning: unused variable 'result' [-Wunused-variable]
    fsrw.cpp: In member function 'int32_t fsrwSpin::Datablock()':
    fsrw.cpp:314:11: warning: unused variable 'result' [-Wunused-variable]
    fsrw.cpp: In member function 'int32_t fsrwSpin::Uc(int32_t)':
    fsrw.cpp:320:11: warning: unused variable 'result' [-Wunused-variable]
    fsrw.cpp: In member function 'int32_t fsrwSpin::Pflushbuf(int32_t, int32_t)':
    fsrw.cpp:330:11: warning: unused variable 'R' [-Wunused-variable]
    fsrw.cpp: In member function 'int32_t fsrwSpin::Pflush()':
    fsrw.cpp:415:11: warning: unused variable 'result' [-Wunused-variable]
    fsrw.cpp: In member function 'int32_t fsrwSpin::Get_filesize()':
    fsrw.cpp:627:11: warning: unused variable 'result' [-Wunused-variable]
    fsrw.cpp: In member function 'int32_t fsrwSpin::Pgetc()':
    fsrw.cpp:662:11: warning: unused variable 'result' [-Wunused-variable]
    fsrw.cpp: In member function 'int32_t fsrwSpin::Pputs(int32_t)':
    fsrw.cpp:696:11: warning: unused variable 'result' [-Wunused-variable]
    fsrw.cpp: In member function 'int32_t fsrwSpin::Seek(int32_t)':
    fsrw.cpp:715:11: warning: unused variable 'result' [-Wunused-variable]
    fsrw.cpp: In member function 'int32_t fsrwSpin::Tell()':
    fsrw.cpp:748:11: warning: unused variable 'result' [-Wunused-variable]
    fsrw.cpp: In member function 'int32_t fsrwSpin::Opendir()':
    fsrw.cpp:755:11: warning: unused variable 'result' [-Wunused-variable]
    fsrw.cpp: In member function 'int32_t fsrwSpin::Getclustersize()':
    fsrw.cpp:811:11: warning: unused variable 'result' [-Wunused-variable]
    fsrw.cpp: In member function 'int32_t fsrwSpin::Getclustercount()':
    fsrw.cpp:817:11: warning: unused variable 'result' [-Wunused-variable]
    safe_spi.cpp: In member function 'int32_t safe_spi::Start(int32_t)':
    safe_spi.cpp:113:11: warning: unused variable 'result' [-Wunused-variable]
    safe_spi.cpp: In member function 'int32_t safe_spi::Get_seconds()':
    safe_spi.cpp:173:11: warning: unused variable 'result' [-Wunused-variable]
    sysdep.cpp: In member function 'int32_t sysdepSpin::Rx()':
    sysdep.cpp:27:11: warning: unused variable 'result' [-Wunused-variable]
    sysdep.cpp: In member function 'int32_t sysdepSpin::Rxtime(int32_t)':
    sysdep.cpp:33:11: warning: unused variable 'result' [-Wunused-variable]
    sysdep.cpp: In member function 'int32_t sysdepSpin::Rxcheck()':
    sysdep.cpp:39:11: warning: unused variable 'result' [-Wunused-variable]
    sysdep.cpp: In member function 'int32_t sysdepSpin::Tx(int32_t)':
    sysdep.cpp:45:11: warning: unused variable 'result' [-Wunused-variable]
    sysdep.cpp: In member function 'int32_t sysdepSpin::Str(int32_t)':
    sysdep.cpp:51:11: warning: unused variable 'result' [-Wunused-variable]
    sysdep.cpp: In member function 'int32_t sysdepSpin::Dec(int32_t)':
    sysdep.cpp:57:11: warning: unused variable 'result' [-Wunused-variable]
    sysdep.cpp: In member function 'int32_t sysdepSpin::Hex(int32_t, int32_t)':
    sysdep.cpp:63:11: warning: unused variable 'result' [-Wunused-variable]
    test_nl.cpp: In member function 'int32_t test_nl::Start_block_layer()':
    test_nl.cpp:41:11: warning: unused variable 'I' [-Wunused-variable]
    test_nl.cpp: In member function 'int32_t test_nl::Start()':
    test_nl.cpp:71:11: error: request for member 'Unmount' in '((test_nl*)this)->test_nl::Sdfat', which is of non-class type 'fsrwSpin [2]'
    test_nl.cpp: In member function 'int32_t test_nl::Mounttests()':
    test_nl.cpp:91:11: warning: unused variable 'R' [-Wunused-variable]
    test_nl.cpp:91:14: warning: unused variable 'Startcnt' [-Wunused-variable]
    test_nl.cpp:91:24: warning: unused variable 'Bytes' [-Wunused-variable]
    test_nl.cpp:91:31: warning: unused variable 'N' [-Wunused-variable]
    test_nl.cpp:91:34: warning: unused variable 'Duration' [-Wunused-variable]
    test_nl.cpp:91:44: warning: unused variable 'I' [-Wunused-variable]
    test_nl.cpp: In member function 'int32_t test_nl::Showallspeed()':
    test_nl.cpp:173:18: error: request for member 'Getclustersize' in '((test_nl*)this)->test_nl::Sdfat', which is of non-class type 'fsrwSpin [2]'
    test_nl.cpp:175:18: error: request for member 'Getclustercount' in '((test_nl*)this)->test_nl::Sdfat', which is of non-class type 'fsrwSpin [2]'
    test_nl.cpp: In member function 'int32_t test_nl::Rawspeed()':
    test_nl.cpp:193:11: warning: unused variable 'R' [-Wunused-variable]
    test_nl.cpp:193:14: warning: unused variable 'Startcnt' [-Wunused-variable]
    test_nl.cpp:193:24: warning: unused variable 'Bytes' [-Wunused-variable]
    test_nl.cpp: In member function 'int32_t test_nl::Fsrwspeed()':
    test_nl.cpp:248:9: error: request for member 'Mount_explicit' in '((test_nl*)this)->test_nl::Sdfat', which is of non-class type 'fsrwSpin [2]'
    test_nl.cpp:254:9: error: request for member 'Popen' in '((test_nl*)this)->test_nl::Sdfat', which is of non-class type 'fsrwSpin [2]'
    test_nl.cpp:263:15: error: request for member 'Pwrite' in '((test_nl*)this)->test_nl::Sdfat', which is of non-class type 'fsrwSpin [2]'
    test_nl.cpp:269:9: error: request for member 'Pclose' in '((test_nl*)this)->test_nl::Sdfat', which is of non-class type 'fsrwSpin [2]'
    test_nl.cpp:272:9: error: request for member 'Popen' in '((test_nl*)this)->test_nl::Sdfat', which is of non-class type 'fsrwSpin [2]'
    test_nl.cpp:278:13: error: request for member 'Pread' in '((test_nl*)this)->test_nl::Sdfat', which is of non-class type 'fsrwSpin [2]'
    test_nl.cpp:283:9: error: request for member 'Pclose' in '((test_nl*)this)->test_nl::Sdfat', which is of non-class type 'fsrwSpin [2]'
    test_nl.cpp:289:9: error: request for member 'Popen' in '((test_nl*)this)->test_nl::Sdfat', which is of non-class type 'fsrwSpin [2]'
    test_nl.cpp:298:15: error: request for member 'Pputc' in '((test_nl*)this)->test_nl::Sdfat', which is of non-class type 'fsrwSpin [2]'
    test_nl.cpp:304:9: error: request for member 'Pclose' in '((test_nl*)this)->test_nl::Sdfat', which is of non-class type 'fsrwSpin [2]'
    test_nl.cpp:307:9: error: request for member 'Popen' in '((test_nl*)this)->test_nl::Sdfat', which is of non-class type 'fsrwSpin [2]'
    test_nl.cpp:313:13: error: request for member 'Pgetc' in '((test_nl*)this)->test_nl::Sdfat', which is of non-class type 'fsrwSpin [2]'
    test_nl.cpp:318:9: error: request for member 'Pclose' in '((test_nl*)this)->test_nl::Sdfat', which is of non-class type 'fsrwSpin [2]'
    test_nl.cpp:320:9: error: request for member 'Popen' in '((test_nl*)this)->test_nl::Sdfat', which is of non-class type 'fsrwSpin [2]'
    test_nl.cpp:322:21: error: request for member 'Pgetc' in '((test_nl*)this)->test_nl::Sdfat', which is of non-class type 'fsrwSpin [2]'
    test_nl.cpp:325:9: error: request for member 'Pclose' in '((test_nl*)this)->test_nl::Sdfat', which is of non-class type 'fsrwSpin [2]'
    test_nl.cpp:244:11: warning: unused variable 'R' [-Wunused-variable]
    test_nl.cpp:244:14: warning: unused variable 'Startcnt' [-Wunused-variable]
    test_nl.cpp:244:24: warning: unused variable 'Bytes' [-Wunused-variable]
    make: *** [.depend] Error 1
    

    Edit: Ok, so it looks like the .spin source used a syntax of "object" to mean "object[0]". So that's probably the reason why spin2cpp didn't work: it doesn't make that conversion in the case of an array of objects.
  • ersmithersmith Posts: 6,092
    edited 2012-12-11 12:36
    SRLM:

    Thanks for the detailed bug reports! I've fixed those problems, and I should have a new version of spin2cpp out in the next day or two.

    Eric
  • SRLMSRLM Posts: 5,045
    edited 2012-12-11 20:39
    Ok. Another problem. The command is
    spin2cpp.linux --gas --main --elf test_nl.spin
    /tmp/ccy6J5Tn.s: Assembler messages:
    /tmp/ccy6J5Tn.s:69: Error: attempt to move .org backwards
    

    I've determined that the problem is in safe_spi_na.cpp. The issue is that it uses a DAT section (at the top of the program) to store variables, and in the --gas generated code the variables are included in the GAS output:
    "		.equ	Cmd59, $7b\n"
    "		.compress off\n"
    "..start\n"
    "Spi_engine_cog\n"
    "		.long	0\n"
    "Spi_command\n"
    "		.long	0\n"
    "Spi_block_index\n"
    "		.long	0\n"
    "Spi_buffer_address\n"
    "		.long	0\n"
    "		.org	0\n"
    "Spi_engine_entry\n"
    "		mov	CTRA, Writemode\n"
    "		mov	CTRB, Clocklinemode\n"
    
    Changing the Spin code so that the variables are in a VAR block solves the issue. I don't know how this issue is affected by DAT blocks after a PASM block.
  • SRLMSRLM Posts: 5,045
    edited 2012-12-11 20:44
    I'd also like to request a feature: comment conversion. I know that you won't be able to get all of the comments, but I think that you could probably get the most bang for your buck by:
    1) Copying function comments (almost always after a PUB or PRI in Spin) to it's equivalent in the .h file
    2) Copying the ASM comments (when the --gas option is enabled), since the commands are directly copied.

    It would be nice if the comments in a function body were able to come along as well, but I assume that would be more difficult.

    The goal of this request would not be to make a "perfect" conversion of the comments. I already expect to go through the code and clean it up anyway. Rather, this would save the effort of having multiple files open and copying the comments between them.
  • SRLMSRLM Posts: 5,045
    edited 2012-12-12 02:28
    Another feature request: can spin2cpp mark all variables as volatile, and the dat sections as volatile? It's annoying to have to make sure to add that in every time. I think it's the safer option than no volatile. And, if it's not needed, then no harm done.
  • ersmithersmith Posts: 6,092
    edited 2012-12-12 12:20
    Thank you for your suggestions. Copying comments over is probably a good idea, but will take some time to implement. I haven't made it a priority because lately I've actually focused on spin2cpp as a "spin compiler", that is, treating the .spin file (possibly marked up with C code) as the original source and only editing that, and doing the conversion as part of the make process. But I realize that not everyone will want to work that way.

    Marking all variables as volatile will have a significant performance impact, since it inhibits a number of optimizations and prevents variables from being cached in registers. So I don't think it's a good idea to make that the default -- you could just as well always compile with -O1 or no optimization instead. It is possible to include {++volatile} as a comment in the spin code to force a variable to be volatile:
      long {++volatile} x
    
    will generate
      int32_t volatile X;
    
    in the C++ output. Another option might be to mark variables whose address is taken as volatile as well... that might get us a lot of the way there.

    Regards,
    Eric
  • SRLMSRLM Posts: 5,045
    edited 2012-12-12 21:38
    Re volatile:
    Thanks for that tip. I like the option of being able annotate the Spin file. Is there something similar that I can do for the DAT blocks?
  • SRLMSRLM Posts: 5,045
    edited 2012-12-12 21:45
    Ok, I've run into another bug, but I can't seem to track this one down.

    The problem: I have a set of spin files (attached), and when I compile them with just --main it works. But when I add in the --gas, the program returns the not mounted warning:
    WARNING: Not mounted. Return value: -20
    

    This seems to be a bug in the --gas output. I know it's not a problem with the card or the code because the Spin program works fine, and the non--gas option works fine. I can run the working version of the program before and after the failure, so it's not setting the SD card in an unusable state or anything.

    A little bit of digging seems to indicate that the FS type is all 0's in the failing version (instead of a byte reversed "FAT32"). Other than that, I don't know where the problem is.
  • SRLMSRLM Posts: 5,045
    edited 2012-12-12 23:16
    A small bug. At least, I think it's a bug. With the following code:
    PUB off
      outa[_pin2.._pin1]~~          ' both leds off.
      ctra := ctrb := 0             ' stop doing counters while updating
    

    I get the following spin2cpp output:
    spin2cpp.linux --main LEDflash_indicator_demo.spin
    LEDflash_Indicator.spin:71: error: Symbol _pin2 is not constant
    LEDflash_Indicator.spin:71: error: Symbol _pin1 is not constant
    2 errors
    

    The code compiles fine with BST. If change the code to not use the range (an outa on each line, with a single pin argument) then spin2cpp works.

    The code is from post #9 in this thread: http://forums.parallax.com/showthread.php?143483-Make-an-LED-pulse-(smoothly-go-on-and-off)-without-any-code-interaction

    I'm not sure if this is a bug, since it seems like spin2cpp caught it. Maybe PropGCC doesn't support non-constant ranges like that?
  • ersmithersmith Posts: 6,092
    edited 2012-12-13 05:45
    SRLM wrote: »
    Re volatile:
    Thanks for that tip. I like the option of being able annotate the Spin file. Is there something similar that I can do for the DAT blocks?

    There isn't at the moment, but I'll add the same feature (so you can put {++volatile} right after the DAT statement to make the DAT block volatile).

    Incidentally, you can also put whole blocks of C code in a {++ ... } comment. Here's a made up example where we override the Spin version of methods with C versions; this is useful for putting both Spin and C/C++ wrappers to PASM in the same file:
    { indicate to spin2cpp that it should not output Spin methods }
    {++!nospin}
    
    { the Spin version of the methods }
    PUB Square(x)
      return x*x
    
    {++
    //
    // and here are the C versions of the methods
    //
    int32_t test95::Square(int32_t x)
    {
      return x*x;
    }
    
    }
    
    
  • ersmithersmith Posts: 6,092
    edited 2012-12-13 05:47
    I'm not sure if this is a bug, since it seems like spin2cpp caught it. Maybe PropGCC doesn't support non-constant ranges like that?

    It's not actually a PropGCC issue, it is spin2cpp that's at fault -- at the moment it doesn't know how to deal with non-constant ranges (which require generation of run time code to sort out the upper and lower bounds). That's a feature that's still on the "to-do" list :-).

    I'm not sure what's going on with your other example (the problem with GAS) but I'll take a look at it.

    Thanks for the bug reports,
    Eric
  • ersmithersmith Posts: 6,092
    edited 2012-12-13 16:46
    I've posted spin2cpp 1.02 at http://code.google.com/p/spin2cpp. Most of the bugs mentioned above are fixed (except that for the --gas output issue; I'm still looking into that). It also has an improved code printing algorithm that eliminates some of the unused "result" variables, which will help performance on compiles that are run optimization.

    Eric
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2012-12-13 22:57
    Hi Eric,

    Superb effort with this program.

    I've gone from a Hello World to a full calculator program which uses Kye's SD engine in the background. Sorry about pushing your program right to the limit!

    Compile with
    spin2cpp --ccode --main calc.spin
    

    which creates 4 .h and 4 .c files

    Getting multiple errors in the C code:
    ||=== Calc, Debug ===|
    SPI_ASM.c|123|warning: inconsistent linkage for `SPI_ASM_Setcommand' previously declared at SPI_ASM.c:28|
    Touch.c: .\SD-MMC_FATEngine.h|31|`0' is an illegal array size|
    Touch.c|33|syntax error; found `__attribute__' expecting `;'|
    Touch.c|33|syntax error; found `(' expecting `)'|
    Touch.c|33|skipping `(' `common'|
    Touch.c|33|syntax error; found `)' expecting `;'|
    Touch.c|33|skipping `)'|
    Touch.c|320|warning: inconsistent linkage for `TouchSpin_Begin' previously declared at Touch.c:40|
    Touch.c|724|illegal expression|
    Touch.c|724|syntax error; found `AbortHook__' expecting `)'|
    Touch.c|724|syntax error; found `AbortHook__' expecting `;'|
    Touch.c|724|illegal use of type name `AbortHook__'|
    Touch.c|724|undeclared identifier `stack__'|
    Touch.c|724|operands of * have illegal types `AbortHook__' and `int'|
    Touch.c|724|operands of = have illegal types `int' and `pointer to AbortHook__'|
    Touch.c|724|lvalue required|
    Touch.c|724|undeclared identifier `here__'|
    Touch.c|724|warning: expression with no effect elided|
    Touch.c|724|illegal use of type name `int32_t'|
    Touch.c|724|warning: expression with no effect elided|
    Touch.c|724|syntax error; found `tmp__' expecting `;'|
    Touch.c|724|warning: expression with no effect elided|
    Touch.c|724|operands of = have illegal types `pointer to AbortHook__' and `pointer to int'|
    Touch.c|724|left operand of . has incompatible type `int'|
    Touch.c|724|type error in argument 1 to `_setjmp'; found `int' expected `pointer to struct defined at C:\Program Files\Catalina\include/setjmp.h:19'|
    Touch.c|724|too many errors|
    ||=== Build finished: 21 errors, 5 warnings ===|
    

    I see you have done some bug fixes and I'm on the version from a few weeks ago.

    If you can take a look some time that would be very much appreciated :)
  • SRLMSRLM Posts: 5,045
    edited 2012-12-13 23:04
    @Dr. Acula

    It works for me. I can convert your code with the command given (after fixing for correct filenames, ie SPI_ASM), and compile with the following commands:
    propeller-elf-gcc -mcmm -Os *.c
    

    I don't get any compile errors. I suspect the problem may be in your makefile.

    Edit: I tested with the older version of spin2cpp (1.01).

    Edit2: What version of PropGCC are you using? If you didn't build it on your computer, it's probably too old.
  • ersmithersmith Posts: 6,092
    edited 2012-12-14 04:36
    Dr_Acula:

    Not all the features of spin2cpp work with Catalina yet, and abort is unfortunately one of them. I hope to fix this eventually, but in the meantime you could try compiling it with PropGCC.

    Eric
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2012-12-14 18:22
    Thanks++. I'll give it a shot with GCC.

    BTW what was wrong with the SPI_ASM again - was it the underscore or something else?
  • SRLMSRLM Posts: 5,045
    edited 2012-12-14 19:14
    Dr_Acula wrote: »
    BTW what was wrong with the SPI_ASM again - was it the underscore or something else?

    It was the filename: linux requires it to match exactly with what the OBJ sections requests.
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2012-12-16 14:36
    Thanks SRLM.

    re Eric
    Not all the features of spin2cpp work with Catalina yet, and abort is unfortunately one of them.

    I note that Kye uses abort a lot in his objects, especially abort with a backslash. I'm reading about abort now. Is there a C equivalent?

    There are 3 pages on abort in the manual and I have to confess that I don't really understand all of it very well, eg
    ...Therefore, the code must be written in a way to detect which type was used. Some possibilities are: 1) code may be designed such that a high-level method is the only place that traps an abort and other mid-level code processes things normally without allowing RETURNs to propagate higher, or 2) aborting methods may return a special value that can not occur in any normal circumstance, or 3) a global flag can be set by the aborting method prior to aborting.

    Coding all that into C may not be all that easy!
  • Heater.Heater. Posts: 21,230
    edited 2012-12-16 15:01
    Dr_A.

    Using abort we end up with A calls B calls C calls D calls E which may ABORT.
    In that case control returns to E and immediately to D and immediately to C and so on until A returns which basically halts your program.
    Unless someone in the chain is using that backslash in which case the roll back described above stops an that point and whoever it was using the backslash can do something about the failure. Try again or print a message or whatever.

    The C language does not really have this but it can be implemented with the setjmp() and longjmp() functions, Knd of like a goto that can get you back somewhere far away from your current function.

    As in the example here : http://publib.boulder.ibm.com/infocenter/tpfhelp/current/index.jsp?topic=%2Fcom.ibm.ztpf-ztpfdf.doc_put.cur%2Fgtpc2%2Fcpp_longjmp.html
    Basically setjmp remebers a place in the code but also a particular state of the stack at that time. Longjmp gets you back there and restores the stack to that state as well so that everything can proceed nicely.

    Sounds like with that ABORT will show up in spin2cpp one day.

    Wait a min, if you are generating C++ that has exceptions which should be able to do something similar.
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2012-12-16 16:55
    Some great ideas there heater. SRLM got it working in C++ in post #21, so this is for C89, and if, like you say, you can use those two jump instructions then that could be a really neat solution.
  • SRLMSRLM Posts: 5,045
    edited 2012-12-16 20:49
    Dr_Acula wrote: »
    Some great ideas there heater. SRLM got it working in C++ in post #21, so this is for C89, and if, like you say, you can use those two jump instructions then that could be a really neat solution.

    Slight correction: I got it working in GCC C, which according to this post, is C89. The "gcc" compile command will compile .c files as C, not C++. It will, however, switch over to C++ for .cpp (etc.) files. The "g++" command will compile all files as C.

    Abort is already in Spin2Cpp as a macro (at least in the cpp version, I haven't tried the --ccode option). You can see it by converting a program that already has it such as FSRW.
Sign In or Register to comment.