From 50c928d224bff0af322f23a7d2b842cd54aa2e68 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 18 Jan 2020 10:01:27 +0100 Subject: Start on bytecode, move object files to build directory --- include/bytecode.h | 40 ++++++++++++++++++++++++++++++++++++++++ include/std/buffer.h | 21 +++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 include/bytecode.h create mode 100644 include/std/buffer.h (limited to 'include') diff --git a/include/bytecode.h b/include/bytecode.h new file mode 100644 index 0000000..4a14b8d --- /dev/null +++ b/include/bytecode.h @@ -0,0 +1,40 @@ +#ifndef TSL_BYTECODE_H +#define TSL_BYTECODE_H + +#include "std/buffer.h" +#include + +/* + All instructions are 4 bytes in size. +*/ + +typedef uint8_t TslOpcodeType; +typedef uint8_t TslRegister; +typedef uint16_t TslValueIndex; + +typedef enum { + TSL_OPCODE_ASSIGN +} TslOpcode; + +typedef struct { + TslBuffer buffer; +} TslBytecodeWriter; + +typedef struct { + TslOpcodeType opcode; + union { + TslRegister dst_reg; + TslRegister src_reg; + } type1; + union { + TslRegister dst_reg; + TslValueIndex value_index; + } type2; +} TslInstruction; + +void tsl_bytecode_writer_init(TslBytecodeWriter *self); +void tsl_bytecode_writer_deinit(TslBytecodeWriter *self); + +int tsl_bytecode_writer_assign(TslBytecodeWriter *self, TslRegister reg, double value); + +#endif /* TSL_BYTECODE_H */ diff --git a/include/std/buffer.h b/include/std/buffer.h new file mode 100644 index 0000000..dea7dbd --- /dev/null +++ b/include/std/buffer.h @@ -0,0 +1,21 @@ +#ifndef TSL_BUFFER_H +#define TSL_BUFFER_H + +#include + +/* + TODO: Optimize small size buffers by using data and size members (16 bytes on x86) + instead of heap allocation +*/ +typedef struct { + void *data; + size_t size; + size_t capacity; +} TslBuffer; + +void tsl_buffer_init(TslBuffer *self); +void tsl_buffer_deinit(TslBuffer *self); + +int tsl_buffer_append(TslBuffer *self, void *data, size_t size); + +#endif /* TSL_BUFFER_H */ -- cgit v1.2.3