mie: add value type hierarchy definitions
every construct within Mie, such as constants, instructions, functions, and translation units, are sub-types of the generic mie_value struct. mie_value will facilitate iterating through the IR, as well as converting the IR to/from different formats.
This commit is contained in:
15
mie/CMakeLists.txt
Normal file
15
mie/CMakeLists.txt
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
file(GLOB_RECURSE mie_sources *.c *.h include/mie/*.h)
|
||||||
|
|
||||||
|
if (WIN32)
|
||||||
|
set(rc_file ${CMAKE_CURRENT_SOURCE_DIR}/../res/win32/mie.rc)
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
if (IVY_STATIC)
|
||||||
|
add_library(mie STATIC ${mie_sources} ${rc_file})
|
||||||
|
else ()
|
||||||
|
add_library(mie SHARED ${mie_sources} ${rc_file})
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
target_include_directories(mie PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include/)
|
||||||
|
target_link_libraries(mie Bluelib::Core Bluelib::Object)
|
||||||
|
target_compile_definitions(mie PRIVATE MIE_EXPORT=1 MIE_STATIC=${IVY_STATIC})
|
||||||
10
mie/include/mie/block.h
Normal file
10
mie/include/mie/block.h
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
#ifndef MIE_BLOCK_H_
|
||||||
|
#define MIE_BLOCK_H_
|
||||||
|
|
||||||
|
#include <mie/value.h>
|
||||||
|
|
||||||
|
struct mie_block {
|
||||||
|
struct mie_value b_base;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
28
mie/include/mie/const.h
Normal file
28
mie/include/mie/const.h
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
#ifndef MIE_CONST_H_
|
||||||
|
#define MIE_CONST_H_
|
||||||
|
|
||||||
|
#include <mie/value.h>
|
||||||
|
|
||||||
|
enum mie_const_type {
|
||||||
|
MIE_CONST_NONE = 0,
|
||||||
|
MIE_CONST_INT,
|
||||||
|
MIE_CONST_FLOAT,
|
||||||
|
MIE_CONST_STRING,
|
||||||
|
MIE_CONST_SYMBOL,
|
||||||
|
MIE_CONST_LABEL,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct mie_const {
|
||||||
|
struct mie_value c_base;
|
||||||
|
enum mie_const_type c_type;
|
||||||
|
|
||||||
|
union {
|
||||||
|
int v_int;
|
||||||
|
float v_float;
|
||||||
|
char *v_str;
|
||||||
|
char *v_sym;
|
||||||
|
char *v_label;
|
||||||
|
} c_v;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
17
mie/include/mie/instr.h
Normal file
17
mie/include/mie/instr.h
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
#ifndef MIE_INSTR_H_
|
||||||
|
#define MIE_INSTR_H_
|
||||||
|
|
||||||
|
#include <mie/value.h>
|
||||||
|
|
||||||
|
enum mie_instr_type {
|
||||||
|
MIE_INSTR_NONE = 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct mie_instr {
|
||||||
|
struct mie_value i_base;
|
||||||
|
enum mie_instr_type i_type;
|
||||||
|
|
||||||
|
b_queue i_operands;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
17
mie/include/mie/misc.h
Normal file
17
mie/include/mie/misc.h
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
#ifndef MIE_MISC_H_
|
||||||
|
#define MIE_MISC_H_
|
||||||
|
|
||||||
|
#if defined(_MSC_VER) && MIE_STATIC == 0
|
||||||
|
#ifdef MIE_EXPORT
|
||||||
|
#define MIE_API extern __declspec(dllexport)
|
||||||
|
#else
|
||||||
|
#define MIE_API extern __declspec(dllimport)
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#define MIE_API extern
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define MIN(x, y) ((x) < (y) ? (x) : (y))
|
||||||
|
#define MAX(x, y) ((x) > (y) ? (x) : (y))
|
||||||
|
|
||||||
|
#endif
|
||||||
12
mie/include/mie/record.h
Normal file
12
mie/include/mie/record.h
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
#ifndef MIE_RECORD_H_
|
||||||
|
#define MIE_RECORD_H_
|
||||||
|
|
||||||
|
#include <mie/const.h>
|
||||||
|
#include <mie/value.h>
|
||||||
|
|
||||||
|
struct mie_record {
|
||||||
|
struct mie_value r_base;
|
||||||
|
struct mie_const *r_value;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
12
mie/include/mie/unit.h
Normal file
12
mie/include/mie/unit.h
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
#ifndef MIE_UNIT_H_
|
||||||
|
#define MIE_UNIT_H_
|
||||||
|
|
||||||
|
#include <blue/core/queue.h>
|
||||||
|
#include <mie/value.h>
|
||||||
|
|
||||||
|
struct mie_unit {
|
||||||
|
struct mie_value u_base;
|
||||||
|
b_queue u_children;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
27
mie/include/mie/value.h
Normal file
27
mie/include/mie/value.h
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
#ifndef MIE_VALUE_H_
|
||||||
|
#define MIE_VALUE_H_
|
||||||
|
|
||||||
|
#include <blue/core/queue.h>
|
||||||
|
#include <mie/misc.h>
|
||||||
|
|
||||||
|
enum mie_value_type {
|
||||||
|
MIE_VALUE_NONE = 0,
|
||||||
|
MIE_VALUE_CONST,
|
||||||
|
MIE_VALUE_ARG,
|
||||||
|
MIE_VALUE_BLOCK,
|
||||||
|
MIE_VALUE_INSTR,
|
||||||
|
MIE_VALUE_OP,
|
||||||
|
MIE_VALUE_RECORD,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct mie_value {
|
||||||
|
unsigned int v_ref;
|
||||||
|
char *v_name;
|
||||||
|
enum mie_value_type v_type;
|
||||||
|
b_queue_entry v_entry;
|
||||||
|
};
|
||||||
|
|
||||||
|
MIE_API struct mie_value *mie_value_retain(struct mie_value *val);
|
||||||
|
MIE_API void mie_value_release(struct mie_value *val);
|
||||||
|
|
||||||
|
#endif
|
||||||
1
mie/value.c
Normal file
1
mie/value.c
Normal file
@@ -0,0 +1 @@
|
|||||||
|
#include <mie/value.h>
|
||||||
Reference in New Issue
Block a user