projects
/
oota-llvm.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
minor tidying of comments.
[oota-llvm.git]
/
examples
/
ModuleMaker
/
ModuleMaker.cpp
diff --git
a/examples/ModuleMaker/ModuleMaker.cpp
b/examples/ModuleMaker/ModuleMaker.cpp
index a057a8c8a1046468f8d140d1e7439a7435c868ee..154e24065c0a82cef9b0a5fadb932d97f0e6671b 100644
(file)
--- a/
examples/ModuleMaker/ModuleMaker.cpp
+++ b/
examples/ModuleMaker/ModuleMaker.cpp
@@
-1,7
+1,14
@@
//===- examples/ModuleMaker/ModuleMaker.cpp - Example project ---*- C++ -*-===//
//
//===- examples/ModuleMaker/ModuleMaker.cpp - Example project ---*- C++ -*-===//
//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
// This programs is a simple example that creates an LLVM module "from scratch",
// This programs is a simple example that creates an LLVM module "from scratch",
-// emitting it as a b
yte
code file to standard out. This is just to show how
+// emitting it as a b
it
code file to standard out. This is just to show how
// LLVM projects work and to demonstrate some of the LLVM APIs.
//
//===----------------------------------------------------------------------===//
// LLVM projects work and to demonstrate some of the LLVM APIs.
//
//===----------------------------------------------------------------------===//
@@
-10,45
+17,44
@@
#include "llvm/DerivedTypes.h"
#include "llvm/Constants.h"
#include "llvm/Instructions.h"
#include "llvm/DerivedTypes.h"
#include "llvm/Constants.h"
#include "llvm/Instructions.h"
-#include "llvm/B
ytecode/
Writer.h"
+#include "llvm/B
itcode/Reader
Writer.h"
#include <iostream>
#include <iostream>
-
using namespace llvm;
int main() {
// Create the "module" or "program" or "translation unit" to hold the
// function
Module *M = new Module("test");
using namespace llvm;
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 ()'
// Create the main function: first create the type 'int ()'
- FunctionType *FT = FunctionType::get(Type::IntTy, std::vector<const Type*>(),
+ FunctionType *FT = FunctionType::get(Type::Int
32
Ty, std::vector<const Type*>(),
/*not vararg*/false);
/*not vararg*/false);
-
+
// By passing a module as the last parameter to the Function constructor,
// it automatically gets appended to the Module.
// 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);
-
+ Function *F =
Function::Create
(FT, Function::ExternalLinkage, "main", M);
+
// Add a basic block to the function... again, it automatically inserts
// because of the last argument.
// Add a basic block to the function... again, it automatically inserts
// because of the last argument.
- BasicBlock *BB =
new BasicBlock
("EntryBlock", F);
-
+ BasicBlock *BB =
BasicBlock::Create
("EntryBlock", F);
+
// Get pointers to the constant integers...
// Get pointers to the constant integers...
- Value *Two = Constant
SInt::get(Type::Int
Ty, 2);
- Value *Three = Constant
SInt::get(Type::Int
Ty, 3);
-
+ Value *Two = Constant
Int::get(Type::Int32
Ty, 2);
+ Value *Three = Constant
Int::get(Type::Int32
Ty, 3);
+
// Create the add instruction... does not insert...
// Create the add instruction... does not insert...
- Instruction *Add = BinaryOperator::
c
reate(Instruction::Add, Two, Three,
+ Instruction *Add = BinaryOperator::
C
reate(Instruction::Add, Two, Three,
"addresult");
"addresult");
-
+
// explicitly insert it into the basic block...
BB->getInstList().push_back(Add);
// explicitly insert it into the basic block...
BB->getInstList().push_back(Add);
-
+
// Create the return instruction and add it to the basic block
// Create the return instruction and add it to the basic block
- BB->getInstList().push_back(
new ReturnInst
(Add));
-
- // Output the b
yte
code file to stdout
- WriteB
yte
codeToFile(M, std::cout);
-
+ BB->getInstList().push_back(
ReturnInst::Create
(Add));
+
+ // Output the b
it
code file to stdout
+ WriteB
it
codeToFile(M, std::cout);
+
// Delete the module and all of its contents.
delete M;
return 0;
// Delete the module and all of its contents.
delete M;
return 0;