e32tools/elf2e32/source/filedump.cpp
changeset 666 76dc8e3e7f2e
parent 590 360bd6b35136
--- a/e32tools/elf2e32/source/filedump.cpp	Wed Oct 27 19:38:12 2010 +0800
+++ b/e32tools/elf2e32/source/filedump.cpp	Thu Oct 28 11:19:23 2010 +0800
@@ -23,7 +23,8 @@
 #include "h_utl.h"
 #include "deffile.h"
 #include "errorhandler.h"
-#include <stdio.h>
+#include <cstdio>
+#include <cassert>
 /**
 Constructor for class FileDump
 @param aParameterListInterface - Instance of class ParameterListInterface
@@ -63,7 +64,7 @@
 		if(!iParameterListInterface->DefInput())
 			throw ParameterParserError(NOREQUIREDOPTIONERROR,"--definput");
 
-		GenerateAsmFile(iParameterListInterface->E32ImageOutput());
+		GenerateAsmFile();
 	}
 	else
 	{
@@ -71,7 +72,7 @@
 			throw ParameterParserError(NOREQUIREDOPTIONERROR,"--e32input");
 		if(iParameterListInterface->DumpOptions() & EDumpAsm )
 			throw InvalidArgumentError(INVALIDARGUMENTERROR,iParameterListInterface->FileDumpSubOptions() ,"--dump");
-		DumpE32Image(iParameterListInterface->E32Input());
+		DumpE32Image();
 	}
 	return 0;
 }
@@ -83,11 +84,26 @@
 @internalComponent
 @released
 */
-int FileDump::GenerateAsmFile(const char* afileName)//DumpAsm
+int FileDump::GenerateAsmFile() //DumpAsm
+{
+	EAsmDialect asmDialect = iParameterListInterface->AsmDialect();
+	switch(asmDialect)
+	{
+	case EGas:
+		return GenerateGasAsmFile();
+	case EArmas:
+		return GenerateArmasAsmFile();
+	default:
+		assert(false);
+	}
+	return 0;
+}
+int FileDump::GenerateArmasAsmFile()
 {
 	DefFile *iDefFile = new DefFile();
 	SymbolList *aSymList;
 	aSymList = iDefFile->ReadDefFile(iParameterListInterface->DefInput());
+	char const *afileName = iParameterListInterface->E32ImageOutput(); 
 
 	FILE *fptr;
 
@@ -155,14 +171,54 @@
 }
 
 /**
+Function to generate a GNU as ASM File.
+@param afileName - ASM File name
+@return 0 on success, otherwise throw error 
+@internalComponent
+@released*/
+int FileDump::GenerateGasAsmFile()
+{
+	DefFile *iDefFile = new DefFile();
+	SymbolList *aSymList;
+	aSymList = iDefFile->ReadDefFile(iParameterListInterface->DefInput());
+	char const *afileName = iParameterListInterface->E32ImageOutput(); 
+	FILE *fptr;
+	if((fptr=fopen(afileName,"w"))==NULL)
+	{
+		throw FileError(FILEOPENERROR,(char*)afileName);
+	}
+	else
+	{
+		SymbolList::iterator aItr = aSymList->begin();
+		SymbolList::iterator last = aSymList->end();
+		Symbol *aSym;
+		while( aItr != last)
+		{
+			aSym = *aItr;
+			if(aSym->Absent())
+			{
+				aItr++;
+				continue;
+			}
+			fputs("\t.global ",fptr);
+			fputs(aSym->SymbolName(),fptr);
+			fputs("\n",fptr);
+			aItr++;
+		}
+		fclose(fptr);
+	}
+	return 0;
+}
+/**
 Function to Dump E32 Image.
 @param afileName - E32 Image File name
 @return 1 on success, otherwise throw error 
 @internalComponent
 @released
 */
-int FileDump::DumpE32Image(const char* afileName)
+int FileDump::DumpE32Image()
 {
+	char const *afileName = iParameterListInterface->E32Input(); 
 	E32ImageFile *aE32Imagefile=new E32ImageFile();
 	TInt result = aE32Imagefile->Open(afileName);