llvm.org GIT mirror llvm / 237cef4
Remove trailing whitespace at the end of lines git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21380 91177308-0d34-0410-b5e6-96231b3b80d8 Misha Brukman 14 years ago
4 changed file(s) with 41 addition(s) and 41 deletion(s). Raw diff Collapse all Expand all
0 //===-- BFtoLLVM.cpp - BF language Front End for LLVM ---------------------===//
1 //
1 //
22 // The LLVM Compiler Infrastructure
33 //
44 // This file was developed by the LLVM research group and is distributed under
55 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
6 //
77 //===----------------------------------------------------------------------===//
88 //
99 // This is a simple front end for the BF language. It is compatible with the
5959 std::string ptr = gensym (op + "ptr"),
6060 val = gensym (op + "val"),
6161 result = gensym (op + "result");
62 dest << ptr << " = load sbyte** %ptrbox\n"
62 dest << ptr << " = load sbyte** %ptrbox\n"
6363 << val << " = load sbyte* " << ptr << "\n"
6464 << result << " = add sbyte " << val << ", " << (int)delta << "\n"
6565 << "store sbyte " << result << ", sbyte* " << ptr << "\n";
171171
172172 char *sourceFileName = argv[1];
173173 char *destFileName = argv[2];
174
174
175175 std::ifstream src (sourceFileName);
176176 if (!src.good()) {
177177 std::cerr << sourceFileName << ": " << strerror(errno) << "\n";
183183 std::cerr << destFileName << ": " << strerror(errno) << "\n";
184184 return 1;
185185 }
186
186
187187 emitDeclarations(dest);
188188 emitMainFunctionProlog(dest);
189189
198198 repeatCount = 0;
199199 }
200200 consume (lastCh, repeatCount, dest);
201
201
202202 emitMainFunctionEpilog(dest);
203203
204204 src.close();
0 //===--- examples/Fibonacci/fibonacci.cpp - An example use of the JIT -----===//
1 //
1 //
22 // The LLVM Compiler Infrastructure
33 //
44 // This file was developed by Valery A. Khamenya and is distributed under the
55 // University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
6 //
77 //===----------------------------------------------------------------------===//
88 //
99 // This small program provides an example of how to build quickly a small module
1616 // if(x<=2) return 1;
1717 // return fib(x-1)+fib(x-2);
1818 // }
19 //
19 //
2020 // Once we have this, we compile the module via JIT, then execute the `fib'
2121 // function and return result to a driver, i.e. to a "host program".
2222 //
3737 // Create the fib function and insert it into module M. This function is said
3838 // to return an int and take an int parameter.
3939 Function *FibF = M->getOrInsertFunction("fib", Type::IntTy, Type::IntTy, 0);
40
40
4141 // Add a basic block to the function.
4242 BasicBlock *BB = new BasicBlock("EntryBlock", FibF);
43
43
4444 // Get pointers to the constants.
4545 Value *One = ConstantSInt::get(Type::IntTy, 1);
4646 Value *Two = ConstantSInt::get(Type::IntTy, 2);
6060
6161 // Create: ret int 1
6262 new ReturnInst(One, RetBB);
63
63
6464 // create fib(x-1)
6565 Value *Sub = BinaryOperator::createSub(ArgX, One, "arg", RecurseBB);
6666 Value *CallFibX1 = new CallInst(FibF, Sub, "fibx1", RecurseBB);
67
67
6868 // create fib(x-2)
6969 Sub = BinaryOperator::createSub(ArgX, Two, "arg", RecurseBB);
7070 Value *CallFibX2 = new CallInst(FibF, Sub, "fibx2", RecurseBB);
7272 // fib(x-1)+fib(x-2)
7373 Value *Sum = BinaryOperator::createAdd(CallFibX1, CallFibX2,
7474 "addresult", RecurseBB);
75
75
7676 // Create the return instruction and add it to the basic block
7777 new ReturnInst(Sum, RecurseBB);
7878
8989 // We are about to create the "fib" function:
9090 Function *FibF = CreateFibFunction(M);
9191
92 // Now we going to create JIT
92 // Now we going to create JIT
9393 ExistingModuleProvider *MP = new ExistingModuleProvider(M);
9494 ExecutionEngine *EE = ExecutionEngine::create(MP, false);
9595
0 //===-- examples/HowToUseJIT/HowToUseJIT.cpp - An example use of the JIT --===//
1 //
1 //
22 // The LLVM Compiler Infrastructure
33 //
44 // This file was developed by Valery A. Khamenya and is distributed under the
55 // University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
6 //
77 //===----------------------------------------------------------------------===//
88 //
99 // This small program provides an example of how to quickly build a small
10 // module with two functions and execute it with the JIT.
11 //
12 // Goal:
10 // module with two functions and execute it with the JIT.
11 //
12 // Goal:
1313 // The goal of this snippet is to create in the memory
1414 // the LLVM module consisting of two functions as follow:
1515 //
1616 // int add1(int x) {
1717 // return x+1;
1818 // }
19 //
19 //
2020 // int foo() {
2121 // return add1(10);
2222 // }
23 //
24 // then compile the module via JIT, then execute the `foo'
23 //
24 // then compile the module via JIT, then execute the `foo'
2525 // function and return result to a driver, i.e. to a "host program".
26 //
26 //
2727 // Some remarks and questions:
28 //
28 //
2929 // - could we invoke some code using noname functions too?
30 // e.g. evaluate "foo()+foo()" without fears to introduce
30 // e.g. evaluate "foo()+foo()" without fears to introduce
3131 // conflict of temporary function name with some real
3232 // existing function name?
33 //
33 //
3434 //===----------------------------------------------------------------------===//
3535
3636 #include "llvm/Module.h"
5555 // Add a basic block to the function. As before, it automatically inserts
5656 // because of the last argument.
5757 BasicBlock *BB = new BasicBlock("EntryBlock", Add1F);
58
58
5959 // Get pointers to the constant `1'.
6060 Value *One = ConstantSInt::get(Type::IntTy, 1);
6161
6666
6767 // Create the add instruction, inserting it into the end of BB.
6868 Instruction *Add = BinaryOperator::createAdd(One, ArgX, "addresult", BB);
69
69
7070 // Create the return instruction and add it to the basic block
7171 new ReturnInst(Add, BB);
7272
8787 std::vector Params;
8888 Params.push_back(Ten);
8989 CallInst * Add1CallRes = new CallInst(Add1F, Params, "add1", BB);
90
90
9191 // Create the return instruction and add it to the basic block.
9292 new ReturnInst(Add1CallRes, BB);
9393
0 //===- examples/ModuleMaker/ModuleMaker.cpp - Example project ---*- C++ -*-===//
1 //
1 //
22 // The LLVM Compiler Infrastructure
33 //
44 // This file was developed by the LLVM research group and is distributed under
55 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
6 //
77 //===----------------------------------------------------------------------===//
88 //
99 // This programs is a simple example that creates an LLVM module "from scratch",
2525 // Create the "module" or "program" or "translation unit" to hold the
2626 // function
2727 Module *M = new Module("test");
28
28
2929 // Create the main function: first create the type 'int ()'
3030 FunctionType *FT = FunctionType::get(Type::IntTy, std::vector(),
3131 /*not vararg*/false);
32
32
3333 // By passing a module as the last parameter to the Function constructor,
3434 // it automatically gets appended to the Module.
3535 Function *F = new Function(FT, Function::ExternalLinkage, "main", M);
36
36
3737 // Add a basic block to the function... again, it automatically inserts
3838 // because of the last argument.
3939 BasicBlock *BB = new BasicBlock("EntryBlock", F);
40
40
4141 // Get pointers to the constant integers...
4242 Value *Two = ConstantSInt::get(Type::IntTy, 2);
4343 Value *Three = ConstantSInt::get(Type::IntTy, 3);
44
44
4545 // Create the add instruction... does not insert...
4646 Instruction *Add = BinaryOperator::create(Instruction::Add, Two, Three,
4747 "addresult");
48
48
4949 // explicitly insert it into the basic block...
5050 BB->getInstList().push_back(Add);
51
51
5252 // Create the return instruction and add it to the basic block
5353 BB->getInstList().push_back(new ReturnInst(Add));
54
54
5555 // Output the bytecode file to stdout
5656 WriteBytecodeToFile(M, std::cout);
57
57
5858 // Delete the module and all of its contents.
5959 delete M;
6060 return 0;