Object pragma or directive?
w8an
Posts: 176
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
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
Leon
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Amateur radio callsign: G1HSM
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
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
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
Post Edited (Todd Chapman) : 11/15/2009 9:44:37 PM GMT
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.
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
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.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.smarthome.viviti.com/build
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
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.
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
-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.
Only Brad's tool does that, not Homespun.