blob: 12115102d0f73397dfa5069a8ccb90fb98e15f58 [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
Jim Stichnoth92a6e5b2015-12-02 16:52:44 -080011/// \brief Defines the general driver class for translating ICE to machine code.
Andrew Scull9612d322015-07-06 14:53:25 -070012///
Karl Schimpf8d7abae2014-07-07 14:50:30 -070013//===----------------------------------------------------------------------===//
14
John Porto67f8de92015-06-25 10:14:17 -070015#include "IceTranslator.h"
16
John Portobd2e2312016-03-15 11:06:25 -070017#include "IceDefs.h"
Karl Schimpf8d7abae2014-07-07 14:50:30 -070018#include "IceCfg.h"
19#include "IceClFlags.h"
Karl Schimpf9d98d792014-10-13 15:01:08 -070020#include "IceGlobalInits.h"
Karl Schimpf8d7abae2014-07-07 14:50:30 -070021#include "IceTargetLowering.h"
Karl Schimpf8d7abae2014-07-07 14:50:30 -070022
John Portobd2e2312016-03-15 11:06:25 -070023#include <utility>
24
25namespace Ice {
Karl Schimpf8d7abae2014-07-07 14:50:30 -070026
Jim Stichnothbbca7542015-02-11 16:08:31 -080027Translator::Translator(GlobalContext *Ctx)
28 : Ctx(Ctx), NextSequenceNumber(GlobalContext::getFirstSequenceNumber()),
29 ErrorStatus() {}
Jim Stichnoth088b2be2014-10-23 12:02:08 -070030
Jim Stichnoth467ffe52016-03-29 15:01:06 -070031std::string Translator::createUnnamedName(const std::string &Prefix,
32 SizeT Index) {
Karl Schimpfe3f64d02014-10-07 10:38:22 -070033 if (Index == 0)
34 return Prefix;
Karl Schimpf5ee234a2014-09-12 10:41:40 -070035 std::string Buffer;
36 llvm::raw_string_ostream StrBuf(Buffer);
Karl Schimpfe3f64d02014-10-07 10:38:22 -070037 StrBuf << Prefix << Index;
38 return StrBuf.str();
Karl Schimpf5ee234a2014-09-12 10:41:40 -070039}
Karl Schimpfe3f64d02014-10-07 10:38:22 -070040
Jim Stichnoth467ffe52016-03-29 15:01:06 -070041bool Translator::checkIfUnnamedNameSafe(const std::string &Name,
42 const char *Kind,
43 const std::string &Prefix) {
Karl Schimpfe3f64d02014-10-07 10:38:22 -070044 if (Name.find(Prefix) == 0) {
45 for (size_t i = Prefix.size(); i < Name.size(); ++i) {
46 if (!isdigit(Name[i])) {
47 return false;
48 }
49 }
Jim Stichnothe4a8f402015-01-20 12:52:51 -080050 OstreamLocker L(Ctx);
51 Ostream &Stream = Ctx->getStrDump();
Karl Schimpfe3f64d02014-10-07 10:38:22 -070052 Stream << "Warning : Default " << Kind << " prefix '" << Prefix
53 << "' potentially conflicts with name '" << Name << "'.\n";
54 return true;
55 }
56 return false;
57}
Karl Schimpf5ee234a2014-09-12 10:41:40 -070058
Jim Stichnoth8e928382015-02-02 17:03:08 -080059void Translator::translateFcn(std::unique_ptr<Cfg> Func) {
Karl Schimpfe8457a22016-03-31 10:20:23 -070060 Ctx->optQueueBlockingPush(makeUnique<CfgOptWorkItem>(std::move(Func)));
Karl Schimpf8d7abae2014-07-07 14:50:30 -070061}
62
Jim Stichnothbbca7542015-02-11 16:08:31 -080063void Translator::lowerGlobals(
64 std::unique_ptr<VariableDeclarationList> VariableDeclarations) {
John Portobd2e2312016-03-15 11:06:25 -070065 Ctx->emitQueueBlockingPush(makeUnique<EmitterWorkItem>(
66 getNextSequenceNumber(), std::move(VariableDeclarations)));
Karl Schimpf6ff33d22014-09-22 10:28:42 -070067}
John Portobd2e2312016-03-15 11:06:25 -070068
69} // end of namespace Ice