Shop OBEX P1 Docs P2 Docs Learn Events
Spin compiler - Page 6 — Parallax Forums

Spin compiler

12346»

Comments

  • PraxisPraxis Posts: 333
    edited 2008-07-08 14:17
    Whilst doing another project some time back we came accross this site:

    http://www.devincook.com/goldparser/download.htm

    Might be worth a look.
  • rokickirokicki Posts: 1,000
    edited 2008-07-08 17:18
    With Propellant providing a reasonable Spin compiler on Linux, I'm a bit less interested in a home-grown compiler (but not completely disinterested).
  • dfletchdfletch Posts: 165
    edited 2008-07-08 19:08
    Having minor mojo issue. Coders block or something. Back on it when my brain starts working again [noparse]:([/noparse]

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Join us in the Un-Official Propeller IRC channel: irc.freenode.net #propeller
    Newbies, oldies, programmers, math professors, and everyone in-between welcome!
    Propeller IRC howto
    spinc - open source Spin compiler
  • Jasper_MJasper_M Posts: 222
    edited 2008-07-21 09:15
    FYI,

    There has been a bytecode emitter in the CVS for about a week or so.

    It supports object structure, but I haven't tried using it with VAR variables yet. Following is code that generates a program that flashes a LED (example0 from spinparser/src/backend-examples/example0.cpp).

     MemoryImage img;
      
      //Object pointer is returned
      unsigned int obj = img.beginObject( 0 /*Parent object pointer = 0 */, 1 /* Contains only one function */, 0 /*Number of sub-objects*/, 0 /* VAR offset */);
    
      unsigned int fnptr = img.getCurrentIndex();
      //This returns function INDEX (1-based per-object index of functions)
      unsigned int fn = img.beginFunction( obj /* Pointer to the object this function belongs to */, 0 /*Number of function locals */ );
      
      //Push DIRA mask  (Literal 1) into stack
      EMIT_PUSH_1( &img );
    
      //Push DIRA index (SPR index) into stack
      EMIT_PUSH_BYTE_LIT( &img, 6 );
    
      //Write the mask into SPR
      EMIT_WRITE_INDEXED_SPR( &img );
    
      //Get current pointer, for looping
      unsigned int loopBegin = img.getCurrentIndex();
    
      //Push OUTA index into stack
      EMIT_PUSH_BYTE_LIT( &img, 4 ); 
    
      //Read OUTA contents
      EMIT_READ_INDEXED_SPR( &img );
    
      //Push OUTA mask into stack
      EMIT_PUSH_1( &img );
    
      //XOR these together, to toggle the led
      EMIT_BIT_XOR( &img );
    
      //Write the XOR result into OUTA
      EMIT_PUSH_BYTE_LIT( &img, 4 ); 
      EMIT_WRITE_INDEXED_SPR( &img );
    
    
      //Wait 0.5 sec
      //Push 24-byte literal into stack
      EMIT_PUSH_LONG_LIT( &img, 40000000 );
      EMIT_PUSH_1( &img ); //CNT index = 1
      EMIT_READ_INDEXED_SPR( &img );
      EMIT_ADD( &img );
      EMIT_WAITCNT( &img );
    
      //Loop. Signed offset given
      EMIT_BRANCH( &img, loopBegin - img.getCurrentIndex() - 2 /*For the branch instruction and the offset (here the offset is one byte, since it's greater than -64 */);
      
      //End object. Writes various information into the object header.
      img.endObject( obj );
    
      //Set various header fields
      img.setInitialFrq( 80000000 );
      img.setInitialClk( 0x6E /*PLL8X XTAL1*/ );  
      img.setEntryPoint( fnptr );
      img.setVarLength( 0 );
    
      //Output a .binary file (not an .eeprom file)
      img.setSaveMode( MemoryImage::MODE_BINARY );
    
      //Generate header for the image.
      img.generateHeader();
    
      //Save the image. 
      ofstream out( "example0.binary" );
      out << img;
      out.close();
    
    
    
Sign In or Register to comment.