registers.h

This commit is contained in:
Timerix 2025-02-04 10:45:37 +05:00
parent 51ef24bb53
commit fe6d690251
6 changed files with 31 additions and 24 deletions

View File

@ -20,18 +20,6 @@ str ArgumentType_toString(ArgumentType t){
return _ArgumentType_str[t]; return _ArgumentType_str[t];
} }
RegisterCode RegisterCode_parse(str r){
if(str_equals(r, STR("ax")))
return RegisterCode_ax;
if(str_equals(r, STR("bx")))
return RegisterCode_bx;
if(str_equals(r, STR("cx")))
return RegisterCode_cx;
if(str_equals(r, STR("dx")))
return RegisterCode_dx;
return RegisterCode_Unset;
}
void Section_init(Section* sec, str name){ void Section_init(Section* sec, str name){
sec->name = name; sec->name = name;

View File

@ -2,6 +2,7 @@
#include "../std.h" #include "../std.h"
#include "../string/str.h" #include "../string/str.h"
#include "../instructions/instructions.h" #include "../instructions/instructions.h"
#include "../instructions/registers.h"
#include "../collections/List.h" #include "../collections/List.h"
typedef enum ArgumentType { typedef enum ArgumentType {
@ -15,16 +16,6 @@ typedef enum ArgumentType {
str ArgumentType_toString(ArgumentType t); str ArgumentType_toString(ArgumentType t);
typedef enum RegisterCode {
RegisterCode_Unset,
RegisterCode_ax,
RegisterCode_bx,
RegisterCode_cx,
RegisterCode_dx
} RegisterCode;
RegisterCode RegisterCode_parse(str register_name);
typedef struct Argument { typedef struct Argument {
ArgumentType type; ArgumentType type;
union { union {

View File

@ -1,5 +1,6 @@
#pragma once #pragma once
#include "../instructions.h" #include "../instructions.h"
#include "../registers.h"
#define readVar(VAR) {\ #define readVar(VAR) {\
if(!VM_dataRead(vm, &VAR, vm->current_pos, sizeof(VAR))) \ if(!VM_dataRead(vm, &VAR, vm->current_pos, sizeof(VAR))) \
@ -16,6 +17,7 @@
#define readRegisterVar(VAR) {\ #define readRegisterVar(VAR) {\
readVar(VAR);\ readVar(VAR);\
VAR -= 1;\
validateRegisterIndex(VAR);\ validateRegisterIndex(VAR);\
} }

View File

@ -0,0 +1,13 @@
#include "registers.h"
RegisterCode RegisterCode_parse(str r){
if(str_equals(r, STR("ax")))
return RegisterCode_ax;
if(str_equals(r, STR("bx")))
return RegisterCode_bx;
if(str_equals(r, STR("cx")))
return RegisterCode_cx;
if(str_equals(r, STR("dx")))
return RegisterCode_dx;
return RegisterCode_Unset;
}

View File

@ -0,0 +1,13 @@
#pragma once
#include "../std.h"
#include "../string/str.h"
typedef enum RegisterCode {
RegisterCode_Unset,
RegisterCode_ax,
RegisterCode_bx,
RegisterCode_cx,
RegisterCode_dx
} RegisterCode;
RegisterCode RegisterCode_parse(str register_name);