summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2016-08-14 18:19:13 +0200
committertomsmeding <tom.smeding@gmail.com>2016-08-14 18:19:13 +0200
commit1d4d6bab83b72c1b02ee1db6b19a65e885f7953d (patch)
treea17fae12af2147bfbd34a9d168563f1c90812871
parent13b733e20a277f0c40d9548553fc2f1453ea424d (diff)
-d -> copyasm
-rw-r--r--bfcomp.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/bfcomp.c b/bfcomp.c
index 804b8a5..fa52087 100644
--- a/bfcomp.c
+++ b/bfcomp.c
@@ -43,6 +43,7 @@ void usage(const char *argv0){
"Reads a Brainfuck program from <srcfile> and saves the compiled executable\n"
"in <dstfile>.\n"
"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"
" -L Output last cell reached\n"
@@ -59,9 +60,9 @@ __attribute__((noreturn)) void usage1(const char *argv0){
typedef struct Params{
int memsize;
const char *srcfname,*dstfname;
- bool lastcell,verbose,heatmap;
+ bool lastcell,verbose,heatmap,copyasm;
} Params;
-Params params={30000,NULL,NULL,false,false,false};
+Params params={30000,NULL,NULL,false,false,false,false};
void parseargs(int argc,char **argv){
if(argc<2)usage1(argv[0]);
@@ -71,6 +72,10 @@ void parseargs(int argc,char **argv){
if(argv[i][0]=='-'){
for(int j=1;argv[i][j];j++){
switch(argv[i][j]){
+ case 'd':
+ params.copyasm=true;
+ break;
+
case 'h':
usage(argv[0]);
exit(0);
@@ -95,6 +100,9 @@ void parseargs(int argc,char **argv){
case 'v':
params.verbose=true;
break;
+
+ default:
+ usage1(argv[0]);
}
}
} else if(params.srcfname==NULL)params.srcfname=argv[i];
@@ -424,10 +432,13 @@ int main(int argc,char **argv){
fclose(asmf);
- /*char *b;
- asprintf(&b,"cp %s %s.asm",asmfname,params.srcfname);
- runcmd(b);
- free(b);*/
+ if(params.copyasm){
+ char *b;
+ asprintf(&b,"cp %s %s.asm",asmfname,params.srcfname);
+ runcmd(b);
+ free(b);
+ }
+
int ret=compilechain(asmfname,params.dstfname);
unlink(asmfname);
if(params.verbose)fprintf(stderr,"unlink(%s) (asmfname)\n",asmfname);