Annotation of sbbs/include/mozilla/js/jsopcode.h, revision 1.1.1.2

1.1       root        1: /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
                      2:  *
                      3:  * ***** BEGIN LICENSE BLOCK *****
                      4:  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
                      5:  *
                      6:  * The contents of this file are subject to the Mozilla Public License Version
                      7:  * 1.1 (the "License"); you may not use this file except in compliance with
                      8:  * the License. You may obtain a copy of the License at
                      9:  * http://www.mozilla.org/MPL/
                     10:  *
                     11:  * Software distributed under the License is distributed on an "AS IS" basis,
                     12:  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
                     13:  * for the specific language governing rights and limitations under the
                     14:  * License.
                     15:  *
                     16:  * The Original Code is Mozilla Communicator client code, released
                     17:  * March 31, 1998.
                     18:  *
                     19:  * The Initial Developer of the Original Code is
                     20:  * Netscape Communications Corporation.
                     21:  * Portions created by the Initial Developer are Copyright (C) 1998
                     22:  * the Initial Developer. All Rights Reserved.
                     23:  *
                     24:  * Contributor(s):
                     25:  *
                     26:  * Alternatively, the contents of this file may be used under the terms of
                     27:  * either of the GNU General Public License Version 2 or later (the "GPL"),
                     28:  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
                     29:  * in which case the provisions of the GPL or the LGPL are applicable instead
                     30:  * of those above. If you wish to allow use of your version of this file only
                     31:  * under the terms of either the GPL or the LGPL, and not to allow others to
                     32:  * use your version of this file under the terms of the MPL, indicate your
                     33:  * decision by deleting the provisions above and replace them with the notice
                     34:  * and other provisions required by the GPL or the LGPL. If you do not delete
                     35:  * the provisions above, a recipient may use your version of this file under
                     36:  * the terms of any one of the MPL, the GPL or the LGPL.
                     37:  *
                     38:  * ***** END LICENSE BLOCK ***** */
                     39: 
                     40: #ifndef jsopcode_h___
                     41: #define jsopcode_h___
                     42: /*
                     43:  * JS bytecode definitions.
                     44:  */
                     45: #include <stddef.h>
                     46: #include "jsprvtd.h"
                     47: #include "jspubtd.h"
1.1.1.2 ! root       48: #include "jsutil.h"
1.1       root       49: 
                     50: JS_BEGIN_EXTERN_C
                     51: 
                     52: /*
                     53:  * JS operation bytecodes.
                     54:  */
                     55: typedef enum JSOp {
                     56: #define OPDEF(op,val,name,token,length,nuses,ndefs,prec,format) \
                     57:     op = val,
                     58: #include "jsopcode.tbl"
                     59: #undef OPDEF
                     60:     JSOP_LIMIT
                     61: } JSOp;
                     62: 
1.1.1.2 ! root       63: typedef enum JSOpLength {
        !            64: #define OPDEF(op,val,name,token,length,nuses,ndefs,prec,format) \
        !            65:     op##_LENGTH = length,
        !            66: #include "jsopcode.tbl"
        !            67: #undef OPDEF
        !            68:     JSOP_LIMIT_LENGTH
        !            69: } JSOpLength;
        !            70: 
1.1       root       71: /*
                     72:  * JS bytecode formats.
                     73:  */
                     74: #define JOF_BYTE          0       /* single bytecode, no immediates */
                     75: #define JOF_JUMP          1       /* signed 16-bit jump offset immediate */
                     76: #define JOF_CONST         2       /* unsigned 16-bit constant pool index */
                     77: #define JOF_UINT16        3       /* unsigned 16-bit immediate operand */
                     78: #define JOF_TABLESWITCH   4       /* table switch */
                     79: #define JOF_LOOKUPSWITCH  5       /* lookup switch */
                     80: #define JOF_QARG          6       /* quickened get/set function argument ops */
                     81: #define JOF_QVAR          7       /* quickened get/set local variable ops */
1.1.1.2 ! root       82: #define JOF_INDEXCONST    8       /* uint16 slot index + constant pool index */
1.1       root       83: #define JOF_JUMPX         9       /* signed 32-bit jump offset immediate */
                     84: #define JOF_TABLESWITCHX  10      /* extended (32-bit offset) table switch */
                     85: #define JOF_LOOKUPSWITCHX 11      /* extended (32-bit offset) lookup switch */
1.1.1.2 ! root       86: #define JOF_UINT24        12      /* extended unsigned 24-bit literal (index) */
        !            87: #define JOF_LITOPX        13      /* JOF_UINT24 followed by op being extended,
        !            88:                                      where op if JOF_CONST has no unsigned 16-
        !            89:                                      bit immediate operand */
        !            90: #define JOF_LOCAL         14      /* block-local operand stack variable */
1.1       root       91: #define JOF_TYPEMASK      0x000f  /* mask for above immediate types */
                     92: #define JOF_NAME          0x0010  /* name operation */
                     93: #define JOF_PROP          0x0020  /* obj.prop operation */
                     94: #define JOF_ELEM          0x0030  /* obj[index] operation */
                     95: #define JOF_MODEMASK      0x0030  /* mask for above addressing modes */
                     96: #define JOF_SET           0x0040  /* set (i.e., assignment) operation */
                     97: #define JOF_DEL           0x0080  /* delete operation */
                     98: #define JOF_DEC           0x0100  /* decrement (--, not ++) opcode */
                     99: #define JOF_INC           0x0200  /* increment (++, not --) opcode */
                    100: #define JOF_INCDEC        0x0300  /* increment or decrement opcode */
                    101: #define JOF_POST          0x0400  /* postorder increment or decrement */
                    102: #define JOF_IMPORT        0x0800  /* import property op */
                    103: #define JOF_FOR           0x1000  /* for-in property op */
                    104: #define JOF_ASSIGNING     JOF_SET /* hint for JSClass.resolve, used for ops
                    105:                                      that do simplex assignment */
                    106: #define JOF_DETECTING     0x2000  /* object detection flag for JSNewResolveOp */
                    107: #define JOF_BACKPATCH     0x4000  /* backpatch placeholder during codegen */
                    108: #define JOF_LEFTASSOC     0x8000  /* left-associative operator */
                    109: #define JOF_DECLARING    0x10000  /* var, const, or function declaration op */
1.1.1.2 ! root      110: #define JOF_XMLNAME      0x20000  /* XML name: *, a::b, @a, @a::b, etc. */
1.1       root      111: 
                    112: #define JOF_TYPE_IS_EXTENDED_JUMP(t) \
                    113:     ((unsigned)((t) - JOF_JUMPX) <= (unsigned)(JOF_LOOKUPSWITCHX - JOF_JUMPX))
                    114: 
                    115: /*
                    116:  * Immediate operand getters, setters, and bounds.
                    117:  */
                    118: 
                    119: /* Short (2-byte signed offset) relative jump macros. */
                    120: #define JUMP_OFFSET_LEN         2
                    121: #define JUMP_OFFSET_HI(off)     ((jsbytecode)((off) >> 8))
                    122: #define JUMP_OFFSET_LO(off)     ((jsbytecode)(off))
                    123: #define GET_JUMP_OFFSET(pc)     ((int16)(((pc)[1] << 8) | (pc)[2]))
                    124: #define SET_JUMP_OFFSET(pc,off) ((pc)[1] = JUMP_OFFSET_HI(off),               \
1.1.1.2 ! root      125:                                  (pc)[2] = JUMP_OFFSET_LO(off))
1.1       root      126: #define JUMP_OFFSET_MIN         ((int16)0x8000)
                    127: #define JUMP_OFFSET_MAX         ((int16)0x7fff)
                    128: 
                    129: /*
                    130:  * When a short jump won't hold a relative offset, its 2-byte immediate offset
                    131:  * operand is an unsigned index of a span-dependency record, maintained until
                    132:  * code generation finishes -- after which some (but we hope not nearly all)
                    133:  * span-dependent jumps must be extended (see OptimizeSpanDeps in jsemit.c).
                    134:  *
                    135:  * If the span-dependency record index overflows SPANDEP_INDEX_MAX, the jump
                    136:  * offset will contain SPANDEP_INDEX_HUGE, indicating that the record must be
                    137:  * found (via binary search) by its "before span-dependency optimization" pc
                    138:  * offset (from script main entry point).
                    139:  */
                    140: #define GET_SPANDEP_INDEX(pc)   ((uint16)(((pc)[1] << 8) | (pc)[2]))
                    141: #define SET_SPANDEP_INDEX(pc,i) ((pc)[1] = JUMP_OFFSET_HI(i),                 \
1.1.1.2 ! root      142:                                  (pc)[2] = JUMP_OFFSET_LO(i))
1.1       root      143: #define SPANDEP_INDEX_MAX       ((uint16)0xfffe)
                    144: #define SPANDEP_INDEX_HUGE      ((uint16)0xffff)
                    145: 
                    146: /* Ultimately, if short jumps won't do, emit long (4-byte signed) offsets. */
                    147: #define JUMPX_OFFSET_LEN        4
                    148: #define JUMPX_OFFSET_B3(off)    ((jsbytecode)((off) >> 24))
                    149: #define JUMPX_OFFSET_B2(off)    ((jsbytecode)((off) >> 16))
                    150: #define JUMPX_OFFSET_B1(off)    ((jsbytecode)((off) >> 8))
                    151: #define JUMPX_OFFSET_B0(off)    ((jsbytecode)(off))
                    152: #define GET_JUMPX_OFFSET(pc)    ((int32)(((pc)[1] << 24) | ((pc)[2] << 16)    \
                    153:                                          | ((pc)[3] << 8) | (pc)[4]))
                    154: #define SET_JUMPX_OFFSET(pc,off)((pc)[1] = JUMPX_OFFSET_B3(off),              \
                    155:                                  (pc)[2] = JUMPX_OFFSET_B2(off),              \
                    156:                                  (pc)[3] = JUMPX_OFFSET_B1(off),              \
                    157:                                  (pc)[4] = JUMPX_OFFSET_B0(off))
                    158: #define JUMPX_OFFSET_MIN        ((int32)0x80000000)
                    159: #define JUMPX_OFFSET_MAX        ((int32)0x7fffffff)
                    160: 
1.1.1.2 ! root      161: /*
        !           162:  * A literal is indexed by a per-script atom map.  Most scripts have relatively
        !           163:  * few literals, so the standard JOF_CONST format specifies a fixed 16 bits of
        !           164:  * immediate operand index.  A script with more than 64K literals must push all
        !           165:  * high-indexed literals on the stack using JSOP_LITERAL, then use JOF_ELEM ops
        !           166:  * instead of JOF_PROP, etc.
        !           167:  */
1.1       root      168: #define ATOM_INDEX_LEN          2
1.1.1.2 ! root      169: #define ATOM_INDEX_HI(i)        ((jsbytecode)((i) >> 8))
        !           170: #define ATOM_INDEX_LO(i)        ((jsbytecode)(i))
1.1       root      171: #define GET_ATOM_INDEX(pc)      ((jsatomid)(((pc)[1] << 8) | (pc)[2]))
1.1.1.2 ! root      172: #define SET_ATOM_INDEX(pc,i)    ((pc)[1] = ATOM_INDEX_HI(i),                  \
        !           173:                                  (pc)[2] = ATOM_INDEX_LO(i))
1.1       root      174: #define GET_ATOM(cx,script,pc)  js_GetAtom((cx), &(script)->atomMap,          \
1.1.1.2 ! root      175:                                            GET_ATOM_INDEX(pc))
        !           176: 
        !           177: /* A full atom index for JSOP_UINT24 uses 24 bits of immediate operand. */
        !           178: #define UINT24_HI(i)            ((jsbytecode)((i) >> 16))
        !           179: #define UINT24_MID(i)           ((jsbytecode)((i) >> 8))
        !           180: #define UINT24_LO(i)            ((jsbytecode)(i))
        !           181: #define GET_UINT24(pc)          ((jsatomid)(((pc)[1] << 16) |                 \
        !           182:                                             ((pc)[2] << 8) |                  \
        !           183:                                             (pc)[3]))
        !           184: #define SET_UINT24(pc,i)        ((pc)[1] = UINT24_HI(i),                      \
        !           185:                                  (pc)[2] = UINT24_MID(i),                     \
        !           186:                                  (pc)[3] = UINT24_LO(i))
        !           187: 
        !           188: /* Same format for JSOP_LITERAL, etc., but future-proof with different names. */
        !           189: #define LITERAL_INDEX_LEN       3
        !           190: #define LITERAL_INDEX_HI(i)     UINT24_HI(i)
        !           191: #define LITERAL_INDEX_MID(i)    UINT24_MID(i)
        !           192: #define LITERAL_INDEX_LO(i)     UINT24_LO(i)
        !           193: #define GET_LITERAL_INDEX(pc)   GET_UINT24(pc)
        !           194: #define SET_LITERAL_INDEX(pc,i) SET_UINT24(pc,i)
        !           195: 
        !           196: /* Atom index limit is determined by SN_3BYTE_OFFSET_FLAG, see jsemit.h. */
        !           197: #define ATOM_INDEX_LIMIT_LOG2   23
1.1       root      198: #define ATOM_INDEX_LIMIT        ((uint32)1 << ATOM_INDEX_LIMIT_LOG2)
                    199: 
1.1.1.2 ! root      200: JS_STATIC_ASSERT(sizeof(jsatomid) * JS_BITS_PER_BYTE >=
        !           201:                  ATOM_INDEX_LIMIT_LOG2 + 1);
        !           202: 
        !           203: /* Common uint16 immediate format helpers. */
        !           204: #define UINT16_HI(i)            ((jsbytecode)((i) >> 8))
        !           205: #define UINT16_LO(i)            ((jsbytecode)(i))
        !           206: #define GET_UINT16(pc)          ((uintN)(((pc)[1] << 8) | (pc)[2]))
        !           207: #define SET_UINT16(pc,i)        ((pc)[1] = UINT16_HI(i), (pc)[2] = UINT16_LO(i))
        !           208: #define UINT16_LIMIT            ((uintN)1 << 16)
        !           209: 
1.1       root      210: /* Actual argument count operand format helpers. */
1.1.1.2 ! root      211: #define ARGC_HI(argc)           UINT16_HI(argc)
        !           212: #define ARGC_LO(argc)           UINT16_LO(argc)
        !           213: #define GET_ARGC(pc)            GET_UINT16(pc)
        !           214: #define ARGC_LIMIT              UINT16_LIMIT
1.1       root      215: 
                    216: /* Synonyms for quick JOF_QARG and JOF_QVAR bytecodes. */
1.1.1.2 ! root      217: #define GET_ARGNO(pc)           GET_UINT16(pc)
        !           218: #define SET_ARGNO(pc,argno)     SET_UINT16(pc,argno)
        !           219: #define ARGNO_LEN               2
        !           220: #define ARGNO_LIMIT             UINT16_LIMIT
        !           221: 
        !           222: #define GET_VARNO(pc)           GET_UINT16(pc)
        !           223: #define SET_VARNO(pc,varno)     SET_UINT16(pc,varno)
        !           224: #define VARNO_LEN               2
        !           225: #define VARNO_LIMIT             UINT16_LIMIT
1.1       root      226: 
                    227: struct JSCodeSpec {
                    228:     const char          *name;          /* JS bytecode name */
                    229:     const char          *token;         /* JS source literal or null */
                    230:     int8                length;         /* length including opcode byte */
                    231:     int8                nuses;          /* arity, -1 if variadic */
                    232:     int8                ndefs;          /* number of stack results */
                    233:     uint8               prec;           /* operator precedence */
                    234:     uint32              format;         /* immediate operand format */
                    235: };
                    236: 
                    237: extern const JSCodeSpec js_CodeSpec[];
                    238: extern uintN            js_NumCodeSpecs;
                    239: extern const jschar     js_EscapeMap[];
                    240: 
                    241: /*
                    242:  * Return a GC'ed string containing the chars in str, with any non-printing
                    243:  * chars or quotes (' or " as specified by the quote argument) escaped, and
                    244:  * with the quote character at the beginning and end of the result string.
                    245:  */
                    246: extern JSString *
                    247: js_QuoteString(JSContext *cx, JSString *str, jschar quote);
                    248: 
                    249: /*
                    250:  * JSPrinter operations, for printf style message formatting.  The return
                    251:  * value from js_GetPrinterOutput() is the printer's cumulative output, in
                    252:  * a GC'ed string.
                    253:  */
                    254: extern JSPrinter *
                    255: js_NewPrinter(JSContext *cx, const char *name, uintN indent, JSBool pretty);
                    256: 
                    257: extern void
                    258: js_DestroyPrinter(JSPrinter *jp);
                    259: 
                    260: extern JSString *
                    261: js_GetPrinterOutput(JSPrinter *jp);
                    262: 
                    263: extern int
                    264: js_printf(JSPrinter *jp, const char *format, ...);
                    265: 
                    266: extern JSBool
                    267: js_puts(JSPrinter *jp, const char *s);
                    268: 
                    269: #ifdef DEBUG
                    270: /*
                    271:  * Disassemblers, for debugging only.
                    272:  */
                    273: #include <stdio.h>
                    274: 
1.1.1.2 ! root      275: extern JS_FRIEND_API(JSBool)
1.1       root      276: js_Disassemble(JSContext *cx, JSScript *script, JSBool lines, FILE *fp);
                    277: 
                    278: extern JS_FRIEND_API(uintN)
                    279: js_Disassemble1(JSContext *cx, JSScript *script, jsbytecode *pc, uintN loc,
1.1.1.2 ! root      280:                 JSBool lines, FILE *fp);
1.1       root      281: #endif /* DEBUG */
                    282: 
                    283: /*
                    284:  * Decompilers, for script, function, and expression pretty-printing.
                    285:  */
                    286: extern JSBool
1.1.1.2 ! root      287: js_DecompileCode(JSPrinter *jp, JSScript *script, jsbytecode *pc, uintN len,
        !           288:                  uintN pcdepth);
1.1       root      289: 
                    290: extern JSBool
                    291: js_DecompileScript(JSPrinter *jp, JSScript *script);
                    292: 
                    293: extern JSBool
                    294: js_DecompileFunctionBody(JSPrinter *jp, JSFunction *fun);
                    295: 
                    296: extern JSBool
                    297: js_DecompileFunction(JSPrinter *jp, JSFunction *fun);
                    298: 
                    299: /*
                    300:  * Find the source expression that resulted in v, and return a new string
                    301:  * containing it.  Fall back on v's string conversion (fallback) if we can't
                    302:  * find the bytecode that generated and pushed v on the operand stack.
                    303:  *
                    304:  * Search the current stack frame if spindex is JSDVG_SEARCH_STACK.  Don't
                    305:  * look for v on the stack if spindex is JSDVG_IGNORE_STACK.  Otherwise,
                    306:  * spindex is the negative index of v, measured from cx->fp->sp, or from a
                    307:  * lower frame's sp if cx->fp is native.
                    308:  */
                    309: extern JSString *
                    310: js_DecompileValueGenerator(JSContext *cx, intN spindex, jsval v,
1.1.1.2 ! root      311:                            JSString *fallback);
1.1       root      312: 
                    313: #define JSDVG_IGNORE_STACK      0
                    314: #define JSDVG_SEARCH_STACK      1
                    315: 
                    316: JS_END_EXTERN_C
                    317: 
                    318: #endif /* jsopcode_h___ */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.