Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
print.c File Reference
#include <ctype.h>
#include <stdio.h>
#include "ldebug.h"
#include "lobject.h"
#include "lopcodes.h"
#include "lundump.h"

Go to the source code of this file.

Macros

#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)
 

Functions

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)
 

Macro Definition Documentation

◆ LUA_CORE

#define LUA_CORE

Definition at line 11 of file print.c.

◆ luac_c

#define luac_c

Definition at line 10 of file print.c.

◆ PrintFunction

#define PrintFunction   luaU_print

Definition at line 18 of file print.c.

Referenced by PrintFunction(), PrintFunction(), PrintFunction(), and PrintFunction().

◆ S

◆ Sizeof

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

Definition at line 20 of file print.c.

Referenced by PrintHeader().

◆ SS

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

Definition at line 158 of file print.c.

Referenced by PrintHeader().

◆ VOID

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

Definition at line 21 of file print.c.

Referenced by PrintCode(), PrintConstants(), PrintHeader(), PrintLocals(), and PrintUpvalues().

Function Documentation

◆ PrintCode()

static void PrintCode ( const Proto * f)
static

Definition at line 74 of file 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}
#define getline(f, pc)
lu_int32 Instruction
#define svalue(o)
#define getstr(ts)
const char *const luaP_opnames[NUM_OPCODES+1]
#define ISK(x)
#define GETARG_A(i)
#define GETARG_sBx(i)
#define GETARG_B(i)
#define getCMode(m)
#define GET_OPCODE(i)
#define INDEXK(r)
#define GETARG_Bx(i)
#define getBMode(m)
#define GETARG_C(i)
#define getOpMode(m)
#define VOID(p)
Definition print.c:21
static void PrintConstant(const Proto *f, int i)
Definition print.c:51
Instruction * code
struct Proto ** p
TString ** upvalues
#define printf

References Proto::code, GET_OPCODE, GETARG_A, GETARG_B, GETARG_Bx, GETARG_C, GETARG_sBx, getBMode, getCMode, getline, getOpMode, getstr, iABC, iABx, iAsBx, INDEXK, ISK, Proto::k, luaP_opnames, OP_ADD, OP_CLOSURE, OP_DIV, OP_EQ, OP_FORLOOP, OP_FORPREP, OP_GETGLOBAL, OP_GETTABLE, OP_GETUPVAL, OP_JMP, OP_LE, OP_LOADK, OP_LT, OP_MUL, OP_POW, OP_SELF, OP_SETGLOBAL, OP_SETLIST, OP_SETTABLE, OP_SETUPVAL, OP_SUB, OpArgK, OpArgN, Proto::p, PrintConstant(), printf, Proto::sizecode, Proto::sizeupvalues, svalue, Proto::upvalues, and VOID.

Referenced by PrintFunction().

◆ PrintConstant()

static void PrintConstant ( const Proto * f,
int i )
static

Definition at line 51 of file 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}
#define nvalue(o)
#define rawtsvalue(o)
#define bvalue(o)
#define ttype(o)
#define LUA_TSTRING
#define LUA_TBOOLEAN
#define LUA_TNUMBER
#define LUA_TNIL
#define LUA_NUMBER_FMT
static void PrintString(const TString *ts)
Definition print.c:23

References bvalue, Proto::k, LUA_NUMBER_FMT, LUA_TBOOLEAN, LUA_TNIL, LUA_TNUMBER, LUA_TSTRING, nvalue, printf, PrintString(), rawtsvalue, and ttype.

Referenced by PrintCode(), and PrintConstants().

◆ PrintConstants()

static void PrintConstants ( const Proto * f)
static

Definition at line 181 of file 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}

References PrintConstant(), printf, Proto::sizek, and VOID.

Referenced by PrintFunction().

◆ PrintFunction()

static void PrintFunction ( const Proto * f,
int full )

Definition at line 215 of file print.c.

216{
217 int i,n=f->sizep;
218 PrintHeader(f);
219 PrintCode(f);
220 if (full)
221 {
223 PrintLocals(f);
224 PrintUpvalues(f);
225 }
226 for (i=0; i<n; i++) PrintFunction(f->p[i],full);
227}
static void PrintUpvalues(const Proto *f)
Definition print.c:204
static void PrintLocals(const Proto *f)
Definition print.c:193
static void PrintHeader(const Proto *f)
Definition print.c:161
static void PrintCode(const Proto *f)
Definition print.c:74
#define PrintFunction
Definition print.c:18
static void PrintConstants(const Proto *f)
Definition print.c:181

References Proto::p, PrintCode(), PrintConstants(), PrintFunction, PrintHeader(), PrintLocals(), PrintUpvalues(), and Proto::sizep.

◆ PrintHeader()

static void PrintHeader ( const Proto * f)
static

Definition at line 161 of file 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,
172 f->linedefined,f->lastlinedefined,
173 S(f->sizecode),f->sizecode*Sizeof(Instruction),VOID(f));
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}
#define LUA_SIGNATURE
CURL_EXTERN CURLMcode curl_socket_t s
Definition multi.h:318
#define Sizeof(x)
Definition print.c:20
#define SS(x)
Definition print.c:158
#define S(x)
Definition print.c:159
TString * source

References getstr, Proto::is_vararg, Proto::lastlinedefined, Proto::linedefined, LUA_SIGNATURE, Proto::maxstacksize, Proto::numparams, Proto::nups, printf, S, s, Proto::sizecode, Proto::sizek, Proto::sizelocvars, Sizeof, Proto::sizep, Proto::source, SS, and VOID.

Referenced by PrintFunction().

◆ PrintLocals()

static void PrintLocals ( const Proto * f)
static

Definition at line 193 of file 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}
TString * varname
struct LocVar * locvars

References LocVar::endpc, getstr, Proto::locvars, printf, Proto::sizelocvars, LocVar::startpc, LocVar::varname, and VOID.

Referenced by PrintFunction().

◆ PrintString()

static void PrintString ( const TString * ts)
static

Definition at line 23 of file 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}
struct TString::@46 tsv

References getstr, TString::len, printf, s, and TString::tsv.

Referenced by PrintConstant().

◆ PrintUpvalues()

static void PrintUpvalues ( const Proto * f)
static

Definition at line 204 of file 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}
#define NULL
Definition gmacros.h:924

References getstr, NULL, printf, Proto::sizeupvalues, Proto::upvalues, and VOID.

Referenced by PrintFunction().