Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 1 | //===- 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 Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 9 | /// |
| 10 | /// \file |
Jim Stichnoth | 92a6e5b | 2015-12-02 16:52:44 -0800 | [diff] [blame] | 11 | /// \brief Defines the general driver class for translating ICE to machine code. |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 12 | /// |
Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 13 | //===----------------------------------------------------------------------===// |
| 14 | |
John Porto | 67f8de9 | 2015-06-25 10:14:17 -0700 | [diff] [blame] | 15 | #include "IceTranslator.h" |
| 16 | |
John Porto | bd2e231 | 2016-03-15 11:06:25 -0700 | [diff] [blame] | 17 | #include "IceDefs.h" |
Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 18 | #include "IceCfg.h" |
| 19 | #include "IceClFlags.h" |
Karl Schimpf | 9d98d79 | 2014-10-13 15:01:08 -0700 | [diff] [blame] | 20 | #include "IceGlobalInits.h" |
Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 21 | #include "IceTargetLowering.h" |
Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 22 | |
John Porto | bd2e231 | 2016-03-15 11:06:25 -0700 | [diff] [blame] | 23 | #include <utility> |
| 24 | |
| 25 | namespace Ice { |
Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 26 | |
Jim Stichnoth | bbca754 | 2015-02-11 16:08:31 -0800 | [diff] [blame] | 27 | Translator::Translator(GlobalContext *Ctx) |
| 28 | : Ctx(Ctx), NextSequenceNumber(GlobalContext::getFirstSequenceNumber()), |
| 29 | ErrorStatus() {} |
Jim Stichnoth | 088b2be | 2014-10-23 12:02:08 -0700 | [diff] [blame] | 30 | |
Jim Stichnoth | 467ffe5 | 2016-03-29 15:01:06 -0700 | [diff] [blame] | 31 | std::string Translator::createUnnamedName(const std::string &Prefix, |
| 32 | SizeT Index) { |
Karl Schimpf | e3f64d0 | 2014-10-07 10:38:22 -0700 | [diff] [blame] | 33 | if (Index == 0) |
| 34 | return Prefix; |
Karl Schimpf | 5ee234a | 2014-09-12 10:41:40 -0700 | [diff] [blame] | 35 | std::string Buffer; |
| 36 | llvm::raw_string_ostream StrBuf(Buffer); |
Karl Schimpf | e3f64d0 | 2014-10-07 10:38:22 -0700 | [diff] [blame] | 37 | StrBuf << Prefix << Index; |
| 38 | return StrBuf.str(); |
Karl Schimpf | 5ee234a | 2014-09-12 10:41:40 -0700 | [diff] [blame] | 39 | } |
Karl Schimpf | e3f64d0 | 2014-10-07 10:38:22 -0700 | [diff] [blame] | 40 | |
Jim Stichnoth | 467ffe5 | 2016-03-29 15:01:06 -0700 | [diff] [blame] | 41 | bool Translator::checkIfUnnamedNameSafe(const std::string &Name, |
| 42 | const char *Kind, |
| 43 | const std::string &Prefix) { |
Karl Schimpf | e3f64d0 | 2014-10-07 10:38:22 -0700 | [diff] [blame] | 44 | 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 Stichnoth | e4a8f40 | 2015-01-20 12:52:51 -0800 | [diff] [blame] | 50 | OstreamLocker L(Ctx); |
| 51 | Ostream &Stream = Ctx->getStrDump(); |
Karl Schimpf | e3f64d0 | 2014-10-07 10:38:22 -0700 | [diff] [blame] | 52 | Stream << "Warning : Default " << Kind << " prefix '" << Prefix |
| 53 | << "' potentially conflicts with name '" << Name << "'.\n"; |
| 54 | return true; |
| 55 | } |
| 56 | return false; |
| 57 | } |
Karl Schimpf | 5ee234a | 2014-09-12 10:41:40 -0700 | [diff] [blame] | 58 | |
Jim Stichnoth | 8e92838 | 2015-02-02 17:03:08 -0800 | [diff] [blame] | 59 | void Translator::translateFcn(std::unique_ptr<Cfg> Func) { |
Karl Schimpf | e8457a2 | 2016-03-31 10:20:23 -0700 | [diff] [blame] | 60 | Ctx->optQueueBlockingPush(makeUnique<CfgOptWorkItem>(std::move(Func))); |
Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 61 | } |
| 62 | |
Jim Stichnoth | bbca754 | 2015-02-11 16:08:31 -0800 | [diff] [blame] | 63 | void Translator::lowerGlobals( |
| 64 | std::unique_ptr<VariableDeclarationList> VariableDeclarations) { |
John Porto | bd2e231 | 2016-03-15 11:06:25 -0700 | [diff] [blame] | 65 | Ctx->emitQueueBlockingPush(makeUnique<EmitterWorkItem>( |
| 66 | getNextSequenceNumber(), std::move(VariableDeclarations))); |
Karl Schimpf | 6ff33d2 | 2014-09-22 10:28:42 -0700 | [diff] [blame] | 67 | } |
John Porto | bd2e231 | 2016-03-15 11:06:25 -0700 | [diff] [blame] | 68 | |
| 69 | } // end of namespace Ice |