[cfe-commits] r39495 - in /cfe/cfe/trunk: CodeGen/ CodeGen/Builder.h CodeGen/Makefile CodeGen/ModuleBuilder.cpp Driver/LLVMCodegen.cpp Driver/Makefile Driver/clang.cpp Driver/clang.h Makefile clang.xcodeproj/project.pbxproj include/clang/CodeGen/ include/clang/CodeGen/ModuleBuilder.h
clattner at cs.uiuc.edu
clattner at cs.uiuc.edu
Wed Jul 11 09:44:58 PDT 2007
Author: clattner
Date: Wed Jul 11 11:44:58 2007
New Revision: 39495
URL: http://llvm.org/viewvc/llvm-project?rev=39495&view=rev
Log:
Initial scaffolding for an -emit-llvm mode. This requires the LLVM VMCore
library to be built for the driver to link.
Added:
cfe/cfe/trunk/CodeGen/
cfe/cfe/trunk/CodeGen/Builder.h (with props)
cfe/cfe/trunk/CodeGen/Makefile (with props)
cfe/cfe/trunk/CodeGen/ModuleBuilder.cpp (with props)
cfe/cfe/trunk/Driver/LLVMCodegen.cpp (with props)
cfe/cfe/trunk/include/clang/CodeGen/
cfe/cfe/trunk/include/clang/CodeGen/ModuleBuilder.h (with props)
Modified:
cfe/cfe/trunk/Driver/Makefile
cfe/cfe/trunk/Driver/clang.cpp
cfe/cfe/trunk/Driver/clang.h
cfe/cfe/trunk/Makefile
cfe/cfe/trunk/clang.xcodeproj/project.pbxproj
Added: cfe/cfe/trunk/CodeGen/Builder.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/CodeGen/Builder.h?rev=39495&view=auto
==============================================================================
--- cfe/cfe/trunk/CodeGen/Builder.h (added)
+++ cfe/cfe/trunk/CodeGen/Builder.h Wed Jul 11 11:44:58 2007
@@ -0,0 +1,40 @@
+//===--- Builder.h - Internal interface for LLVM Builder ------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file was developed by Chris Lattner and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This is the internal per-translation-unit state used for llvm translation.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef CODEGEN_BUILDER_H
+#define CODEGEN_BUILDER_H
+
+namespace llvm {
+ class Module;
+namespace clang {
+ class ASTContext;
+ class FunctionDecl;
+
+namespace CodeGen {
+
+class Builder {
+ ASTContext &Context;
+ Module &TheModule;
+public:
+ Builder(ASTContext &C, Module &M) : Context(C), TheModule(M) {}
+
+ void CodeGenFunction(FunctionDecl *FD) {}
+
+ void PrintStats() {}
+
+};
+} // end namespace CodeGen
+} // end namespace clang
+} // end namespace llvm
+
+#endif
Propchange: cfe/cfe/trunk/CodeGen/Builder.h
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cfe/cfe/trunk/CodeGen/Builder.h
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: cfe/cfe/trunk/CodeGen/Makefile
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/CodeGen/Makefile?rev=39495&view=auto
==============================================================================
--- cfe/cfe/trunk/CodeGen/Makefile (added)
+++ cfe/cfe/trunk/CodeGen/Makefile Wed Jul 11 11:44:58 2007
@@ -0,0 +1,23 @@
+##===- clang/CodeGen/Makefile ------------------------------*- Makefile -*-===##
+#
+# The LLVM Compiler Infrastructure
+#
+# This file was developed by Chris Lattner and is distributed under
+# the University of Illinois Open Source License. See LICENSE.TXT for details.
+#
+##===----------------------------------------------------------------------===##
+#
+# This implements the AST -> LLVM code generation library for the
+# C-Language front-end.
+#
+##===----------------------------------------------------------------------===##
+
+LEVEL = ../../..
+LIBRARYNAME := clangCodeGen
+BUILD_ARCHIVE = 1
+CXXFLAGS = -fno-rtti
+
+CPPFLAGS += -I$(PROJ_SRC_DIR)/../include
+
+include $(LEVEL)/Makefile.common
+
Propchange: cfe/cfe/trunk/CodeGen/Makefile
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cfe/cfe/trunk/CodeGen/Makefile
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: cfe/cfe/trunk/CodeGen/ModuleBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/CodeGen/ModuleBuilder.cpp?rev=39495&view=auto
==============================================================================
--- cfe/cfe/trunk/CodeGen/ModuleBuilder.cpp (added)
+++ cfe/cfe/trunk/CodeGen/ModuleBuilder.cpp Wed Jul 11 11:44:58 2007
@@ -0,0 +1,40 @@
+//===--- ModuleBuilder.cpp - Emit LLVM Code from ASTs ---------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file was developed by Chris Lattner and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This builds an AST and converts it to LLVM Code.
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/CodeGen/ModuleBuilder.h"
+#include "Builder.h"
+using namespace llvm;
+using namespace clang;
+
+
+/// Init - Create an ModuleBuilder with the specified ASTContext.
+llvm::clang::CodeGen::BuilderTy *
+llvm::clang::CodeGen::Init(ASTContext &Context, Module &M) {
+ return new Builder(Context, M);
+}
+
+void llvm::clang::CodeGen::Terminate(BuilderTy *B) {
+ delete static_cast<Builder*>(B);
+}
+
+/// CodeGenFunction - Convert the AST node for a FunctionDecl into LLVM.
+///
+void llvm::clang::CodeGen::CodeGenFunction(BuilderTy *B, FunctionDecl *D) {
+ static_cast<Builder*>(B)->CodeGenFunction(D);
+}
+
+/// PrintStats - Emit statistic information to stderr.
+///
+void llvm::clang::CodeGen::PrintStats(BuilderTy *B) {
+ static_cast<Builder*>(B)->PrintStats();
+}
Propchange: cfe/cfe/trunk/CodeGen/ModuleBuilder.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cfe/cfe/trunk/CodeGen/ModuleBuilder.cpp
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: cfe/cfe/trunk/Driver/LLVMCodegen.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Driver/LLVMCodegen.cpp?rev=39495&view=auto
==============================================================================
--- cfe/cfe/trunk/Driver/LLVMCodegen.cpp (added)
+++ cfe/cfe/trunk/Driver/LLVMCodegen.cpp Wed Jul 11 11:44:58 2007
@@ -0,0 +1,65 @@
+//===--- LLVMCodegen.cpp - Emit LLVM Code from ASTs -----------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file was developed by Chris Lattner and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This builds an AST and converts it to LLVM Code.
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang.h"
+#include "clang/CodeGen/ModuleBuilder.h"
+#include "clang/Sema/ASTStreamer.h"
+#include "clang/AST/AST.h"
+#include "clang/Lex/Preprocessor.h"
+#include "llvm/Module.h"
+#include <iostream>
+using namespace llvm;
+using namespace clang;
+
+//===----------------------------------------------------------------------===//
+// LLVM Emission
+//===----------------------------------------------------------------------===//
+
+void llvm::clang::EmitLLVMFromASTs(Preprocessor &PP, unsigned MainFileID,
+ bool PrintStats) {
+ Diagnostic &Diags = PP.getDiagnostics();
+ // Create the streamer to read the file.
+ ASTContext Context(PP.getTargetInfo(), PP.getIdentifierTable());
+ ASTStreamerTy *Streamer = ASTStreamer_Init(PP, Context, MainFileID);
+
+ // Create the module to codegen into.
+ Module M("foo");
+
+ CodeGen::BuilderTy *Builder = CodeGen::Init(Context, M);
+
+ while (Decl *D = ASTStreamer_ReadTopLevelDecl(Streamer)) {
+ // FIXME: if (Diags.error ever occurred) continue;
+
+ if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
+ CodeGen::CodeGenFunction(Builder, FD);
+ } else if (isa<TypedefDecl>(D)) {
+ std::cerr << "Read top-level typedef decl: '" << D->getName() << "'\n";
+ } else {
+ std::cerr << "Read top-level variable decl: '" << D->getName() << "'\n";
+ }
+ }
+
+ if (PrintStats) {
+ std::cerr << "\nSTATISTICS:\n";
+ CodeGen::PrintStats(Builder);
+ ASTStreamer_PrintStats(Streamer);
+ Context.PrintStats();
+ }
+
+ CodeGen::Terminate(Builder);
+ ASTStreamer_Terminate(Streamer);
+
+ // Print the generated code.
+ M.print(std::cout);
+}
+
Propchange: cfe/cfe/trunk/Driver/LLVMCodegen.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cfe/cfe/trunk/Driver/LLVMCodegen.cpp
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified: cfe/cfe/trunk/Driver/Makefile
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Driver/Makefile?rev=39495&r1=39494&r2=39495&view=diff
==============================================================================
--- cfe/cfe/trunk/Driver/Makefile (original)
+++ cfe/cfe/trunk/Driver/Makefile Wed Jul 11 11:44:58 2007
@@ -3,6 +3,6 @@
CXXFLAGS = -fno-rtti
TOOLNAME = clang
-USEDLIBS = clangSEMA.a clangAST.a clangParse.a clangLex.a clangBasic.a LLVMSupport.a LLVMSystem.a
+USEDLIBS = LLVMCore.a clangCodeGen.a clangSEMA.a clangAST.a clangParse.a clangLex.a clangBasic.a LLVMSupport.a LLVMSystem.a
include $(LEVEL)/Makefile.common
Modified: cfe/cfe/trunk/Driver/clang.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Driver/clang.cpp?rev=39495&r1=39494&r2=39495&view=diff
==============================================================================
--- cfe/cfe/trunk/Driver/clang.cpp (original)
+++ cfe/cfe/trunk/Driver/clang.cpp Wed Jul 11 11:44:58 2007
@@ -52,6 +52,7 @@
Stats("stats", cl::desc("Print performance metrics and statistics"));
enum ProgActions {
+ EmitLLVM, // Emit a .ll file.
ParseASTPrint, // Parse ASTs and print them.
ParseAST, // Parse ASTs.
ParsePrintCallbacks, // Parse and print each callback.
@@ -82,6 +83,8 @@
"Run parser and build ASTs"),
clEnumValN(ParseASTPrint, "parse-ast-print",
"Run parser, build ASTs, then print ASTs"),
+ clEnumValN(EmitLLVM, "emit-llvm",
+ "Build ASTs then convert to LLVM, emit .ll file"),
clEnumValEnd));
//===----------------------------------------------------------------------===//
@@ -1141,6 +1144,9 @@
case ParseASTPrint:
PrintASTs(PP, MainFileID);
break;
+ case EmitLLVM:
+ EmitLLVMFromASTs(PP, MainFileID, Stats);
+ break;
}
if (Stats) {
Modified: cfe/cfe/trunk/Driver/clang.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Driver/clang.h?rev=39495&r1=39494&r2=39495&view=diff
==============================================================================
--- cfe/cfe/trunk/Driver/clang.h (original)
+++ cfe/cfe/trunk/Driver/clang.h Wed Jul 11 11:44:58 2007
@@ -34,6 +34,10 @@
/// the -arch command line option.
TargetInfo *CreateTargetInfo(Diagnostic &Diags);
+
+void EmitLLVMFromASTs(Preprocessor &PP, unsigned MainFileID,
+ bool PrintStats);
+
} // end namespace clang
} // end namespace llvm
Modified: cfe/cfe/trunk/Makefile
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Makefile?rev=39495&r1=39494&r2=39495&view=diff
==============================================================================
--- cfe/cfe/trunk/Makefile (original)
+++ cfe/cfe/trunk/Makefile Wed Jul 11 11:44:58 2007
@@ -1,5 +1,5 @@
LEVEL = ../..
-DIRS := Basic Lex Parse AST Sema Driver
+DIRS := Basic Lex Parse AST Sema CodeGen Driver
include $(LEVEL)/Makefile.common
Modified: cfe/cfe/trunk/clang.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/clang.xcodeproj/project.pbxproj?rev=39495&r1=39494&r2=39495&view=diff
==============================================================================
--- cfe/cfe/trunk/clang.xcodeproj/project.pbxproj (original)
+++ cfe/cfe/trunk/clang.xcodeproj/project.pbxproj Wed Jul 11 11:44:58 2007
@@ -55,6 +55,10 @@
DE67E7280C02109800F66BC5 /* ASTStreamer.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DE67E7270C02109800F66BC5 /* ASTStreamer.h */; };
DE75ED290B044DC90020CF81 /* ASTContext.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DE75ED280B044DC90020CF81 /* ASTContext.h */; };
DE75EDF10B06880E0020CF81 /* Type.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DE75EDF00B06880E0020CF81 /* Type.cpp */; };
+ DE927FFD0C055DE900231DA4 /* LLVMCodegen.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DE927FFC0C055DE900231DA4 /* LLVMCodegen.cpp */; };
+ DE928B110C05658A00231DA4 /* Builder.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DE928B100C05658A00231DA4 /* Builder.h */; };
+ DE928B130C05659200231DA4 /* ModuleBuilder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DE928B120C05659200231DA4 /* ModuleBuilder.cpp */; };
+ DE928B200C0565B000231DA4 /* ModuleBuilder.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DE928B1F0C0565B000231DA4 /* ModuleBuilder.h */; };
DEAEE98B0A5A2B970045101B /* MultipleIncludeOpt.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DEAEE98A0A5A2B970045101B /* MultipleIncludeOpt.h */; };
DEAEED4B0A5AF89A0045101B /* NOTES.txt in CopyFiles */ = {isa = PBXBuildFile; fileRef = DEAEED4A0A5AF89A0045101B /* NOTES.txt */; };
DEC8D9910A9433CD00353FCA /* Decl.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DEC8D9900A9433CD00353FCA /* Decl.h */; };
@@ -147,6 +151,8 @@
1A869A700BA2164C008DA07A /* LiteralSupport.h in CopyFiles */,
DE67E7150C020EDF00F66BC5 /* Sema.h in CopyFiles */,
DE67E7280C02109800F66BC5 /* ASTStreamer.h in CopyFiles */,
+ DE928B110C05658A00231DA4 /* Builder.h in CopyFiles */,
+ DE928B200C0565B000231DA4 /* ModuleBuilder.h in CopyFiles */,
);
runOnlyForDeploymentPostprocessing = 1;
};
@@ -202,6 +208,10 @@
DE67E7270C02109800F66BC5 /* ASTStreamer.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = ASTStreamer.h; path = clang/Sema/ASTStreamer.h; sourceTree = "<group>"; };
DE75ED280B044DC90020CF81 /* ASTContext.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = ASTContext.h; path = clang/AST/ASTContext.h; sourceTree = "<group>"; };
DE75EDF00B06880E0020CF81 /* Type.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = Type.cpp; path = AST/Type.cpp; sourceTree = "<group>"; };
+ DE927FFC0C055DE900231DA4 /* LLVMCodegen.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = LLVMCodegen.cpp; path = Driver/LLVMCodegen.cpp; sourceTree = "<group>"; };
+ DE928B100C05658A00231DA4 /* Builder.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = Builder.h; path = CodeGen/Builder.h; sourceTree = "<group>"; };
+ DE928B120C05659200231DA4 /* ModuleBuilder.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = ModuleBuilder.cpp; path = CodeGen/ModuleBuilder.cpp; sourceTree = "<group>"; };
+ DE928B1F0C0565B000231DA4 /* ModuleBuilder.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = ModuleBuilder.h; path = clang/CodeGen/ModuleBuilder.h; sourceTree = "<group>"; };
DEAEE98A0A5A2B970045101B /* MultipleIncludeOpt.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = MultipleIncludeOpt.h; sourceTree = "<group>"; };
DEAEED4A0A5AF89A0045101B /* NOTES.txt */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; path = NOTES.txt; sourceTree = "<group>"; };
DEC8D9900A9433CD00353FCA /* Decl.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = Decl.h; path = clang/AST/Decl.h; sourceTree = "<group>"; };
@@ -274,6 +284,7 @@
DE1F22600A7D8C9B00FBF588 /* Parse */,
DEC8D9920A9433F400353FCA /* AST */,
DE67E7070C020EAB00F66BC5 /* Sema */,
+ DE927FCC0C0557CD00231DA4 /* CodeGen */,
);
name = Source;
sourceTree = "<group>";
@@ -345,6 +356,23 @@
name = Sema;
sourceTree = "<group>";
};
+ DE927FCC0C0557CD00231DA4 /* CodeGen */ = {
+ isa = PBXGroup;
+ children = (
+ DE928B100C05658A00231DA4 /* Builder.h */,
+ DE928B120C05659200231DA4 /* ModuleBuilder.cpp */,
+ );
+ name = CodeGen;
+ sourceTree = "<group>";
+ };
+ DE928B140C05659A00231DA4 /* CodeGen */ = {
+ isa = PBXGroup;
+ children = (
+ DE928B1F0C0565B000231DA4 /* ModuleBuilder.h */,
+ );
+ name = CodeGen;
+ sourceTree = "<group>";
+ };
DEAEECAE0A5AF0FA0045101B /* Driver */ = {
isa = PBXGroup;
children = (
@@ -353,6 +381,7 @@
DED627020AE0C51D001E80A4 /* Targets.cpp */,
DED67AEF0B6DB92F00AAD4A3 /* PPCBuiltins.def */,
DED67AED0B6DB92A00AAD4A3 /* X86Builtins.def */,
+ DE927FFC0C055DE900231DA4 /* LLVMCodegen.cpp */,
DE5932CF0AD60FF400BC794C /* PrintParserCallbacks.cpp */,
DE5932D00AD60FF400BC794C /* PrintPreprocessedOutput.cpp */,
);
@@ -400,6 +429,7 @@
DE1F21F20A7D84E800FBF588 /* Parse */,
DEC8D98B0A9433BC00353FCA /* AST */,
DE67E7260C02108300F66BC5 /* Sema */,
+ DE928B140C05659A00231DA4 /* CodeGen */,
);
path = include;
sourceTree = "<group>";
@@ -556,6 +586,8 @@
DE67E7170C020EE400F66BC5 /* Sema.cpp in Sources */,
DE67E71A0C020F4F00F66BC5 /* ASTStreamer.cpp in Sources */,
DE06756C0C051CFE00EBBFD8 /* ParseExprCXX.cpp in Sources */,
+ DE927FFD0C055DE900231DA4 /* LLVMCodegen.cpp in Sources */,
+ DE928B130C05659200231DA4 /* ModuleBuilder.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Added: cfe/cfe/trunk/include/clang/CodeGen/ModuleBuilder.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/CodeGen/ModuleBuilder.h?rev=39495&view=auto
==============================================================================
--- cfe/cfe/trunk/include/clang/CodeGen/ModuleBuilder.h (added)
+++ cfe/cfe/trunk/include/clang/CodeGen/ModuleBuilder.h Wed Jul 11 11:44:58 2007
@@ -0,0 +1,46 @@
+//===--- CodeGen/ModuleBuilder.h - Build LLVM from ASTs ---------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file was developed by Chris Lattner and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file defines the ModuleBuilder interface.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_CODEGEN_MODULEBUILDER_H
+#define LLVM_CLANG_CODEGEN_MODULEBUILDER_H
+
+namespace llvm {
+ class Module;
+namespace clang {
+ class ASTContext;
+ class FunctionDecl;
+
+namespace CodeGen {
+ /// BuilderTy - This is an opaque type used to reference ModuleBuilder
+ /// objects.
+ typedef void BuilderTy;
+
+ /// Init - Create an ModuleBuilder with the specified ASTContext.
+ BuilderTy *Init(ASTContext &Context, Module &M);
+
+ /// CodeGenFunction - Convert the AST node for a FunctionDecl into LLVM.
+ ///
+ void CodeGenFunction(BuilderTy *Builder, FunctionDecl *D);
+
+ /// PrintStats - Emit statistic information to stderr.
+ ///
+ void PrintStats(BuilderTy *Builder);
+
+ /// Terminate - Gracefully shut down the builder.
+ ///
+ void Terminate(BuilderTy *Builder);
+} // end namespace CodeGen
+} // end namespace clang
+} // end namespace llvm
+
+#endif
Propchange: cfe/cfe/trunk/include/clang/CodeGen/ModuleBuilder.h
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cfe/cfe/trunk/include/clang/CodeGen/ModuleBuilder.h
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
More information about the cfe-commits
mailing list