Let me open with the statement that I am not a C++/C programmer. The environment that I am programming in is ARMbasic, an embedded BASIC targeted toward ARM-based micro-controllers. So why am I posting herein? Well, the ARMbasic environment makes use of a tool borrowed from your folk's environment - CPP. The build details are:
C:\Program Files\Coridium>cpp --version
cpp (GCC) 3.2.3 (mingw special 20030504-1)
Copyright (C) 2002 Free Software Foundation, Inc.
CPP was added recently to the ARMbasic environment to enable the building of more complex apps, via the leveraging of existing code libraries, as I am sure all of you are aware of in the C++/C environment.
My question is this: Is there a way to get a proprocessor macro to expand to multiple lines of code?
Scenario: I have a function created where the internal Analog to Digital Converter is queried and the integer result is returned. On the target that I am programming (an NXP 2103 micro), the ADC converter is able to run at 4.5 MHZ (or less) - this equates to approx 3us if coded in ASM. If coded in C (by the ARMbasic developer), the read time is ~5us. With my ARMbasic function, due to system overhead, etc., my function is taking 11us. This is acceptable in most cases, but I have a peer that is needing higher throughput.
If I manually code my ADC reads in-line, via 2 POKES, 2 PEEKS and 1 conditional loop per ADC read, I can get the acquisition time down to 8us. The target, in this case of helping my peer out, is to get the code down to <=10us. So, the problem is solvable by manually coding in a bunch of in-line pokes/peeks. However, with the Preprocessor, it seems that I could substitute in-line code vs. the function calls by simply #define-ing a new in-line ADC input routine:
==================================================
CURRENT IMPLEMENTATION
==================================================
Current Function:
Function AD (channel as integer) as integer
CALL POKE (AD_ADCR, ((1 << channel) + AD_ENABLE))
CALL POKE (AD_ADCR, ((1 << channel) + AD_START))
DO
UNTIL (PEEK(AD_ADGDR) AND $80000000) // wait for the conversion
RETURN (PEEK(AD_ADGDR) AND $FFFF)>>6
ENDFUNCTION
Calling Code:
blah = AD(ch) // <<<<< this is 11us with above function
ARMbasic doesn't allow multiple commands on a single line of code - i.e. 1 command per line, period. If I correctly understand the many CPP guidance texts that I have read, I take it that multi-line macro definitions, when 'expanded' will actually concatenate the multi-line definition to a single line, with new-line operators embedded therein - this is my root issue...
Is there a means to easily get CPP to expand a macro definition, with passed argument substitution, to multiple lines, exactly as defined in the Macro Def?
I have searched high and low, and have come up empty handed (actually dirty handed, as I have found a couple of solutions, but those solutions require skill sets that I do not possess).
The most attractive solution is a patch to CPP that has a #begin/#end macro definition construct/directive. It is located @ http://www.cs.cornell.edu/andru/mlm.html.
The problem with both of these approaches is that I simply do not possess the tools or skill sets to take this source and compile it for use on a win32 platform...
So, my plea is this: Can someone point me toward either a win32 CPP binary that has the desired construct built-in already, or advise, in a rather detailed fashion (TIA) how one could use MCPP, in it's native form, to expand a macro definition to multiple lines, with parameter replacement and without extra syntax being added or definition syntax being altered? Please.
Is MCPP a good candidate for fulfilling my need?
Thanks for taking the time to read my diatribe.
-Tod Wulff
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Currently, MCPP does not have the requested functionality. It is a
token-oriented C/C++ preprocessor, not a line-oriented one.
Though I want to implement the feature in the future, I have many other
tasks to do for MCPP. So, its implementation will be one or more years
later from now, if any. Sorry.
I don't know whether some other tools have such feature or not. If
anyone knows something about the theme, please inform Tod.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks so much for your timely reply. Fully understood. If MCPP does indeed come to possess said functionality, and you are able to recall this thread, please reply advising same.
I bit you a wonderful 2008!
Domo arigato.
-t
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Good day folks.
Let me open with the statement that I am not a C++/C programmer. The environment that I am programming in is ARMbasic, an embedded BASIC targeted toward ARM-based micro-controllers. So why am I posting herein? Well, the ARMbasic environment makes use of a tool borrowed from your folk's environment - CPP. The build details are:
C:\Program Files\Coridium>cpp --version
cpp (GCC) 3.2.3 (mingw special 20030504-1)
Copyright (C) 2002 Free Software Foundation, Inc.
CPP was added recently to the ARMbasic environment to enable the building of more complex apps, via the leveraging of existing code libraries, as I am sure all of you are aware of in the C++/C environment.
My question is this: Is there a way to get a proprocessor macro to expand to multiple lines of code?
Scenario: I have a function created where the internal Analog to Digital Converter is queried and the integer result is returned. On the target that I am programming (an NXP 2103 micro), the ADC converter is able to run at 4.5 MHZ (or less) - this equates to approx 3us if coded in ASM. If coded in C (by the ARMbasic developer), the read time is ~5us. With my ARMbasic function, due to system overhead, etc., my function is taking 11us. This is acceptable in most cases, but I have a peer that is needing higher throughput.
If I manually code my ADC reads in-line, via 2 POKES, 2 PEEKS and 1 conditional loop per ADC read, I can get the acquisition time down to 8us. The target, in this case of helping my peer out, is to get the code down to <=10us. So, the problem is solvable by manually coding in a bunch of in-line pokes/peeks. However, with the Preprocessor, it seems that I could substitute in-line code vs. the function calls by simply #define-ing a new in-line ADC input routine:
==================================================
CURRENT IMPLEMENTATION
==================================================
Current Function:
Function AD (channel as integer) as integer
CALL POKE (AD_ADCR, ((1 << channel) + AD_ENABLE))
CALL POKE (AD_ADCR, ((1 << channel) + AD_START))
DO
UNTIL (PEEK(AD_ADGDR) AND $80000000) // wait for the conversion
RETURN (PEEK(AD_ADGDR) AND $FFFF)>>6
ENDFUNCTION
Calling Code:
blah = AD(ch) // <<<<< this is 11us with above function
==================================================
DESIRED IMPLEMENTATION
==================================================
Desired Inline Macro:
#begin ADC_INLINE (channel,variable)
CALL POKE (AD_ADCR, ((1 << channel) + AD_ENABLE))
CALL POKE (AD_ADCR, ((1 << channel) + AD_START))
DO
UNTIL (PEEK(AD_ADGDR) AND $80000000) // wait for the conversion
variable = (PEEK(AD_ADGDR) AND $FFFF)>>6
#end[/CODE]
New Calling Code?:
[CODE]ADC_INLINE (6, blah) // <<< this should yield target speed
==================================================
ARMbasic doesn't allow multiple commands on a single line of code - i.e. 1 command per line, period. If I correctly understand the many CPP guidance texts that I have read, I take it that multi-line macro definitions, when 'expanded' will actually concatenate the multi-line definition to a single line, with new-line operators embedded therein - this is my root issue...
Is there a means to easily get CPP to expand a macro definition, with passed argument substitution, to multiple lines, exactly as defined in the Macro Def?
I have searched high and low, and have come up empty handed (actually dirty handed, as I have found a couple of solutions, but those solutions require skill sets that I do not possess).
The most attractive solution is a patch to CPP that has a #begin/#end macro definition construct/directive. It is located @ http://www.cs.cornell.edu/andru/mlm.html.
A viable alternate solution seems to be located @ http://www.cabaret.demon.co.uk/filepp/.
The problem with both of these approaches is that I simply do not possess the tools or skill sets to take this source and compile it for use on a win32 platform...
So, my plea is this: Can someone point me toward either a win32 CPP binary that has the desired construct built-in already, or advise, in a rather detailed fashion (TIA) how one could use MCPP, in it's native form, to expand a macro definition to multiple lines, with parameter replacement and without extra syntax being added or definition syntax being altered? Please.
Is MCPP a good candidate for fulfilling my need?
Thanks for taking the time to read my diatribe.
-Tod Wulff
Currently, MCPP does not have the requested functionality. It is a
token-oriented C/C++ preprocessor, not a line-oriented one.
Though I want to implement the feature in the future, I have many other
tasks to do for MCPP. So, its implementation will be one or more years
later from now, if any. Sorry.
I don't know whether some other tools have such feature or not. If
anyone knows something about the theme, please inform Tod.
Kiyoshi,
Thanks so much for your timely reply. Fully understood. If MCPP does indeed come to possess said functionality, and you are able to recall this thread, please reply advising same.
I bit you a wonderful 2008!
Domo arigato.
-t