最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c++ - How to expand Macros of a huge project - Stack Overflow

programmeradmin5浏览0评论

Is there an easy way to get entire definition of ValueTy. It it diffcult to complile the single file with -E option. llvm-projct part of Value.h code

  /// Concrete subclass of this.
  ///
  /// An enumeration for keeping track of the concrete subclass of Value that
  /// is actually instantiated. Values of this enumeration are kept in the
  /// Value classes SubclassID field. They are used for concrete type
  /// identification.
  enum ValueTy { 
    #define HANDLE_VALUE(Name) Name##Val,
    #include "llvm/IR/Value.def"

    // Markers:
    #define HANDLE_CONSTANT_MARKER(Marker, Constant) Marker = Constant##Val,
    #include "llvm/IR/Value.def"
  };

the include lines are like this.

HANDLE_VALUE(Argument)
HANDLE_VALUE(BasicBlock)

It can be parsed by clangd, but I don't know how to get the entire.

Is there an easy way to get entire definition of ValueTy. It it diffcult to complile the single file with -E option. llvm-projct part of Value.h code

  /// Concrete subclass of this.
  ///
  /// An enumeration for keeping track of the concrete subclass of Value that
  /// is actually instantiated. Values of this enumeration are kept in the
  /// Value classes SubclassID field. They are used for concrete type
  /// identification.
  enum ValueTy { 
    #define HANDLE_VALUE(Name) Name##Val,
    #include "llvm/IR/Value.def"

    // Markers:
    #define HANDLE_CONSTANT_MARKER(Marker, Constant) Marker = Constant##Val,
    #include "llvm/IR/Value.def"
  };

the include lines are like this.

HANDLE_VALUE(Argument)
HANDLE_VALUE(BasicBlock)

It can be parsed by clangd, but I don't know how to get the entire.

Share edited Jan 9 at 0:23 A. K. 38.3k17 gold badges56 silver badges102 bronze badges asked Nov 28, 2024 at 11:49 huiiiiihuiiiii 312 bronze badges 3
  • 1 "It it diffcult to complile the single file with -E option." How do you want the result then? – Jarod42 Commented Nov 28, 2024 at 12:50
  • 1 Some build systems allow you to get compile commands as json file, you can look up command there and just add -E. Or if it doesn't work, you could use verbose mode of your build system and grep to find correct command for the interesting file. If your build system doesn't allow compiling header files separately, add source file that only has single line with include and look up command for this file. – Yksisarvinen Commented Nov 28, 2024 at 13:03
  • 1 Try find how cppinsights works here is repo. – Marek R Commented Nov 28, 2024 at 13:08
Add a comment  | 

1 Answer 1

Reset to default 0

If you can compile a single file, try passing --save-temps that will give you the .ii file with all the preprocessed macros. Two easy ways to get the compile commands

  1. ninja -v will print the commands on console. This is most straight forward as you can copy and run that command.
  2. The build.ninja file also has the compilation commands in a specific format. It is easy to concatenate them together if you understand compiler flags. e.g., for the file llvm/lib/Transforms/Scalar/GVNHoist.cpp, the command is listed like:
build lib/Transforms/Scalar/CMakeFiles/LLVMScalarOpts.dir/GVNHoist.cpp.o: CXX_COMPILER__LLVMScalarOpts_unscanned_Release /home/g/llvm-project/llvm/lib/Transforms/Scalar/GVNHoist.cpp || cmake_object_order_depends_target_LLVMScalarOpts
  DEFINES = -DGTEST_HAS_RTTI=0 -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
  DEP_FILE = lib/Transforms/Scalar/CMakeFiles/LLVMScalarOpts.dir/GVNHoist.cpp.o.d
  FLAGS = -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -fno-lifetime-dse -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-maybe-uninitialized -Wno-nonnull -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -O3 -DNDEBUG -std=c++17  -fno-exceptions -funwind-tables -fno-rtti
  INCLUDES = -I/home/g/llvm-project/build/lib/Transforms/Scalar -I/home/g/llvm-project/llvm/lib/Transforms/Scalar -I/home/g/llvm-project/build/include -I/home/g/llvm-project/llvm/include
  OBJECT_DIR = lib/Transforms/Scalar/CMakeFiles/LLVMScalarOpts.dir
  OBJECT_FILE_DIR = lib/Transforms/Scalar/CMakeFiles/LLVMScalarOpts.dir
发布评论

评论列表(0)

  1. 暂无评论