disable "Removed dead code"

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

disable "Removed dead code"

4,096 Views
nic_mcp
Contributor I
Hi guys,

how can i force CodeWarrior to disabling the removal of dead code?

I'm using the DEMO9S12XDT512 (HCS12) and i must disable this feature!
I read about #pragma implementation, but i don't know which pragma it is for the HCS12!

thx

nic
Labels (1)
0 Kudos
Reply
8 Replies

1,200 Views
CompilerGuru
NXP Employee
NXP Employee
What kind of "dead code" do you want to keep?
Code inside of a function which never gets executed (that's what I would call dead code)?
Or functions or other objects which do not get linked because they are not referenced?
Normally dead code inside of a function is dead, and I don't really see any reason to ever keep it, there are options in the compiler for that tought, I think.
But normally the question is asked with the idea of unreferences objects and for that case check the linker manual, more precisly the ENTRIES keywords.
Basically in the prm file, list all the additional objects in a ENTRIES name0 name1 END block.

Daniel
0 Kudos
Reply

1,200 Views
Ricardo_RauppV
Contributor I

Daniel

Meanwhile the post before I made:

 

ENTRIES
lcd_char_drv.cpp.o:*
keyboard_drv.cpp.o:*
buzzer_drv.cpp.o:*
gpio_drv.cpp.o:*
END

 

and all of my not referenced functions are now allocated in a specific address...

It seems nice..not hard taks, since the whole file can be added into list and not function by function as I thought...

Is it ok?Some side effect?

 

Thanks

Ricardo Raupp

0 Kudos
Reply

1,200 Views
Ricardo_RauppV
Contributor I

Daniel

I have several functions wich in fact are accessed only through pointer to function.

I use it to state machine control.

CW considered these functions as NOT USED, and so my pointer has allways 0x0000.

I´m using CW6.0 Pro , C++.

How can I tell CW to keep these function active, that is, they are really needed although there is not a explicit call...

Use ENTRIES? for each function? for Claases?

Is tehere a global way to make it works, like a checkbox like:

( ) Don´t discard not used objects.

Thanks in advance !!

 

Ricardo Raupp

0 Kudos
Reply

1,200 Views
CompilerGuru
NXP Employee
NXP Employee

Usages through pointer to functions should be considered too as long as the function pointer on its own is referenced.

Where do you see "and so my pointer has allways 0x0000."?

In the map file or in a target data structure?

 

Daniel

0 Kudos
Reply

1,200 Views
Ricardo_RauppV
Contributor I

Daniel

Attached a screenshot (JPG) of IDE..

It helps?

Ricardo

0 Kudos
Reply

1,200 Views
CompilerGuru
NXP Employee
NXP Employee

Strange, the first thing which comes to my mind is that the a,b,c, d locals are all unused local variables.

Therefore I wonder if the compiler did not just remove those variables.

Does it change anything if the code actually uses those variables (without ENTRIES) or with ENTRIES, are the seen values different? (without any other changes).

Which addresses does the debugger show when selecting a,b,c,d?

 

Daniel

0 Kudos
Reply

1,200 Views
Ricardo_RauppV
Contributor I

Daniel

I think this question I solved now ...

I got the right address of those functions AFTER I add "static" in fornt of its declaration in the class.

About those variables a,b,c,d....they worked perfectly after I change the functions to static....

I undesrtood that that only static function can have its address "captured/read" by a var,pointer..whatever....

Is this understanding right?

If yes..so it is finished...

Thanks Daniel ...

 

Ricardo Raupp

0 Kudos
Reply

1,200 Views
Ricardo_RauppV
Contributor I

Daniel

As I mentioned before, now my functions are allocated on ROM.Ican see their address in the map files.

Before the use of ENTRIES , none of them was there, unless in the NOT USED list...

In the constructor below I tried to catch the address of one function, but it is returning 0x00...

 


// general pointer4 to function declaration
typedef uint8 (*state_handler_t)(void*,Event const*)

 

 

Keyboard::Keyboard():
 // Super_class constructor
 Active_object((state_handler_t)&Keyboard::smileysurprised:n_initial),   // default state!!!
 // timer(s) object(s) constructor(s)
 main_timer(EVENT_KEYBOARD_MAIN_TIMER_TIMEOUT)
{
state_handler_t far a;
state_handler_t far d;
uint16 b;
uint8 c;


 
 c=Keyboard::smileysurprised:n_initial(this);   // it really runs on_initial() function...
 b=(uint16)&Keyboard::smileysurprised:n_initial;   // this result is zero.. ???
 a=(state_handler_t)&(Keyboard::smileysurprised:n_ready); // this result is zero.. ???
 d=(state_handler_t)&(Keyboard::smileysurprised:n_initial);// this result is zero.. ???
 // dummy ...
 if(a)
 {
  b++; 
 }
 
}
 
}

 

The map file shows:

  Name                                                          Addr   hSize   dSize     Ref    Section   RLIB

  on_initial__8KeyboardFP8Keyboard                    3254      15      21       1   .text       
  on_ready__8KeyboardFP8KeyboardPC5Event       3269      10      16       0   .text      

The function is:

//
uint8 Keyboard::smileysurprised:n_initial(Keyboard *me)
{
 (void)me;
 return FSM_NEW_STATE_HANDLER(&Keyboard::smileysurprised:n_ready);
}
 

It is clean for you?

Very thanks for your attention Daniel ...

0 Kudos
Reply