Permalink
Browse files

Run "make h2j && ./h2j" to see all of julia.h's function signatures.

This requires downloading and compiling clang under LLVM:

  cd external/llvm-3.0/tools
  svn co http://llvm.org/svn/llvm-project/cfe/tags/RELEASE_30/final/ clang
  cd ..
  make
  • Loading branch information...
1 parent 4395ac5 commit cf6f13fa92c65f46b98714bd57bd12ef3e3c9289 @StefanKarpinski StefanKarpinski committed Dec 30, 2011
Showing with 81 additions and 2 deletions.
  1. +1 −2 .gitignore
  2. +3 −0 Makefile
  3. +77 −0 src/h2j.cpp
View
@@ -2,7 +2,6 @@
*#
/tmp
-/README.html
/julia
/julia-debug-*
@@ -13,4 +12,4 @@
/libjulia-release.dylib
/sys.ji
-/boot.j.inc
+/h2j
View
@@ -30,6 +30,9 @@ install: release
cp -r examples $(DESTDIR)/usr/share/julia
cp -r sys.ji $(DESTDIR)/usr/share/julia
+h2j: lib/libLLVM*.a lib/libclang*.a src/h2j.cpp
+ g++ -O2 -fno-rtti -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -Iinclude $^ -o $@
+
clean:
rm -f julia
rm -f *~ *#
View
@@ -0,0 +1,77 @@
+#include <iostream>
+
+#include "llvm/Support/Host.h"
+#include "llvm/Support/raw_ostream.h"
+
+#include "clang/AST/AST.h"
+#include "clang/AST/ASTConsumer.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/DeclGroup.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/FileManager.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Basic/TargetInfo.h"
+#include "clang/Basic/TargetOptions.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Parse/ParseAST.h"
+#include "clang/Parse/Parser.h"
+
+using namespace std;
+using namespace clang;
+
+class PrintFunctionsConsumer : public ASTConsumer {
+public:
+ virtual void HandleTopLevelDecl(DeclGroupRef DG) {
+ for (DeclGroupRef::iterator i = DG.begin(), e = DG.end(); i != e; ++i) {
+ const Decl *D = *i;
+ const FunctionDecl *FD = dyn_cast<FunctionDecl>(D);
+ if (!FD || !FD->hasPrototype() || !FD->isExternC() || !FD->isGlobal()) return;
+ cout << FD->getResultType().getAsString() << " ";
+ cout << FD->getNameAsString() << "(";
+ bool printComma = false;
+ FunctionDecl::param_const_iterator I = FD->param_begin(),
+ E = FD->param_end();
+ while (I != E) {
+ ParmVarDecl *PVD = *I++;
+ if (printComma) cout << ", ";
+ cout << PVD->getOriginalType().getAsString();
+ printComma = true;
+ }
+ cout << ");\n";
+ }
+ }
+};
+
+int main()
+{
+ CompilerInstance ci;
+ ci.createDiagnostics(0,NULL);
+
+ TargetOptions to;
+ to.Triple = llvm::sys::getHostTriple();
+ TargetInfo *pti = TargetInfo::CreateTargetInfo(ci.getDiagnostics(), to);
+ ci.setTarget(pti);
+
+ ci.getHeaderSearchOpts().AddPath(
+ StringRef("lib/clang/3.0/include"), frontend::Angled, false, false, false
+ );
+ ci.getHeaderSearchOpts().AddPath(
+ StringRef("src/support"), frontend::Quoted, true, false, false
+ );
+
+ ci.createFileManager();
+ ci.createSourceManager(ci.getFileManager());
+ ci.createPreprocessor();
+ PrintFunctionsConsumer *astConsumer = new PrintFunctionsConsumer();
+ ci.setASTConsumer(astConsumer);
+
+ ci.createASTContext();
+ const FileEntry *pFile = ci.getFileManager().getFile("src/julia.h");
+ ci.getSourceManager().createMainFileID(pFile);
+ ci.getDiagnosticClient().BeginSourceFile(ci.getLangOpts(), &ci.getPreprocessor());
+ clang::ParseAST(ci.getPreprocessor(), astConsumer, ci.getASTContext());
+ ci.getDiagnosticClient().EndSourceFile();
+
+ return 0;
+}

0 comments on commit cf6f13f

Please sign in to comment.