1 typedef char *pvcontents;
2 typedef char *strconst;
4 typedef char *op_tr_array;
11 #define BGET_FREAD(argp, len, nelem) \
12 bl_read(bstate->bs_fdata,(char*)(argp),(len),(nelem))
13 #define BGET_FGETC() bl_getc(bstate->bs_fdata)
15 #define BGET_U32(arg) \
16 BGET_FREAD(&arg, sizeof(U32), 1)
17 #define BGET_I32(arg) \
18 BGET_FREAD(&arg, sizeof(I32), 1)
19 #define BGET_U16(arg) \
20 BGET_FREAD(&arg, sizeof(U16), 1)
21 #define BGET_U8(arg) arg = BGET_FGETC()
23 #define BGET_PV(arg) STMT_START { \
26 New(666, bstate->bs_pv.xpv_pv, arg, char); \
27 bl_read(bstate->bs_fdata, (void*)bstate->bs_pv.xpv_pv, arg, 1); \
28 bstate->bs_pv.xpv_len = arg; \
29 bstate->bs_pv.xpv_cur = arg - 1; \
31 bstate->bs_pv.xpv_pv = 0; \
32 bstate->bs_pv.xpv_len = 0; \
33 bstate->bs_pv.xpv_cur = 0; \
37 #ifdef BYTELOADER_LOG_COMMENTS
38 # define BGET_comment_t(arg) \
44 buf[i++] = (char)arg; \
45 } while (arg != '\n' && arg != EOF); \
47 PerlIO_printf(PerlIO_stderr(), "%s", buf); \
50 # define BGET_comment_t(arg) \
51 do { arg = BGET_FGETC(); } while (arg != '\n' && arg != EOF)
55 * In the following, sizeof(IV)*4 is just a way of encoding 32 on 64-bit-IV
56 * machines such that 32-bit machine compilers don't whine about the shift
57 * count being too high even though the code is never reached there.
59 #define BGET_IV64(arg) STMT_START { \
63 if (sizeof(IV) == 8) \
64 arg = ((IV)hi << (sizeof(IV)*4) | (IV)lo); \
65 else if (((I32)hi == -1 && (I32)lo < 0) \
66 || ((I32)hi == 0 && (I32)lo >= 0)) { \
70 bstate->bs_iv_overflows++; \
76 # define BGET_IV(arg) BGET_I32(arg)
79 # define BGET_IV(arg) BGET_IV64(arg)
83 #define BGET_op_tr_array(arg) do { \
84 unsigned short *ary; \
85 New(666, ary, 256, unsigned short); \
86 BGET_FREAD(ary, sizeof(unsigned short), 256); \
90 #define BGET_pvcontents(arg) arg = bstate->bs_pv.xpv_pv
91 #define BGET_strconst(arg) STMT_START { \
92 for (arg = PL_tokenbuf; (*arg = BGET_FGETC()); arg++) /* nothing */; \
96 #define BGET_NV(arg) STMT_START { \
102 #define BGET_objindex(arg, type) STMT_START { \
104 arg = (type)bstate->bs_obj_list[ix]; \
106 #define BGET_svindex(arg) BGET_objindex(arg, svindex)
107 #define BGET_opindex(arg) BGET_objindex(arg, opindex)
108 #define BGET_pvindex(arg) STMT_START { \
109 BGET_objindex(arg, pvindex); \
110 arg = arg ? savepv(arg) : arg; \
113 #define BSET_ldspecsv(sv, arg) sv = specialsv_list[arg]
114 #define BSET_stpv(pv, arg) STMT_START { \
115 BSET_OBJ_STORE(pv, arg); \
119 #define BSET_sv_refcnt_add(svrefcnt, arg) svrefcnt += arg
120 #define BSET_gp_refcnt_add(gprefcnt, arg) gprefcnt += arg
121 #define BSET_gp_share(sv, arg) STMT_START { \
123 GvGP(sv) = GvGP(arg); \
126 #define BSET_gv_fetchpv(sv, arg) sv = (SV*)gv_fetchpv(arg, TRUE, SVt_PV)
127 #define BSET_gv_stashpv(sv, arg) sv = (SV*)gv_stashpv(arg, TRUE)
128 #define BSET_sv_magic(sv, arg) sv_magic(sv, Nullsv, arg, 0, 0)
129 #define BSET_mg_pv(mg, arg) mg->mg_ptr = arg; mg->mg_len = bstate->bs_pv.xpv_cur
130 #define BSET_sv_upgrade(sv, arg) (void)SvUPGRADE(sv, arg)
131 #define BSET_xpv(sv) do { \
132 SvPV_set(sv, bstate->bs_pv.xpv_pv); \
133 SvCUR_set(sv, bstate->bs_pv.xpv_cur); \
134 SvLEN_set(sv, bstate->bs_pv.xpv_len); \
136 #define BSET_av_extend(sv, arg) av_extend((AV*)sv, arg)
138 #define BSET_av_push(sv, arg) av_push((AV*)sv, arg)
139 #define BSET_hv_store(sv, arg) \
140 hv_store((HV*)sv, bstate->bs_pv.xpv_pv, bstate->bs_pv.xpv_cur, arg, 0)
141 #define BSET_pv_free(pv) Safefree(pv.xpv_pv)
142 #define BSET_pregcomp(o, arg) \
143 (PM_SETRE(((PMOP*)o), (arg ? \
144 CALLREGCOMP(aTHX_ arg, arg + bstate->bs_pv.xpv_cur, ((PMOP*)o)) : 0)))
145 #define BSET_newsv(sv, arg) \
147 sv = (arg == SVt_PVAV ? (SV*)newAV() : \
148 arg == SVt_PVHV ? (SV*)newHV() : \
150 SvUPGRADE(sv, arg); \
152 #define BSET_newop(o, arg) ((o = (OP*)safemalloc(optype_size[arg])), \
153 memzero((char*)o,optype_size[arg]))
154 #define BSET_newopn(o, arg) STMT_START { \
156 BSET_newop(o, arg); \
157 oldop->op_next = o; \
160 #define BSET_ret(foo) STMT_START { \
161 Safefree(bstate->bs_obj_list); \
166 * Kludge special-case workaround for OP_MAPSTART
167 * which needs the ppaddr for OP_GREPSTART. Blech.
169 #define BSET_op_type(o, arg) STMT_START { \
171 if (arg == OP_MAPSTART) \
172 arg = OP_GREPSTART; \
173 o->op_ppaddr = PL_ppaddr[arg]; \
175 #define BSET_op_ppaddr(o, arg) Perl_croak(aTHX_ "op_ppaddr not yet implemented")
176 #define BSET_curpad(pad, arg) STMT_START { \
177 PL_comppad = (AV *)arg; \
178 pad = AvARRAY(arg); \
180 /* this works now that Sarathy's changed the CopFILE_set macro to do the SvREFCNT_inc()
182 #define BSET_cop_file(cop, arg) CopFILE_set(cop,arg)
183 #define BSET_cop_line(cop, arg) CopLINE_set(cop,arg)
184 #define BSET_cop_stashpv(cop, arg) CopSTASHPV_set(cop,arg)
186 /* this is simply stolen from the code in newATTRSUB() */
187 #define BSET_push_begin(ary,cv) \
189 I32 oldscope = PL_scopestack_ix; \
191 SAVECOPFILE(&PL_compiling); \
192 SAVECOPLINE(&PL_compiling); \
194 PL_beginav = newAV(); \
195 av_push(PL_beginav, cv); \
196 call_list(oldscope, PL_beginav); \
197 PL_curcop = &PL_compiling; \
198 PL_compiling.op_private = PL_hints; \
201 #define BSET_push_init(ary,cv) \
203 av_unshift((PL_initav ? PL_initav : (PL_initav = newAV(), PL_initav)), 1); \
204 av_store(PL_initav, 0, cv); \
206 #define BSET_push_end(ary,cv) \
208 av_unshift((PL_endav ? PL_endav : (PL_endav = newAV(), PL_endav)), 1); \
209 av_store(PL_endav, 0, cv); \
211 #define BSET_OBJ_STORE(obj, ix) \
212 (I32)ix > bstate->bs_obj_list_fill ? \
213 bset_obj_store(aTHX_ bstate, obj, (I32)ix) : (bstate->bs_obj_list[ix] = obj)
215 /* NOTE: the bytecode header only sanity-checks the bytecode. If a script cares about
216 * what version of Perl it's being called under, it should do a 'use 5.006_001' or
217 * equivalent. However, since the header includes checks requiring an exact match in
218 * ByteLoader versions (we can't guarantee forward compatibility), you don't
219 * need to specify one:
225 #define HEADER_FAIL(f) \
226 Perl_croak(aTHX_ "Invalid bytecode for this architecture: " f)
227 #define HEADER_FAIL1(f, arg1) \
228 Perl_croak(aTHX_ "Invalid bytecode for this architecture: " f, arg1)
229 #define HEADER_FAIL2(f, arg1, arg2) \
230 Perl_croak(aTHX_ "Invalid bytecode for this architecture: " f, arg1, arg2)
232 #define BYTECODE_HEADER_CHECK \
237 BGET_U32(sz); /* Magic: 'PLBC' */ \
238 if (sz != 0x43424c50) { \
239 HEADER_FAIL1("bad magic (want 0x43424c50, got %#x)", (int)sz); \
241 BGET_strconst(str); /* archname */ \
242 if (strNE(str, ARCHNAME)) { \
243 HEADER_FAIL2("wrong architecture (want %s, you have %s)",str,ARCHNAME); \
245 BGET_strconst(str); /* ByteLoader version */ \
246 if (strNE(str, VERSION)) { \
247 HEADER_FAIL2("mismatched ByteLoader versions (want %s, you have %s)", \
250 BGET_U32(sz); /* ivsize */ \
251 if (sz != IVSIZE) { \
252 HEADER_FAIL("different IVSIZE"); \
254 BGET_U32(sz); /* ptrsize */ \
255 if (sz != PTRSIZE) { \
256 HEADER_FAIL("different PTRSIZE"); \
258 BGET_strconst(str); /* byteorder */ \
259 if (strNE(str, STRINGIFY(BYTEORDER))) { \
260 HEADER_FAIL("different byteorder"); \