Index: CMakeLists.txt =================================================================== --- CMakeLists.txt +++ CMakeLists.txt @@ -564,6 +564,7 @@ add_subdirectory(lib/TableGen) add_subdirectory(utils/TableGen) +add_subdirectory(utils/Misc) add_subdirectory(include/llvm) Index: include/llvm/IR/CMakeLists.txt =================================================================== --- include/llvm/IR/CMakeLists.txt +++ include/llvm/IR/CMakeLists.txt @@ -3,3 +3,15 @@ tablegen(LLVM Intrinsics.gen -gen-intrinsic) add_public_tablegen_target(intrinsics_gen) + +add_custom_command(TARGET intrinsics_gen + POST_BUILD +# COMMAND ${LLVM_SOURCE_DIR}/utils/Misc/extract_ifdef_block.sh GET_INTRINSIC_ENUM_VALUES < Intrinsics.gen > Intrinsics.ids.tmp + COMMAND extract_ifdef_block GET_INTRINSIC_ENUM_VALUES < Intrinsics.gen > Intrinsics.ids.tmp + COMMAND ${CMAKE_COMMAND} -E copy_if_different Intrinsics.ids.tmp Intrinsics.ids + COMMENT "Updating Intrinsics.ids..." +) + +set_source_files_properties(Intrinsics.ids PROPERTIES GENERATED 1) +set_property(DIRECTORY APPEND + PROPERTY ADDITIONAL_MAKE_CLEAN_FILES Intrinsics.ids.tmp Intrinsics.ids) Index: include/llvm/IR/Intrinsics.h =================================================================== --- include/llvm/IR/Intrinsics.h +++ include/llvm/IR/Intrinsics.h @@ -37,7 +37,7 @@ // Get the intrinsic enums generated from Intrinsics.td #define GET_INTRINSIC_ENUM_VALUES -#include "llvm/IR/Intrinsics.gen" +#include "llvm/IR/Intrinsics.ids" #undef GET_INTRINSIC_ENUM_VALUES , num_intrinsics }; Index: lib/IR/Makefile =================================================================== --- lib/IR/Makefile +++ lib/IR/Makefile @@ -10,11 +10,13 @@ LIBRARYNAME = LLVMCore BUILD_ARCHIVE = 1 -BUILT_SOURCES = $(PROJ_OBJ_ROOT)/include/llvm/IR/Intrinsics.gen +GENFILE=$(PROJ_OBJ_ROOT)/include/llvm/IR/Intrinsics.gen +IDSFILE=$(PROJ_OBJ_ROOT)/include/llvm/IR/Intrinsics.ids + +BUILT_SOURCES = $(GENFILE) $(IDSFILE) include $(LEVEL)/Makefile.common -GENFILE:=$(PROJ_OBJ_ROOT)/include/llvm/IR/Intrinsics.gen INTRINSICTD := $(PROJ_SRC_ROOT)/include/llvm/IR/Intrinsics.td INTRINSICTDS := $(wildcard $(PROJ_SRC_ROOT)/include/llvm/IR/Intrinsics*.td) @@ -28,6 +30,16 @@ $(EchoCmd) Updated Intrinsics.gen because Intrinsics.gen.tmp \ changed significantly. ) -install-local:: $(GENFILE) +$(ObjDir)/Intrinsics.ids.tmp: $(GENFILE) $(ObjDir)/.dir + $(Echo) Building Intrinsics.ids.tmp from Intrinsics.gen + $(Verb) $(PROJ_SRC_ROOT)/utils/Misc/extract_ifdef_block.sh GET_INTRINSIC_ENUM_VALUES < $< > $@ + +$(IDSFILE): $(ObjDir)/Intrinsics.ids.tmp $(PROJ_OBJ_ROOT)/include/llvm/IR/.dir + $(Verb) $(CMP) -s $@ $< || ( $(CP) $< $@ && \ + $(EchoCmd) Updated Intrinsics.ids because Intrinsics.ids.tmp \ + changed significantly. ) + +install-local:: $(GENFILE) $(IDSFILE) $(Echo) Installing $(DESTDIR)$(PROJ_includedir)/llvm/IR/Intrinsics.gen $(Verb) $(DataInstall) $(GENFILE) $(DESTDIR)$(PROJ_includedir)/llvm/IR/Intrinsics.gen + $(Verb) $(DataInstall) $(GENFILE) $(DESTDIR)$(PROJ_includedir)/llvm/IR/Intrinsics.ids Index: utils/Misc/CMakeLists.txt =================================================================== --- /dev/null +++ utils/Misc/CMakeLists.txt @@ -0,0 +1,5 @@ +set(LLVM_LINK_COMPONENTS Support) + +add_executable(extract_ifdef_block + extract_ifdef_block.cpp + ) Index: utils/Misc/extract_ifdef_block.cpp =================================================================== --- /dev/null +++ utils/Misc/extract_ifdef_block.cpp @@ -0,0 +1,85 @@ +//===-- utils/Misc/extract_ifdef_block.cpp - rudimentary C-preprocessor ---===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// extract_ifdef_block is a primitive utility for postprocessing the output of +// 'llvm-tblgen -gen-intrinsic'. Though it can be used with any C/C++ source +// file containing #ifdef blocks, its only current usage is for extracting +// the intrinsics enum section from the TableGen'erated Intrinsics.gen file. +// +//===----------------------------------------------------------------------===// + +#include + +using namespace std; +typedef std::string Str; + +void +promptUsage(const Str& progName) +{ + cerr << + "Usage: " << progName << " " "\n" + "" "\n" + << progName << "is a rudimentary C-preprocessor that" "\n" + "filters from the standard input blocks of text surrounded" "\n" + "by '#ifdef block_name' and '#endif' lines." "\n" + "" "\n" + "Limitations:" "\n" + " - Nested #if/#ifdef/#ifndef blocks are not supported." "\n" + " - #else/#elif are not supported" "\n" + << flush; +} + +void +ensureAgainstNestedIfdefs(const Str& line) +{ + if ( line.substr(0,3) == "#if" ) + { + cerr << "Nested #if/#ifdef/#ifndef blocks are not supported"; + exit(1); + } +} + +void +extractIfdefBlock(istream& in, ostream& out, const Str& blockName) +{ + const Str startMarker = "#ifdef " + blockName; + const Str endMarker = "#endif"; + + bool insideRequestedBlock = false; + Str line; + while ( getline(in, line) ) + { + if ( !insideRequestedBlock ) + { + insideRequestedBlock = (line == startMarker); + } + else + { + ensureAgainstNestedIfdefs(line); + if ( line == endMarker ) + insideRequestedBlock = false; + else + out << line << "\n"; + } + } + + out << flush; +} + +int main(int argc, char *argv[]) +{ + if ( argc != 2 ) + { + promptUsage(argv[0]); + return 1; + } + + extractIfdefBlock(cin, cout, argv[1]); + return 0; +} Index: utils/Misc/extract_ifdef_block.sh =================================================================== --- /dev/null +++ utils/Misc/extract_ifdef_block.sh @@ -0,0 +1,46 @@ +#!/bin/bash +#===-- utils/Misc/extract_ifdef_block.sh - rudimentary C-preprocessor ---===// +# +# The LLVM Compiler Infrastructure +# +# This file is distributed under the University of Illinois Open Source +# License. See LICENSE.TXT for details. +# +#===----------------------------------------------------------------------===// +# +# extract_ifdef_block.sh is a primitive utility for postprocessing the output of +# 'llvm-tblgen -gen-intrinsic'. Though it can be used with any C/C++ source +# file containing #ifdef blocks, its only current usage is for extracting +# the intrinsics enum section from the TableGen'erated Intrinsics.gen file. +# +#===----------------------------------------------------------------------===// + + +myname=$(basename $0) + +MAX_LINES=100000000 +function usage() +{ +cat < + +Filters from the standard input a single block of text +surrounded by '#ifdef block_name' and '#endif' lines. + +Limitations: + - Nested #if/#ifdef/#ifndef blocks are not supported. + - #else/#elif are not supported + - The sought block of text must not exceed $MAX_LINES lines. +END +exit 1 +} + +if [ $# -ne 1 ]; +then + usage +fi + +grep -m 1 -A $MAX_LINES "^#ifdef $1\$" \ +| grep -m 1 -B $MAX_LINES '^#endif$' \ +| grep -v "^#ifdef $1\$" \ +| grep -v '^#endif$'