[Top][All Lists]

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

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

From: Russell Shaw
Subject: Re: [avr-gcc-list] AVR-GCC question
Date: Tue, 24 May 2005 12:11:12 +1000
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.5) Gecko/20050105 Debian/1.7.5-1

Trampas wrote:
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 127
#elseif TYPE(x)==INT16
//etc, maybe if the variable is unsigned change max unsigned scaling or //
generate an error at compile time. #endif
#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++.

Look at glib/gtype in gtk. You can register simple and complex types, so that
conversions between them are automatic. gtype is far too heavy for embedded
systems. You can do similar with a much smaller implementation tho.

reply via email to

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