summaryrefslogtreecommitdiff
path: root/bfcomp.c
diff options
context:
space:
mode:
Diffstat (limited to 'bfcomp.c')
-rw-r--r--bfcomp.c36
1 files changed, 28 insertions, 8 deletions
diff --git a/bfcomp.c b/bfcomp.c
index fa52087..4039856 100644
--- a/bfcomp.c
+++ b/bfcomp.c
@@ -45,7 +45,7 @@ void usage(const char *argv0){
"Uses nasm for assembling and gcc for linking.\n"
" -d Copies generated assembly to <srcfile>.asm\n"
" -h Show help\n"
- " -H Calculate heatmap while executing\n"
+ " -H <HMfname> Calculate heatmap while executing, writing data to <HMfname>\n"
" -L Output last cell reached\n"
" -m <memsize> Specify amount of tape cells (bytes) for the BF code\n"
" -v Show more info about the compile process\n",
@@ -60,9 +60,10 @@ __attribute__((noreturn)) void usage1(const char *argv0){
typedef struct Params{
int memsize;
const char *srcfname,*dstfname;
- bool lastcell,verbose,heatmap,copyasm;
+ bool lastcell,verbose,copyasm;
+ const char *heatmapfname;
} Params;
-Params params={30000,NULL,NULL,false,false,false,false};
+Params params={30000,NULL,NULL,false,false,false,NULL};
void parseargs(int argc,char **argv){
if(argc<2)usage1(argv[0]);
@@ -81,7 +82,9 @@ void parseargs(int argc,char **argv){
exit(0);
case 'H':
- params.heatmap=true;
+ if(i==argc-1)usage1(argv[0]);
+ params.heatmapfname=argv[i+1];
+ skipnext=true;
break;
case 'L':
@@ -195,12 +198,29 @@ int compilechain(const char *asmfname,const char *dstfname){
return ret;
}
+char hexdigit(int n){
+ if(n<0)return '?';
+ else if(n<10)return n+'0';
+ else if(n<16)return n-10+'a';
+ else return '?';
+}
+
void writesettings(FILE *asmf,Sourcemap *sm){
fprintf(asmf,"%%define PARAMS_MEMSIZE %d\n",params.memsize);
if(params.lastcell)fprintf(asmf,"%%define OUTPUT_LAST_CELL\n");
- if(params.heatmap){
+ if(params.heatmapfname){
assert(sm);
- fprintf(asmf,"%%define HEATMAP\n");
+ char buf[5*(strlen(params.heatmapfname)+1)];
+ int i;
+ for(i=0;i==0||params.heatmapfname[i-1];i++){
+ buf[5*i+0]='0';
+ buf[5*i+1]='x';
+ buf[5*i+2]=hexdigit(params.heatmapfname[i]/16);
+ buf[5*i+3]=hexdigit(params.heatmapfname[i]%16);
+ buf[5*i+4]=',';
+ }
+ buf[5*(i-1)+4]='\0';
+ fprintf(asmf,"%%define HEATMAPFNAME %s\n",buf);
fprintf(asmf,"%%define SOURCE_LENGTH %d\n",sm->origlen);
}
fputc('\n',asmf);
@@ -413,13 +433,13 @@ int main(int argc,char **argv){
char *source;
Sourcemap *sm1=NULL;
- readsource(srcf,&source,params.heatmap?&sm1:NULL);
+ readsource(srcf,&source,params.heatmapfname?&sm1:NULL);
assert(source);
fclose(srcf);
Sourcemap *sm2=NULL;
- optimise(source,sm1,params.heatmap?&sm2:NULL);
+ optimise(source,sm1,params.heatmapfname?&sm2:NULL);
char asmfname[20];
FILE *asmf=gettempfilew(asmfname);