1 typedef char *pvcontents;
2 typedef char *strconst;
4 typedef char *op_tr_array;
10 #define BGET_FREAD(argp, len, nelem) \
11 PerlIO_read(PL_rsfp,(char*)(argp),(len)*(nelem))
12 #define BGET_FGETC() PerlIO_getc(PL_rsfp)
14 #define BGET_U32(arg) \
15 BGET_FREAD(&arg, sizeof(U32), 1)
16 #define BGET_I32(arg) \
17 BGET_FREAD(&arg, sizeof(I32), 1)
18 #define BGET_U16(arg) \
19 BGET_FREAD(&arg, sizeof(U16), 1)
20 #define BGET_U8(arg) arg = BGET_FGETC()
22 #define BGET_PV(arg) STMT_START { \
25 New(666, bytecode_pv.xpv_pv, arg, char); \
26 PerlIO_read(PL_rsfp, (void*)bytecode_pv.xpv_pv, arg); \
27 bytecode_pv.xpv_len = arg; \
28 bytecode_pv.xpv_cur = arg - 1; \
30 bytecode_pv.xpv_pv = 0; \
31 bytecode_pv.xpv_len = 0; \
32 bytecode_pv.xpv_cur = 0; \
36 #ifdef BYTELOADER_LOG_COMMENTS
37 # define BGET_comment_t(arg) \
43 buf[i++] = (char)arg; \
44 } while (arg != '\n' && arg != EOF); \
46 PerlIO_printf(PerlIO_stderr(), "%s", buf); \
49 # define BGET_comment_t(arg) \
50 do { arg = BGET_FGETC(); } while (arg != '\n' && arg != EOF)
54 * In the following, sizeof(IV)*4 is just a way of encoding 32 on 64-bit-IV
55 * machines such that 32-bit machine compilers don't whine about the shift
56 * count being too high even though the code is never reached there.
58 #define BGET_IV64(arg) STMT_START { \
62 if (sizeof(IV) == 8) \
63 arg = ((IV)hi << (sizeof(IV)*4) | (IV)lo); \
64 else if (((I32)hi == -1 && (I32)lo < 0) \
65 || ((I32)hi == 0 && (I32)lo >= 0)) { \
69 bytecode_iv_overflows++; \
74 #define BGET_op_tr_array(arg) do { \
75 unsigned short *ary; \
77 New(666, ary, 256, unsigned short); \
78 BGET_FREAD(ary, sizeof(unsigned short), 256); \
82 #define BGET_pvcontents(arg) arg = bytecode_pv.xpv_pv
83 #define BGET_strconst(arg) STMT_START { \
84 for (arg = PL_tokenbuf; (*arg = BGET_FGETC()); arg++) /* nothing */; \
88 #define BGET_NV(arg) STMT_START { \
94 #define BGET_objindex(arg, type) STMT_START { \
97 arg = (type)bytecode_obj_list[ix]; \
99 #define BGET_svindex(arg) BGET_objindex(arg, svindex)
100 #define BGET_opindex(arg) BGET_objindex(arg, opindex)
102 #define BSET_ldspecsv(sv, arg) sv = specialsv_list[arg]
104 #define BSET_sv_refcnt_add(svrefcnt, arg) svrefcnt += arg
105 #define BSET_gp_refcnt_add(gprefcnt, arg) gprefcnt += arg
106 #define BSET_gp_share(sv, arg) STMT_START { \
108 GvGP(sv) = GvGP(arg); \
111 #define BSET_gv_fetchpv(sv, arg) sv = (SV*)gv_fetchpv(arg, TRUE, SVt_PV)
112 #define BSET_gv_stashpv(sv, arg) sv = (SV*)gv_stashpv(arg, TRUE)
113 #define BSET_sv_magic(sv, arg) sv_magic(sv, Nullsv, arg, 0, 0)
114 #define BSET_mg_pv(mg, arg) mg->mg_ptr = arg; mg->mg_len = bytecode_pv.xpv_cur
115 #define BSET_sv_upgrade(sv, arg) (void)SvUPGRADE(sv, arg)
116 #define BSET_xpv(sv) do { \
117 SvPV_set(sv, bytecode_pv.xpv_pv); \
118 SvCUR_set(sv, bytecode_pv.xpv_cur); \
119 SvLEN_set(sv, bytecode_pv.xpv_len); \
121 #define BSET_av_extend(sv, arg) av_extend((AV*)sv, arg)
123 #define BSET_av_push(sv, arg) av_push((AV*)sv, arg)
124 #define BSET_hv_store(sv, arg) \
125 hv_store((HV*)sv, bytecode_pv.xpv_pv, bytecode_pv.xpv_cur, arg, 0)
126 #define BSET_pv_free(pv) Safefree(pv.xpv_pv)
127 #define BSET_pregcomp(o, arg) \
128 ((PMOP*)o)->op_pmregexp = arg ? \
129 CALLREGCOMP(aTHX_ arg, arg + bytecode_pv.xpv_cur, ((PMOP*)o)) : 0
130 #define BSET_newsv(sv, arg) \
132 sv = (arg == SVt_PVAV ? (SV*)newAV() : \
133 arg == SVt_PVHV ? (SV*)newHV() : \
135 SvUPGRADE(sv, arg); \
137 #define BSET_newop(o, arg) ((o = (OP*)safemalloc(optype_size[arg])), \
138 memzero((char*)o,optype_size[arg]))
139 #define BSET_newopn(o, arg) STMT_START { \
141 BSET_newop(o, arg); \
142 oldop->op_next = o; \
145 #define BSET_ret(foo) STMT_START { \
146 if (bytecode_obj_list) \
147 Safefree(bytecode_obj_list); \
153 * Kludge special-case workaround for OP_MAPSTART
154 * which needs the ppaddr for OP_GREPSTART. Blech.
156 #define BSET_op_type(o, arg) STMT_START { \
158 if (arg == OP_MAPSTART) \
159 arg = OP_GREPSTART; \
160 o->op_ppaddr = PL_ppaddr[arg]; \
162 #define BSET_op_ppaddr(o, arg) Perl_croak(aTHX_ "op_ppaddr not yet implemented")
163 #define BSET_curpad(pad, arg) STMT_START { \
164 PL_comppad = (AV *)arg; \
165 pad = AvARRAY(arg); \
167 /* this works now that Sarathy's changed the CopFILE_set macro to do the SvREFCNT_inc()
169 #define BSET_cop_file(cop, arg) CopFILE_set(cop,arg)
170 #define BSET_cop_line(cop, arg) CopLINE_set(cop,arg)
171 #define BSET_cop_stashpv(cop, arg) CopSTASHPV_set(cop,arg)
173 /* this is simply stolen from the code in newATTRSUB() */
174 #define BSET_push_begin(ary,cv) \
176 I32 oldscope = PL_scopestack_ix; \
178 SAVECOPFILE(&PL_compiling); \
179 SAVECOPLINE(&PL_compiling); \
180 save_svref(&PL_rs); \
181 sv_setsv(PL_rs, PL_nrs); \
183 PL_beginav = newAV(); \
184 av_push(PL_beginav, cv); \
185 call_list(oldscope, PL_beginav); \
186 PL_curcop = &PL_compiling; \
187 PL_compiling.op_private = PL_hints; \
190 #define BSET_push_init(ary,cv) \
192 av_unshift((PL_initav ? PL_initav : (PL_initav = newAV(), PL_initav)), 1); \
193 av_store(PL_initav, 0, cv); \
195 #define BSET_push_end(ary,cv) \
197 av_unshift((PL_endav ? PL_endav : (PL_endav = newAV(), PL_endav)), 1); \
198 av_store(PL_endav, 0, cv); \
200 #define BSET_OBJ_STORE(obj, ix) \
201 (I32)ix > bytecode_obj_list_fill ? \
202 bset_obj_store(aTHXo_ obj, (I32)ix) : (bytecode_obj_list[ix] = obj)
203 #define BYTECODE_HEADER_CHECK \
209 BGET_U32(sz); /* Magic: 'PLBC' */ \
210 if (sz != 0x43424c50) { \
211 badpart = "bad magic"; \
214 BGET_strconst(str); /* archname */ \
215 if (strNE(str, ARCHNAME)) { \
216 badpart = "wrong architecture"; \
219 BGET_U32(sz); /* ivsize */ \
220 if (sz != IVSIZE) { \
221 badpart = "different IVSIZE"; \
224 BGET_U32(sz); /* ptrsize */ \
225 if (sz != PTRSIZE) { \
226 badpart = "different PTRSIZE"; \
229 BGET_strconst(str); /* byteorder */ \
230 if (strNE(str, STRINGIFY(BYTEORDER))) { \
231 badpart = "different byteorder"; \
233 Perl_croak(aTHX_ "Invalid bytecode for this architecture: %s\n", \