1
0
mirror of https://github.com/c64scene-ar/llvm-6502.git synced 2025-04-14 06:37:33 +00:00

Moved the "SmallExamples" out of the /projects directory and into a new

/examples directory. History was maintained. These programs do not need to
be configured but things in /projects must be.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16002 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Reid Spencer 2004-08-23 19:28:39 +00:00
parent c21214ac59
commit 157b956e42
20 changed files with 0 additions and 18489 deletions

@ -1,15 +0,0 @@
##===- projects/HowToUseJIT/Makefile -----------------------*- Makefile -*-===##
#
# The LLVM Compiler Infrastructure
#
# This file was developed by Valery A. Khamenya and is distributed under
# the University of Illinois Open Source License. See LICENSE.TXT for details.
#
##===----------------------------------------------------------------------===##
LEVEL = ../../..
TOOLNAME = Fibonacci
USEDLIBS = lli-jit lli-interpreter codegen executionengine x86 selectiondag \
scalaropts analysis.a transformutils.a bcreader target.a vmcore \
support.a
include $(LEVEL)/Makefile.common

@ -1,188 +0,0 @@
//===--- fibonacci.cpp - An example use of the JIT ----------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file was developed by Valery A. Khamenya and is distributed under the
// University of Illinois Open Source License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This small program provides an example of how to build quickly a small
// module with function Fibonacci and execute it with the JIT.
//
// This simple example shows as well 30% speed up with LLVM 1.3
// in comparison to gcc 3.3.3 at AMD Athlon XP 1500+ .
//
// (Modified from HowToUseJIT.cpp and Stacker/lib/compiler/StackerCompiler.cpp)
//
//===------------------------------------------------------------------------===
// Goal:
// The goal of this snippet is to create in the memory
// the LLVM module consisting of one function as follow:
//
// int fib(int x) {
// if(x<=2) return 1;
// return fib(x-1)+fib(x-2);
// }
//
// then compile the module via JIT, then execute the `fib'
// function and return result to a driver, i.e. to a "host program".
//
#include <iostream>
#include <llvm/Module.h>
#include <llvm/DerivedTypes.h>
#include <llvm/Constants.h>
#include <llvm/Instructions.h>
#include <llvm/ModuleProvider.h>
#include <llvm/Analysis/Verifier.h>
#include "llvm/ExecutionEngine/ExecutionEngine.h"
#include "llvm/ExecutionEngine/GenericValue.h"
using namespace llvm;
int main(int argc, char**argv) {
int n = argc > 1 ? atol(argv[1]) : 44;
// Create some module to put our function into it.
Module *M = new Module("test");
// We are about to create the "fib" function:
Function *FibF;
{
// first create type for the single argument of fib function:
// the type is 'int ()'
std::vector<const Type*> ArgT(1);
ArgT[0] = Type::IntTy;
// now create full type of the "fib" function:
FunctionType *FibT = FunctionType::get(Type::IntTy, // type of result
ArgT,
/*not vararg*/false);
// Now create the fib function entry and
// insert this entry into module M
// (By passing a module as the last parameter to the Function constructor,
// it automatically gets appended to the Module.)
FibF = new Function(FibT,
Function::ExternalLinkage, // maybe too much
"fib", M);
// Add a basic block to the function... (again, it automatically inserts
// because of the last argument.)
BasicBlock *BB = new BasicBlock("EntryBlock of fib function", FibF);
// Get pointers to the constants ...
Value *One = ConstantSInt::get(Type::IntTy, 1);
Value *Two = ConstantSInt::get(Type::IntTy, 2);
// Get pointers to the integer argument of the add1 function...
assert(FibF->abegin() != FibF->aend()); // Make sure there's an arg
Argument &ArgX = FibF->afront(); // Get the arg
ArgX.setName("AnArg"); // Give it a nice symbolic name for fun.
SetCondInst* CondInst
= new SetCondInst( Instruction::SetLE,
&ArgX, Two );
BB->getInstList().push_back(CondInst);
// Create the true_block
BasicBlock* true_bb = new BasicBlock("arg<=2");
// Create the return instruction and add it
// to the basic block for true case:
true_bb->getInstList().push_back(new ReturnInst(One));
// Create an exit block
BasicBlock* exit_bb = new BasicBlock("arg>2");
{
// create fib(x-1)
CallInst* CallFibX1;
{
// Create the sub instruction... does not insert...
Instruction *Sub
= BinaryOperator::create(Instruction::Sub, &ArgX, One,
"arg");
exit_bb->getInstList().push_back(Sub);
CallFibX1 = new CallInst(FibF, Sub, "fib(x-1)");
exit_bb->getInstList().push_back(CallFibX1);
}
// create fib(x-2)
CallInst* CallFibX2;
{
// Create the sub instruction... does not insert...
Instruction * Sub
= BinaryOperator::create(Instruction::Sub, &ArgX, Two,
"arg");
exit_bb->getInstList().push_back(Sub);
CallFibX2 = new CallInst(FibF, Sub, "fib(x-2)");
exit_bb->getInstList().push_back(CallFibX2);
}
// Create the add instruction... does not insert...
Instruction *Add =
BinaryOperator::create(Instruction::Add,
CallFibX1, CallFibX2, "addresult");
// explicitly insert it into the basic block...
exit_bb->getInstList().push_back(Add);
// Create the return instruction and add it to the basic block
exit_bb->getInstList().push_back(new ReturnInst(Add));
}
// Create a branch on the SetCond
BranchInst* br_inst =
new BranchInst( true_bb, exit_bb, CondInst );
BB->getInstList().push_back( br_inst );
FibF->getBasicBlockList().push_back(true_bb);
FibF->getBasicBlockList().push_back(exit_bb);
}
// Now we going to create JIT
ExistingModuleProvider* MP = new ExistingModuleProvider(M);
ExecutionEngine* EE = ExecutionEngine::create( MP, false );
// Call the `foo' function with argument n:
std::vector<GenericValue> args(1);
args[0].IntVal = n;
std::clog << "verifying... ";
if (verifyModule(*M)) {
std::cerr << argv[0]
<< ": assembly parsed, but does not verify as correct!\n";
return 1;
}
else
std::clog << "OK\n";
std::clog << "We just constructed this LLVM module:\n\n---------\n" << *M;
std::clog << "---------\nstarting fibonacci("
<< n << ") with JIT...\n" << std::flush;
GenericValue gv = EE->runFunction(FibF, args);
// import result of execution:
std::cout << "Result: " << gv.IntVal << std:: endl;
return 0;
}

@ -1,109 +0,0 @@
//===--- HowToUseJIT.cpp - An example use of the JIT ----------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file was developed by Valery A. Khamenya and is distributed under the
// University of Illinois Open Source License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This small program provides an example of how to quickly build a small
// module with two functions and execute it with the JIT.
//
// Goal:
// The goal of this snippet is to create in the memory
// the LLVM module consisting of two functions as follow:
//
// int add1(int x) {
// return x+1;
// }
//
// int foo() {
// return add1(10);
// }
//
// then compile the module via JIT, then execute the `foo'
// function and return result to a driver, i.e. to a "host program".
//
// Some remarks and questions:
//
// - could we invoke some code using noname functions too?
// e.g. evaluate "foo()+foo()" without fears to introduce
// conflict of temporary function name with some real
// existing function name?
//
//===----------------------------------------------------------------------===//
#include "llvm/Module.h"
#include "llvm/Constants.h"
#include "llvm/Type.h"
#include "llvm/Instructions.h"
#include "llvm/ModuleProvider.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"
#include "llvm/ExecutionEngine/GenericValue.h"
#include <iostream>
using namespace llvm;
int main() {
// Create some module to put our function into it.
Module *M = new Module("test");
// Create the add1 function entry and insert this entry into module M. The
// function will have a return type of "int" and take an argument of "int".
// The '0' terminates the list of argument types.
Function *Add1F = M->getOrInsertFunction("add1", Type::IntTy, Type::IntTy, 0);
// Add a basic block to the function. As before, it automatically inserts
// because of the last argument.
BasicBlock *BB = new BasicBlock("EntryBlock", Add1F);
// Get pointers to the constant `1'.
Value *One = ConstantSInt::get(Type::IntTy, 1);
// Get pointers to the integer argument of the add1 function...
assert(Add1F->abegin() != Add1F->aend()); // Make sure there's an arg
Argument *ArgX = Add1F->abegin(); // Get the arg
ArgX->setName("AnArg"); // Give it a nice symbolic name for fun.
// Create the add instruction, inserting it into the end of BB.
Instruction *Add = BinaryOperator::createAdd(One, ArgX, "addresult", BB);
// Create the return instruction and add it to the basic block
new ReturnInst(Add, BB);
// Now, function add1 is ready.
// Now we going to create function `foo', which returns an int and takes no
// arguments.
Function *FooF = M->getOrInsertFunction("foo", Type::IntTy, 0);
// Add a basic block to the FooF function.
BB = new BasicBlock("EntryBlock", FooF);
// Get pointers to the constant `10'.
Value *Ten = ConstantSInt::get(Type::IntTy, 10);
// Pass Ten to the call call:
std::vector<Value*> Params;
Params.push_back(Ten);
CallInst * Add1CallRes = new CallInst(Add1F, Params, "add1", BB);
// Create the return instruction and add it to the basic block.
new ReturnInst(Add1CallRes, BB);
// Now we create the JIT.
ExistingModuleProvider* MP = new ExistingModuleProvider(M);
ExecutionEngine* EE = ExecutionEngine::create(MP, false);
std::cout << "We just constructed this LLVM module:\n\n" << *M;
std::cout << "\n\nRunning foo: " << std::flush;
// Call the `foo' function with no arguments:
std::vector<GenericValue> noargs;
GenericValue gv = EE->runFunction(FooF, noargs);
// Import result of execution:
std::cout << "Result: " << gv.IntVal << "\n";
return 0;
}

@ -1,15 +0,0 @@
##===- projects/HowToUseJIT/Makefile -----------------------*- Makefile -*-===##
#
# The LLVM Compiler Infrastructure
#
# This file was developed by Valery A. Khamenya and is distributed under
# the University of Illinois Open Source License. See LICENSE.TXT for details.
#
##===----------------------------------------------------------------------===##
LEVEL = ../../..
TOOLNAME = HowToUseJIT
USEDLIBS = lli-jit lli-interpreter codegen executionengine x86 selectiondag \
scalaropts analysis.a transformutils.a bcreader target.a vmcore \
support.a
include $(LEVEL)/Makefile.common

@ -1,15 +0,0 @@
##===- projects/Makefile ------------------------------*- Makefile -*-===##
#
# The LLVM Compiler Infrastructure
#
# This file was developed by the LLVM research group and is distributed under
# the University of Illinois Open Source License. See LICENSE.TXT for details.
#
##===----------------------------------------------------------------------===##
LEVEL=../..
include $(LEVEL)/Makefile.config
DIRS = Fibonacci HowToUseJIT
include $(BUILD_SRC_ROOT)/Makefile.rules

@ -1,27 +0,0 @@
##===- projects/ModuleMaker/Makefile -----------------------*- Makefile -*-===##
#
# The LLVM Compiler Infrastructure
#
# This file was developed by the LLVM research group and is distributed under
# the University of Illinois Open Source License. See LICENSE.TXT for details.
#
##===----------------------------------------------------------------------===##
#
# This is a sample Makefile for a project that uses LLVM.
#
#
# Indicates our relative path to the top of the project's root directory.
#
LEVEL = .
#
# Directories that needs to be built.
#
DIRS = tools
#
# Include the Master Makefile that knows how to build all.
#
include $(LEVEL)/Makefile.common

@ -1,23 +0,0 @@
#
# Configure the location of the LLVM object root. We know it is two
# directories up. The source tree location we do not know; let the LLVM
# Makefiles find it for us.
#
LLVM_OBJ_ROOT=$(LEVEL)/../../..
#
# Grab the LLVM configuration file.
#
include $(LEVEL)/../../../Makefile.config
#
# Reconfigure the source directories
#
BUILD_SRC_ROOT:=$(LLVM_SRC_ROOT)/projects/SmallExamples/ModuleMaker
BUILD_SRC_DIR := $(subst //,/,$(BUILD_SRC_ROOT)/$(patsubst $(BUILD_OBJ_ROOT)%,%,$(BUILD_OBJ_DIR)))
#
# Include LLVM's build rules.
#
include $(LLVM_SRC_ROOT)/Makefile.rules

@ -1,9 +0,0 @@
//===----------------------------------------------------------------------===//
// ModuleMaker Sample project
//===----------------------------------------------------------------------===//
This project is a extremely simple example of two things: building an LLVM
"project" and using some simple pieces of the LLVM API. The actual executable
generated by this project simply emits an LLVM bytecode file to standard output.
It is designed to show some basic usage of LLVM APIs, and how to link to LLVM
libraries.

@ -1,24 +0,0 @@
------------------------------------------------------------------------------
Autoconf Files
------------------------------------------------------------------------------
All autoconf files are licensed under the LLVM license with the following
additions:
llvm/autoconf/install-sh:
This script is licensed under the LLVM license, with the following
additional copyrights and restrictions:
Copyright 1991 by the Massachusetts Institute of Technology
Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that
the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation, and that the name of M.I.T. not be used in advertising or
publicity pertaining to distribution of the software without specific,
written prior permission. M.I.T. makes no representations about the
suitability of this software for any purpose. It is provided "as is"
without express or implied warranty.
Please see the source files for additional copyrights.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -1,60 +0,0 @@
dnl **************************************************************************
dnl * Initialize
dnl **************************************************************************
AC_INIT([[[ModuleMaker]]],[[[x.xx]]],[bugs@yourdomain])
dnl Place all of the extra autoconf files into the config subdirectory
AC_CONFIG_AUX_DIR([autoconf])
dnl Configure a header file
dnl Configure Makefiles
dnl List every Makefile that exists within your source tree
AC_CONFIG_MAKEFILE(Makefile)
dnl **************************************************************************
dnl * Determine which system we are building on
dnl **************************************************************************
dnl **************************************************************************
dnl * Check for programs.
dnl **************************************************************************
dnl Verify that the source directory is valid
AC_CONFIG_SRCDIR(["Makefile.common.in"])
dnl **************************************************************************
dnl * Check for libraries.
dnl **************************************************************************
dnl **************************************************************************
dnl * Checks for header files.
dnl **************************************************************************
dnl **************************************************************************
dnl * Checks for typedefs, structures, and compiler characteristics.
dnl **************************************************************************
dnl **************************************************************************
dnl * Checks for library functions.
dnl **************************************************************************
dnl **************************************************************************
dnl * Enable various compile-time options
dnl **************************************************************************
dnl **************************************************************************
dnl * Set the location of various third-party software packages
dnl **************************************************************************
dnl Location of LLVM source code
AC_ARG_WITH(llvmsrc,AC_HELP_STRING([--with-llvmsrc],[Location of LLVM Source Code]),AC_SUBST(LLVM_SRC,[$withval]),AC_SUBST(LLVM_SRC,[`cd ${srcdir}/../..; pwd`]))
dnl Location of LLVM object code
AC_ARG_WITH(llvmobj,AC_HELP_STRING([--with-llvmobj],[Location of LLVM Object Code]),AC_SUBST(LLVM_OBJ,[$withval]),AC_SUBST(LLVM_OBJ,[`cd ../..; pwd`]))
dnl **************************************************************************
dnl * Create the output files
dnl **************************************************************************
AC_OUTPUT(Makefile.common)

@ -1,251 +0,0 @@
#!/bin/sh
#
# install - install a program, script, or datafile
# This comes from X11R5 (mit/util/scripts/install.sh).
#
# Copyright 1991 by the Massachusetts Institute of Technology
#
# Permission to use, copy, modify, distribute, and sell this software and its
# documentation for any purpose is hereby granted without fee, provided that
# the above copyright notice appear in all copies and that both that
# copyright notice and this permission notice appear in supporting
# documentation, and that the name of M.I.T. not be used in advertising or
# publicity pertaining to distribution of the software without specific,
# written prior permission. M.I.T. makes no representations about the
# suitability of this software for any purpose. It is provided "as is"
# without express or implied warranty.
#
# Calling this script install-sh is preferred over install.sh, to prevent
# `make' implicit rules from creating a file called install from it
# when there is no Makefile.
#
# This script is compatible with the BSD install script, but was written
# from scratch. It can only install one file at a time, a restriction
# shared with many OS's install programs.
# set DOITPROG to echo to test this script
# Don't use :- since 4.3BSD and earlier shells don't like it.
doit="${DOITPROG-}"
# put in absolute paths if you don't have them in your path; or use env. vars.
mvprog="${MVPROG-mv}"
cpprog="${CPPROG-cp}"
chmodprog="${CHMODPROG-chmod}"
chownprog="${CHOWNPROG-chown}"
chgrpprog="${CHGRPPROG-chgrp}"
stripprog="${STRIPPROG-strip}"
rmprog="${RMPROG-rm}"
mkdirprog="${MKDIRPROG-mkdir}"
transformbasename=""
transform_arg=""
instcmd="$mvprog"
chmodcmd="$chmodprog 0755"
chowncmd=""
chgrpcmd=""
stripcmd=""
rmcmd="$rmprog -f"
mvcmd="$mvprog"
src=""
dst=""
dir_arg=""
while [ x"$1" != x ]; do
case $1 in
-c) instcmd="$cpprog"
shift
continue;;
-d) dir_arg=true
shift
continue;;
-m) chmodcmd="$chmodprog $2"
shift
shift
continue;;
-o) chowncmd="$chownprog $2"
shift
shift
continue;;
-g) chgrpcmd="$chgrpprog $2"
shift
shift
continue;;
-s) stripcmd="$stripprog"
shift
continue;;
-t=*) transformarg=`echo $1 | sed 's/-t=//'`
shift
continue;;
-b=*) transformbasename=`echo $1 | sed 's/-b=//'`
shift
continue;;
*) if [ x"$src" = x ]
then
src=$1
else
# this colon is to work around a 386BSD /bin/sh bug
:
dst=$1
fi
shift
continue;;
esac
done
if [ x"$src" = x ]
then
echo "install: no input file specified"
exit 1
else
:
fi
if [ x"$dir_arg" != x ]; then
dst=$src
src=""
if [ -d $dst ]; then
instcmd=:
chmodcmd=""
else
instcmd=$mkdirprog
fi
else
# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
# might cause directories to be created, which would be especially bad
# if $src (and thus $dsttmp) contains '*'.
if [ -f $src -o -d $src ]
then
:
else
echo "install: $src does not exist"
exit 1
fi
if [ x"$dst" = x ]
then
echo "install: no destination specified"
exit 1
else
:
fi
# If destination is a directory, append the input filename; if your system
# does not like double slashes in filenames, you may need to add some logic
if [ -d $dst ]
then
dst="$dst"/`basename $src`
else
:
fi
fi
## this sed command emulates the dirname command
dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
# Make sure that the destination directory exists.
# this part is taken from Noah Friedman's mkinstalldirs script
# Skip lots of stat calls in the usual case.
if [ ! -d "$dstdir" ]; then
defaultIFS='
'
IFS="${IFS-${defaultIFS}}"
oIFS="${IFS}"
# Some sh's can't handle IFS=/ for some reason.
IFS='%'
set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
IFS="${oIFS}"
pathcomp=''
while [ $# -ne 0 ] ; do
pathcomp="${pathcomp}${1}"
shift
if [ ! -d "${pathcomp}" ] ;
then
$mkdirprog "${pathcomp}"
else
:
fi
pathcomp="${pathcomp}/"
done
fi
if [ x"$dir_arg" != x ]
then
$doit $instcmd $dst &&
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else : ; fi &&
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else : ; fi &&
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else : ; fi &&
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else : ; fi
else
# If we're going to rename the final executable, determine the name now.
if [ x"$transformarg" = x ]
then
dstfile=`basename $dst`
else
dstfile=`basename $dst $transformbasename |
sed $transformarg`$transformbasename
fi
# don't allow the sed command to completely eliminate the filename
if [ x"$dstfile" = x ]
then
dstfile=`basename $dst`
else
:
fi
# Make a temp file name in the proper directory.
dsttmp=$dstdir/#inst.$$#
# Move or copy the file name to the temp name
$doit $instcmd $src $dsttmp &&
trap "rm -f ${dsttmp}" 0 &&
# and set any options; do chmod last to preserve setuid bits
# If any of these fail, we abort the whole thing. If we want to
# ignore errors from any of these, just make sure not to ignore
# errors from the above "$doit $instcmd $src $dsttmp" command.
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else :;fi &&
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else :;fi &&
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else :;fi &&
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else :;fi &&
# Now rename the file to the real destination.
$doit $rmcmd -f $dstdir/$dstfile &&
$doit $mvcmd $dsttmp $dstdir/$dstfile
fi &&
exit 0

File diff suppressed because it is too large Load Diff

@ -1,101 +0,0 @@
#! /bin/sh
# mkinstalldirs --- make directory hierarchy
# Author: Noah Friedman <friedman@prep.ai.mit.edu>
# Created: 1993-05-16
# Public domain
# $Id$
errstatus=0
dirmode=""
usage="\
Usage: mkinstalldirs [-h] [--help] [-m mode] dir ..."
# process command line arguments
while test $# -gt 0 ; do
case "${1}" in
-h | --help | --h* ) # -h for help
echo "${usage}" 1>&2; exit 0 ;;
-m ) # -m PERM arg
shift
test $# -eq 0 && { echo "${usage}" 1>&2; exit 1; }
dirmode="${1}"
shift ;;
-- ) shift; break ;; # stop option processing
-* ) echo "${usage}" 1>&2; exit 1 ;; # unknown option
* ) break ;; # first non-opt arg
esac
done
for file
do
if test -d "$file"; then
shift
else
break
fi
done
case $# in
0) exit 0 ;;
esac
case $dirmode in
'')
if mkdir -p -- . 2>/dev/null; then
echo "mkdir -p -- $*"
exec mkdir -p -- "$@"
fi ;;
*)
if mkdir -m "$dirmode" -p -- . 2>/dev/null; then
echo "mkdir -m $dirmode -p -- $*"
exec mkdir -m "$dirmode" -p -- "$@"
fi ;;
esac
for file
do
set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'`
shift
pathcomp=
for d
do
pathcomp="$pathcomp$d"
case "$pathcomp" in
-* ) pathcomp=./$pathcomp ;;
esac
if test ! -d "$pathcomp"; then
echo "mkdir $pathcomp"
mkdir "$pathcomp" || lasterr=$?
if test ! -d "$pathcomp"; then
errstatus=$lasterr
else
if test ! -z "$dirmode"; then
echo "chmod $dirmode $pathcomp"
lasterr=""
chmod "$dirmode" "$pathcomp" || lasterr=$?
if test ! -z "$lasterr"; then
errstatus=$lasterr
fi
fi
fi
fi
pathcomp="$pathcomp/"
done
done
exit $errstatus
# Local Variables:
# mode: shell-script
# sh-indentation: 3
# End:
# mkinstalldirs ends here

File diff suppressed because it is too large Load Diff

@ -1,19 +0,0 @@
##===- projects/ModuleMaker/tools/Makefile -----------------*- Makefile -*-===##
#
# The LLVM Compiler Infrastructure
#
# This file was developed by the LLVM research group and is distributed under
# the University of Illinois Open Source License. See LICENSE.TXT for details.
#
##===----------------------------------------------------------------------===##
#
# Relative path to the top of the source tree.
#
LEVEL=..
#
# List all of the subdirectories that we will compile.
#
DIRS=ModuleMaker
include $(LEVEL)/Makefile.common

@ -1,33 +0,0 @@
##===- projects/ModuleMaker/tools/ModuleMaker/Makefile -----*- Makefile -*-===##
#
# The LLVM Compiler Infrastructure
#
# This file was developed by the LLVM research group and is distributed under
# the University of Illinois Open Source License. See LICENSE.TXT for details.
#
##===----------------------------------------------------------------------===##
#
# 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

@ -1,55 +0,0 @@
//===- 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"
#include <iostream>
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 ()'
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;
}