[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [avr-gcc-list] AVR-GCC question

From: Trampas
Subject: RE: [avr-gcc-list] AVR-GCC question
Date: Mon, 23 May 2005 13:55:21 -0400

My dream is for "Meta" compiler. 

That is I would like a compiler where I could expand the functionality, such
that I write code to write the code for me. 

For example, lets take a real world example in which I want to run a debug
version of my code which keeps track of the stack usage. I have done this in
the past by something like:

void foo(void)
        UINT8 temp;

        printf("stack %s %x\n","foo",&temp);

Well I would like a similar printf statement added to each  and every
function in my program, so what I would like is to have a way to incorporate
macros into code based upon C's grammer and lexial structure. Kind of like:

#pragma @eachfunction { UINT8 temp123; printf("stack %s
%x\n",__FUNCTION_NAME_,&temp123); }

Thus it would insert macro at the beginning of each and every function. This
would generate a call graph and stack usage as the program ran. Imagine what
you could do if you also printed out the arguments and return values from
the function. Sure most debuggers do it now, but.... 

Additionally you could have the compiler implement polymorphism while
keeping C code. For example you could at compile time check variables types
and conditionally create code. 

For example lets say I wanted to convert a fixed point number to a floating
point number from -1.0 to 1.0; Normally for an 8 bit value you might do the

float new;
INT8  old;


well imagine having a compiler which could look at the variable's
attritubts, then you could create a macro:

#define ToFloat(x) ((float)x/(float)MAX_SIGNED(x));

Where MAX_SIGNED could be macro like:

#pragma macro MAX_SIGNED(x)

#if TYPE(x)==INT8 
#elseif TYPE(x)==INT16
//etc, maybe if the variable is unsigned change max unsigned scaling or //
generate an error at compile time. 
#pragma end macro

Of course the syntax and grammar would need to be further developed but you
get the idea. 

The advantages would be that you could start making some really generic
libraries and could code the way you wanted. You could prototype compiler
features easy, kind of like scripting. 

Think about having a FIFO coded in C where it used polymorphism like C++
with out all the overhead, that is the FIFO library code would be generated
at compile time kind of like standard templates in C++.  



-----Original Message-----
From: address@hidden
[mailto:address@hidden On Behalf Of Joerg
Sent: Monday, May 23, 2005 12:57 PM
To: address@hidden
Subject: Re: [avr-gcc-list] AVR-GCC question

"E. Weddington" <address@hidden> wrote:

>>It would be nice if some form of polymorphism happened that allowed
>>the compiler/linker to automagically pick the right function to
>>handle a given data type though.

> Sure, it's called C++. :-)

And not so sure whether you'd really want to pay the penalty for it,
as it causes code bloat (all routines must be able to handle all
memory regions, even though some of them perhaps aren't used in all of
the functions), as well as increased execution time (late binding
model, aka. virtual method table).

cheers, J"org               .-.-.   --... ...--   -.. .  DL8DTL

http://www.sax.de/~joerg/                        NIC: JW11-RIPE
Never trust an operating system you don't have sources for. ;-)

AVR-GCC-list mailing list

reply via email to

[Prev in Thread] Current Thread [Next in Thread]