X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fasm.c;h=b22d352e269232a584926633aa9f1c73e3133afe;hb=c2a0ea8e1e3331b8ea967a0c23cfaabf6fc33e59;hp=9722ced0cb076d67565ad2c5fb1c8522718a75c9;hpb=14ff0763cec40a80c8fbb7519533bca1d7d44589;p=fw%2Fsdcc diff --git a/src/asm.c b/src/asm.c index 9722ced0..b22d352e 100644 --- a/src/asm.c +++ b/src/asm.c @@ -9,6 +9,14 @@ #include "common.h" #include "asm.h" +#if defined __MINGW32__ + // for O_BINARY in _pipe() +# include +#elif !defined(__BORLANDC__) && !defined(_MSC_VER) + // for pipe and close +# include +#endif + /* A 'token' is like !blah or %24f and is under the programmers control. */ #define MAX_TOKEN_LEN 64 @@ -204,7 +212,42 @@ asm_addTree (const ASM_MAPPINGS * pMappings) } /*-----------------------------------------------------------------*/ -/* printCLine - try to find the c-code for this lineno */ +/* printILine - return the readable i-code for this ic */ +/* */ +/* iCodePrint wants a file stream so we need a pipe to fool it */ +/*-----------------------------------------------------------------*/ +static char verbalICode[1024]; + +char *printILine (iCode *ic) { + int filedes[2]; + FILE *pipeStream; + iCodeTable *icTab=getTableEntry(ic->op); + +#if defined __MINGW32__ + assert(_pipe(filedes, 256, O_BINARY)!=-1); // forget it +#else + assert(pipe(filedes)!=-1); // forget it +#endif + + // stuff the pipe with the readable icode + pipeStream=fdopen(filedes[1],"w"); + icTab->iCodePrint(pipeStream, ic, icTab->printName); + // it really needs an extra push + fflush(pipeStream); + // now swallow it + pipeStream=fdopen(filedes[0],"r"); + fgets(verbalICode, sizeof(verbalICode), pipeStream); + // clean up the mess, we'll return here for all icodes!! + assert(!close (filedes[0])); + assert(!close (filedes[1])); + // kill the trailing NL + verbalICode[strlen(verbalICode)-1]='\0'; + // and throw it up + return verbalICode; +} + +/*-----------------------------------------------------------------*/ +/* printCLine - return the c-code for this lineno */ /*-----------------------------------------------------------------*/ static FILE *inFile=NULL; static char inLineString[1024]; @@ -219,6 +262,7 @@ char *printCLine (char *srcFile, int lineno) { if (strcmp (lastSrcFile, srcFile) != 0) { fclose (inFile); inFile = NULL; + inLineNo = 0; } } if (!inFile) {