huiiiii
huiiiii

Reputation: 31

How to expand Macros of a huge project

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)

Screenshot

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

Upvotes: 3

Views: 74

Answers (1)

A. K.
A. K.

Reputation: 38234

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

Upvotes: 0

Related Questions