Shop OBEX P1 Docs P2 Docs Learn Events
Object pragma or directive? — Parallax Forums

Object pragma or directive?

w8anw8an Posts: 176
edited 2009-11-16 05:37 in Propeller 1
I'm new to this wonderful Propeller chip and am finding many fine library objects out there to increase my programming productivity. However some of these objects have far more functions built in than I need.

I'm wondering if there is any pragma or directive mechanism in place that will load only the object functions that I use in my project, rather than the full set of each object spin file?

Steve

Comments

  • LeonLeon Posts: 7,620
    edited 2009-11-15 20:51
    Just remove the ones you don't need.

    Leon

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Amateur radio callsign: G1HSM
  • w8anw8an Posts: 176
    edited 2009-11-15 21:22
    So I guess that means no.
  • MicrocontrolledMicrocontrolled Posts: 2,461
    edited 2009-11-15 21:24
    Yes you are correct. There is nothing that can do that.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Computers are microcontrolled.

    Robots are microcontrolled.
    I am microcontrolled.

    But you·can·call me micro.

    Want to·experiment with the SX or just put together a cool project?
    SX Spinning light display·
    Want cheap wholesale electronic parts?
    Transistor parts wholesale
  • T ChapT Chap Posts: 4,223
    edited 2009-11-15 21:24
    http://forums.parallax.com/showthread.php?p=735978

    Clean will delete all unused parts and resave the object with a new name CLEAN_objectname. Then in the future you can only refer to the CLEANED object which contains your minimal content.

    Post Edited (Todd Chapman) : 11/15/2009 9:38:49 PM GMT
  • w8anw8an Posts: 176
    edited 2009-11-15 21:33
    Thanks, Todd. That will work.
  • T ChapT Chap Posts: 4,223
    edited 2009-11-15 21:38
    Actually use wClean, a self contained app that does the same thing, thats my pref.

    Post Edited (Todd Chapman) : 11/15/2009 9:44:37 PM GMT
  • w8anw8an Posts: 176
    edited 2009-11-15 21:43
    Both CLEAN.zip and wCLEAN.zip are attached to that forum post you referenced.
  • Mike GreenMike Green Posts: 23,101
    edited 2009-11-15 22:10
    mpark's HomeSpun Spin compiler has an option to remove unused method code in an object and leaving just a "stub" entry in one of the tables used internally in the object's compiled code.
  • w8anw8an Posts: 176
    edited 2009-11-15 22:19
    Thanks, Mike. I'll check that one out too.
  • BradCBradC Posts: 2,601
    edited 2009-11-16 00:28
    microcontrolled said...
    Yes you are correct. There is nothing that can do that.

    Actually that's not correct. With redundant method removal enabled, bst[noparse][[/noparse]c] does not compile any spin code that is not used.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    If you always do what you always did, you always get what you always got.
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2009-11-16 00:39
    To expand on BradC's comment, yes there is a solution as BST allows the use of #ifdef commands so you can set a list of these at the beginning (true by including them, false by putting a ' in front of that line). Then go through the entire code and put the blocks you want inside #ifdefs. Only the ones that are true will be compiled. This technique is being used extensively in the zicog project where there are multiple hardware platforms for the same code and one needs an easy system of having one set of code, multiple developers and different hardware. If this looks interesting, maybe take a look at the zicog thread and download some example code.

    Another option is to mindlessly go through and put a ' in front of all the code you don't want. But I prefer Brad's program. BST takes a little bit of fiddling to get working but if you write a tiny batch file you can do a compile/download/run with one double click.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.smarthome.viviti.com/build
  • w8anw8an Posts: 176
    edited 2009-11-16 01:10
    I'm not familiar with BST or bst[noparse][[/noparse]c]. Is this a C compiler for the Propeller?

    I was looking for a way to exclude unused object functions from from my final spin code.
  • BradCBradC Posts: 2,601
    edited 2009-11-16 01:14
    w8an said...
    I'm not familiar with BST or bst[noparse][[/noparse]c]. Is this a C compiler for the Propeller?

    I was looking for a way to exclude unused object functions from from my final spin code.

    No, it's a third party tool that is code compatible with the Parallax tools.

    www.fnarfbargle.com/bst.html

    Both compilers (the command line and the IDE) have an option to remove all unused spin code in the final compile. It can save a significant amount of space when you are including objects to only use one or two methods.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    If you always do what you always did, you always get what you always got.
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2009-11-16 01:49
    BST is a complete replacement for the Propeller tool. It edits. It compiles. It does all the things the Parallax program does, but in addition it has the ability to do conditional compiles. So you can easily leave out large parts of existing objects by putting #ifdef and #endif round the code and then adding a list of #defines at the beginning. (the exact sytnax eludes my memory for the moment as I don't have an example in front of me but I can get this if you like). Follow that link of Brads, then I think it is the 184 version.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.smarthome.viviti.com/build
  • w8anw8an Posts: 176
    edited 2009-11-16 02:01
    Ooh! BST sounds great. I will definitely check that out! Thanks
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2009-11-16 03:10
    The synax is
    CON
    #define MyObj1 ' where MyObj1 is now true
    '#define MyObj2 ' where MyObj2 is false as it is commented out

    PUB or PRI
    #ifdef MyObj1
    ... code here
    #else
    ... optional else code here (or don't use #else)
    #endif

    #ifdef MyObj2
    ... code here
    #endif

    So you could take an existing object, add a #define SmallObject at the beginning and then put lots of #ifdef SmallObject all through the code around (say) each PUB or PRI. That defaults to including that #ifdef code, so then if you want to exclude that from compilation, comment out the #define at the beginning. Now the #define is false and all the #ifdef code will not be included in the compilation. Maybe do it in stages as some bits of code might depend on other parts.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.smarthome.viviti.com/build
  • BradCBradC Posts: 2,601
    edited 2009-11-16 03:24
    Dr_Acula said...

    So you could take an existing object, add a #define SmallObject at the beginning and then put lots of #ifdef SmallObject all through the code around (say) each PUB or PRI. That defaults to including that #ifdef code, so then if you want to exclude that from compilation, comment out the #define at the beginning. Now the #define is false and all the #ifdef code will not be included in the compilation. Maybe do it in stages as some bits of code might depend on other parts.

    But James, the point I'm trying to make is you don't have to go to all those lengths. Just enable -Or (in the command line version) and the compiler automatically does it for you. Each Spin method is reference checked. On the next compilation pass any methods not referenced in the previous compilation are excluded. This occurs repetitively until all unused methods are completely eliminated. No stubs, no traces.. just gone.. No #define required [noparse]:)[/noparse]

    It has occurred to me that I don't actually know what happens if you include an object and none of the object is referenced. I must check that. Would be useful for a common object that just contained constants and a dummy spin method as it should be completely omitted in the final link. I don't actually think I thought of that when I did the elimination code though.

    In the IDE, redundant method removal is an option in the compiler options dialog (either globally or on a per-project basis).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    If you always do what you always did, you always get what you always got.
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2009-11-16 04:38
    Ah Brad, that sounds nifty. In fact, there seems to be a number of very clever features with BST. I only recently had a 'lightbulb' moment having used the command line interface for some time. Being a typical male I was ignoring the instructions, or what I thought was the 'guide'. LOL to me when I worked out that the 'guide' was in fact the "GUI IDE"

    To w8an, I have no affiliation with BST, except as a very happy user who is now using it exclusively for all my propeller work.

    To Brad, I *think* I understand the -Or directive. That works in the command line version right? Checking the IDE version now...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.smarthome.viviti.com/build
  • BradCBradC Posts: 2,601
    edited 2009-11-16 04:45
    Dr_Acula said...

    To Brad, I *think* I understand the -Or directive. That works in the command line IDE, right? Does it also apply to the IDE version?

    -Or is for the command line compiler only. In the IDE you need to go
    Tools -> Compiler Preferences -> Optimisations -> "Eliminate unused SPIN methods".
    ..or..
    Project -> Project Options -> Optimisations -> and so on...

    If you do it in the project specific box, don't forget to tell it to override the global compiler optimisations.

    Most of the other optimisations are pretty minor, although "Fold Constants" can save a bit of space and runtime if you have constant expressions in your code and don't have them in Constant() methods.

    I guess you are already using -Ox for the "Non-Parallax compatible Extensions", so you need only add an "r" to that. Or, do what I do and use -Oa to enable all the optimisations.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    If you always do what you always did, you always get what you always got.
  • mparkmpark Posts: 1,305
    edited 2009-11-16 05:37
    Mike Green said...
    mpark's HomeSpun Spin compiler has an option to remove unused method code in an object and leaving just a "stub" entry in one of the tables used internally in the object's compiled code.

    Only Brad's tool does that, not Homespun.
Sign In or Register to comment.