llvm.org GIT mirror llvm / 8ca0eeb
Initial checkin of ModuleMaker project git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8036 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 16 years ago
16 changed file(s) with 403 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 #
1 # This is a sample Makefile for a project that uses LLVM.
2 #
3
4 #
5 # Indicates our relative path to the top of the project's root directory.
6 #
7 LEVEL = .
8
9 #
10 # Directories that needs to be built.
11 #
12 DIRS = tools
13
14 #
15 # Include the Master Makefile that knows how to build all.
16 #
17 include $(LEVEL)/Makefile.common
18
0 #
1 # Set this variable to the top of the LLVM source tree.
2 #
3 LLVM_SRC_ROOT = $(LEVEL)/../..
4
5 #
6 # Include LLVM's Master Makefile.
7 #
8 include $(LLVM_SRC_ROOT)/Makefile.common
9
0 //===- ModuleMaker.cpp - Example project which creates modules --*- C++ -*-===//
1 //
2 // This programs is a simple example that creates an LLVM module "from scratch",
3 // emitting it as a bytecode file to standard out. This is just to show how
4 // LLVM projects work and to demonstrate some of the LLVM APIs.
5 //
6 //===----------------------------------------------------------------------===//
7
8 #include "llvm/Module.h"
9 #include "llvm/DerivedTypes.h"
10 #include "llvm/Constants.h"
11 #include "llvm/Instructions.h"
12 #include "llvm/Bytecode/Writer.h"
13
14 int main() {
15 // Create the "module" or "program" or "translation unit" to hold the
16 // function
17 Module *M = new Module("test");
18
19 // Create the main function: first create the type 'int ()'
20 FunctionType *FT = FunctionType::get(Type::IntTy, std::vector(),
21 /*not vararg*/false);
22
23 // By passing a module as the last parameter to the Function constructor,
24 // it automatically gets appended to the Module.
25 Function *F = new Function(FT, Function::ExternalLinkage, "main", M);
26
27 // Add a basic block to the function... again, it automatically inserts
28 // because of the last argument.
29 BasicBlock *BB = new BasicBlock("EntryBlock", F);
30
31 // Get pointers to the constant integers...
32 Value *Two = ConstantSInt::get(Type::IntTy, 2);
33 Value *Three = ConstantSInt::get(Type::IntTy, 3);
34
35 // Create the add instruction... does not insert...
36 Instruction *Add = BinaryOperator::create(Instruction::Add, Two, Three,
37 "addresult");
38
39 // explicitly insert it into the basic block...
40 BB->getInstList().push_back(Add);
41
42 // Create the return instruction and add it to the basic block
43 BB->getInstList().push_back(new ReturnInst(Add));
44
45 // Output the bytecode file to stdout
46 WriteBytecodeToFile(M, std::cout);
47
48 // Delete the module and all of its contents.
49 delete M;
50 return 0;
51 }
0 #
1 # Relative path to the top of the source tree.
2 #
3 LEVEL=..
4
5 #
6 # List all of the subdirectories that we will compile.
7 #
8 DIRS=ModuleMaker
9
10 include $(LEVEL)/Makefile.common
0 #
1 # LEVEL - Indicate where we are relative to the top of the source tree.
2 #
3 LEVEL=../..
4
5 #
6 # TOOLNAME = Give the name of the tool.
7 #
8 TOOLNAME=ModuleMaker
9
10 #
11 # LLVMLIBS - List LLVM libraries that we'll need
12 #
13 LLVMLIBS= bcwriter vmcore support.a
14
15 #
16 # USEDLIBS - List all project local libraries here
17 #
18 #USEDLIBS=
19
20 #
21 # Include Makefile.common so we know what to do.
22 #
23 include $(LEVEL)/Makefile.common
24
0 //===- ModuleMaker.cpp - Example project which creates modules --*- C++ -*-===//
1 //
2 // This programs is a simple example that creates an LLVM module "from scratch",
3 // emitting it as a bytecode file to standard out. This is just to show how
4 // LLVM projects work and to demonstrate some of the LLVM APIs.
5 //
6 //===----------------------------------------------------------------------===//
7
8 #include "llvm/Module.h"
9 #include "llvm/DerivedTypes.h"
10 #include "llvm/Constants.h"
11 #include "llvm/Instructions.h"
12 #include "llvm/Bytecode/Writer.h"
13
14 int main() {
15 // Create the "module" or "program" or "translation unit" to hold the
16 // function
17 Module *M = new Module("test");
18
19 // Create the main function: first create the type 'int ()'
20 FunctionType *FT = FunctionType::get(Type::IntTy, std::vector(),
21 /*not vararg*/false);
22
23 // By passing a module as the last parameter to the Function constructor,
24 // it automatically gets appended to the Module.
25 Function *F = new Function(FT, Function::ExternalLinkage, "main", M);
26
27 // Add a basic block to the function... again, it automatically inserts
28 // because of the last argument.
29 BasicBlock *BB = new BasicBlock("EntryBlock", F);
30
31 // Get pointers to the constant integers...
32 Value *Two = ConstantSInt::get(Type::IntTy, 2);
33 Value *Three = ConstantSInt::get(Type::IntTy, 3);
34
35 // Create the add instruction... does not insert...
36 Instruction *Add = BinaryOperator::create(Instruction::Add, Two, Three,
37 "addresult");
38
39 // explicitly insert it into the basic block...
40 BB->getInstList().push_back(Add);
41
42 // Create the return instruction and add it to the basic block
43 BB->getInstList().push_back(new ReturnInst(Add));
44
45 // Output the bytecode file to stdout
46 WriteBytecodeToFile(M, std::cout);
47
48 // Delete the module and all of its contents.
49 delete M;
50 return 0;
51 }
0 #
1 # This is a sample Makefile for a project that uses LLVM.
2 #
3
4 #
5 # Indicates our relative path to the top of the project's root directory.
6 #
7 LEVEL = .
8
9 #
10 # Directories that needs to be built.
11 #
12 DIRS = tools
13
14 #
15 # Include the Master Makefile that knows how to build all.
16 #
17 include $(LEVEL)/Makefile.common
18
0 #
1 # Set this variable to the top of the LLVM source tree.
2 #
3 LLVM_SRC_ROOT = $(LEVEL)/../..
4
5 #
6 # Include LLVM's Master Makefile.
7 #
8 include $(LLVM_SRC_ROOT)/Makefile.common
9
0 #
1 # Relative path to the top of the source tree.
2 #
3 LEVEL=..
4
5 #
6 # List all of the subdirectories that we will compile.
7 #
8 DIRS=ModuleMaker
9
10 include $(LEVEL)/Makefile.common
0 #
1 # LEVEL - Indicate where we are relative to the top of the source tree.
2 #
3 LEVEL=../..
4
5 #
6 # TOOLNAME = Give the name of the tool.
7 #
8 TOOLNAME=ModuleMaker
9
10 #
11 # LLVMLIBS - List LLVM libraries that we'll need
12 #
13 LLVMLIBS= bcwriter vmcore support.a
14
15 #
16 # USEDLIBS - List all project local libraries here
17 #
18 #USEDLIBS=
19
20 #
21 # Include Makefile.common so we know what to do.
22 #
23 include $(LEVEL)/Makefile.common
24
0 //===- ModuleMaker.cpp - Example project which creates modules --*- C++ -*-===//
1 //
2 // This programs is a simple example that creates an LLVM module "from scratch",
3 // emitting it as a bytecode file to standard out. This is just to show how
4 // LLVM projects work and to demonstrate some of the LLVM APIs.
5 //
6 //===----------------------------------------------------------------------===//
7
8 #include "llvm/Module.h"
9 #include "llvm/DerivedTypes.h"
10 #include "llvm/Constants.h"
11 #include "llvm/Instructions.h"
12 #include "llvm/Bytecode/Writer.h"
13
14 int main() {
15 // Create the "module" or "program" or "translation unit" to hold the
16 // function
17 Module *M = new Module("test");
18
19 // Create the main function: first create the type 'int ()'
20 FunctionType *FT = FunctionType::get(Type::IntTy, std::vector(),
21 /*not vararg*/false);
22
23 // By passing a module as the last parameter to the Function constructor,
24 // it automatically gets appended to the Module.
25 Function *F = new Function(FT, Function::ExternalLinkage, "main", M);
26
27 // Add a basic block to the function... again, it automatically inserts
28 // because of the last argument.
29 BasicBlock *BB = new BasicBlock("EntryBlock", F);
30
31 // Get pointers to the constant integers...
32 Value *Two = ConstantSInt::get(Type::IntTy, 2);
33 Value *Three = ConstantSInt::get(Type::IntTy, 3);
34
35 // Create the add instruction... does not insert...
36 Instruction *Add = BinaryOperator::create(Instruction::Add, Two, Three,
37 "addresult");
38
39 // explicitly insert it into the basic block...
40 BB->getInstList().push_back(Add);
41
42 // Create the return instruction and add it to the basic block
43 BB->getInstList().push_back(new ReturnInst(Add));
44
45 // Output the bytecode file to stdout
46 WriteBytecodeToFile(M, std::cout);
47
48 // Delete the module and all of its contents.
49 delete M;
50 return 0;
51 }
0 #
1 # This is a sample Makefile for a project that uses LLVM.
2 #
3
4 #
5 # Indicates our relative path to the top of the project's root directory.
6 #
7 LEVEL = .
8
9 #
10 # Directories that needs to be built.
11 #
12 DIRS = tools
13
14 #
15 # Include the Master Makefile that knows how to build all.
16 #
17 include $(LEVEL)/Makefile.common
18
0 #
1 # Set this variable to the top of the LLVM source tree.
2 #
3 LLVM_SRC_ROOT = $(LEVEL)/../..
4
5 #
6 # Include LLVM's Master Makefile.
7 #
8 include $(LLVM_SRC_ROOT)/Makefile.common
9
0 #
1 # Relative path to the top of the source tree.
2 #
3 LEVEL=..
4
5 #
6 # List all of the subdirectories that we will compile.
7 #
8 DIRS=ModuleMaker
9
10 include $(LEVEL)/Makefile.common
0 #
1 # LEVEL - Indicate where we are relative to the top of the source tree.
2 #
3 LEVEL=../..
4
5 #
6 # TOOLNAME = Give the name of the tool.
7 #
8 TOOLNAME=ModuleMaker
9
10 #
11 # LLVMLIBS - List LLVM libraries that we'll need
12 #
13 LLVMLIBS= bcwriter vmcore support.a
14
15 #
16 # USEDLIBS - List all project local libraries here
17 #
18 #USEDLIBS=
19
20 #
21 # Include Makefile.common so we know what to do.
22 #
23 include $(LEVEL)/Makefile.common
24
0 //===- ModuleMaker.cpp - Example project which creates modules --*- C++ -*-===//
1 //
2 // This programs is a simple example that creates an LLVM module "from scratch",
3 // emitting it as a bytecode file to standard out. This is just to show how
4 // LLVM projects work and to demonstrate some of the LLVM APIs.
5 //
6 //===----------------------------------------------------------------------===//
7
8 #include "llvm/Module.h"
9 #include "llvm/DerivedTypes.h"
10 #include "llvm/Constants.h"
11 #include "llvm/Instructions.h"
12 #include "llvm/Bytecode/Writer.h"
13
14 int main() {
15 // Create the "module" or "program" or "translation unit" to hold the
16 // function
17 Module *M = new Module("test");
18
19 // Create the main function: first create the type 'int ()'
20 FunctionType *FT = FunctionType::get(Type::IntTy, std::vector(),
21 /*not vararg*/false);
22
23 // By passing a module as the last parameter to the Function constructor,
24 // it automatically gets appended to the Module.
25 Function *F = new Function(FT, Function::ExternalLinkage, "main", M);
26
27 // Add a basic block to the function... again, it automatically inserts
28 // because of the last argument.
29 BasicBlock *BB = new BasicBlock("EntryBlock", F);
30
31 // Get pointers to the constant integers...
32 Value *Two = ConstantSInt::get(Type::IntTy, 2);
33 Value *Three = ConstantSInt::get(Type::IntTy, 3);
34
35 // Create the add instruction... does not insert...
36 Instruction *Add = BinaryOperator::create(Instruction::Add, Two, Three,
37 "addresult");
38
39 // explicitly insert it into the basic block...
40 BB->getInstList().push_back(Add);
41
42 // Create the return instruction and add it to the basic block
43 BB->getInstList().push_back(new ReturnInst(Add));
44
45 // Output the bytecode file to stdout
46 WriteBytecodeToFile(M, std::cout);
47
48 // Delete the module and all of its contents.
49 delete M;
50 return 0;
51 }