Kannel: Open Source WAP and SMS gateway  svn-r5335
wsasm.h File Reference

Go to the source code of this file.

Data Structures

struct  WsAsmInsRec
 

Macros

#define WS_ASM_CLASS1P(op)   (((op) & 0x80) == 0x80)
 
#define WS_ASM_CLASS1_OP(op)   ((op) & 0xe0)
 
#define WS_ASM_CLASS1_ARG(op)   ((op) & 0x1f)
 
#define WS_ASM_CLASS2P(op)   (((op) & 0xe0) == 0x40)
 
#define WS_ASM_CLASS2_OP(op)   ((op) & 0xf0)
 
#define WS_ASM_CLASS2_ARG(op)   ((op) & 0x0f)
 
#define WS_ASM_CLASS3P(op)   (((op) & 0xe0) == 0x60)
 
#define WS_ASM_CLASS3_OP(op)   ((op) & 0x78)
 
#define WS_ASM_CLASS3_ARG(op)   ((op) & 0x07)
 
#define WS_ASM_CLASS4P(op)   (((op) & 0xc0) == 0x00)
 
#define WS_ASM_CLASS4_OP(op)   (op)
 
#define WS_ASM_OP(op)
 
#define WS_ASM_ARG(op)
 
#define WS_ASM_GLUE(op, arg)   ((WsByte) (((WsByte) (op)) | ((WsByte) (arg))))
 
#define WS_ASM_JUMP_FW_S   0x80 /* 10000000 1 */
 
#define WS_ASM_JUMP_FW   0x01 /* 00000001 2 */
 
#define WS_ASM_JUMP_FW_W   0x02 /* 00000010 3 */
 
#define WS_ASM_JUMP_BW_S   0xa0 /* 10100000 1 */
 
#define WS_ASM_JUMP_BW   0x03 /* 00000011 2 */
 
#define WS_ASM_JUMP_BW_W   0x04 /* 00000100 3 */
 
#define WS_ASM_TJUMP_FW_S   0xc0 /* 11000000 1 */
 
#define WS_ASM_TJUMP_FW   0x05 /* 00000101 2 */
 
#define WS_ASM_TJUMP_FW_W   0x06 /* 00000110 3 */
 
#define WS_ASM_TJUMP_BW   0x07 /* 00000111 2 */
 
#define WS_ASM_TJUMP_BW_W   0x08 /* 00001000 3 */
 
#define WS_ASM_CALL_S   0x60 /* 01100000 1 */
 
#define WS_ASM_CALL   0x09 /* 00001001 2 */
 
#define WS_ASM_CALL_LIB_S   0x68 /* 01101000 2 */
 
#define WS_ASM_CALL_LIB   0x0a /* 00001010 3 */
 
#define WS_ASM_CALL_LIB_W   0x0b /* 00001011 4 */
 
#define WS_ASM_CALL_URL   0x0c /* 00001100 4 */
 
#define WS_ASM_CALL_URL_W   0x0d /* 00001101 6 */
 
#define WS_ASM_LOAD_VAR_S   0xe0 /* 11100000 1 */
 
#define WS_ASM_LOAD_VAR   0x0e /* 00001110 2 */
 
#define WS_ASM_STORE_VAR_S   0x40 /* 01000000 1 */
 
#define WS_ASM_STORE_VAR   0x0f /* 00001111 2 */
 
#define WS_ASM_INCR_VAR_S   0x70 /* 01110000 1 */
 
#define WS_ASM_INCR_VAR   0x10 /* 00010000 2 */
 
#define WS_ASM_DECR_VAR   0x11 /* 00010001 2 */
 
#define WS_ASM_LOAD_CONST_S   0x50 /* 01010000 1 */
 
#define WS_ASM_LOAD_CONST   0x12 /* 00010010 2 */
 
#define WS_ASM_LOAD_CONST_W   0x13 /* 00010011 3 */
 
#define WS_ASM_CONST_0   0x14 /* 00010100 1 */
 
#define WS_ASM_CONST_1   0x15 /* 00010101 1 */
 
#define WS_ASM_CONST_M1   0x16 /* 00010110 1 */
 
#define WS_ASM_CONST_ES   0x17 /* 00010111 1 */
 
#define WS_ASM_CONST_INVALID   0x18 /* 00011000 1 */
 
#define WS_ASM_CONST_TRUE   0x19 /* 00011001 1 */
 
#define WS_ASM_CONST_FALSE   0x1a /* 00011010 1 */
 
#define WS_ASM_INCR   0x1b /* 00011011 1 */
 
#define WS_ASM_DECR   0x1c /* 00011100 1 */
 
#define WS_ASM_ADD_ASG   0x1d /* 00011101 2 */
 
#define WS_ASM_SUB_ASG   0x1e /* 00011110 2 */
 
#define WS_ASM_UMINUS   0x1f /* 00011111 1 */
 
#define WS_ASM_ADD   0x20 /* 00100000 1 */
 
#define WS_ASM_SUB   0x21 /* 00100001 1 */
 
#define WS_ASM_MUL   0x22 /* 00100010 1 */
 
#define WS_ASM_DIV   0x23 /* 00100011 1 */
 
#define WS_ASM_IDIV   0x24 /* 00100100 1 */
 
#define WS_ASM_REM   0x25 /* 00100101 1 */
 
#define WS_ASM_B_AND   0x26 /* 00100110 1 */
 
#define WS_ASM_B_OR   0x27 /* 00100111 1 */
 
#define WS_ASM_B_XOR   0x28 /* 00101000 1 */
 
#define WS_ASM_B_NOT   0x29 /* 00101001 1 */
 
#define WS_ASM_B_LSHIFT   0x2a /* 00101010 1 */
 
#define WS_ASM_B_RSSHIFT   0x2b /* 00101011 1 */
 
#define WS_ASM_B_RSZSHIFT   0x2c /* 00101100 1 */
 
#define WS_ASM_EQ   0x2d /* 00101101 1 */
 
#define WS_ASM_LE   0x2e /* 00101110 1 */
 
#define WS_ASM_LT   0x2f /* 00101111 1 */
 
#define WS_ASM_GE   0x30 /* 00110000 1 */
 
#define WS_ASM_GT   0x31 /* 00110001 1 */
 
#define WS_ASM_NE   0x32 /* 00110010 1 */
 
#define WS_ASM_NOT   0x33 /* 00110011 1 */
 
#define WS_ASM_SCAND   0x34 /* 00110100 1 */
 
#define WS_ASM_SCOR   0x35 /* 00110101 1 */
 
#define WS_ASM_TOBOOL   0x36 /* 00110110 1 */
 
#define WS_ASM_POP   0x37 /* 00110111 1 */
 
#define WS_ASM_TYPEOF   0x38 /* 00111000 1 */
 
#define WS_ASM_ISVALID   0x39 /* 00111001 1 */
 
#define WS_ASM_RETURN   0x3a /* 00111010 1 */
 
#define WS_ASM_RETURN_ES   0x3b /* 00111011 1 */
 
#define WS_ASM_DEBUG   0x3c /* 00111100 1 */
 
#define WS_ASM_P_LABEL   0x0100
 
#define WS_ASM_P_JUMP   0x0200
 
#define WS_ASM_P_TJUMP   0x0300
 
#define WS_ASM_P_CALL   0x0400
 
#define WS_ASM_P_CALL_LIB   0x0500
 
#define WS_ASM_P_CALL_URL   0x0600
 
#define WS_ASM_P_LOAD_VAR   0x0700
 
#define WS_ASM_P_STORE_VAR   0x0800
 
#define WS_ASM_P_INCR_VAR   0x0900
 
#define WS_ASM_P_LOAD_CONST   0x0a00
 
#define WS_ASM_P_BRANCH(ins)   ((ins)->type == WS_ASM_P_JUMP || (ins)->type == WS_ASM_P_TJUMP)
 
#define ws_label_idx   u.ivalues.i1
 
#define ws_label_refcount   u.ivalues.i2
 
#define ws_findex   u.ivalues.i1
 
#define ws_lindex   u.ivalues.i2
 
#define ws_args   u.ivalues.i3
 
#define ws_vindex   u.ivalues.i1
 
#define ws_cindex   u.ivalues.i1
 
#define ws_label   u.branch.label
 
#define ws_offset   u.branch.offset
 

Typedefs

typedef struct WsAsmInsRec WsAsmIns
 

Functions

void ws_asm_link (WsCompilerPtr compiler, WsAsmIns *ins)
 
void ws_asm_print (WsCompilerPtr compiler)
 
void ws_asm_dasm (WsCompilerPtr compiler, const unsigned char *code, size_t len)
 
void ws_asm_linearize (WsCompilerPtr compiler)
 
WsAsmInsws_asm_label (WsCompilerPtr compiler, WsUInt32 line)
 
WsAsmInsws_asm_branch (WsCompilerPtr compiler, WsUInt32 line, WsUInt16 ins, WsAsmIns *label)
 
WsAsmInsws_asm_call (WsCompilerPtr compiler, WsUInt32 line, WsUInt8 findex)
 
WsAsmInsws_asm_call_lib (WsCompilerPtr compiler, WsUInt32 line, WsUInt8 findex, WsUInt16 lindex)
 
WsAsmInsws_asm_call_url (WsCompilerPtr compiler, WsUInt32 line, WsUInt16 findex, WsUInt16 urlindex, WsUInt8 args)
 
WsAsmInsws_asm_variable (WsCompilerPtr compiler, WsUInt32 line, WsUInt16 ins, WsUInt8 vindex)
 
WsAsmInsws_asm_load_const (WsCompilerPtr compiler, WsUInt32 line, WsUInt16 cindex)
 
WsAsmInsws_asm_ins (WsCompilerPtr compiler, WsUInt32 line, WsUInt8 opcode)
 

Macro Definition Documentation

◆ ws_args

#define ws_args   u.ivalues.i3

Definition at line 247 of file wsasm.h.

◆ WS_ASM_ADD

#define WS_ASM_ADD   0x20 /* 00100000 1 */

Definition at line 183 of file wsasm.h.

Referenced by ws_asm_linearize(), ws_expr_linearize(), and yyparse().

◆ WS_ASM_ADD_ASG

#define WS_ASM_ADD_ASG   0x1d /* 00011101 2 */

Definition at line 180 of file wsasm.h.

Referenced by ws_asm_dasm(), ws_asm_linearize(), ws_asm_print(), and ws_expr_linearize().

◆ WS_ASM_ARG

#define WS_ASM_ARG (   op)
Value:
: (WS_ASM_CLASS2P(op) \
: (WS_ASM_CLASS3P(op) \
: 0)))
#define WS_ASM_CLASS3P(op)
Definition: wsasm.h:91
#define WS_ASM_CLASS2P(op)
Definition: wsasm.h:85
#define WS_ASM_CLASS2_ARG(op)
Definition: wsasm.h:87
#define WS_ASM_CLASS1_ARG(op)
Definition: wsasm.h:81
#define WS_ASM_CLASS1P(op)
Definition: wsasm.h:79
#define WS_ASM_CLASS3_ARG(op)
Definition: wsasm.h:93

Definition at line 114 of file wsasm.h.

Referenced by ws_asm_dasm().

◆ WS_ASM_B_AND

#define WS_ASM_B_AND   0x26 /* 00100110 1 */

Definition at line 190 of file wsasm.h.

Referenced by ws_asm_linearize(), ws_expr_linearize(), and yyparse().

◆ WS_ASM_B_LSHIFT

#define WS_ASM_B_LSHIFT   0x2a /* 00101010 1 */

Definition at line 194 of file wsasm.h.

Referenced by ws_asm_linearize(), ws_expr_linearize(), and yyparse().

◆ WS_ASM_B_NOT

#define WS_ASM_B_NOT   0x29 /* 00101001 1 */

Definition at line 193 of file wsasm.h.

Referenced by ws_asm_linearize(), and yyparse().

◆ WS_ASM_B_OR

#define WS_ASM_B_OR   0x27 /* 00100111 1 */

Definition at line 191 of file wsasm.h.

Referenced by ws_asm_linearize(), ws_expr_linearize(), and yyparse().

◆ WS_ASM_B_RSSHIFT

#define WS_ASM_B_RSSHIFT   0x2b /* 00101011 1 */

Definition at line 195 of file wsasm.h.

Referenced by ws_asm_linearize(), ws_expr_linearize(), and yyparse().

◆ WS_ASM_B_RSZSHIFT

#define WS_ASM_B_RSZSHIFT   0x2c /* 00101100 1 */

Definition at line 196 of file wsasm.h.

Referenced by ws_asm_linearize(), ws_expr_linearize(), and yyparse().

◆ WS_ASM_B_XOR

#define WS_ASM_B_XOR   0x28 /* 00101000 1 */

Definition at line 192 of file wsasm.h.

Referenced by ws_asm_linearize(), ws_expr_linearize(), and yyparse().

◆ WS_ASM_CALL

#define WS_ASM_CALL   0x09 /* 00001001 2 */

Definition at line 146 of file wsasm.h.

Referenced by ws_asm_dasm(), and ws_asm_linearize().

◆ WS_ASM_CALL_LIB

#define WS_ASM_CALL_LIB   0x0a /* 00001010 3 */

Definition at line 149 of file wsasm.h.

Referenced by ws_asm_dasm(), and ws_asm_linearize().

◆ WS_ASM_CALL_LIB_S

#define WS_ASM_CALL_LIB_S   0x68 /* 01101000 2 */

Definition at line 148 of file wsasm.h.

Referenced by ws_asm_dasm(), and ws_asm_linearize().

◆ WS_ASM_CALL_LIB_W

#define WS_ASM_CALL_LIB_W   0x0b /* 00001011 4 */

Definition at line 150 of file wsasm.h.

Referenced by ws_asm_dasm(), and ws_asm_linearize().

◆ WS_ASM_CALL_S

#define WS_ASM_CALL_S   0x60 /* 01100000 1 */

Definition at line 145 of file wsasm.h.

Referenced by ws_asm_dasm(), and ws_asm_linearize().

◆ WS_ASM_CALL_URL

#define WS_ASM_CALL_URL   0x0c /* 00001100 4 */

Definition at line 152 of file wsasm.h.

Referenced by ws_asm_dasm(), and ws_asm_linearize().

◆ WS_ASM_CALL_URL_W

#define WS_ASM_CALL_URL_W   0x0d /* 00001101 6 */

Definition at line 153 of file wsasm.h.

Referenced by ws_asm_dasm(), and ws_asm_linearize().

◆ WS_ASM_CLASS1_ARG

#define WS_ASM_CLASS1_ARG (   op)    ((op) & 0x1f)

Definition at line 81 of file wsasm.h.

◆ WS_ASM_CLASS1_OP

#define WS_ASM_CLASS1_OP (   op)    ((op) & 0xe0)

Definition at line 80 of file wsasm.h.

◆ WS_ASM_CLASS1P

#define WS_ASM_CLASS1P (   op)    (((op) & 0x80) == 0x80)

Definition at line 79 of file wsasm.h.

◆ WS_ASM_CLASS2_ARG

#define WS_ASM_CLASS2_ARG (   op)    ((op) & 0x0f)

Definition at line 87 of file wsasm.h.

◆ WS_ASM_CLASS2_OP

#define WS_ASM_CLASS2_OP (   op)    ((op) & 0xf0)

Definition at line 86 of file wsasm.h.

◆ WS_ASM_CLASS2P

#define WS_ASM_CLASS2P (   op)    (((op) & 0xe0) == 0x40)

Definition at line 85 of file wsasm.h.

◆ WS_ASM_CLASS3_ARG

#define WS_ASM_CLASS3_ARG (   op)    ((op) & 0x07)

Definition at line 93 of file wsasm.h.

◆ WS_ASM_CLASS3_OP

#define WS_ASM_CLASS3_OP (   op)    ((op) & 0x78)

Definition at line 92 of file wsasm.h.

◆ WS_ASM_CLASS3P

#define WS_ASM_CLASS3P (   op)    (((op) & 0xe0) == 0x60)

Definition at line 91 of file wsasm.h.

◆ WS_ASM_CLASS4_OP

#define WS_ASM_CLASS4_OP (   op)    (op)

Definition at line 98 of file wsasm.h.

◆ WS_ASM_CLASS4P

#define WS_ASM_CLASS4P (   op)    (((op) & 0xc0) == 0x00)

Definition at line 97 of file wsasm.h.

◆ WS_ASM_CONST_0

#define WS_ASM_CONST_0   0x14 /* 00010100 1 */

Definition at line 170 of file wsasm.h.

Referenced by opt_peephole(), ws_asm_linearize(), and ws_expr_linearize().

◆ WS_ASM_CONST_1

#define WS_ASM_CONST_1   0x15 /* 00010101 1 */

Definition at line 171 of file wsasm.h.

Referenced by opt_peephole(), ws_asm_linearize(), and ws_expr_linearize().

◆ WS_ASM_CONST_ES

#define WS_ASM_CONST_ES   0x17 /* 00010111 1 */

Definition at line 173 of file wsasm.h.

Referenced by opt_peephole(), ws_asm_linearize(), and ws_expr_linearize().

◆ WS_ASM_CONST_FALSE

#define WS_ASM_CONST_FALSE   0x1a /* 00011010 1 */

Definition at line 176 of file wsasm.h.

Referenced by opt_peephole(), ws_asm_linearize(), and ws_expr_linearize().

◆ WS_ASM_CONST_INVALID

#define WS_ASM_CONST_INVALID   0x18 /* 00011000 1 */

Definition at line 174 of file wsasm.h.

Referenced by opt_peephole(), ws_asm_linearize(), and ws_expr_linearize().

◆ WS_ASM_CONST_M1

#define WS_ASM_CONST_M1   0x16 /* 00010110 1 */

Definition at line 172 of file wsasm.h.

Referenced by opt_peephole(), and ws_asm_linearize().

◆ WS_ASM_CONST_TRUE

#define WS_ASM_CONST_TRUE   0x19 /* 00011001 1 */

Definition at line 175 of file wsasm.h.

Referenced by opt_peephole(), ws_asm_linearize(), and ws_expr_linearize().

◆ WS_ASM_DEBUG

#define WS_ASM_DEBUG   0x3c /* 00111100 1 */

Definition at line 218 of file wsasm.h.

Referenced by ws_asm_linearize().

◆ WS_ASM_DECR

#define WS_ASM_DECR   0x1c /* 00011100 1 */

Definition at line 179 of file wsasm.h.

Referenced by ws_asm_linearize().

◆ WS_ASM_DECR_VAR

#define WS_ASM_DECR_VAR   0x11 /* 00010001 2 */

Definition at line 164 of file wsasm.h.

Referenced by ws_asm_dasm(), ws_asm_linearize(), and ws_expr_linearize().

◆ WS_ASM_DIV

#define WS_ASM_DIV   0x23 /* 00100011 1 */

Definition at line 186 of file wsasm.h.

Referenced by ws_asm_linearize(), ws_expr_linearize(), and yyparse().

◆ WS_ASM_EQ

#define WS_ASM_EQ   0x2d /* 00101101 1 */

Definition at line 198 of file wsasm.h.

Referenced by ws_asm_linearize(), and yyparse().

◆ WS_ASM_GE

#define WS_ASM_GE   0x30 /* 00110000 1 */

Definition at line 201 of file wsasm.h.

Referenced by ws_asm_linearize(), and yyparse().

◆ WS_ASM_GLUE

#define WS_ASM_GLUE (   op,
  arg 
)    ((WsByte) (((WsByte) (op)) | ((WsByte) (arg))))

Definition at line 125 of file wsasm.h.

Referenced by ws_asm_linearize().

◆ WS_ASM_GT

#define WS_ASM_GT   0x31 /* 00110001 1 */

Definition at line 202 of file wsasm.h.

Referenced by ws_asm_linearize(), and yyparse().

◆ WS_ASM_IDIV

#define WS_ASM_IDIV   0x24 /* 00100100 1 */

Definition at line 187 of file wsasm.h.

Referenced by ws_asm_linearize(), ws_expr_linearize(), and yyparse().

◆ WS_ASM_INCR

#define WS_ASM_INCR   0x1b /* 00011011 1 */

Definition at line 178 of file wsasm.h.

Referenced by ws_asm_linearize().

◆ WS_ASM_INCR_VAR

#define WS_ASM_INCR_VAR   0x10 /* 00010000 2 */

Definition at line 162 of file wsasm.h.

Referenced by ws_asm_dasm(), and ws_asm_linearize().

◆ WS_ASM_INCR_VAR_S

#define WS_ASM_INCR_VAR_S   0x70 /* 01110000 1 */

Definition at line 161 of file wsasm.h.

Referenced by ws_asm_dasm(), and ws_asm_linearize().

◆ WS_ASM_ISVALID

#define WS_ASM_ISVALID   0x39 /* 00111001 1 */

Definition at line 213 of file wsasm.h.

Referenced by ws_asm_linearize(), and yyparse().

◆ WS_ASM_JUMP_BW

#define WS_ASM_JUMP_BW   0x03 /* 00000011 2 */

Definition at line 135 of file wsasm.h.

Referenced by ws_asm_dasm(), and ws_asm_linearize().

◆ WS_ASM_JUMP_BW_S

#define WS_ASM_JUMP_BW_S   0xa0 /* 10100000 1 */

Definition at line 134 of file wsasm.h.

Referenced by ws_asm_dasm(), and ws_asm_linearize().

◆ WS_ASM_JUMP_BW_W

#define WS_ASM_JUMP_BW_W   0x04 /* 00000100 3 */

Definition at line 136 of file wsasm.h.

Referenced by ws_asm_dasm(), and ws_asm_linearize().

◆ WS_ASM_JUMP_FW

#define WS_ASM_JUMP_FW   0x01 /* 00000001 2 */

Definition at line 131 of file wsasm.h.

Referenced by ws_asm_dasm(), and ws_asm_linearize().

◆ WS_ASM_JUMP_FW_S

#define WS_ASM_JUMP_FW_S   0x80 /* 10000000 1 */

Definition at line 130 of file wsasm.h.

Referenced by ws_asm_dasm(), and ws_asm_linearize().

◆ WS_ASM_JUMP_FW_W

#define WS_ASM_JUMP_FW_W   0x02 /* 00000010 3 */

Definition at line 132 of file wsasm.h.

Referenced by ws_asm_dasm(), and ws_asm_linearize().

◆ WS_ASM_LE

#define WS_ASM_LE   0x2e /* 00101110 1 */

Definition at line 199 of file wsasm.h.

Referenced by ws_asm_linearize(), and yyparse().

◆ WS_ASM_LOAD_CONST

#define WS_ASM_LOAD_CONST   0x12 /* 00010010 2 */

Definition at line 167 of file wsasm.h.

Referenced by ws_asm_dasm(), and ws_asm_linearize().

◆ WS_ASM_LOAD_CONST_S

#define WS_ASM_LOAD_CONST_S   0x50 /* 01010000 1 */

Definition at line 166 of file wsasm.h.

Referenced by ws_asm_dasm(), and ws_asm_linearize().

◆ WS_ASM_LOAD_CONST_W

#define WS_ASM_LOAD_CONST_W   0x13 /* 00010011 3 */

Definition at line 168 of file wsasm.h.

Referenced by ws_asm_dasm(), and ws_asm_linearize().

◆ WS_ASM_LOAD_VAR

#define WS_ASM_LOAD_VAR   0x0e /* 00001110 2 */

Definition at line 156 of file wsasm.h.

Referenced by ws_asm_dasm(), and ws_asm_linearize().

◆ WS_ASM_LOAD_VAR_S

#define WS_ASM_LOAD_VAR_S   0xe0 /* 11100000 1 */

Definition at line 155 of file wsasm.h.

Referenced by ws_asm_dasm(), and ws_asm_linearize().

◆ WS_ASM_LT

#define WS_ASM_LT   0x2f /* 00101111 1 */

Definition at line 200 of file wsasm.h.

Referenced by ws_asm_linearize(), and yyparse().

◆ WS_ASM_MUL

#define WS_ASM_MUL   0x22 /* 00100010 1 */

Definition at line 185 of file wsasm.h.

Referenced by ws_asm_linearize(), ws_expr_linearize(), and yyparse().

◆ WS_ASM_NE

#define WS_ASM_NE   0x32 /* 00110010 1 */

Definition at line 203 of file wsasm.h.

Referenced by ws_asm_linearize(), and yyparse().

◆ WS_ASM_NOT

#define WS_ASM_NOT   0x33 /* 00110011 1 */

Definition at line 205 of file wsasm.h.

Referenced by opt_conv(), ws_asm_linearize(), and yyparse().

◆ WS_ASM_OP

#define WS_ASM_OP (   op)
Value:
: (WS_ASM_CLASS2P(op) \
: (WS_ASM_CLASS3P(op) \
#define WS_ASM_CLASS3_OP(op)
Definition: wsasm.h:92
#define WS_ASM_CLASS2_OP(op)
Definition: wsasm.h:86
#define WS_ASM_CLASS3P(op)
Definition: wsasm.h:91
#define WS_ASM_CLASS2P(op)
Definition: wsasm.h:85
#define WS_ASM_CLASS1_OP(op)
Definition: wsasm.h:80
#define WS_ASM_CLASS1P(op)
Definition: wsasm.h:79
#define WS_ASM_CLASS4_OP(op)
Definition: wsasm.h:98

Definition at line 102 of file wsasm.h.

Referenced by ws_asm_dasm(), and ws_asm_print().

◆ WS_ASM_P_BRANCH

#define WS_ASM_P_BRANCH (   ins)    ((ins)->type == WS_ASM_P_JUMP || (ins)->type == WS_ASM_P_TJUMP)

Definition at line 238 of file wsasm.h.

Referenced by opt_dead_code(), and opt_jumps_to_jumps().

◆ WS_ASM_P_CALL

#define WS_ASM_P_CALL   0x0400

Definition at line 228 of file wsasm.h.

Referenced by ws_asm_call(), ws_asm_linearize(), and ws_asm_print().

◆ WS_ASM_P_CALL_LIB

#define WS_ASM_P_CALL_LIB   0x0500

Definition at line 229 of file wsasm.h.

Referenced by ws_asm_call_lib(), ws_asm_linearize(), and ws_asm_print().

◆ WS_ASM_P_CALL_URL

#define WS_ASM_P_CALL_URL   0x0600

Definition at line 230 of file wsasm.h.

Referenced by ws_asm_call_url(), ws_asm_linearize(), and ws_asm_print().

◆ WS_ASM_P_INCR_VAR

#define WS_ASM_P_INCR_VAR   0x0900

Definition at line 233 of file wsasm.h.

Referenced by ws_asm_linearize(), ws_asm_print(), and ws_expr_linearize().

◆ WS_ASM_P_JUMP

◆ WS_ASM_P_LABEL

#define WS_ASM_P_LABEL   0x0100

◆ WS_ASM_P_LOAD_CONST

#define WS_ASM_P_LOAD_CONST   0x0a00

Definition at line 234 of file wsasm.h.

Referenced by opt_peephole(), ws_asm_linearize(), ws_asm_load_const(), and ws_asm_print().

◆ WS_ASM_P_LOAD_VAR

#define WS_ASM_P_LOAD_VAR   0x0700

Definition at line 231 of file wsasm.h.

Referenced by opt_peephole(), ws_asm_linearize(), ws_asm_print(), and ws_expr_linearize().

◆ WS_ASM_P_STORE_VAR

#define WS_ASM_P_STORE_VAR   0x0800

◆ WS_ASM_P_TJUMP

#define WS_ASM_P_TJUMP   0x0300

◆ WS_ASM_POP

#define WS_ASM_POP   0x37 /* 00110111 1 */

◆ WS_ASM_REM

#define WS_ASM_REM   0x25 /* 00100101 1 */

Definition at line 188 of file wsasm.h.

Referenced by ws_asm_linearize(), ws_expr_linearize(), and yyparse().

◆ WS_ASM_RETURN

#define WS_ASM_RETURN   0x3a /* 00111010 1 */

Definition at line 215 of file wsasm.h.

Referenced by opt_dead_code(), opt_peephole(), ws_asm_linearize(), and ws_stmt_linearize().

◆ WS_ASM_RETURN_ES

#define WS_ASM_RETURN_ES   0x3b /* 00111011 1 */

Definition at line 216 of file wsasm.h.

Referenced by opt_dead_code(), opt_peephole(), ws_asm_linearize(), and ws_stmt_linearize().

◆ WS_ASM_SCAND

#define WS_ASM_SCAND   0x34 /* 00110100 1 */

Definition at line 206 of file wsasm.h.

Referenced by opt_conv(), ws_asm_linearize(), and yyparse().

◆ WS_ASM_SCOR

#define WS_ASM_SCOR   0x35 /* 00110101 1 */

Definition at line 207 of file wsasm.h.

Referenced by opt_conv(), ws_asm_linearize(), and yyparse().

◆ WS_ASM_STORE_VAR

#define WS_ASM_STORE_VAR   0x0f /* 00001111 2 */

Definition at line 159 of file wsasm.h.

Referenced by ws_asm_dasm(), and ws_asm_linearize().

◆ WS_ASM_STORE_VAR_S

#define WS_ASM_STORE_VAR_S   0x40 /* 01000000 1 */

Definition at line 158 of file wsasm.h.

Referenced by ws_asm_dasm(), and ws_asm_linearize().

◆ WS_ASM_SUB

#define WS_ASM_SUB   0x21 /* 00100001 1 */

Definition at line 184 of file wsasm.h.

Referenced by ws_asm_linearize(), ws_expr_linearize(), and yyparse().

◆ WS_ASM_SUB_ASG

#define WS_ASM_SUB_ASG   0x1e /* 00011110 2 */

Definition at line 181 of file wsasm.h.

Referenced by ws_asm_dasm(), ws_asm_linearize(), ws_asm_print(), and ws_expr_linearize().

◆ WS_ASM_TJUMP_BW

#define WS_ASM_TJUMP_BW   0x07 /* 00000111 2 */

Definition at line 142 of file wsasm.h.

Referenced by ws_asm_dasm(), and ws_asm_linearize().

◆ WS_ASM_TJUMP_BW_W

#define WS_ASM_TJUMP_BW_W   0x08 /* 00001000 3 */

Definition at line 143 of file wsasm.h.

Referenced by ws_asm_dasm(), and ws_asm_linearize().

◆ WS_ASM_TJUMP_FW

#define WS_ASM_TJUMP_FW   0x05 /* 00000101 2 */

Definition at line 139 of file wsasm.h.

Referenced by ws_asm_dasm(), and ws_asm_linearize().

◆ WS_ASM_TJUMP_FW_S

#define WS_ASM_TJUMP_FW_S   0xc0 /* 11000000 1 */

Definition at line 138 of file wsasm.h.

Referenced by ws_asm_dasm(), and ws_asm_linearize().

◆ WS_ASM_TJUMP_FW_W

#define WS_ASM_TJUMP_FW_W   0x06 /* 00000110 3 */

Definition at line 140 of file wsasm.h.

Referenced by ws_asm_dasm(), and ws_asm_linearize().

◆ WS_ASM_TOBOOL

#define WS_ASM_TOBOOL   0x36 /* 00110110 1 */

Definition at line 208 of file wsasm.h.

Referenced by opt_conv(), ws_asm_linearize(), and ws_expr_linearize().

◆ WS_ASM_TYPEOF

#define WS_ASM_TYPEOF   0x38 /* 00111000 1 */

Definition at line 212 of file wsasm.h.

Referenced by ws_asm_linearize(), and yyparse().

◆ WS_ASM_UMINUS

#define WS_ASM_UMINUS   0x1f /* 00011111 1 */

Definition at line 182 of file wsasm.h.

Referenced by ws_asm_linearize(), ws_expr_unary(), and yyparse().

◆ ws_cindex

#define ws_cindex   u.ivalues.i1

Definition at line 249 of file wsasm.h.

◆ ws_findex

#define ws_findex   u.ivalues.i1

Definition at line 245 of file wsasm.h.

◆ ws_label

#define ws_label   u.branch.label

Definition at line 250 of file wsasm.h.

◆ ws_label_idx

#define ws_label_idx   u.ivalues.i1

Definition at line 243 of file wsasm.h.

◆ ws_label_refcount

#define ws_label_refcount   u.ivalues.i2

Definition at line 244 of file wsasm.h.

◆ ws_lindex

#define ws_lindex   u.ivalues.i2

Definition at line 246 of file wsasm.h.

◆ ws_offset

#define ws_offset   u.branch.offset

Definition at line 251 of file wsasm.h.

◆ ws_vindex

#define ws_vindex   u.ivalues.i1

Definition at line 248 of file wsasm.h.

Typedef Documentation

◆ WsAsmIns

typedef struct WsAsmInsRec WsAsmIns

Definition at line 289 of file wsasm.h.

Function Documentation

◆ ws_asm_branch()

WsAsmIns* ws_asm_branch ( WsCompilerPtr  compiler,
WsUInt32  line,
WsUInt16  ins,
WsAsmIns label 
)

◆ ws_asm_call()

WsAsmIns* ws_asm_call ( WsCompilerPtr  compiler,
WsUInt32  line,
WsUInt8  findex 
)

◆ ws_asm_call_lib()

WsAsmIns* ws_asm_call_lib ( WsCompilerPtr  compiler,
WsUInt32  line,
WsUInt8  findex,
WsUInt16  lindex 
)

◆ ws_asm_call_url()

WsAsmIns* ws_asm_call_url ( WsCompilerPtr  compiler,
WsUInt32  line,
WsUInt16  findex,
WsUInt16  urlindex,
WsUInt8  args 
)

◆ ws_asm_dasm()

void ws_asm_dasm ( WsCompilerPtr  compiler,
const unsigned char *  code,
size_t  len 
)

Definition at line 185 of file wsasm.c.

References code, WS_ASM_ADD_ASG, WS_ASM_ARG, WS_ASM_CALL, WS_ASM_CALL_LIB, WS_ASM_CALL_LIB_S, WS_ASM_CALL_LIB_W, WS_ASM_CALL_S, WS_ASM_CALL_URL, WS_ASM_CALL_URL_W, WS_ASM_DECR_VAR, WS_ASM_INCR_VAR, WS_ASM_INCR_VAR_S, WS_ASM_JUMP_BW, WS_ASM_JUMP_BW_S, WS_ASM_JUMP_BW_W, WS_ASM_JUMP_FW, WS_ASM_JUMP_FW_S, WS_ASM_JUMP_FW_W, WS_ASM_LOAD_CONST, WS_ASM_LOAD_CONST_S, WS_ASM_LOAD_CONST_W, WS_ASM_LOAD_VAR, WS_ASM_LOAD_VAR_S, WS_ASM_OP, WS_ASM_STORE_VAR, WS_ASM_STORE_VAR_S, WS_ASM_SUB_ASG, WS_ASM_TJUMP_BW, WS_ASM_TJUMP_BW_W, WS_ASM_TJUMP_FW, WS_ASM_TJUMP_FW_S, WS_ASM_TJUMP_FW_W, ws_fprintf(), WS_GET_UINT16, WS_GET_UINT8, WS_OPNAME, WS_OPSIZE, ws_stdlib_function_name(), and WS_STDOUT.

Referenced by compile_stream(), and main().

186 {
187  size_t i = 0;
188 
189  while (i < len) {
190  WsUInt8 byt = code[i];
191  WsUInt8 op;
192  WsUInt8 arg;
193  WsUInt8 i8, j8, k8;
194  WsUInt16 i16, j16;
195 
196  op = WS_ASM_OP(byt);
197  arg = WS_ASM_ARG(byt);
198 
199  ws_fprintf(WS_STDOUT, "%4x:\t%-16s", i, WS_OPNAME(op));
200 
201  switch (op) {
202  /* The `short jumps'. */
203  case WS_ASM_JUMP_FW_S:
204  case WS_ASM_TJUMP_FW_S:
205  ws_fprintf(WS_STDOUT, "%x\n", i + WS_OPSIZE(op) + arg);
206  break;
207 
208  case WS_ASM_JUMP_BW_S:
209  ws_fprintf(WS_STDOUT, "%x\n", i - arg);
210  break;
211 
212  /* Jumps with WsUInt8 argument. */
213  case WS_ASM_JUMP_FW:
214  case WS_ASM_TJUMP_FW:
215  WS_GET_UINT8(code + i + 1, i8);
216  ws_fprintf(WS_STDOUT, "%x\n", i + WS_OPSIZE(op) + i8);
217  break;
218 
219  case WS_ASM_JUMP_BW:
220  case WS_ASM_TJUMP_BW:
221  WS_GET_UINT8(code + i + 1, i8);
222  ws_fprintf(WS_STDOUT, "%x\n", i - i8);
223  break;
224 
225  /* Jumps with wide argument. */
226  case WS_ASM_JUMP_FW_W:
227  case WS_ASM_TJUMP_FW_W:
228  WS_GET_UINT16(code + i + 1, i16);
229  ws_fprintf(WS_STDOUT, "%x\n", i + WS_OPSIZE(op) + i16);
230  break;
231 
232  case WS_ASM_JUMP_BW_W:
233  case WS_ASM_TJUMP_BW_W:
234  WS_GET_UINT16(code + i + 1, i16);
235  ws_fprintf(WS_STDOUT, "%x\n", i - i16);
236  break;
237 
238  /* The `short' opcodes. */
239  case WS_ASM_LOAD_VAR_S:
240  case WS_ASM_STORE_VAR_S:
241  case WS_ASM_INCR_VAR_S:
242  ws_fprintf(WS_STDOUT, "%d\n", arg);
243  break;
244 
245  /* Local script function calls. */
246  case WS_ASM_CALL_S:
247  ws_fprintf(WS_STDOUT, "%d\n", arg);
248  break;
249 
250  case WS_ASM_CALL:
251  WS_GET_UINT8(code + i + 1, i8);
252  ws_fprintf(WS_STDOUT, "%d\n", i8);
253  break;
254 
255  /* Library calls. */
256  case WS_ASM_CALL_LIB_S:
257  case WS_ASM_CALL_LIB:
258  case WS_ASM_CALL_LIB_W:
259  {
260  WsUInt8 findex;
261  WsUInt16 lindex;
262  char lnamebuf[64];
263  char fnamebuf[64];
264  const char *lname;
265  const char *fname;
266 
267  if (op == WS_ASM_CALL_LIB_S) {
268  WS_GET_UINT8(code + i + 1, lindex);
269  findex = arg;
270  } else if (op == WS_ASM_CALL_LIB) {
271  WS_GET_UINT8(code + i + 1, findex);
272  WS_GET_UINT8(code + i + 2, lindex);
273  } else {
274  WS_GET_UINT8(code + i + 1, findex);
275  WS_GET_UINT16(code + i + 2, lindex);
276  }
277 
278  if (!ws_stdlib_function_name(lindex, findex, &lname, &fname)) {
279  snprintf(lnamebuf, sizeof(lnamebuf), "%d", lindex);
280  snprintf(fnamebuf, sizeof(lnamebuf), "%d", findex);
281  lname = lnamebuf;
282  fname = fnamebuf;
283  }
284  ws_fprintf(WS_STDOUT, "%s.%s\n", lname, fname);
285  }
286  break;
287 
288  /* URL calls. */
289  case WS_ASM_CALL_URL:
290  WS_GET_UINT8(code + i + 1, i8);
291  WS_GET_UINT8(code + i + 2, j8);
292  WS_GET_UINT8(code + i + 3, k8);
293  ws_fprintf(WS_STDOUT, "%d.%d %d\n", i8, j8, k8);
294  break;
295 
296  case WS_ASM_CALL_URL_W:
297  WS_GET_UINT16(code + i + 1, i16);
298  WS_GET_UINT16(code + i + 3, j16);
299  WS_GET_UINT8(code + i + 5, i8);
300  ws_fprintf(WS_STDOUT, "%d.%d %d\n", i16, j16, i8);
301  break;
302 
303  /* Constant access. */
304  case WS_ASM_LOAD_CONST_S:
305  case WS_ASM_LOAD_CONST:
306  case WS_ASM_LOAD_CONST_W:
307  if (op == WS_ASM_LOAD_CONST_S)
308  i16 = arg;
309  else if (op == WS_ASM_LOAD_CONST) {
310  WS_GET_UINT8(code + i + 1, i8);
311  i16 = i8;
312  } else
313  WS_GET_UINT16(code + i + 1, i16);
314 
315  ws_fprintf(WS_STDOUT, "%d\n", i16);
316  break;
317 
318  /* Operands with WsUInt8 argument. */
319  case WS_ASM_LOAD_VAR:
320  case WS_ASM_STORE_VAR:
321  case WS_ASM_INCR_VAR:
322  case WS_ASM_DECR_VAR:
323  case WS_ASM_ADD_ASG:
324  case WS_ASM_SUB_ASG:
325  WS_GET_UINT8(code + i + 1, i8);
326  ws_fprintf(WS_STDOUT, "%d\n", i8);
327  break;
328 
329  /* The trivial cases. */
330  default:
331  ws_fprintf(WS_STDOUT, "\n");
332  break;
333  }
334 
335  i += WS_OPSIZE(op);
336  }
337 }
#define WS_ASM_JUMP_FW_S
Definition: wsasm.h:130
#define WS_GET_UINT16(buf, var)
Definition: wsencode.h:107
#define WS_ASM_JUMP_FW_W
Definition: wsasm.h:132
#define WS_ASM_LOAD_CONST
Definition: wsasm.h:167
#define WS_ASM_ADD_ASG
Definition: wsasm.h:180
int code
Definition: smsc_cimd2.c:346
#define WS_ASM_CALL_LIB
Definition: wsasm.h:149
#define WS_ASM_JUMP_BW
Definition: wsasm.h:135
#define WS_GET_UINT8(buf, var)
Definition: wsencode.h:101
#define WS_ASM_ARG(op)
Definition: wsasm.h:114
#define WS_ASM_CALL_URL
Definition: wsasm.h:152
unsigned char WsUInt8
Definition: wsint.h:116
#define WS_ASM_JUMP_BW_W
Definition: wsasm.h:136
#define WS_OPNAME(op)
Definition: wsasm.c:76
#define WS_ASM_TJUMP_BW_W
Definition: wsasm.h:143
void ws_fprintf(WsIOProc io, void *context, const char *fmt,...)
Definition: wserror.c:190
unsigned short WsUInt16
Definition: wsint.h:119
#define WS_ASM_CALL
Definition: wsasm.h:146
#define WS_ASM_JUMP_BW_S
Definition: wsasm.h:134
#define WS_ASM_INCR_VAR_S
Definition: wsasm.h:161
#define WS_OPSIZE(op)
Definition: wsasm.c:77
#define WS_ASM_LOAD_VAR
Definition: wsasm.h:156
#define WS_ASM_LOAD_CONST_W
Definition: wsasm.h:168
#define WS_ASM_CALL_LIB_S
Definition: wsasm.h:148
#define WS_ASM_LOAD_VAR_S
Definition: wsasm.h:155
#define WS_ASM_TJUMP_BW
Definition: wsasm.h:142
#define WS_ASM_TJUMP_FW_S
Definition: wsasm.h:138
#define WS_ASM_STORE_VAR
Definition: wsasm.h:159
#define WS_ASM_DECR_VAR
Definition: wsasm.h:164
#define WS_ASM_CALL_URL_W
Definition: wsasm.h:153
#define WS_ASM_CALL_LIB_W
Definition: wsasm.h:150
#define WS_ASM_TJUMP_FW
Definition: wsasm.h:139
#define WS_ASM_INCR_VAR
Definition: wsasm.h:162
#define WS_ASM_STORE_VAR_S
Definition: wsasm.h:158
WsBool ws_stdlib_function_name(WsUInt16 lindex, WsUInt8 findex, const char **library_return, const char **function_return)
Definition: wsstdlib.c:375
#define WS_ASM_SUB_ASG
Definition: wsasm.h:181
#define WS_ASM_TJUMP_FW_W
Definition: wsasm.h:140
#define WS_ASM_LOAD_CONST_S
Definition: wsasm.h:166
#define WS_ASM_CALL_S
Definition: wsasm.h:145
#define WS_ASM_JUMP_FW
Definition: wsasm.h:131
#define WS_STDOUT
Definition: wserror.h:113
#define WS_ASM_OP(op)
Definition: wsasm.h:102

◆ ws_asm_ins()

WsAsmIns* ws_asm_ins ( WsCompilerPtr  compiler,
WsUInt32  line,
WsUInt8  opcode 
)

◆ ws_asm_label()

WsAsmIns* ws_asm_label ( WsCompilerPtr  compiler,
WsUInt32  line 
)

◆ ws_asm_linearize()

void ws_asm_linearize ( WsCompilerPtr  compiler)

◆ ws_asm_link()

void ws_asm_link ( WsCompilerPtr  compiler,
WsAsmIns ins 
)

◆ ws_asm_load_const()

WsAsmIns* ws_asm_load_const ( WsCompilerPtr  compiler,
WsUInt32  line,
WsUInt16  cindex 
)

◆ ws_asm_print()

void ws_asm_print ( WsCompilerPtr  compiler)

◆ ws_asm_variable()

WsAsmIns* ws_asm_variable ( WsCompilerPtr  compiler,
WsUInt32  line,
WsUInt16  ins,
WsUInt8  vindex 
)
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.