aboutsummaryrefslogtreecommitdiff
path: root/tools/stack_machine_instruction.h
diff options
context:
space:
mode:
authorWojciech Kosior <kwojtus@protonmail.com>2020-10-03 21:45:24 +0200
committerWojciech Kosior <kwojtus@protonmail.com>2020-10-05 10:13:38 +0200
commit7a61f213fb9be8ab7f9bd0fb33940b21fa143b05 (patch)
tree1bd5beab68c778d4d3a2543cf3661bfcb23445c2 /tools/stack_machine_instruction.h
parentc548c0ce5b2e7ca2784257966ebdd386e1f31218 (diff)
downloadAGH-engineering-thesis-7a61f213fb9be8ab7f9bd0fb33940b21fa143b05.tar.gz
AGH-engineering-thesis-7a61f213fb9be8ab7f9bd0fb33940b21fa143b05.zip
fixes, conditional if-not jump and translation of if-else instruction from wasm
Diffstat (limited to 'tools/stack_machine_instruction.h')
-rw-r--r--tools/stack_machine_instruction.h69
1 files changed, 41 insertions, 28 deletions
diff --git a/tools/stack_machine_instruction.h b/tools/stack_machine_instruction.h
index 7b22c83..ea65334 100644
--- a/tools/stack_machine_instruction.h
+++ b/tools/stack_machine_instruction.h
@@ -1,5 +1,7 @@
#include <stdbool.h>
+#include "wasm_compile.h"
+
/*
* TODO: this enum is to be removed; it it only still here as a cheat sheet
* for use when defining missing inline functions for those instructions
@@ -43,7 +45,8 @@ enum instruction_code {
#define DATA_KNOWN 1
#define DATA_KNOWN_21_BITS 2
#define DATA_KNOWN_6_BITS 3
-#define DATA_UNKNOWN 4
+#define DATA_INSTR_ADDR 4
+#define DATA_ADDR_AFTER 5
struct instruction_data {
char info;
@@ -65,8 +68,6 @@ struct instruction {
.info = DATA_NONE \
})
-#define POW(n) (((int64_t) 1) << (n))
-
inline static uint8_t im_instruction_size(int32_t im)
{
if (im < POW(6) && im >= -POW(6))
@@ -98,7 +99,16 @@ inline static struct instruction_data im(uint32_t im)
inline static struct instruction_data ptr(struct instruction **val) {
struct instruction_data data;
- data.info = DATA_UNKNOWN;
+ data.info = DATA_INSTR_ADDR;
+ data.data.ptr = val;
+
+ return data;
+}
+
+inline static struct instruction_data ptr_after(struct instruction **val) {
+ struct instruction_data data;
+
+ data.info = DATA_ADDR_AFTER;
data.data.ptr = val;
return data;
@@ -122,30 +132,33 @@ int add_instruction(struct instruction **expr, uint16_t encoding,
return add_instruction(expr, encoding, NO_DATA); \
}
-X(store, 0x7E00) /* 0111_1110_0xxx_xxxx */
-X(store_p, 0x6E00) /* 0110_1110_0xxx_xxxx */
-X(storeb_p, 0x6C00) /* 0110_1100_0xxx_xxxx */
-X(storew_p, 0x6D00) /* 0110_1101_0xxx_xxxx */
-X(load, 0x5E00) /* 0101_1110_0xxx_xxxx */
-X(load_p, 0x4E00) /* 0100_1110_0xxx_xxxx */
-X(loadbzx_p, 0x4C00) /* 0100_1100_0xxx_xxxx */
-X(loadbsx_p, 0x4C80) /* 0100_1100_1xxx_xxxx */
-X(loadwzx_p, 0x4D00) /* 0100_1101_0xxx_xxxx */
-X(loadwsx_p, 0x4D80) /* 0100_1101_1xxx_xxxx */
-Y(swap, 0x0002) /* 0000_0000_0000_0010 */
-X(set_sp, 0x4000) /* 0100_0000_0xxx_xxxx */
-X(jump, 0x4080) /* 0100_0000_1xxx_xxxx */
-Y(tee, 0x1000) /* 0001_0000_0000_0000 */
-Y(get_frame, 0x1001) /* 0001_0000_0000_0001 */
-X(const, 0x5000) /* 0101_0000_0xxx_xxxx */
-X(call, 0x5080) /* 0101_0000_1xxx_xxxx */
-Y(add, 0x3000) /* 0011_0000_0000_0000 */
-Y(sub, 0x3001) /* 0011_0000_0000_0001 */
-Y(div, 0x3002) /* 0011_0000_0000_0010 */
-Y(mul, 0x3003) /* 0011_0000_0000_0011 */
-Y(drop, 0x3004) /* 0011_0000_0000_0100 */
-Y(ret, 0x3080) /* 0011_0000_1000_0000 */
-Y(halt, 0x0000) /* 0000_0000_0000_0000 */
+X(store, 0x7E00) /* 0111_1110_0xxx_xxxx */
+X(store_p, 0x6E00) /* 0110_1110_0xxx_xxxx */
+X(storeb_p, 0x6C00) /* 0110_1100_0xxx_xxxx */
+X(storew_p, 0x6D00) /* 0110_1101_0xxx_xxxx */
+X(load, 0x5E00) /* 0101_1110_0xxx_xxxx */
+X(load_p, 0x4E00) /* 0100_1110_0xxx_xxxx */
+X(loadbzx_p, 0x4C00) /* 0100_1100_0xxx_xxxx */
+X(loadbsx_p, 0x4C80) /* 0100_1100_1xxx_xxxx */
+X(loadwzx_p, 0x4D00) /* 0100_1101_0xxx_xxxx */
+X(loadwsx_p, 0x4D80) /* 0100_1101_1xxx_xxxx */
+Y(nop, 0x0001) /* 0000_0000_0000_0001 */
+Y(swap, 0x0002) /* 0000_0000_0000_0010 */
+X(set_sp, 0x4000) /* 0100_0000_0xxx_xxxx */
+X(jump, 0x4080) /* 0100_0000_1xxx_xxxx */
+Y(tee, 0x1000) /* 0001_0000_0000_0000 */
+Y(get_frame, 0x1001) /* 0001_0000_0000_0001 */
+X(const, 0x5000) /* 0101_0000_0xxx_xxxx */
+X(call, 0x5080) /* 0101_0000_1xxx_xxxx */
+Y(add, 0x3000) /* 0011_0000_0000_0000 */
+Y(sub, 0x3001) /* 0011_0000_0000_0001 */
+Y(div, 0x3002) /* 0011_0000_0000_0010 */
+Y(mul, 0x3003) /* 0011_0000_0000_0011 */
+Y(drop, 0x3004) /* 0011_0000_0000_0100 */
+Y(ret, 0x3080) /* 0011_0000_1000_0000 */
+X(cond_jump, 0x7080) /* 0111_0000_1xxx_xxxx */
+X(cond_jump_n, 0x7100) /* 0111_0001_0xxx_xxxx */
+Y(halt, 0x0000) /* 0000_0000_0000_0000 */
#undef X
#undef Y