6 char* rcs_print
="$Id: print.c,v 1.17 1997/06/25 17:07:28 lhf Exp $";
14 void LinkFunctions(TFunc
* m
)
16 static TFunc
* lastF
; /* list of functions seen in code */
18 Byte
* end
=code
+m
->size
;
20 if (IsMain(m
)) lastF
=m
;
100 p
+=5; /* assumes sizeof(float)==4 */
108 tf
->next
=NULL
; /* TODO: remove? */
109 lastF
=lastF
->next
=tf
;
118 default: /* cannot happen */
119 fprintf(stderr
,"luac: bad opcode %d at %d\n",*p
,(int)(p
-code
));
126 #define LocStr(i) luaI_getlocalname(tf,i+1,line)
128 static void PrintCode(TFunc
* tf
)
131 Byte
* end
=code
+tf
->size
;
134 for (p
=code
; p
!=end
;)
139 fprintf(stderr
,"luac: bad opcode %d at %d\n",op
,(int)(p
-code
));
142 printf("%6d\t%s",(int)(p
-code
),OpCodeName
[op
]);
181 if (tf
->locvars
) printf("\t\t; %s",LocStr(i
));
196 int i
=op
-STORELOCAL0
;
197 if (tf
->locvars
) printf("\t\t; %s",LocStr(i
));
205 if (tf
->locvars
) printf("\t%d\t; %s",i
,LocStr(i
));
216 printf("\t%d",*(p
+1));
227 if (op
==SETLINE
) line
=w
;
234 { /* suggested by Norman Ramsey <nr@cs.virginia.edu> */
238 printf("\t%d\t\t; to %d",w
,(int)(p
-code
)+w
);
243 { /* suggested by Norman Ramsey <nr@cs.virginia.edu> */
247 printf("\t%d\t\t; to %d",w
,(int)(p
-code
)-w
);
264 printf("\t%d\t; \"%s\"",w
,StrStr(w
));
272 printf("\t%p\t; \"%s\":%d",tf
,tf
->fileName
,tf
->lineDefined
);
281 printf("\t%d\t; %s",w
,VarStr(w
));
286 printf("\t%d %d",*(p
+1),*(p
+2));
297 printf("\n%6d\t FIELD",(int)(p
-code
));
299 printf("\t%d\t; \"%s\"",w
,StrStr(w
));
304 printf("\tcannot happen: opcode=%d\n",*p
);
305 fprintf(stderr
,"luac: bad opcode %d at %d\n",op
,(int)(p
-code
));
315 static void PrintLocals(LocVar
* v
, int n
)
318 if (v
==NULL
|| v
->varname
==NULL
) return;
321 printf("parameters:");
322 for (i
=0; i
<n
; v
++,i
++) printf(" %s[%d@%d]",v
->varname
->str
,i
,v
->line
);
325 if (v
->varname
!=NULL
)
328 for (; v
->line
>=0; v
++)
330 if (v
->varname
==NULL
)
332 printf(" %s[%d@%d]","*",--i
,v
->line
);
337 printf(" %s[%d@%d]",v
->varname
->str
,i
++,v
->line
);
343 void PrintFunction(TFunc
* tf
, TFunc
* Main
)
347 printf("\nmain of \"%s\" (%d bytes at %p)\n",tf
->fileName
,tf
->size
,tf
);
351 p
=tf
->code
; /* get number of parameters */
352 while (*p
==SETLINE
) p
+=3;
353 if (*p
==ADJUST
) n
=p
[1];
354 p
=Main
->code
+tf
->marked
+sizeof(TFunc
*);
355 printf("\nfunction ");
356 switch (*p
) /* try to get name */
361 p
++; get_word(w
,p
); printf("%s defined at ",VarStr(w
));
364 case STOREINDEXED0
: /* try method definition */
366 if (p
[-11]==PUSHGLOBAL
&& p
[-8]==PUSHSTRING
)
370 int c
=(tf
->locvars
&& n
>0 && strcmp(tf
->locvars
->varname
->str
,"self")==0)
372 p
=op
-11; p
++; get_word(w
,p
); printf("%s%c",VarStr(w
),c
);
373 p
=op
-8; p
++; get_word(w
,p
); printf("%s defined at ",StrStr(w
));
378 printf("\"%s\":%d (%d bytes at %p); used at main+%d\n",
379 tf
->fileName
,tf
->lineDefined
,tf
->size
,tf
,tf
->marked
);
381 PrintLocals(tf
->locvars
,n
);