Unused methods are increasing code size
DavidZemon
Posts: 2,973
I'm looking for a way to add printf support to PropWare's UART classes, but I certainly don't want it to balloon the code size when they aren't being used. In my latest commit I added printf support to abstractsimplexuart.h as well as a new CMake option called "AUTO_CUT_SECTIONS" which simply adds the "-ffunction-sections -fdata-sections" and "--gc-sections".
Without changing the code in the Duplex demo, size increased by ~1kB (based on the size reported by propeller-load which, though not accurate, is good enough for comparison's sake right?).
Anyone have ideas on why these unused functions aren't being deleted?
Thanks,
David
Without changing the code in the Duplex demo, size increased by ~1kB (based on the size reported by propeller-load which, though not accurate, is good enough for comparison's sake right?).
Anyone have ideas on why these unused functions aren't being deleted?
Thanks,
David
Comments
There used to be an option "-fvtable-gc" but it reportedly didn't work and was removed. I tried "-fwhole-program" too and though it helped in other regards, it didn't help remove the unused virtual methods.
Separation of concerns would suggest that a UART class does UART things and a formatted printing class does formatting things.
That way both functionalities can be used independently and neither bloats the other.
I'm 100% with you on that. But the next best option is way more difficult: using C++'s stream functionality. Never done it before. Any idea if it would make code size bloat up significantly?
_Edit_
Nevermind. Maybe you're right about creating a wrapper class that contains an instance of UART and has all of the formatted printing functionality. Hmm......
In the C world we would just gave functions for formatted printing that get their actual output device from a function pointer. You can redirect output to different places by initialising them with different output functions.
I guess in C++ you might want to do this by passing a output device object into the constructor of you printing class.
Hmm...thinks...perhaps that what you said above:)
Yep, that's exactly what I ended up doing. I created a PrintCapable interface that UART inherits from and a Printer class that takes a PrintCapable in the constructor. It will allow you to very easily use any communication protocol you want with the printf method - the same way the Simple libraries use text_t structs. I also created an instance of a UART and a Printer in printer.cpp so that the user can just call "pwOut.printf" from their code without having to instantiate any instances of their own. I think PropWare is really coming along nicely
Now if only I could get synchronous printing to work :frown: