blob: e3a32dcdba1b7f82175ee1e4cd253a162533a7de [file] [log] [blame]
Karl Schimpf8d7abae2014-07-07 14:50:30 -07001//===- subzero/src/IceTranslator.cpp - ICE to machine code ------*- C++ -*-===//
2//
3// The Subzero Code Generator
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
Andrew Scull9612d322015-07-06 14:53:25 -07009///
10/// \file
11/// This file defines the general driver class for translating ICE to
12/// machine code.
13///
Karl Schimpf8d7abae2014-07-07 14:50:30 -070014//===----------------------------------------------------------------------===//
15
John Porto67f8de92015-06-25 10:14:17 -070016#include "IceTranslator.h"
17
Karl Schimpf8d7abae2014-07-07 14:50:30 -070018#include "IceCfg.h"
19#include "IceClFlags.h"
Karl Schimpf5ee234a2014-09-12 10:41:40 -070020#include "IceDefs.h"
Karl Schimpf9d98d792014-10-13 15:01:08 -070021#include "IceGlobalInits.h"
Karl Schimpf8d7abae2014-07-07 14:50:30 -070022#include "IceTargetLowering.h"
Karl Schimpf8d7abae2014-07-07 14:50:30 -070023
24using namespace Ice;
25
Jim Stichnothbbca7542015-02-11 16:08:31 -080026Translator::Translator(GlobalContext *Ctx)
27 : Ctx(Ctx), NextSequenceNumber(GlobalContext::getFirstSequenceNumber()),
28 ErrorStatus() {}
Jim Stichnoth088b2be2014-10-23 12:02:08 -070029
Karl Schimpfe3f64d02014-10-07 10:38:22 -070030IceString Translator::createUnnamedName(const IceString &Prefix, SizeT Index) {
31 if (Index == 0)
32 return Prefix;
Karl Schimpf5ee234a2014-09-12 10:41:40 -070033 std::string Buffer;
34 llvm::raw_string_ostream StrBuf(Buffer);
Karl Schimpfe3f64d02014-10-07 10:38:22 -070035 StrBuf << Prefix << Index;
36 return StrBuf.str();
Karl Schimpf5ee234a2014-09-12 10:41:40 -070037}
Karl Schimpfe3f64d02014-10-07 10:38:22 -070038
39bool Translator::checkIfUnnamedNameSafe(const IceString &Name, const char *Kind,
Jim Stichnothe4a8f402015-01-20 12:52:51 -080040 const IceString &Prefix) {
Karl Schimpfe3f64d02014-10-07 10:38:22 -070041 if (Name.find(Prefix) == 0) {
42 for (size_t i = Prefix.size(); i < Name.size(); ++i) {
43 if (!isdigit(Name[i])) {
44 return false;
45 }
46 }
Jim Stichnothe4a8f402015-01-20 12:52:51 -080047 OstreamLocker L(Ctx);
48 Ostream &Stream = Ctx->getStrDump();
Karl Schimpfe3f64d02014-10-07 10:38:22 -070049 Stream << "Warning : Default " << Kind << " prefix '" << Prefix
50 << "' potentially conflicts with name '" << Name << "'.\n";
51 return true;
52 }
53 return false;
54}
Karl Schimpf5ee234a2014-09-12 10:41:40 -070055
Jim Stichnoth8e928382015-02-02 17:03:08 -080056void Translator::translateFcn(std::unique_ptr<Cfg> Func) {
Jim Stichnothbbca7542015-02-11 16:08:31 -080057 Ctx->optQueueBlockingPush(std::move(Func));
Karl Schimpf8d7abae2014-07-07 14:50:30 -070058}
59
Jim Stichnothbbca7542015-02-11 16:08:31 -080060void Translator::lowerGlobals(
61 std::unique_ptr<VariableDeclarationList> VariableDeclarations) {
62 EmitterWorkItem *Item = new EmitterWorkItem(getNextSequenceNumber(),
63 VariableDeclarations.release());
64 Ctx->emitQueueBlockingPush(Item);
Karl Schimpf6ff33d22014-09-22 10:28:42 -070065}