[cfe-dev] using the original file name for compiling preprocessed files ("-main-file-name"?)
Robert Lytton
robert at xmos.com
Tue May 6 12:10:22 PDT 2014
Hi Richard,
The data route to set the ModuleID is below.
At some stage the code should have used getCompilerInstance().getCodeGenOpts().MainFileName I believe.
However, I am not familiar enough to know who needs the real file name and who needs the original file name.
I tried a patch at FrontendAction::BeginSourceFile(), but not all unit tests passed - not looked into why yet.
A patch later when we create the BackendConsumer() "seems to work" - see below-below.
Robert
lib/Frontend/CompilerInstance.cpp
CompilerInstance::ExecuteAction()
(Input = getFrontendOpts())
lib/Frontend/FrontendAction.cpp
BeginSourceFile(Input)
InFile = Input.getFile();
FrontendAction::CreateWrappedASTConsumer(InFile)
lib/CodeGen/CodeGenAction.cpp
CodeGenAction::CreateASTConsumer(InFile)
OS(Infile)
BackendConsumer(infile) : ASTConsumer
lib/CodeGen/ModuleBuilder.cpp
clang::CreateLLVMCodeGen(ModuleName)
CodeGeneratorImpl(ModuleName)
llvm
llvm::Module(ModuleName)
diff --git a/lib/CodeGen/CodeGenAction.cpp b/lib/CodeGen/CodeGenAction.cpp
index 795b127..d952fbf 100644
--- a/lib/CodeGen/CodeGenAction.cpp
+++ b/lib/CodeGen/CodeGenAction.cpp
@@ -543,10 +543,12 @@ ASTConsumer *CodeGenAction::CreateASTConsumer(CompilerInstance &CI,
LinkModuleToUse = ModuleOrErr.get();
}
+ StringRef mainFileName = getCompilerInstance().getCodeGenOpts().MainFileName;
+ if (mainFileName.empty())
+ mainFileName = InFile;
BEConsumer = new BackendConsumer(BA, CI.getDiagnostics(), CI.getCodeGenOpts(),
CI.getTargetOpts(), CI.getLangOpts(),
- CI.getFrontendOpts().ShowTimers, InFile,
+ CI.getFrontendOpts().ShowTimers, mainFileName,
LinkModuleToUse, OS.release(), *VMContext);
return BEConsumer;
}
________________________________
From: metafoo at gmail.com [metafoo at gmail.com] on behalf of Richard Smith [richard at metafoo.co.uk]
Sent: 02 May 2014 00:35
To: Robert Lytton
Cc: cfe-dev at cs.uiuc.edu
Subject: Re: [cfe-dev] using the original file name for compiling preprocessed files ("-main-file-name"?)
On Thu, May 1, 2014 at 2:22 AM, Robert Lytton <robert at xmos.com<mailto:robert at xmos.com>> wrote:
Hi,
I would like to call clang twice, once to preprocess and second time to compile.
The second time clang is called, I would like to pass in the original file name for it to use as the ModuleID.
I tried to use:
clang -E test.c -o tmp.i
clang -S -x c tmp.i -o test.s -Xclang -main-file-name -Xclang test.c -emit-llvm
However, the ModuleID is 'tmp.i' rather than that passed in by '-main-file-name'.
This seems like a bug to me; -main-file-name should be used as the name of the input in all respects other than where we find it on disk. Care to put together a patch to fix this? (I doubt you'll be able to get anyone else to care much about what ends up in ModuleID, so I think you'll need to do the work yourself here...)
Same with:
clang -cc1 -triple x86_64-unknown-linux-gnu -x c tmp.i -o test.s -main-file-name test.c -emit-llvm
I am trying to achieve the same affect as using "-fpreprocessed -dumpbase <file>" with llvm-gcc.
Here it seems the gcc front end fetches the file name from the first line of the preprocessed file.
Thank you.
Robert
_______________________________________________
cfe-dev mailing list
cfe-dev at cs.uiuc.edu<mailto:cfe-dev at cs.uiuc.edu>
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140506/a749d038/attachment.html>
More information about the cfe-dev
mailing list