[cfe-dev] Tool programming. Where can I get default platform configuration ?

Manuel Klimek klimek at google.com
Sat Sep 1 08:40:05 PDT 2012


On Sat, Sep 1, 2012 at 2:51 AM, Y. Orçun Gökbulut
<orcun.gokbulut at zinekengine.com> wrote:
> Hello everyone,
>
>
>
> I’m trying to develop a tool based on cmake and I have couple of problems.
> I’ll be really happy if anyone would help me. J
>
>
>
> In our project we have a custom c++ reflection library and we are using it
> pretty much everywhere. Our developer uses a simple tool to generate type
> information from header files. It is a very simple tool which requires ugly
> syntax (I’m not fond of it) in source code.  Therefore we have decided to
> replaced it with an source to source transformation tool based on cmake. We
> have developed the tool simply by using CompilerInstance and ASTConsumer
> which is pretty neat and simple. :D It works perfectly in our test inputs.
>
>
>
> The tool works perfectly and is going to improve our code quality massively.
> However the problem is when we have tried to use our new tool in our actual
> project code. It produces tremendous amounts of error output in system
> headers. (crtlib, ostream, string) Our main development platform is Windows
> and Visual Studio 2010. When I tried to compile the actual project code in
> clang.exe it compiled the files perfectly fine.
>
>
>
> So I have looked out for a way to make our tool behave more like clang.exe;
>
> ·         I have tried to set CompilerInstance options manually. I have
> compiled target code with clang.exe –v and tried to match the clangs.exe’s
> default options in the tool’s source code. I have achieved some progress but
> not fully get rid of the errors.
>
> ·         I have tried tooling library. But I could not get it working.
>
> ·         I have tried to reverse engineer frondend, driver and clang code.
> But I got stuck.
>
>
>
> So, my question is how can I automatically configure my CompilerInstance for
> my platform ? (Include paths, compiler definitions, compiler options,
> preprocessor options, language options) Is there a way, function, class or
> mechanism that automatically configures CompilerInstance ?
>
>
>
> Here is my actual code;
>
> int main_compiler_instance(int argc, const char** argv)
>
> {
>
>        CompilerInstance Compiler;
>
>        Compiler.createDiagnostics(0, NULL);
>
>
>
>        TargetOptions to;
>
>        to.Triple = llvm::sys::getDefaultTargetTriple();
>
>        TargetInfo *pti =
> TargetInfo::CreateTargetInfo(Compiler.getDiagnostics(), to);
>
>        Compiler.setTarget(pti);
>
>
>
>        Compiler.getPreprocessorOpts().UsePredefines = false;
>
>
>
>        Compiler.getLangOpts().CPlusPlus = 1;
>
>        Compiler.getLangOpts().Bool = 1;
>
>        Compiler.getLangOpts().MSCVersion = 1300;
>
>        Compiler.getLangOpts().MicrosoftExt = 1;
>
>        Compiler.getLangOpts().MicrosoftMode = 1;
>
>        Compiler.getLangOpts().CPlusPlus0x = 1;
>
>        Compiler.getLangOpts().ShortWChar = 1;
>
>        Compiler.getLangOpts().Exceptions = 1;
>
>        Compiler.getLangOpts().CXXExceptions = 1;
>
>        Compiler.getLangOpts().DelayedTemplateParsing = 1;
>
>        Compiler.getLangOpts().MathErrno = 1;
>
>        Compiler.getHeaderSearchOpts().ResourceDir =
> "c:/llvm/bin\\..\\lib\\clang\\3.2";
>
>
> Compiler.getHeaderSearchOpts().AddPath("c:/llvm/bin/../lib/clang/3.2/include",
> frontend::System, false, false, true, true);
>
>        Compiler.getHeaderSearchOpts().AddPath("C:\\Program Files
> (x86)\\Microsoft SDKs\Windows\v7.0A\Include", frontend::System, false,
> false, true, true);
>
>        Compiler.getHeaderSearchOpts().AddPath("C:\\Program Files
> (x86)\\Microsoft Visual Studio 10.0\\VC\\include", frontend::System, false,
> false, true, true);
>
>
> Compiler.getHeaderSearchOpts().AddPath("C:\\Users\\Orcun\\Desktop\\ZEPrototypes\\Source",
> frontend::Quoted, false, false, true);
>
>
> Compiler.getHeaderSearchOpts().AddPath("C:\\Users\\Orcun\\Desktop\\ZEPrototypes\\Source\\ZEFoundation",
> frontend::Quoted, false, false, true);
>
>
> Compiler.getHeaderSearchOpts().AddPath("C:\\Users\\Orcun\\Desktop\\ZEPrototypes\\Source\\ZECodeGenerator",
> frontend::Quoted, false, false, true);
>
>
>
>        Compiler.getPreprocessorOpts().addMacroDef("_WIN32");
>
>        Compiler.getPreprocessorOpts().addMacroDef("_WINDOWS");
>
>        Compiler.getPreprocessorOpts().addMacroDef("_WCHAR_T_DEFINED");
>
>
>
>        Compiler.createFileManager();
>
>        Compiler.createSourceManager(Compiler.getFileManager());
>
>        Compiler.createPreprocessor();
>
>        Compiler.setASTConsumer(new ZECodeGeneratorASTConsumer());
>
>        Compiler.createASTContext();
>
>
>
>        const FileEntry *pFile = Compiler.getFileManager().getFile(argv[1]);
>
>        Compiler.getSourceManager().createMainFileID(pFile);
>
>
> Compiler.getDiagnosticClient().BeginSourceFile(Compiler.getLangOpts(),
> &Compiler.getPreprocessor());
>
>
>
>        ParseAST(Compiler.getPreprocessor(), &Compiler.getASTConsumer(),
> Compiler.getASTContext(), false, clang::TU_Complete, NULL, true);
>
>
>
>        Compiler.getDiagnosticClient().EndSourceFile();
>
>
>
>        return 1;
>
> }
>
>
>
> #include "clang/Tooling/Tooling.h"
>
> #include "llvm/Support/CommandLine.h"
>
> #include "clang/Tooling/CompilationDatabase.h"
>
>
>
> using namespace clang::tooling;
>
> using namespace llvm;
>
>
>
> int main_tooling(int argc, const char **argv)
>
> {
>
>        FixedCompilationDatabase* Database =
> FixedCompilationDatabase::loadFromCommandLine(argc, argv); //Actually I’m
> not pretty sure what it does.
>
>        ClangTool Tool(*Database, Database->getAllFiles());
>
>        return
> Tool.run(newFrontendActionFactory<ZECodeGeneratorFrontendAction>());
>
> }
>
>
>
> int main(int argc, const char** argv)
>
> {
>
>        /* Select one of them */
>
>        //main_compiler_instance(argc, argv);
>
>        //main_tooling(argc, argv);
>
> }
>
>
>
> And here is the command line options that I use: ZEMeta.cpp -I
> ..\ZEFoundation -I ..

You need to put '--' in between the ZEMeta.cpp and the command line
arguments. This is so that you can still add other command line
options you'd want for your tool.

Cheers,
/Manuel

> “main_tooling” function does not work because
> “FixedCompilationDatabase::loadFromCommandLine(argc, argv);” function return
> NULL.
>
>
>
> I have appended output log of “main_compiler_instance” function at the end
> of this email. Output log is very big (256+ KB) so I have removed some of
> the errors. When compiling the ZEMeta.cpp with clang.exe It does not
> produces these errors.
>
>
>
> Thanks to anyone has read this long email and have a nice day,
>
> Orcun.
>
>
>
> Note: My native language is not English. Therefore, I’m sorry if I could not
> express myself clearly or correctly.
>
>
>
> --- Output Log ---
>
> In file included from ZEMeta.h:2:
>
> In file included from
> C:\Users\Orcun\Desktop\ZEPrototypes\Source\ZEFoundation\ZEDS/ZEArray.h:66:
>
> In file included from
> C:\Users\Orcun\Desktop\ZEPrototypes\Source\ZEFoundation\ZEError.h:41:
>
> In file included from
> C:\Users\Orcun\Desktop\ZEPrototypes\Source\ZEFoundation/ZELog.h:5:
>
> In file included from
> C:\Users\Orcun\Desktop\ZEPrototypes\Source\ZEFoundation/ZEDS/ZEString.h:40:
>
> In file included from C:\Program Files (x86)\Microsoft Visual Studio
> 10.0\VC\include\string:6:
>
> In file included from C:\Program Files (x86)\Microsoft Visual Studio
> 10.0\VC\include\istream:6:
>
> In file included from C:\Program Files (x86)\Microsoft Visual Studio
> 10.0\VC\include\ostream:6:
>
> In file included from C:\Program Files (x86)\Microsoft Visual Studio
> 10.0\VC\include\ios:6:
>
> In file included from C:\Program Files (x86)\Microsoft Visual Studio
> 10.0\VC\include\xlocnum:10:
>
> In file included from C:\Program Files (x86)\Microsoft Visual Studio
> 10.0\VC\include\streambuf:6:
>
> In file included from C:\Program Files (x86)\Microsoft Visual Studio
> 10.0\VC\include\xiosbase:6:
>
> In file included from C:\Program Files (x86)\Microsoft Visual Studio
> 10.0\VC\include\xlocale:8:
>
> In file included from C:\Program Files (x86)\Microsoft Visual Studio
> 10.0\VC\include\stdexcept:6:
>
> In file included from C:\Program Files (x86)\Microsoft Visual Studio
> 10.0\VC\include\exception:38:
>
> C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\eh.h:58:53:
> error: unknown type name 'type_info'
>
> _CRTIMP int __cdecl _is_exception_typeof(_In_ const type_info &_Type, _In_
> struct _EXCEPTION_POINTERS * _ExceptionPtr);
>
>
>
> In file included from ZEMeta.h:2:
>
> In file included from
> C:\Users\Orcun\Desktop\ZEPrototypes\Source\ZEFoundation\ZEDS/ZEArray.h:66:
>
> In file included from
> C:\Users\Orcun\Desktop\ZEPrototypes\Source\ZEFoundation\ZEError.h:41:
>
> In file included from
> C:\Users\Orcun\Desktop\ZEPrototypes\Source\ZEFoundation/ZELog.h:5:
>
> In file included from
> C:\Users\Orcun\Desktop\ZEPrototypes\Source\ZEFoundation/ZEDS/ZEString.h:40:
>
> In file included from C:\Program Files (x86)\Microsoft Visual Studio
> 10.0\VC\include\string:6:
>
> In file included from C:\Program Files (x86)\Microsoft Visual Studio
> 10.0\VC\include\istream:6:
>
> In file included from C:\Program Files (x86)\Microsoft Visual Studio
> 10.0\VC\include\ostream:6:
>
> In file included from C:\Program Files (x86)\Microsoft Visual Studio
> 10.0\VC\include\ios:6:
>
> In file included from C:\Program Files (x86)\Microsoft Visual Studio
> 10.0\VC\include\xlocnum:10:
>
> In file included from C:\Program Files (x86)\Microsoft Visual Studio
> 10.0\VC\include\streambuf:6:
>
> In file included from C:\Program Files (x86)\Microsoft Visual Studio
> 10.0\VC\include\xiosbase:6:
>
> In file included from C:\Program Files (x86)\Microsoft Visual Studio
> 10.0\VC\include\xlocale:8:
>
> In file included from C:\Program Files (x86)\Microsoft Visual Studio
> 10.0\VC\include\stdexcept:6:
>
> In file included from C:\Program Files (x86)\Microsoft Visual Studio
> 10.0\VC\include\exception:39:
>
> C:\Program Files (x86)\Microsoft Visual Studio
> 10.0\VC\include\malloc.h:187:40: error: use of undeclared identifier
> '_ALLOCA_S_MARKER_SIZE'
>
> _STATIC_ASSERT(sizeof(unsigned int) <= _ALLOCA_S_MARKER_SIZE);
>
>                                        ^
>
> C:\Program Files (x86)\Microsoft Visual Studio
> 10.0\VC\include\malloc.h:43:63: note: expanded from macro '_STATIC_ASSERT'
>
> #define _STATIC_ASSERT(expr) typedef char __static_assert_t[ (expr) ]
>
>
>
> In file included from ZEMeta.h:2:
>
> In file included from
> C:\Users\Orcun\Desktop\ZEPrototypes\Source\ZEFoundation\ZEDS/ZEArray.h:66:
>
> In file included from
> C:\Users\Orcun\Desktop\ZEPrototypes\Source\ZEFoundation\ZEError.h:41:
>
> In file included from
> C:\Users\Orcun\Desktop\ZEPrototypes\Source\ZEFoundation/ZELog.h:5:
>
> In file included from
> C:\Users\Orcun\Desktop\ZEPrototypes\Source\ZEFoundation/ZEDS/ZEString.h:40:
>
> In file included from C:\Program Files (x86)\Microsoft Visual Studio
> 10.0\VC\include\string:6:
>
> In file included from C:\Program Files (x86)\Microsoft Visual Studio
> 10.0\VC\include\istream:6:
>
> In file included from C:\Program Files (x86)\Microsoft Visual Studio
> 10.0\VC\include\ostream:6:
>
> In file included from C:\Program Files (x86)\Microsoft Visual Studio
> 10.0\VC\include\ios:6:
>
> In file included from C:\Program Files (x86)\Microsoft Visual Studio
> 10.0\VC\include\xlocnum:10:
>
> In file included from C:\Program Files (x86)\Microsoft Visual Studio
> 10.0\VC\include\streambuf:6:
>
> In file included from C:\Program Files (x86)\Microsoft Visual Studio
> 10.0\VC\include\xiosbase:6:
>
> In file included from C:\Program Files (x86)\Microsoft Visual Studio
> 10.0\VC\include\xlocale:8:
>
> In file included from C:\Program Files (x86)\Microsoft Visual Studio
> 10.0\VC\include\stdexcept:7:
>
> In file included from C:\Program Files (x86)\Microsoft Visual Studio
> 10.0\VC\include\xstring:6:
>
> In file included from C:\Program Files (x86)\Microsoft Visual Studio
> 10.0\VC\include\xmemory:8:
>
> In file included from C:\Program Files (x86)\Microsoft Visual Studio
> 10.0\VC\include\xutility:8:
>
> In file included from C:\Program Files (x86)\Microsoft Visual Studio
> 10.0\VC\include\utility:9:
>
> In file included from C:\Program Files (x86)\Microsoft Visual Studio
> 10.0\VC\include\type_traits:6:
>
> C:\Program Files (x86)\Microsoft Visual Studio
> 10.0\VC\include\limits:182:22: error: use of undeclared identifier
> '__FLT_RADIX__'
>
>         _STCONS(int, radix, FLT_RADIX);
>
>
>
> In file included from ZEMeta.h:2:
>
> In file included from
> C:\Users\Orcun\Desktop\ZEPrototypes\Source\ZEFoundation\ZEDS/ZEArray.h:66:
>
> In file included from
> C:\Users\Orcun\Desktop\ZEPrototypes\Source\ZEFoundation\ZEError.h:41:
>
> In file included from
> C:\Users\Orcun\Desktop\ZEPrototypes\Source\ZEFoundation/ZELog.h:5:
>
> In file included from
> C:\Users\Orcun\Desktop\ZEPrototypes\Source\ZEFoundation/ZEDS/ZEString.h:40:
>
> In file included from C:\Program Files (x86)\Microsoft Visual Studio
> 10.0\VC\include\string:6:
>
> In file included from C:\Program Files (x86)\Microsoft Visual Studio
> 10.0\VC\include\istream:6:
>
> In file included from C:\Program Files (x86)\Microsoft Visual Studio
> 10.0\VC\include\ostream:6:
>
> In file included from C:\Program Files (x86)\Microsoft Visual Studio
> 10.0\VC\include\ios:6:
>
> In file included from C:\Program Files (x86)\Microsoft Visual Studio
> 10.0\VC\include\xlocnum:10:
>
> In file included from C:\Program Files (x86)\Microsoft Visual Studio
> 10.0\VC\include\streambuf:6:
>
> In file included from C:\Program Files (x86)\Microsoft Visual Studio
> 10.0\VC\include\xiosbase:6:
>
> In file included from C:\Program Files (x86)\Microsoft Visual Studio
> 10.0\VC\include\xlocale:8:
>
> In file included from C:\Program Files (x86)\Microsoft Visual Studio
> 10.0\VC\include\stdexcept:7:
>
> In file included from C:\Program Files (x86)\Microsoft Visual Studio
> 10.0\VC\include\xstring:6:
>
> In file included from C:\Program Files (x86)\Microsoft Visual Studio
> 10.0\VC\include\xmemory:8:
>
> In file included from C:\Program Files (x86)\Microsoft Visual Studio
> 10.0\VC\include\xutility:8:
>
> In file included from C:\Program Files (x86)\Microsoft Visual Studio
> 10.0\VC\include\utility:9:
>
> In file included from C:\Program Files (x86)\Microsoft Visual Studio
> 10.0\VC\include\type_traits:6:
>
> C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\limits:27:61:
> note: expanded from macro '_STCONS'
>
> #define _STCONS(ty, name, val) static const ty name = (ty)(val)
>
>                                                             ^
>
> C:\Program Files (x86)\Microsoft Visual Studio
> 10.0\VC\include\limits:240:23: error: use of undeclared identifier
> '__CHAR_BIT__'
>
>         _STCONS(int, digits, CHAR_BIT - (CHAR_MIN != 0 ? 1 : 0));
>
>
>
> C:\Program Files (x86)\Microsoft Visual Studio
> 10.0\VC\include\limits:1467:15: error: default initialization of an object
> of const type 'const int'
>
>         _STCONS(int, digits, CHAR_BIT);
>
>
>
> C:\Program Files (x86)\Microsoft Visual Studio
> 10.0\VC\include\limits:1490:15: error: no member named 'digits10' in
> 'std::numeric_limits<unsigned short>'
>
>         _STCONS(int, digits10, (CHAR_BIT * sizeof (unsigned short) - 1)
>
>
>
> C:\Users\Orcun\Desktop\ZEPrototypes\Source\ZEFoundation/ZEDS/ZEString.h:233:74:
> error: expected expression
>
>                 static ZEString                         FromUInt64(ZEUInt64
> Value, const char* Format = NULL);
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>




More information about the cfe-dev mailing list