cdump.c: fix instruction and line info dumping

This commit is contained in:
CPunch 2023-05-27 23:15:12 -05:00 committed by cpunch
parent 395f352c6e
commit 8efecf71a4
2 changed files with 6 additions and 7 deletions

View File

@ -3,6 +3,7 @@
#include "cmem.h" #include "cmem.h"
#include "cobj.h" #include "cobj.h"
#include "cvalue.h" #include "cvalue.h"
#include "cdebug.h"
typedef struct typedef struct
{ {
@ -45,10 +46,10 @@ static void writeSize(DumpState *dstate, size_t d)
writeBlock(dstate, &d, sizeof(size_t)); writeBlock(dstate, &d, sizeof(size_t));
} }
static void writeVector(DumpState *dstate, const void *data, size_t size) static void writeVector(DumpState *dstate, const void *data, size_t size, size_t count)
{ {
writeSize(dstate, size); writeSize(dstate, count);
writeBlock(dstate, data, size); writeBlock(dstate, data, size * count);
} }
static void writeHeader(DumpState *dstate) static void writeHeader(DumpState *dstate)
@ -86,10 +87,10 @@ static void writeCObjFunction(DumpState *dstate, CObjFunction *obj)
writeu8(dstate, obj->variadic); writeu8(dstate, obj->variadic);
/* write chunk info */ /* write chunk info */
writeVector(dstate, obj->chunk.buf, sizeof(uint8_t) * obj->chunk.count); writeVector(dstate, obj->chunk.buf, sizeof(uint8_t), obj->chunk.count);
/* write line info */ /* write line info */
writeVector(dstate, obj->chunk.lineInfo, sizeof(int) * obj->chunk.count); writeVector(dstate, obj->chunk.lineInfo, sizeof(int), obj->chunk.count);
/* write constants */ /* write constants */
writeSize(dstate, obj->chunk.constants.count); writeSize(dstate, obj->chunk.constants.count);

View File

@ -9,8 +9,6 @@
#define COSMO_MAGIC "COS\x12" #define COSMO_MAGIC "COS\x12"
#define COSMO_MAGIC_LEN 4 #define COSMO_MAGIC_LEN 4
typedef int (*cosmo_Writer)(CState *state, const void *data, size_t size, const void *ud);
bool cosmoD_isBigEndian(); bool cosmoD_isBigEndian();
/* returns non-zero on error */ /* returns non-zero on error */