Divise le classi, boilerplate
This commit is contained in:
parent
16d57bf64b
commit
bea0edfd10
@ -1,5 +1,6 @@
|
||||
#ifndef DBG_H
|
||||
#define DBG_H
|
||||
#include <stdio.h>
|
||||
|
||||
#if DBG
|
||||
#define DBG_INFO(_x_) \
|
||||
|
@ -1,19 +1,19 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <fstream>
|
||||
#include "instructions.h"
|
||||
#include "vm.h"
|
||||
#include "debug.h"
|
||||
#include "vm.h"
|
||||
#include <fstream>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
ifstream vmbytecode;
|
||||
VM * vm;
|
||||
VM vm;
|
||||
uint8_t *data;
|
||||
|
||||
|
||||
vm.status();
|
||||
// vm.status();
|
||||
/*
|
||||
if (vmbytecode != NULL) {
|
||||
fread()
|
||||
|
@ -1,41 +0,0 @@
|
||||
#include "vm.h"
|
||||
#ifndef INS_H
|
||||
#define INS_H
|
||||
enum regs {
|
||||
R0,
|
||||
R1,
|
||||
R2,
|
||||
R3,
|
||||
S0,
|
||||
S1,
|
||||
S2,
|
||||
S3,
|
||||
IP,
|
||||
BP,
|
||||
SP
|
||||
};
|
||||
|
||||
enum ins {
|
||||
MOVI,
|
||||
MOVR,
|
||||
MOVM,
|
||||
ADDI,
|
||||
ADDR,
|
||||
ADDM,
|
||||
SUBI,
|
||||
SUBR,
|
||||
SUBM,
|
||||
XORI,
|
||||
XORR,
|
||||
XORM,
|
||||
MULI,
|
||||
MULR,
|
||||
MULM,
|
||||
DIVI,
|
||||
DIVR,
|
||||
DIVM,
|
||||
HALT,
|
||||
NOPE
|
||||
};
|
||||
|
||||
#endif
|
66
cpp/vm.cpp
66
cpp/vm.cpp
@ -1,15 +1,71 @@
|
||||
#include "vm.hh"
|
||||
#include "vm.h"
|
||||
#include "debug.h"
|
||||
#include "vmas.h"
|
||||
#include <string.h>
|
||||
|
||||
void VM::VM(void) {
|
||||
VM::VM() {
|
||||
DBG_INFO(("Creating VM without code.\n"));
|
||||
init_regs();
|
||||
}
|
||||
|
||||
void VM::VM(uint8_t * code, uint32_t codesize) {
|
||||
VM::VM(uint8_t *code, uint32_t codesize) {
|
||||
DBG_INFO(("Creating VM with code.\n"));
|
||||
memcpy(&vm.as.code, code, codesize);
|
||||
init_regs();
|
||||
as.insCode(code, codesize);
|
||||
}
|
||||
|
||||
void VM::run(uint8_t * code) {
|
||||
void VM::init_regs(void) {
|
||||
uint8_t i;
|
||||
|
||||
for (i = R0; i <= SP; i++) {
|
||||
this->regs[i] = 0;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void VM::status(void) {
|
||||
uint8_t i;
|
||||
DBG_INFO(("VM Status:\n"));
|
||||
DBG_INFO(("~~~~~~~~~~\n"));
|
||||
for (i = R0; i <= SP; i++) {
|
||||
switch (i) {
|
||||
case R0:
|
||||
DBG_INFO(("R0:\t0x%x\n", this->regs[i]));
|
||||
break;
|
||||
case R1:
|
||||
DBG_INFO(("R1:\t0x%x\n", this->regs[i]));
|
||||
break;
|
||||
case R2:
|
||||
DBG_INFO(("R2:\t0x%x\n", this->regs[i]));
|
||||
break;
|
||||
case R3:
|
||||
DBG_INFO(("R3:\t0x%x\n", this->regs[i]));
|
||||
break;
|
||||
case S0:
|
||||
DBG_INFO(("S0:\t0x%x\n", this->regs[i]));
|
||||
break;
|
||||
case S1:
|
||||
DBG_INFO(("S1:\t0x%x\n", this->regs[i]));
|
||||
break;
|
||||
case S2:
|
||||
DBG_INFO(("S2:\t0x%x\n", this->regs[i]));
|
||||
break;
|
||||
case S3:
|
||||
DBG_INFO(("S3:\t0x%x\n", this->regs[i]));
|
||||
break;
|
||||
case IP:
|
||||
DBG_INFO(("IP:\t0x%x\n", this->regs[i]));
|
||||
break;
|
||||
case BP:
|
||||
DBG_INFO(("BP:\t0x%x\n", this->regs[i]));
|
||||
break;
|
||||
case SP:
|
||||
DBG_INFO(("SP:\t0x%x\n", this->regs[i]));
|
||||
break;
|
||||
}
|
||||
}
|
||||
DBG_INFO(("~~~~~~~~~~\n"));
|
||||
return;
|
||||
}
|
||||
|
||||
void VM::run(uint8_t *code) { return; }
|
37
cpp/vm.h
37
cpp/vm.h
@ -1,8 +1,37 @@
|
||||
#ifndef VM_H
|
||||
#define VM_H
|
||||
#include <stdint.h>
|
||||
#include "vmas.h"
|
||||
|
||||
class VMAddrSpace {
|
||||
uint8_t stack[0x100], code[0x300], data[0x500];
|
||||
enum regs { R0, R1, R2, R3, S0, S1, S2, S3, IP, BP, SP };
|
||||
|
||||
enum ins {
|
||||
MOVI,
|
||||
MOVR,
|
||||
MOVM,
|
||||
ADDI,
|
||||
ADDR,
|
||||
ADDM,
|
||||
SUBI,
|
||||
SUBR,
|
||||
SUBM,
|
||||
XORI,
|
||||
XORR,
|
||||
XORM,
|
||||
NOTI,
|
||||
NOTR,
|
||||
NOTM,
|
||||
MULI,
|
||||
MULR,
|
||||
MULM,
|
||||
DIVI,
|
||||
DIVR,
|
||||
DIVM,
|
||||
PUSH,
|
||||
POOP,
|
||||
CALL,
|
||||
HALT,
|
||||
NOPE
|
||||
};
|
||||
|
||||
class VM {
|
||||
@ -14,6 +43,10 @@ class VM {
|
||||
VMAddrSpace as;
|
||||
|
||||
public:
|
||||
VM();
|
||||
VM(uint8_t *code, uint32_t codesize);
|
||||
void init_regs(void);
|
||||
void status(void);
|
||||
void run(uint8_t *code);
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user