]> git.gag.com Git - fw/sdcc/commitdiff
first pass at including c-code as asm comments
authorjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 19 Jan 2002 14:39:27 +0000 (14:39 +0000)
committerjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 19 Jan 2002 14:39:27 +0000 (14:39 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1818 4a8a32a2-be11-0410-ad9d-d568d2c75423

src/asm.c
src/asm.h

index c7ef55c5d1e24fdd80dfcd4d27e92ec23956b5ba..cd819e432e17b1803e8a497c1f4601ff08c8fffe 100644 (file)
--- a/src/asm.c
+++ b/src/asm.c
@@ -203,6 +203,42 @@ asm_addTree (const ASM_MAPPINGS * pMappings)
   }
 }
 
+/*-----------------------------------------------------------------*/
+/* printCLine - try to find the c-code for this lineno             */
+/*-----------------------------------------------------------------*/
+static FILE *inFile=NULL;
+static char inLineString[1024];
+static int inLineNo=0;
+int rewinds=0;
+
+char *printCLine (char *srcFile, int lineno) {
+  char *ilsP=inLineString;
+  if (!inFile) {
+    inFile=fopen(srcFile, "r");
+    if (!inFile) {
+      perror ("printCLine");
+      exit (1);
+    }
+  }
+  if (lineno<inLineNo) {
+    fseek (inFile, 0, SEEK_SET);
+    inLineNo=0;
+    rewinds++;
+  }
+  while (fgets (inLineString, 1024, inFile)) {
+    inLineNo++;
+    if (inLineNo==lineno) {
+      // remove the trailing NL
+      inLineString[strlen(inLineString)-1]='\0';
+      break;
+    }
+  }
+  while (isspace ((int)*ilsP))
+    ilsP++;
+
+  return ilsP;
+}
+
 static const ASM_MAPPING _asxxxx_mapping[] =
 {
   {"labeldef", "%s::"},
index 1e242fa2dcda99b403ffa7d2c8791a9a823f1d27..96baca6b91b4d361bb94a393507daf92dbfe54c2 100644 (file)
--- a/src/asm.h
+++ b/src/asm.h
@@ -34,4 +34,5 @@ void asm_addTree (const ASM_MAPPINGS * pMappings);
 
 char *FileBaseName (char *fileFullName);
 
+char *printCLine (char *srcFile, int lineno);
 #endif