[llvm-commits] CVS: llvm/projects/ModuleMaker/tools/ModuleMaker/Makefile ModuleMaker.cpp

Chris Lattner lattner at cs.uiuc.edu
Thu Aug 21 17:31:02 PDT 2003


Changes in directory llvm/projects/ModuleMaker/tools/ModuleMaker:

Makefile added (r1.1)
ModuleMaker.cpp added (r1.1)

---
Log message:

Initial checkin of ModuleMaker project


---
Diffs of the changes:

Index: llvm/projects/ModuleMaker/tools/ModuleMaker/Makefile
diff -c /dev/null llvm/projects/ModuleMaker/tools/ModuleMaker/Makefile:1.1
*** /dev/null	Thu Aug 21 17:30:02 2003
--- llvm/projects/ModuleMaker/tools/ModuleMaker/Makefile	Thu Aug 21 17:29:52 2003
***************
*** 0 ****
--- 1,25 ----
+ #
+ # LEVEL - Indicate where we are relative to the top of the source tree.
+ #
+ LEVEL=../..
+ 
+ #
+ # TOOLNAME = Give the name of the tool.
+ #
+ TOOLNAME=ModuleMaker
+ 
+ #
+ # LLVMLIBS - List LLVM libraries that we'll need
+ #
+ LLVMLIBS= bcwriter vmcore support.a
+ 
+ # 
+ # USEDLIBS - List all project local libraries here
+ #
+ #USEDLIBS=
+ 
+ #
+ # Include Makefile.common so we know what to do.
+ #
+ include $(LEVEL)/Makefile.common
+ 


Index: llvm/projects/ModuleMaker/tools/ModuleMaker/ModuleMaker.cpp
diff -c /dev/null llvm/projects/ModuleMaker/tools/ModuleMaker/ModuleMaker.cpp:1.1
*** /dev/null	Thu Aug 21 17:30:02 2003
--- llvm/projects/ModuleMaker/tools/ModuleMaker/ModuleMaker.cpp	Thu Aug 21 17:29:52 2003
***************
*** 0 ****
--- 1,52 ----
+ //===- ModuleMaker.cpp - Example project which creates modules --*- C++ -*-===//
+ //
+ // This programs is a simple example that creates an LLVM module "from scratch",
+ // emitting it as a bytecode file to standard out.  This is just to show how
+ // LLVM projects work and to demonstrate some of the LLVM APIs.
+ //
+ //===----------------------------------------------------------------------===//
+ 
+ #include "llvm/Module.h"
+ #include "llvm/DerivedTypes.h"
+ #include "llvm/Constants.h"
+ #include "llvm/Instructions.h"
+ #include "llvm/Bytecode/Writer.h"
+ 
+ int main() {
+   // Create the "module" or "program" or "translation unit" to hold the
+   // function
+   Module *M = new Module("test");
+   
+   // Create the main function: first create the type 'int ()'
+   FunctionType *FT = FunctionType::get(Type::IntTy, std::vector<const Type*>(),
+                                        /*not vararg*/false);
+   
+   // By passing a module as the last parameter to the Function constructor,
+   // it automatically gets appended to the Module.
+   Function *F = new Function(FT, Function::ExternalLinkage, "main", M);
+   
+   // Add a basic block to the function... again, it automatically inserts
+   // because of the last argument.
+   BasicBlock *BB = new BasicBlock("EntryBlock", F);
+   
+   // Get pointers to the constant integers...
+   Value *Two = ConstantSInt::get(Type::IntTy, 2);
+   Value *Three = ConstantSInt::get(Type::IntTy, 3);
+   
+   // Create the add instruction... does not insert...
+   Instruction *Add = BinaryOperator::create(Instruction::Add, Two, Three,
+                                             "addresult");
+   
+   // explicitly insert it into the basic block...
+   BB->getInstList().push_back(Add);
+   
+   // Create the return instruction and add it to the basic block
+   BB->getInstList().push_back(new ReturnInst(Add));
+   
+   // Output the bytecode file to stdout
+   WriteBytecodeToFile(M, std::cout);
+   
+   // Delete the module and all of its contents.
+   delete M;
+   return 0;
+ }





More information about the llvm-commits mailing list