浏览代码

bytecode v5 reader ok

Nicolas Cannasse 6 年之前
父节点
当前提交
e00856c5b5
共有 4 个文件被更改,包括 24 次插入5 次删除
  1. 15 2
      src/code.c
  2. 1 1
      src/hl.h
  3. 3 0
      src/hlmodule.h
  4. 5 2
      src/jit.c

+ 15 - 2
src/code.c

@@ -426,6 +426,7 @@ hl_code *hl_code_read( const unsigned char *data, int size ) {
 	hl_alloc alloc;
 	hl_alloc alloc;
 	int i;
 	int i;
 	int flags;
 	int flags;
+	int max_version = 5;
 	hl_alloc_init(&alloc);
 	hl_alloc_init(&alloc);
 	c = hl_zalloc(&alloc,sizeof(hl_code));
 	c = hl_zalloc(&alloc,sizeof(hl_code));
 	c->alloc = alloc;
 	c->alloc = alloc;
@@ -434,14 +435,16 @@ hl_code *hl_code_read( const unsigned char *data, int size ) {
 		EXIT("Invalid header");
 		EXIT("Invalid header");
 	r->code = c;
 	r->code = c;
 	c->version = READ();
 	c->version = READ();
-	if( c->version <= 1 || c->version > 4 ) {
-		printf("VER=%d\n",c->version);
+	if( c->version <= 1 || c->version > max_version ) {
+		printf("Found version %d while HL %d.%d supports up to %d\n",c->version,HL_VERSION>>8,(HL_VERSION>>4)&15,max_version);
 		EXIT("Unsupported bytecode version");
 		EXIT("Unsupported bytecode version");
 	}
 	}
 	flags = UINDEX();
 	flags = UINDEX();
 	c->nints = UINDEX();
 	c->nints = UINDEX();
 	c->nfloats = UINDEX();
 	c->nfloats = UINDEX();
 	c->nstrings = UINDEX();
 	c->nstrings = UINDEX();
+	if( c->version >= 5 ) 
+		c->nbytes = UINDEX();
 	c->ntypes = UINDEX();
 	c->ntypes = UINDEX();
 	c->nglobals = UINDEX();
 	c->nglobals = UINDEX();
 	c->nnatives = UINDEX();
 	c->nnatives = UINDEX();
@@ -461,6 +464,16 @@ hl_code *hl_code_read( const unsigned char *data, int size ) {
 	c->strings = hl_read_strings(r, c->nstrings, &c->strings_lens);
 	c->strings = hl_read_strings(r, c->nstrings, &c->strings_lens);
 	ALLOC(c->ustrings,uchar*,c->nstrings);
 	ALLOC(c->ustrings,uchar*,c->nstrings);
 	CHK_ERROR();
 	CHK_ERROR();
+	if( c->version >= 5 ) {
+		int size = hl_read_i32(r);
+		c->bytes = hl_malloc(&c->alloc,size);
+		hl_read_bytes(r,c->bytes,size);
+		ALLOC(c->bytes_pos,int,c->nbytes);
+		CHK_ERROR();
+		for(i=0;i<c->nbytes;i++)
+			c->bytes_pos[i] = UINDEX();
+		CHK_ERROR();
+	}
 	if( c->hasdebug ) {
 	if( c->hasdebug ) {
 		c->ndebugfiles = UINDEX();
 		c->ndebugfiles = UINDEX();
 		c->debugfiles = hl_read_strings(r, c->ndebugfiles, &c->debugfiles_lens);
 		c->debugfiles = hl_read_strings(r, c->ndebugfiles, &c->debugfiles_lens);

+ 1 - 1
src/hl.h

@@ -27,7 +27,7 @@
 	https://github.com/HaxeFoundation/hashlink/wiki/
 	https://github.com/HaxeFoundation/hashlink/wiki/
 **/
 **/
 
 
-#define HL_VERSION	0x180
+#define HL_VERSION	0x190
 
 
 #if defined(_WIN32)
 #if defined(_WIN32)
 #	define HL_WIN
 #	define HL_WIN

+ 3 - 0
src/hlmodule.h

@@ -61,6 +61,7 @@ typedef struct {
 	int nints;
 	int nints;
 	int nfloats;
 	int nfloats;
 	int nstrings;
 	int nstrings;
+	int nbytes;
 	int ntypes;
 	int ntypes;
 	int nglobals;
 	int nglobals;
 	int nnatives;
 	int nnatives;
@@ -73,6 +74,8 @@ typedef struct {
 	double*		floats;
 	double*		floats;
 	char**		strings;
 	char**		strings;
 	int*		strings_lens;
 	int*		strings_lens;
+	char*		bytes;
+	int*		bytes_pos;
 	char**		debugfiles;
 	char**		debugfiles;
 	int*		debugfiles_lens;
 	int*		debugfiles_lens;
 	uchar**		ustrings;
 	uchar**		ustrings;

+ 5 - 2
src/jit.c

@@ -3088,8 +3088,11 @@ int hl_jit_function( jit_ctx *ctx, hl_module *m, hl_function *f ) {
 			store(ctx,dst,dst->current,false);
 			store(ctx,dst,dst->current,false);
 			break;
 			break;
 		case OBytes:
 		case OBytes:
-			op64(ctx,MOV,alloc_cpu(ctx,dst,false),pconst64(&p,(int_val)m->code->strings[o->p2]));
-			store(ctx,dst,dst->current,false);
+			{
+				char *b = m->code->version >= 5 ? m->code->bytes + m->code->bytes_pos[o->p2] : m->code->strings[o->p2];
+				op64(ctx,MOV,alloc_cpu(ctx,dst,false),pconst64(&p,(int_val)b));
+				store(ctx,dst,dst->current,false);
+			}
 			break;
 			break;
 		case ONull:
 		case ONull:
 			{
 			{