Skip to content
This repository has been archived by the owner on Jun 5, 2019. It is now read-only.

Commit

Permalink
Initial checkin
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenatwork committed Apr 16, 2012
1 parent 97aa37f commit 5a307f4
Show file tree
Hide file tree
Showing 6 changed files with 1,880 additions and 0 deletions.
29 changes: 29 additions & 0 deletions Makefile
@@ -0,0 +1,29 @@

CONFIG := Release
CONFIG := Debug
LLVM_DIR ?= /PATH/TO/LLVM/

EXENAME := ./clang-extract.$(CONFIG)

CXXFLAGS := -I$(LLVM_DIR)/include -I$(LLVM_DIR)/tools/clang/include \
-DNDEBUG -D_GNU_SOURCE -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS \
-pedantic -fomit-frame-pointer -fno-exceptions -fno-rtti -fPIC -fno-strict-aliasing \
-W -Wall -Woverloaded-virtual -Wcast-qual -Wno-long-long -Wno-unused-parameter -Wwrite-strings \
-Wno-variadic-macros -Wno-reorder -Wno-trigraphs -Wno-unknown-pragmas -Wno-unused
LDFLAGS := -L$(LLVM_DIR)/$(CONFIG)/lib
LIBS := -lclangFrontend -lclangSerialization -lclangParse -lclangSema -lclangAnalysis -lclangAST \
-lclangLex -lclangBasic -lLLVMMC -lLLVMCore -lLLVMSupport -lpthread -ldl -lm

ifeq ($(CONFIG),"Debug")
CXXFLAGS += -DDEBUG -g
endif
ifeq ($(CONFIG),"Release")
CXXFLAGS += -O3
endif

SRCS := extract.cpp main.cpp
$(EXENAME) : $(SRCS) extract.h Makefile
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $(SRCS) $(LIBS)

test : test1.h #$(EXENAME)
$(EXENAME) -I . test1.h -o test.out
34 changes: 34 additions & 0 deletions README
@@ -0,0 +1,34 @@

Clang-extract uses clang to parse your header files and then prints out a description of what it parsed.

This project was described in a talk a GDC 2012 http://www.gdcvault.com/play/1015586/ (subscription required)
It was funded by Havok and is used as the basis of its reflection system.


Building:
* Either in your environment or in the Makefile, set LLVM_DIR to the folder containing a prebuilt LLVM and Clang.
* make


Test:
To run clang-extract on a small test:
* make test

You'll notice the output format is actually python code so you can parse it with thus
def parse(text):
output = # your output structure
def Method(id, recordid, typeid, name, static):
# code here for a method, modifids output
# more local function definitions here
exec text in locals()
return output


Invoking:
Run clang-extract --help to see command line options.


Notes:
clang-extract internally creates a file which includes all the input files specified on the command line.
You may need to add "-I ." to find the input files.
The -A option is useful to pass through annotations which are stored in the output file.

0 comments on commit 5a307f4

Please sign in to comment.