* Author: Benjamin Segovia <benjamin.segovia@intel.com>
*/
-//===-- CBackend.cpp - Library for converting LLVM code to C --------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This library converts LLVM code to C code, compilable by GCC and other C
-// compilers.
-//
-//===----------------------------------------------------------------------===//
-
#include "GenTargetMachine.h"
#include "llvm/CallingConv.h"
#include "llvm/Constants.h"
#include <algorithm>
using namespace llvm;
-
+#if 0
extern "C" void LLVMInitializeGenBackendTarget() {
// Register the target.
RegisterTargetMachine<GenTargetMachine> X(TheGenBackendTarget);
}
+#endif
namespace {
class CBEMCAsmInfo : public MCAsmInfo {
FPCounter = 0;
}
- virtual const char *getPassName() const { return "Gen backend"; }
+ virtual const char *getPassName() const { return "Gen Back-End"; }
void getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired<LoopInfo>();
PointerType *Ty);
std::string getStructName(StructType *ST);
-
+
/// writeOperandDeref - Print the result of dereferencing the specified
/// operand with '*'. This is equivalent to printing '*' then using
/// writeOperand, but avoids excess syntax in some cases.
char GenWriter::ID = 0;
-
static std::string CBEMangle(const std::string &S) {
std::string Result;
}
void GenWriter::printFunction(Function &F) {
+
/// isStructReturn - Should this function actually return a struct by-value?
bool isStructReturn = F.hasStructRetAttr();
switch (F.getIntrinsicID()) {
default:
llvm_unreachable("Unsupported Intrinsic.");
- case Intrinsic::uadd_with_overflow:
- // static inline Rty uadd_ixx(unsigned ixx a, unsigned ixx b) {
- // Rty r;
- // r.field0 = a + b;
- // r.field1 = (r.field0 < a);
- // return r;
- // }
- Out << "static inline ";
- printType(Out, retT);
- Out << GetValueName(&F);
- Out << "(";
- printSimpleType(Out, elemT, false);
- Out << "a,";
- printSimpleType(Out, elemT, false);
- Out << "b) {\n ";
- printType(Out, retT);
- Out << "r;\n";
- Out << " r.field0 = a + b;\n";
- Out << " r.field1 = (r.field0 < a);\n";
- Out << " return r;\n}\n";
- break;
-
- case Intrinsic::sadd_with_overflow:
- // static inline Rty sadd_ixx(ixx a, ixx b) {
- // Rty r;
- // r.field1 = (b > 0 && a > XX_MAX - b) ||
- // (b < 0 && a < XX_MIN - b);
- // r.field0 = r.field1 ? 0 : a + b;
- // return r;
- // }
- Out << "static ";
- printType(Out, retT);
- Out << GetValueName(&F);
- Out << "(";
- printSimpleType(Out, elemT, true);
- Out << "a,";
- printSimpleType(Out, elemT, true);
- Out << "b) {\n ";
- printType(Out, retT);
- Out << "r;\n";
- Out << " r.field1 = (b > 0 && a > ";
- printLimitValue(*elemT, true, true, Out);
- Out << " - b) || (b < 0 && a < ";
- printLimitValue(*elemT, true, false, Out);
- Out << " - b);\n";
- Out << " r.field0 = r.field1 ? 0 : a + b;\n";
- Out << " return r;\n}\n";
- break;
}
}
/// visitBuiltinCall - Handle the call to the specified builtin. Returns true
/// if the entire call is handled, return false if it wasn't handled, and
/// optionally set 'WroteCallee' if the callee has already been printed out.
-bool GenWriter::visitBuiltinCall(CallInst &I, Intrinsic::ID ID,
- bool &WroteCallee) {
+bool GenWriter::visitBuiltinCall(CallInst &I, Intrinsic::ID ID, bool &WroteCallee) {
switch (ID) {
default: {
// If this is an intrinsic that directly corresponds to a GCC
//===----------------------------------------------------------------------===//
// External Interface declaration
//===----------------------------------------------------------------------===//
-
+#if 0
bool GenTargetMachine::addPassesToEmitFile(PassManagerBase &PM,
formatted_raw_ostream &o,
CodeGenFileType FileType,
PM.add(createGCInfoDeleter());
return false;
}
+#endif
+
+llvm::FunctionPass *createGenPass(formatted_raw_ostream &o) {
+ return new GenWriter(o);
+}
+
#include "llvm/CodeGen/LinkAllAsmWriterComponents.h"
#include "llvm/CodeGen/LinkAllCodegenComponents.h"
#include "llvm/Config/config.h"
+#include "llvm/Assembly/PrintModulePass.h"
#include "llvm/MC/SubtargetFeature.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
extern "C" void LLVMInitializeGenBackendTarget();
extern "C" void LLVMInitializeGenBackendTargetInfo();
+#if 0
extern "C" int llvmToGen(int argc, char **argv)
{
sys::PrintStackTraceOnErrorSignal();
LLVMContext &Context = getGlobalContext();
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
-
- // Initialize targets first, so that --version shows registered targets.
LLVMInitializeGenBackendTarget();
LLVMInitializeGenBackendTargetInfo();
- //InitializeAllTargetMCs();
- //InitializeAllAsmPrinters();
- //InitializeAllAsmParsers();
// Register the target printer for --version.
cl::AddExtraVersionPrinter(TargetRegistry::printRegisteredTargetsForVersion);
// Declare success.
Out->keep();
-
return 0;
}
+#else
+#include <iostream>
+extern llvm::FunctionPass *createGenPass(formatted_raw_ostream &o);
+extern "C" int llvmToGen(const char *fileName)
+{
+ // Get the global LLVM context
+ llvm::LLVMContext& c = llvm::getGlobalContext();
+
+ // Get the module from its file
+ SMDiagnostic Err;
+ std::auto_ptr<Module> M;
+ M.reset(ParseIRFile(fileName, Err, c));
+ if (M.get() == 0) {
+ Err.Print(fileName, errs());
+ return 1;
+ }
+ Module &mod = *M.get();
+
+ llvm::PassManager passes;
+ std::string error;
+
+ llvm::tool_output_file *FDOut = new llvm::tool_output_file("hop.ll", error, 0);
+ llvm::formatted_raw_ostream outstream(FDOut->os());
+
+ passes.add(llvm::createPrintModulePass(&outstream));
+ passes.add(createGenPass(outstream));
+ passes.run(mod);
+
+ FDOut->keep();
+ return 0;
+}
+#endif