CHDK_DE Vorschauversion  Trunk Rev. 6014
 Alle Datenstrukturen Dateien Funktionen Variablen Typdefinitionen Aufzählungen Aufzählungswerte Makrodefinitionen
print.c-Dateireferenz
#include <ctype.h>
#include <stdio.h>
#include "ldebug.h"
#include "lobject.h"
#include "lopcodes.h"
#include "lundump.h"
+ Include-Abhängigkeitsdiagramm für print.c:

gehe zum Quellcode dieser Datei

Makrodefinitionen

#define luac_c
 
#define LUA_CORE
 
#define PrintFunction   luaU_print
 
#define Sizeof(x)   ((int)sizeof(x))
 
#define VOID(p)   ((const void*)(p))
 
#define SS(x)   (x==1)?"":"s"
 
#define S(x)   x,SS(x)
 

Funktionen

static void PrintString (const TString *ts)
 
static void PrintConstant (const Proto *f, int i)
 
static void PrintCode (const Proto *f)
 
static void PrintHeader (const Proto *f)
 
static void PrintConstants (const Proto *f)
 
static void PrintLocals (const Proto *f)
 
static void PrintUpvalues (const Proto *f)
 
void PrintFunction (const Proto *f, int full)
 

Makro-Dokumentation

#define LUA_CORE

Definiert in Zeile 11 der Datei print.c.

#define luac_c

Definiert in Zeile 10 der Datei print.c.

#define PrintFunction   luaU_print

Definiert in Zeile 18 der Datei print.c.

#define S (   x)    x,SS(x)

Definiert in Zeile 159 der Datei print.c.

#define Sizeof (   x)    ((int)sizeof(x))

Definiert in Zeile 20 der Datei print.c.

#define SS (   x)    (x==1)?"":"s"

Definiert in Zeile 158 der Datei print.c.

#define VOID (   p)    ((const void*)(p))

Definiert in Zeile 21 der Datei print.c.

Dokumentation der Funktionen

static void PrintCode ( const Proto f)
static

Definiert in Zeile 74 der Datei print.c.

75 {
76  const Instruction* code=f->code;
77  int pc,n=f->sizecode;
78  for (pc=0; pc<n; pc++)
79  {
80  Instruction i=code[pc];
81  OpCode o=GET_OPCODE(i);
82  int a=GETARG_A(i);
83  int b=GETARG_B(i);
84  int c=GETARG_C(i);
85  int bx=GETARG_Bx(i);
86  int sbx=GETARG_sBx(i);
87  int line=getline(f,pc);
88  printf("\t%d\t",pc+1);
89  if (line>0) printf("[%d]\t",line); else printf("[-]\t");
90  printf("%-9s\t",luaP_opnames[o]);
91  switch (getOpMode(o))
92  {
93  case iABC:
94  printf("%d",a);
95  if (getBMode(o)!=OpArgN) printf(" %d",ISK(b) ? (-1-INDEXK(b)) : b);
96  if (getCMode(o)!=OpArgN) printf(" %d",ISK(c) ? (-1-INDEXK(c)) : c);
97  break;
98  case iABx:
99  if (getBMode(o)==OpArgK) printf("%d %d",a,-1-bx); else printf("%d %d",a,bx);
100  break;
101  case iAsBx:
102  if (o==OP_JMP) printf("%d",sbx); else printf("%d %d",a,sbx);
103  break;
104  }
105  switch (o)
106  {
107  case OP_LOADK:
108  printf("\t; "); PrintConstant(f,bx);
109  break;
110  case OP_GETUPVAL:
111  case OP_SETUPVAL:
112  printf("\t; %s", (f->sizeupvalues>0) ? getstr(f->upvalues[b]) : "-");
113  break;
114  case OP_GETGLOBAL:
115  case OP_SETGLOBAL:
116  printf("\t; %s",svalue(&f->k[bx]));
117  break;
118  case OP_GETTABLE:
119  case OP_SELF:
120  if (ISK(c)) { printf("\t; "); PrintConstant(f,INDEXK(c)); }
121  break;
122  case OP_SETTABLE:
123  case OP_ADD:
124  case OP_SUB:
125  case OP_MUL:
126  case OP_DIV:
127  case OP_POW:
128  case OP_EQ:
129  case OP_LT:
130  case OP_LE:
131  if (ISK(b) || ISK(c))
132  {
133  printf("\t; ");
134  if (ISK(b)) PrintConstant(f,INDEXK(b)); else printf("-");
135  printf(" ");
136  if (ISK(c)) PrintConstant(f,INDEXK(c)); else printf("-");
137  }
138  break;
139  case OP_JMP:
140  case OP_FORLOOP:
141  case OP_FORPREP:
142  printf("\t; to %d",sbx+pc+2);
143  break;
144  case OP_CLOSURE:
145  printf("\t; %p",VOID(f->p[bx]));
146  break;
147  case OP_SETLIST:
148  if (c==0) printf("\t; %d",(int)code[++pc]);
149  else printf("\t; %d",c);
150  break;
151  default:
152  break;
153  }
154  printf("\n");
155  }
156 }
static void PrintConstant ( const Proto f,
int  i 
)
static

Definiert in Zeile 51 der Datei print.c.

52 {
53  const TValue* o=&f->k[i];
54  switch (ttype(o))
55  {
56  case LUA_TNIL:
57  printf("nil");
58  break;
59  case LUA_TBOOLEAN:
60  printf(bvalue(o) ? "true" : "false");
61  break;
62  case LUA_TNUMBER:
64  break;
65  case LUA_TSTRING:
67  break;
68  default: /* cannot happen */
69  printf("? type=%d",ttype(o));
70  break;
71  }
72 }
static void PrintConstants ( const Proto f)
static

Definiert in Zeile 181 der Datei print.c.

182 {
183  int i,n=f->sizek;
184  printf("constants (%d) for %p:\n",n,VOID(f));
185  for (i=0; i<n; i++)
186  {
187  printf("\t%d\t",i+1);
188  PrintConstant(f,i);
189  printf("\n");
190  }
191 }
void PrintFunction ( const Proto f,
int  full 
)

Definiert in Zeile 215 der Datei print.c.

216 {
217  int i,n=f->sizep;
218  PrintHeader(f);
219  PrintCode(f);
220  if (full)
221  {
222  PrintConstants(f);
223  PrintLocals(f);
224  PrintUpvalues(f);
225  }
226  for (i=0; i<n; i++) PrintFunction(f->p[i],full);
227 }
static void PrintHeader ( const Proto f)
static

Definiert in Zeile 161 der Datei print.c.

162 {
163  const char* s=getstr(f->source);
164  if (*s=='@' || *s=='=')
165  s++;
166  else if (*s==LUA_SIGNATURE[0])
167  s="(bstring)";
168  else
169  s="(string)";
170  printf("\n%s <%s:%d,%d> (%d instruction%s, %d bytes at %p)\n",
171  (f->linedefined==0)?"main":"function",s,
174  printf("%d%s param%s, %d slot%s, %d upvalue%s, ",
175  f->numparams,f->is_vararg?"+":"",SS(f->numparams),
176  S(f->maxstacksize),S(f->nups));
177  printf("%d local%s, %d constant%s, %d function%s\n",
178  S(f->sizelocvars),S(f->sizek),S(f->sizep));
179 }
static void PrintLocals ( const Proto f)
static

Definiert in Zeile 193 der Datei print.c.

194 {
195  int i,n=f->sizelocvars;
196  printf("locals (%d) for %p:\n",n,VOID(f));
197  for (i=0; i<n; i++)
198  {
199  printf("\t%d\t%s\t%d\t%d\n",
200  i,getstr(f->locvars[i].varname),f->locvars[i].startpc+1,f->locvars[i].endpc+1);
201  }
202 }
static void PrintString ( const TString ts)
static

Definiert in Zeile 23 der Datei print.c.

24 {
25  const char* s=getstr(ts);
26  size_t i,n=ts->tsv.len;
27  putchar('"');
28  for (i=0; i<n; i++)
29  {
30  int c=s[i];
31  switch (c)
32  {
33  case '"': printf("\\\""); break;
34  case '\\': printf("\\\\"); break;
35  case '\a': printf("\\a"); break;
36  case '\b': printf("\\b"); break;
37  case '\f': printf("\\f"); break;
38  case '\n': printf("\\n"); break;
39  case '\r': printf("\\r"); break;
40  case '\t': printf("\\t"); break;
41  case '\v': printf("\\v"); break;
42  default: if (isprint((unsigned char)c))
43  putchar(c);
44  else
45  printf("\\%03u",(unsigned char)c);
46  }
47  }
48  putchar('"');
49 }
static void PrintUpvalues ( const Proto f)
static

Definiert in Zeile 204 der Datei print.c.

205 {
206  int i,n=f->sizeupvalues;
207  printf("upvalues (%d) for %p:\n",n,VOID(f));
208  if (f->upvalues==NULL) return;
209  for (i=0; i<n; i++)
210  {
211  printf("\t%d\t%s\n",i,getstr(f->upvalues[i]));
212  }
213 }