1
0
mirror of https://github.com/pevans/erc-c.git synced 2024-12-21 23:29:16 +00:00

Use the DI container to get machine/cpu/etc

This commit is contained in:
Peter Evans 2018-02-07 00:02:20 -06:00
parent c35a6cb827
commit 360e9243f8
2 changed files with 7 additions and 5 deletions

View File

@ -70,7 +70,7 @@ extern int vm_reflect_disasm_on(vm_reflect *);
extern int vm_reflect_machine_info(vm_reflect *); extern int vm_reflect_machine_info(vm_reflect *);
extern int vm_reflect_pause(vm_reflect *); extern int vm_reflect_pause(vm_reflect *);
extern int vm_reflect_resume(vm_reflect *); extern int vm_reflect_resume(vm_reflect *);
extern vm_reflect *vm_reflect_create(void *, void *, FILE *); extern vm_reflect *vm_reflect_create();
extern void vm_reflect_free(vm_reflect *); extern void vm_reflect_free(vm_reflect *);
#endif #endif

View File

@ -5,6 +5,7 @@
#include <stdlib.h> #include <stdlib.h>
#include "log.h" #include "log.h"
#include "vm_di.h"
#include "vm_reflect.h" #include "vm_reflect.h"
/* /*
@ -12,7 +13,7 @@
* stream. * stream.
*/ */
vm_reflect * vm_reflect *
vm_reflect_create(void *mach, void *cpu, FILE *stream) vm_reflect_create()
{ {
vm_reflect *ref; vm_reflect *ref;
@ -22,9 +23,9 @@ vm_reflect_create(void *mach, void *cpu, FILE *stream)
return NULL; return NULL;
} }
ref->machine = mach; ref->machine = vm_di_get(VM_MACHINE);
ref->cpu = cpu; ref->cpu = vm_di_get(VM_CPU);
ref->stream = stream; ref->stream = vm_di_get(VM_OUTPUT);
ref->cpu_info = NULL; ref->cpu_info = NULL;
ref->machine_info = NULL; ref->machine_info = NULL;
@ -52,6 +53,7 @@ vm_reflect_free(vm_reflect *ref)
*/ */
#define REFLECT_HANDLER(x) \ #define REFLECT_HANDLER(x) \
int vm_reflect_##x(vm_reflect *ref) { \ int vm_reflect_##x(vm_reflect *ref) { \
if (ref == NULL) ref = (vm_reflect *)vm_di_get(VM_REFLECT); \
if (ref->x == NULL) return ERR_INVALID; ref->x(ref); return OK; } if (ref->x == NULL) return ERR_INVALID; ref->x(ref); return OK; }
REFLECT_HANDLER(cpu_info); // ignore docblock REFLECT_HANDLER(cpu_info); // ignore docblock