1#ifndef REDUCT_DISASM_IMPL_H
2#define REDUCT_DISASM_IMPL_H 1
18 REDUCT_FPRINTF(out,
"================================================================================\n");
23 REDUCT_FPRINTF(out,
"--------------------------------------------------------------------------------\n");
35 const char* opName =
"UNKNOWN";
149 REDUCT_FPRINTF(out,
"R%-5u %-6u %c%-5u", a, b, isConst ?
'K' :
'R', c);
152 REDUCT_FPRINTF(out,
"%c%-5u %-6s %-6s", isConst ?
'K' :
'R', c,
"",
"");
157 REDUCT_FPRINTF(out,
"R%-5u %-6s %c%-5u", a,
"", isConst ?
'K' :
'R', c);
163 REDUCT_FPRINTF(out,
"R%-5u R%-5u %c%-5u", a, b, isConst ?
'K' :
'R', c);
175 int target = (int)i + 1 + sbx;
178 else if (hasInlineConst && c < function->constantCount)
219 REDUCT_FPRINTF(out,
"--------------------------------------------------------------------------------\n");
233 REDUCT_FPRINTF(out,
"[K%03u] (list of %u handles)\n", (
unsigned int)i,
257 REDUCT_FPRINTF(out,
"================================================================================\n");
reduct_bool_t
Boolean type.
#define REDUCT_ASSERT(_cond)
static void reduct_disasm_internal(reduct_t *reduct, reduct_function_t *function, reduct_file_t out)
REDUCT_API void reduct_disasm(reduct_t *reduct, reduct_function_t *function, reduct_file_t out)
Disassembles a compiled function.
#define REDUCT_CONST_SLOT_CAPTURE(_capture)
Create a constant slot containing a variable name to be captured.
#define REDUCT_CONST_SLOT_ITEM(_item)
Create a constant slot containing an item.
#define REDUCT_INST_GET_C(_inst)
Get the C operand from an instruction.
#define REDUCT_INST_GET_A(_inst)
Get the A operand from an instruction.
#define REDUCT_INST_GET_SBX(_inst)
Get the SBX operand from an instruction.
#define REDUCT_INST_GET_OP(_inst)
Get the opcode from an instruction.
reduct_opcode_t
Opcode enumeration.
reduct_uint32_t reduct_inst_t
Instruction type.
#define REDUCT_INST_GET_B(_inst)
Get the B operand from an instruction.
#define REDUCT_INST_GET_OP_BASE(_inst)
Get the opcode base (without reduct_mode_t) from an instruction. Mask clears the REDUCT_MODE_CONST bi...
@ REDUCT_MODE_CONST
Constant operand mode.
@ REDUCT_OPCODE_DIV
(A, B, C) R(A) = R(B) / R/K(C)
@ REDUCT_OPCODE_JMPF
(A, sBx) Jump by sBx if R(A) is falsy.
@ REDUCT_OPCODE_JMPT
(A, sBx) Jump by sBx if R(A) is truthy.
@ REDUCT_OPCODE_APPEND
(A, C) Append value in R/K(C) to the back of the list in R(A).
@ REDUCT_OPCODE_SHR
(A, B, C) R(A) = R(B) >> R/K(C)
@ REDUCT_OPCODE_SEQ
(A, B, C) If R(B) === R/K(C) store true in R(A), else false.
@ REDUCT_OPCODE_SHL
(A, B, C) R(A) = R(B) << R/K(C)
@ REDUCT_OPCODE_SUB
(A, B, C) R(A) = R(B) - R/K(C)
@ REDUCT_OPCODE_NEQ
(A, B, C) If R(B) != R/K(C) store true in R(A), else false.
@ REDUCT_OPCODE_MOV
(A, C) Move value in R/K(C) to R(A).
@ REDUCT_OPCODE_MUL
(A, B, C) R(A) = R(B) * R/K(C)
@ REDUCT_OPCODE_ADD
(A, B, C) R(A) = R(B) + R/K(C)
@ REDUCT_OPCODE_BAND
(A, B, C) R(A) = R(B) & R/K(C)
@ REDUCT_OPCODE_RET
(C) Return value in R/K(C).
@ REDUCT_OPCODE_BNOT
(A, C) R(A) = ~R/K(C)
@ REDUCT_OPCODE_EQ
(A, B, C) If R(B) == R/K(C) store true in R(A), else false.
@ REDUCT_OPCODE_CALL
(A, B, C) Call callable in R/K(C) with B args starting from R(A). Result in R(A).
@ REDUCT_OPCODE_GT
(A, B, C) If R(B) > R/K(C) store true in R(A), else false.
@ REDUCT_OPCODE_JMP
(sBx) Unconditional jump by relative offset sBx.
@ REDUCT_OPCODE_SNEQ
(A, B, C) If R(B) !== R/K(C) store true in R(A), else false.
@ REDUCT_OPCODE_GE
(A, B, C) If R(B) >= R/K(C) store true in R(A), else false.
@ REDUCT_OPCODE_BOR
(A, B, C) R(A) = R(B) | R/K(C)
@ REDUCT_OPCODE_CLOSURE
(A, C) Wrap the function prototype in K(C) in a closure and store in R(A).
@ REDUCT_OPCODE_LE
(A, B, C) If R(B) <= R/K(C) store true in R(A), else false.
@ REDUCT_OPCODE_LIST
(A) Create a new list and store it in R(A).
@ REDUCT_OPCODE_TAILCALL
(A, B, C) Tail call callable in R/K(C) with B args starting from R(A).
@ REDUCT_OPCODE_BXOR
(A, B, C) R(A) = R(B) ^ R/K(C)
@ REDUCT_OPCODE_CAPTURE
(A, B, C) Capture R/K(C) into constant slot B in closure R(A).
@ REDUCT_OPCODE_MOD
(A, B, C) R(A) = R(B) % R/K(C)
@ REDUCT_OPCODE_LT
(A, B, C) If R(B) < R/K(C) store true in R(A), else false.
#define REDUCT_ITEM_TYPE_LIST
A list.
#define REDUCT_ITEM_TYPE_ATOM
An atom.
#define REDUCT_ITEM_TYPE_FUNCTION
A function.
reduct_uint32_t length
The length of the string (must be first, check the reduct_item_t structure).
char * string
Pointer to the string.
reduct_const_slot_type_t type
The type of the constant slot.
struct reduct_item * item
The item contained in the constant slot.
struct reduct_atom * capture
The name of the variable to be captured.
Compiled function structure.
reduct_inst_t * insts
An array of instructions.
reduct_const_slot_t * constants
The array of constant slots forming the constant template.
reduct_uint32_t instCount
Number of instructions.
reduct_uint16_t constantCount
Number of constants.
reduct_uint8_t arity
The number of arguments the function expects.
reduct_list_t list
A list.
reduct_function_t function
A function.
reduct_atom_t atom
An atom.
reduct_item_type_t type
The type of the item.
reduct_uint32_t length
Total number of elements.