-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Dibyendu Majumdar
committed
Mar 17, 2015
1 parent
4e85840
commit fbb14bf
Showing
2 changed files
with
369 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,288 @@ | ||
extern int printf(const char *, ...); | ||
|
||
struct GCObject { | ||
struct GCObject *next; | ||
unsigned char tt; | ||
unsigned char marked; | ||
}; | ||
|
||
struct lua_State; | ||
|
||
union Value { | ||
struct GCObject *gc; | ||
void *p; | ||
int b; | ||
int (*f)(struct lua_State *); | ||
long long i; | ||
double n; | ||
}; | ||
|
||
struct TValue { | ||
union Value value_; | ||
int tt_; | ||
}; | ||
|
||
struct TString { | ||
struct GCObject *next; | ||
unsigned char tt; | ||
unsigned char marked; | ||
unsigned char extra; | ||
unsigned int hash; | ||
unsigned long long len; | ||
struct TString *hnext; | ||
}; | ||
|
||
union MaxAlign { | ||
double u; | ||
void *s; | ||
long long i; | ||
long l; | ||
}; | ||
|
||
union UTString { | ||
union MaxAlign dummy; | ||
struct TString tsv; | ||
}; | ||
|
||
struct Udata { | ||
struct GCObject *next; | ||
unsigned char tt; | ||
unsigned char marked; | ||
unsigned char ttuv_; /* user value's tag */ | ||
struct Table *metatable; | ||
unsigned long long len; /* number of bytes */ | ||
union Value user_; /* user value */ | ||
}; | ||
|
||
union UUdata { | ||
union MaxAlign dummy; /* ensures maximum alignment for 'local' udata */ | ||
struct Udata uv; | ||
}; | ||
|
||
struct Upvaldesc { | ||
struct TString *name; /* upvalue name (for debug information) */ | ||
unsigned char instack; /* whether it is in stack */ | ||
unsigned char | ||
idx; /* index of upvalue (in stack or in outer function's list) */ | ||
}; | ||
|
||
enum ravitype_t { | ||
RAVI_TANY, /* Lua dynamic type */ | ||
RAVI_TNUMINT, /* integer number */ | ||
RAVI_TNUMFLT, /* floating point number */ | ||
RAVI_TARRAYINT, /* array of ints */ | ||
RAVI_TARRAYFLT, /* array of doubles */ | ||
RAVI_TFUNCTION, | ||
RAVI_TTABLE, | ||
RAVI_TSTRING, | ||
RAVI_TNIL, | ||
RAVI_TBOOLEAN | ||
}; | ||
|
||
struct LocVar { | ||
struct TString *varname; | ||
int startpc; /* first point where variable is active */ | ||
int endpc; /* first point where variable is dead */ | ||
enum ravitype_t | ||
ravi_type; /* RAVI type of the variable - RAVI_TANY if unknown */ | ||
}; | ||
|
||
struct Proto { | ||
struct GCObject *next; | ||
unsigned char tt; | ||
unsigned char marked; | ||
unsigned char numparams; /* number of fixed parameters */ | ||
unsigned char is_vararg; | ||
unsigned char maxstacksize; /* maximum stack used by this function */ | ||
int sizeupvalues; /* size of 'upvalues' */ | ||
int sizek; /* size of 'k' */ | ||
int sizecode; | ||
int sizelineinfo; | ||
int sizep; /* size of 'p' */ | ||
int sizelocvars; | ||
int linedefined; | ||
int lastlinedefined; | ||
struct TValue *k; /* constants used by the function */ | ||
unsigned int *code; | ||
struct Proto **p; /* functions defined inside the function */ | ||
int *lineinfo; /* map from opcodes to source lines (debug information) */ | ||
struct LocVar * | ||
locvars; /* information about local variables (debug information) */ | ||
struct Upvaldesc *upvalues; /* upvalue information */ | ||
struct LClosure *cache; /* last created closure with this prototype */ | ||
struct TString *source; /* used for debug information */ | ||
struct GCObject *gclist; | ||
} Proto; | ||
|
||
struct UpVal; | ||
|
||
struct CClosure { | ||
struct GCObject *next; | ||
unsigned char tt; | ||
unsigned char marked; | ||
unsigned char nupvalues; | ||
struct GCObject *gclist; | ||
int (*f)(struct lua_State *); | ||
struct TValue upvalue[1]; /* list of upvalues */ | ||
}; | ||
|
||
struct LClosure { | ||
struct GCObject *next; | ||
unsigned char tt; | ||
unsigned char marked; | ||
unsigned char nupvalues; | ||
struct GCObject *gclist; | ||
struct Proto *p; | ||
struct UpVal *upvals[1]; /* list of upvalues */ | ||
}; | ||
|
||
union Closure { | ||
struct CClosure c; | ||
struct LClosure l; | ||
}; | ||
|
||
union TKey { | ||
struct { | ||
union Value value_; | ||
int tt_; | ||
int next; /* for chaining (offset for next node) */ | ||
} nk; | ||
struct TValue tvk; | ||
}; | ||
|
||
struct Node { | ||
struct TValue i_val; | ||
union TKey i_key; | ||
}; | ||
|
||
struct Table { | ||
struct GCObject *next; | ||
unsigned char tt; | ||
unsigned char marked; | ||
unsigned char flags; /* 1<<p means tagmethod(p) is not present */ | ||
unsigned char lsizenode; /* log2 of size of 'node' array */ | ||
unsigned int sizearray; /* size of 'array' array */ | ||
struct TValue *array; /* array part */ | ||
struct Node *node; | ||
struct Node *lastfree; /* any free position is before this position */ | ||
struct Table *metatable; | ||
struct GCObject *gclist; | ||
enum ravitype_t ravi_array_type; /* RAVI specialization */ | ||
unsigned int ravi_array_len; /* RAVI len specialization */ | ||
}; | ||
|
||
struct Mbuffer { | ||
char *buffer; | ||
unsigned long long n; | ||
unsigned long long buffsize; | ||
}; | ||
|
||
struct stringtable { | ||
struct TString **hash; | ||
int nuse; /* number of elements */ | ||
int size; | ||
}; | ||
|
||
struct lua_Debug; | ||
typedef long long ptrdiff_t; | ||
typedef ptrdiff_t lua_KContext; | ||
typedef int (*lua_KFunction)(struct lua_State *L, int status, lua_KContext ctx); | ||
typedef void *(*lua_Alloc)(void *ud, void *ptr, unsigned long long osize, | ||
unsigned long long nsize); | ||
typedef void (*lua_Hook)(struct lua_State *L, struct lua_Debug *ar); | ||
|
||
struct CallInfoL { /* only for Lua functions */ | ||
struct TValue *base; /* base for this function */ | ||
const unsigned int *savedpc; | ||
ptrdiff_t dummy; | ||
}; | ||
|
||
struct CallInfoC { /* only for C functions */ | ||
lua_KFunction k; /* continuation in case of yields */ | ||
ptrdiff_t old_errfunc; | ||
lua_KContext ctx; /* context info. in case of yields */ | ||
}; | ||
|
||
struct CallInfo { | ||
struct TValue *func; /* function index in the stack */ | ||
struct TValue *top; /* top for this function */ | ||
struct CallInfo *previous, *next; /* dynamic call link */ | ||
union { | ||
struct CallInfoL l; | ||
struct CallInfoC c; | ||
} u; | ||
ptrdiff_t extra; | ||
short nresults; /* expected number of results from this function */ | ||
unsigned char callstatus; | ||
}; | ||
|
||
struct CallInfoLua { | ||
struct TValue *func; /* function index in the stack */ | ||
struct TValue *top; /* top for this function */ | ||
struct CallInfo *previous, *next; /* dynamic call link */ | ||
struct CallInfoL l; | ||
ptrdiff_t extra; | ||
short nresults; /* expected number of results from this function */ | ||
unsigned char callstatus; | ||
}; | ||
|
||
struct global_State; | ||
struct lua_longjmp; | ||
|
||
/* | ||
** 'per thread' state | ||
*/ | ||
struct lua_State { | ||
struct GCObject *next; | ||
unsigned char tt; | ||
unsigned char marked; | ||
unsigned char status; | ||
struct TValue *top; /* first free slot in the stack */ | ||
struct global_State *l_G; | ||
struct CallInfoLua *ci; /* call info for current function */ | ||
const unsigned int *oldpc; /* last pc traced */ | ||
struct TValue *stack_last; /* last free slot in the stack */ | ||
struct TValue *stack; /* stack base */ | ||
struct UpVal *openupval; /* list of open upvalues in this stack */ | ||
struct GCObject *gclist; | ||
struct lua_State *twups; /* list of threads with open upvalues */ | ||
struct lua_longjmp *errorJmp; /* current error recover point */ | ||
struct CallInfo base_ci; /* CallInfo for first level (C calling Lua) */ | ||
lua_Hook hook; | ||
ptrdiff_t errfunc; /* current error handling function (stack index) */ | ||
int stacksize; | ||
int basehookcount; | ||
int hookcount; | ||
unsigned short nny; /* number of non-yieldable calls in stack */ | ||
unsigned short nCcalls; /* number of nested C calls */ | ||
unsigned char hookmask; | ||
unsigned char allowhook; | ||
}; | ||
|
||
struct UpVal { | ||
struct TValue *v; /* points to stack or to its own value */ | ||
unsigned long long refcount; /* reference counter */ | ||
union { | ||
struct { /* (when open) */ | ||
struct UpVal *next; /* linked list */ | ||
int touched; /* mark to avoid cycles with dead threads */ | ||
} open; | ||
struct TValue value; /* the value (when closed) */ | ||
} u; | ||
}; | ||
|
||
#define rttype(o) ((o)->tt_) | ||
#define BIT_ISCOLLECTABLE (1 << 6) | ||
#define iscollectable(o) (rttype(o) & BIT_ISCOLLECTABLE) | ||
#define upisopen(up) ((up)->v != &(up)->u.value) | ||
|
||
extern void luaC_upvalbarrier_ (struct lua_State *L, struct UpVal *uv); | ||
|
||
void luaV_op_call(struct lua_State *L, struct LClosure *cl, struct TValue *ra, int b, int c) { | ||
struct UpVal *uv = cl->upvals[b]; | ||
*uv->v = *ra; | ||
int b1 = iscollectable(uv->v); | ||
int b2 = uv->v != &uv->u.value; | ||
if (b1 && !b2) | ||
luaC_upvalbarrier_(L,uv); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
; ModuleID = 'lua_upval.c' | ||
target datalayout = "e-m:w-p:32:32-i64:64-f80:32-n8:16:32-S32" | ||
target triple = "i686-pc-windows-gnu" | ||
|
||
%struct.Proto = type { %struct.GCObject*, i8, i8, i8, i8, i8, i32, i32, i32, i32, i32, i32, i32, i32, %struct.TValue*, i32*, %struct.Proto**, i32*, %struct.LocVar*, %struct.Upvaldesc*, %struct.LClosure*, %struct.TString*, %struct.GCObject* } | ||
%struct.TValue = type { %union.Value, i32 } | ||
%union.Value = type { i64 } | ||
%struct.LocVar = type { %struct.TString*, i32, i32, i32 } | ||
%struct.Upvaldesc = type { %struct.TString*, i8, i8 } | ||
%struct.LClosure = type { %struct.GCObject*, i8, i8, i8, %struct.GCObject*, %struct.Proto*, [1 x %struct.UpVal*] } | ||
%struct.UpVal = type { %struct.TValue*, i64, %union.anon.0 } | ||
%union.anon.0 = type { %struct.TValue } | ||
%struct.TString = type { %struct.GCObject*, i8, i8, i8, i32, i64, %struct.TString* } | ||
%struct.GCObject = type { %struct.GCObject*, i8, i8 } | ||
%struct.lua_State = type { %struct.GCObject*, i8, i8, i8, %struct.TValue*, %struct.global_State*, %struct.CallInfoLua*, i32*, %struct.TValue*, %struct.TValue*, %struct.UpVal*, %struct.GCObject*, %struct.lua_State*, %struct.lua_longjmp*, %struct.CallInfo, void (%struct.lua_State*, %struct.lua_Debug*)*, i64, i32, i32, i32, i16, i16, i8, i8 } | ||
%struct.global_State = type opaque | ||
%struct.CallInfoLua = type { %struct.TValue*, %struct.TValue*, %struct.CallInfo*, %struct.CallInfo*, %struct.CallInfoL, i64, i16, i8 } | ||
%struct.CallInfoL = type { %struct.TValue*, i32*, i64 } | ||
%struct.lua_longjmp = type opaque | ||
%struct.CallInfo = type { %struct.TValue*, %struct.TValue*, %struct.CallInfo*, %struct.CallInfo*, %union.anon, i64, i16, i8 } | ||
%union.anon = type { %struct.CallInfoC } | ||
%struct.CallInfoC = type { i32 (%struct.lua_State*, i32, i64)*, i64, i64 } | ||
%struct.lua_Debug = type opaque | ||
|
||
@Proto = common global %struct.Proto zeroinitializer, align 4 | ||
|
||
; Function Attrs: nounwind | ||
define void @luaV_op_call(%struct.lua_State* %L, %struct.LClosure* nocapture readonly %cl, %struct.TValue* nocapture readonly %ra, i32 %b, i32 %c) #0 { | ||
entry: | ||
%arrayidx = getelementptr inbounds %struct.LClosure* %cl, i32 0, i32 6, i32 %b | ||
%0 = load %struct.UpVal** %arrayidx, align 4, !tbaa !1 | ||
%v = getelementptr inbounds %struct.UpVal* %0, i32 0, i32 0 | ||
%1 = bitcast %struct.UpVal* %0 to i8** | ||
%2 = load i8** %1, align 4, !tbaa !5 | ||
%3 = bitcast %struct.TValue* %ra to i8* | ||
tail call void @llvm.memcpy.p0i8.p0i8.i32(i8* %2, i8* %3, i32 16, i32 8, i1 false), !tbaa.struct !8 | ||
%4 = load %struct.TValue** %v, align 4, !tbaa !5 | ||
%tt_ = getelementptr inbounds %struct.TValue* %4, i32 0, i32 1 | ||
%5 = load i32* %tt_, align 4, !tbaa !14 | ||
%and = and i32 %5, 64 | ||
%value = getelementptr inbounds %struct.UpVal* %0, i32 0, i32 2, i32 0 | ||
%cmp = icmp ne %struct.TValue* %4, %value | ||
%tobool = icmp eq i32 %and, 0 | ||
%or.cond = or i1 %cmp, %tobool | ||
br i1 %or.cond, label %if.end, label %if.then | ||
|
||
if.then: ; preds = %entry | ||
tail call void @luaC_upvalbarrier_(%struct.lua_State* %L, %struct.UpVal* %0) #1 | ||
br label %if.end | ||
|
||
if.end: ; preds = %entry, %if.then | ||
ret void | ||
} | ||
|
||
; Function Attrs: nounwind | ||
declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture readonly, i32, i32, i1) #1 | ||
|
||
declare void @luaC_upvalbarrier_(%struct.lua_State*, %struct.UpVal*) #2 | ||
|
||
attributes #0 = { nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } | ||
attributes #1 = { nounwind } | ||
attributes #2 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } | ||
|
||
!llvm.ident = !{!0} | ||
|
||
!0 = metadata !{metadata !"clang version 3.6.0 (trunk)"} | ||
!1 = metadata !{metadata !2, metadata !2, i64 0} | ||
!2 = metadata !{metadata !"any pointer", metadata !3, i64 0} | ||
!3 = metadata !{metadata !"omnipotent char", metadata !4, i64 0} | ||
!4 = metadata !{metadata !"Simple C/C++ TBAA"} | ||
!5 = metadata !{metadata !6, metadata !2, i64 0} | ||
!6 = metadata !{metadata !"UpVal", metadata !2, i64 0, metadata !7, i64 8, metadata !3, i64 16} | ||
!7 = metadata !{metadata !"long long", metadata !3, i64 0} | ||
!8 = metadata !{i64 0, i64 4, metadata !1, i64 0, i64 4, metadata !1, i64 0, i64 4, metadata !9, i64 0, i64 4, metadata !1, i64 0, i64 8, metadata !11, i64 0, i64 8, metadata !12, i64 8, i64 4, metadata !9} | ||
!9 = metadata !{metadata !10, metadata !10, i64 0} | ||
!10 = metadata !{metadata !"int", metadata !3, i64 0} | ||
!11 = metadata !{metadata !7, metadata !7, i64 0} | ||
!12 = metadata !{metadata !13, metadata !13, i64 0} | ||
!13 = metadata !{metadata !"double", metadata !3, i64 0} | ||
!14 = metadata !{metadata !15, metadata !10, i64 8} | ||
!15 = metadata !{metadata !"TValue", metadata !3, i64 0, metadata !10, i64 8} |