Article 1186 of dec.notes.technology.dechips:
Title: New instructions in EV56
Reply Title: Running the proggie is not necessary

  >>  One could always code up a simple atom tool to count the number of load
  >>  byte instructions and whatever other instructions you wanted.
  >  
  >  But that would involve running the proggie. 
    
    Not at all.  Here's a atom program which gives a static count of
    the number of loads, stores, and instructions in a program.
    
        atom  a.out below.c
    
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cmplrs/atom.inst.h>

unsigned InstrumentAll(int argc, char **argv) {
    Obj *obj;
    Proc *proc;
    Block *blk;
    Inst *inst;
    const char *obj_name;

    int num_inst = 0;
    int num_store = 0;
    int num_loads = 0;


    for (obj = GetFirstObj(); obj; obj = GetNextObj(obj)) {
	int obj_inst = 0;
	int obj_store = 0;
	int obj_loads = 0;

	if (BuildObj(obj)) continue;
	obj_name = GetObjName(obj);
	if (strncmp(obj_name, "/usr/shlib", 10) == 0) {
	  WriteObj(obj);
	  continue;
	}

#if 0
	printf("%10s: %8s %8s %8s\n", "Procedure", "Insts", "Stores", "Loads");
#endif
	for(proc = GetFirstProc(); proc; proc = GetNextProc(proc)) {
	    const char *procname = ProcName(proc);
	    const char *filename = ProcFileName(proc);

	    int proc_inst = 0;
	    int proc_store = 0;
	    int proc_loads = 0;

#if 0
	    if ((procname == NULL) || (procname[0] == '_')) continue;
	    if (filename == NULL) continue;
	    if ((strncmp(filename+strlen(filename)-3, "bli", 3) == 0)
	     || (strncmp(filename, "/tle", 4) == 0)) {
		continue;
	    }
	    printf("%s in %s\n", ProcName(proc), ProcFileName(proc)); fflush(0);
#endif

	    for(blk = GetFirstBlock(proc); blk; blk = GetNextBlock(blk)) {
		for(inst = GetFirstInst(blk); inst; inst = GetNextInst(inst)) {
		    proc_inst++;
		    if (IsInstType(inst, InstTypeStore)) {
			proc_store++;
		    } else if (IsInstType(inst, InstTypeLoad)) {
			proc_loads++;
		    }
		}
	    }
	    printf("%10s: %8d %8d %8d\n", ProcName(proc) ? ProcName(proc) : "?", 
                   proc_inst, proc_store, proc_loads);

            obj_inst += proc_inst;
            obj_store += proc_store;
            obj_loads += proc_loads;
	 }

#if 0
	puts("---------------------------------------");
#endif
	printf("%10s: %8d %8d %8d\n", 
               obj_name, obj_inst, obj_store, obj_loads);
	fflush(0);

	num_inst += obj_inst;
	num_store += obj_store;
        num_loads += obj_loads;

	WriteObj(obj);
    }
#if 0
    puts("----------------------------------");
    printf("%40s: %8d %8d %8d\n", "grand total", 
            num_inst, num_store, num_loads);
#endif
    exit(EXIT_SUCCESS);

    return 1;
}


