finished compiler output format dvander
authorDavid Anderson <dvander@alliedmods.net>
Sat Jul 15 03:05:56 2006 +0000 (2006-07-15)
branchdvander
changeset 19ead9b78fa747
parent 18 2df1cff112d4
child 20 acfbfd258f7c
finished compiler output format
compiler-init/pawncc.c
compiler-init/sp_file.h
     1.1 --- a/compiler-init/pawncc.c	Sat Jul 15 01:39:33 2006 +0000
     1.2 +++ b/compiler-init/pawncc.c	Sat Jul 15 03:05:56 2006 +0000
     1.3 @@ -89,7 +89,10 @@
     1.4  
     1.5  		lastsection = curoffs;
     1.6  
     1.7 -		/** write the code table */
     1.8 +		/** 
     1.9 +		 * Begin writing each of our known tables out
    1.10 +		 */
    1.11 +		
    1.12  		if (strcmp(tables[0], ".code") == 0)
    1.13  		{
    1.14  			sp_file_code_t cod;
    1.15 @@ -109,6 +112,7 @@
    1.16  				cod.flags |= SP_FILE_DEBUG;
    1.17  			}
    1.18  			cod.code = sizeof(cod);
    1.19 +			cod.main = hdr->cip;
    1.20  
    1.21  			/* write the code in our newer format */
    1.22  			cbase = (unsigned char *)hdr + hdr->cod;
    1.23 @@ -308,7 +312,6 @@
    1.24  				case OP_CASETBL:
    1.25  					{
    1.26  						cell num;
    1.27 -						int i;
    1.28  						DBGPARAM(*(cell *)tptr);
    1.29  						num = *(cell *)tptr;
    1.30  						tptr += sizeof(cell);
    1.31 @@ -332,9 +335,9 @@
    1.32  			/* backtrack and write this section's header info */
    1.33  			curoffs = (uint32_t)ftell(fp);
    1.34  			fseek(fp, offsets[0], SEEK_SET);
    1.35 -			sfwrite(&lastsection, sizeof(lastsection), 1, fp);
    1.36 +			sfwrite(&lastsection, sizeof(uint32_t), 1, fp);
    1.37  			cod.codesize += sizeof(cod);
    1.38 -			sfwrite(&cod.codesize, sizeof(cod.codesize), 1, fp);
    1.39 +			sfwrite(&cod.codesize, sizeof(uint32_t), 1, fp);
    1.40  			fseek(fp, curoffs, SEEK_SET);
    1.41  			lastsection = curoffs;
    1.42  		}
    1.43 @@ -358,9 +361,127 @@
    1.44  			/* backtrack and write this section's header info */
    1.45  			curoffs = ftell(fp);
    1.46  			fseek(fp, offsets[1], SEEK_SET);
    1.47 -			sfwrite(&lastsection, sizeof(lastsection), 1, fp);
    1.48 +			sfwrite(&lastsection, sizeof(uint32_t), 1, fp);
    1.49  			dat.datasize += sizeof(dat);
    1.50 -			sfwrite(&dat.datasize, sizeof(dat.datasize),1, fp);
    1.51 +			sfwrite(&dat.datasize, sizeof(uint32_t),1, fp);
    1.52 +			fseek(fp, curoffs, SEEK_SET);
    1.53 +			lastsection = curoffs;
    1.54 +		}
    1.55 +
    1.56 +		if (strcmp(tables[2], ".publics") == 0)
    1.57 +		{
    1.58 +			sp_file_publics_t *pbtbl;
    1.59 +			AMX_FUNCSTUBNT *stub;
    1.60 +			uint32_t publics = (hdr->natives - hdr->publics) / hdr->defsize;
    1.61 +
    1.62 +			pbtbl = (sp_file_publics_t *)malloc(sizeof(sp_file_publics_t) * publics);
    1.63 +			stub = (AMX_FUNCSTUBNT *)((unsigned char *)hdr + hdr->publics);
    1.64 +
    1.65 +			for (i=0; i<publics; i++)
    1.66 +			{
    1.67 +				pbtbl[i].address = stub->address;
    1.68 +				pbtbl[i].name = stub->nameofs - (hdr->nametable + sizeof(uint16_t));
    1.69 +
    1.70 +				stub += hdr->defsize;
    1.71 +			}
    1.72 +			if (publics)
    1.73 +			{
    1.74 +				sfwrite(pbtbl, sizeof(sp_file_publics_t), publics, fp);
    1.75 +			}
    1.76 +			free(pbtbl);
    1.77 +
    1.78 +			/* backtrack and write section's header info */
    1.79 +			curoffs = ftell(fp);
    1.80 +			fseek(fp, offsets[2], SEEK_SET);
    1.81 +			sfwrite(&lastsection, sizeof(uint32_t), 1, fp);
    1.82 +			publics *= sizeof(sp_file_publics_t);
    1.83 +			sfwrite(&publics, sizeof(uint32_t), 1, fp);
    1.84 +			fseek(fp, curoffs, SEEK_SET);
    1.85 +			lastsection = curoffs;
    1.86 +		}
    1.87 +
    1.88 +		if (strcmp(tables[3], ".pubvars") == 0)
    1.89 +		{
    1.90 +			sp_file_pubvars_t *pbvars;
    1.91 +			AMX_FUNCSTUBNT *stub;
    1.92 +			uint32_t pubvars = (hdr->tags - hdr->pubvars) / hdr->defsize;
    1.93 +
    1.94 +			pbvars = (sp_file_pubvars_t *)malloc(sizeof(sp_file_pubvars_t) * pubvars);
    1.95 +			stub = (AMX_FUNCSTUBNT *)((unsigned char *)hdr + hdr->pubvars);
    1.96 +
    1.97 +			for (i=0; i<pubvars; i++)
    1.98 +			{
    1.99 +				pbvars[i].address = stub->address;
   1.100 +				pbvars[i].name = stub->nameofs - (hdr->nametable + sizeof(uint16_t));
   1.101 +
   1.102 +				stub += hdr->defsize;
   1.103 +			}
   1.104 +			if (pubvars)
   1.105 +			{
   1.106 +				sfwrite(pbvars, sizeof(sp_file_pubvars_t), pubvars, fp);
   1.107 +			}
   1.108 +			free(pbvars);
   1.109 +
   1.110 +			/* backtrack and write section's header info */
   1.111 +			curoffs = ftell(fp);
   1.112 +			fseek(fp, offsets[3], SEEK_SET);
   1.113 +			sfwrite(&lastsection, sizeof(uint32_t), 1, fp);
   1.114 +			pubvars *= sizeof(sp_file_pubvars_t);
   1.115 +			sfwrite(&pubvars, sizeof(uint32_t), 1, fp);
   1.116 +			fseek(fp, curoffs, SEEK_SET);
   1.117 +			lastsection = curoffs;
   1.118 +		}
   1.119 +
   1.120 +		if (strcmp(tables[4], ".natives") == 0)
   1.121 +		{
   1.122 +			sp_file_natives_t *nvtbl;
   1.123 +			AMX_FUNCSTUBNT *stub;
   1.124 +			uint32_t natives = (hdr->libraries - hdr->natives) / hdr->defsize;
   1.125 +
   1.126 +			nvtbl = (sp_file_natives_t *)malloc(sizeof(sp_file_natives_t) * natives);
   1.127 +			stub = (AMX_FUNCSTUBNT *)((unsigned char *)hdr + hdr->natives);
   1.128 +
   1.129 +			for (i=0; i<natives; i++)
   1.130 +			{
   1.131 +				nvtbl[i].name = stub->nameofs - (hdr->nametable + sizeof(uint16_t));
   1.132 +
   1.133 +				stub += hdr->defsize;
   1.134 +			}
   1.135 +			if (natives)
   1.136 +			{
   1.137 +				sfwrite(nvtbl, sizeof(sp_file_natives_t), natives, fp);
   1.138 +			}
   1.139 +			free(nvtbl);
   1.140 +
   1.141 +			/* backtrack and write header */
   1.142 +			curoffs = ftell(fp);
   1.143 +			fseek(fp, offsets[4], SEEK_SET);
   1.144 +			sfwrite(&lastsection, sizeof(uint32_t), 1, fp);
   1.145 +			natives *= sizeof(sp_file_natives_t);
   1.146 +			sfwrite(&natives, sizeof(uint32_t), 1, fp);
   1.147 +			fseek(fp, curoffs, SEEK_SET);
   1.148 +			lastsection = curoffs;
   1.149 +		}
   1.150 +
   1.151 +		if (strcmp(tables[5], ".names") == 0)
   1.152 +		{
   1.153 +			unsigned char *base;
   1.154 +			uint32_t namelen;
   1.155 +
   1.156 +			/* write the entire block */
   1.157 +			base = (unsigned char *)hdr + hdr->nametable + sizeof(uint16_t);
   1.158 +			/**
   1.159 +			 * note - the name table will be padded to sizeof(cell) bytes.
   1.160 +			 * this may clip at most an extra three bytes in!
   1.161 +			 */
   1.162 +			namelen = hdr->cod - hdr->nametable;
   1.163 +			sfwrite(base, namelen, 1, fp);
   1.164 +
   1.165 +			/* backtrack and write header */
   1.166 +			curoffs = ftell(fp);
   1.167 +			fseek(fp, offsets[5], SEEK_SET);
   1.168 +			sfwrite(&lastsection, sizeof(uint32_t), 1, fp);
   1.169 +			sfwrite(&namelen, sizeof(uint32_t), 1, fp);
   1.170  			fseek(fp, curoffs, SEEK_SET);
   1.171  			lastsection = curoffs;
   1.172  		}
     2.1 --- a/compiler-init/sp_file.h	Sat Jul 15 01:39:33 2006 +0000
     2.2 +++ b/compiler-init/sp_file.h	Sat Jul 15 03:05:56 2006 +0000
     2.3 @@ -58,6 +58,7 @@
     2.4  	uint8_t		cellsize;		/* cellsize in bytes */
     2.5  	uint8_t		codeversion;	/* version of opcodes supported */
     2.6  	uint16_t	flags;			/* flags */
     2.7 +	uint32_t	main;			/* address to "main" if any */
     2.8  	uint32_t	code;			/* rel offset to code */
     2.9  } sp_file_code_t;
    2.10