• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 //===----------------------------------------------------------------------===//
9 ///
10 /// \file
11 /// \brief Defines the general driver class for translating ICE to machine code.
12 ///
13 //===----------------------------------------------------------------------===//
14 
15 #include "IceTranslator.h"
16 
17 #include "IceCfg.h"
18 #include "IceClFlags.h"
19 #include "IceDefs.h"
20 #include "IceGlobalInits.h"
21 #include "IceTargetLowering.h"
22 
23 #include <utility>
24 
25 namespace Ice {
26 
Translator(GlobalContext * Ctx)27 Translator::Translator(GlobalContext *Ctx)
28     : Ctx(Ctx), NextSequenceNumber(GlobalContext::getFirstSequenceNumber()),
29       ErrorStatus() {}
30 
createUnnamedName(const std::string & Prefix,SizeT Index)31 std::string Translator::createUnnamedName(const std::string &Prefix,
32                                           SizeT Index) {
33   if (Index == 0)
34     return Prefix;
35   std::string Buffer;
36   llvm::raw_string_ostream StrBuf(Buffer);
37   StrBuf << Prefix << Index;
38   return StrBuf.str();
39 }
40 
checkIfUnnamedNameSafe(const std::string & Name,const char * Kind,const std::string & Prefix)41 bool Translator::checkIfUnnamedNameSafe(const std::string &Name,
42                                         const char *Kind,
43                                         const std::string &Prefix) {
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     }
50     OstreamLocker L(Ctx);
51     Ostream &Stream = Ctx->getStrDump();
52     Stream << "Warning : Default " << Kind << " prefix '" << Prefix
53            << "' potentially conflicts with name '" << Name << "'.\n";
54     return true;
55   }
56   return false;
57 }
58 
translateFcn(std::unique_ptr<Cfg> Func)59 void Translator::translateFcn(std::unique_ptr<Cfg> Func) {
60   Ctx->optQueueBlockingPush(makeUnique<CfgOptWorkItem>(std::move(Func)));
61 }
62 
lowerGlobals(std::unique_ptr<VariableDeclarationList> VariableDeclarations)63 void Translator::lowerGlobals(
64     std::unique_ptr<VariableDeclarationList> VariableDeclarations) {
65   Ctx->emitQueueBlockingPush(makeUnique<EmitterWorkItem>(
66       getNextSequenceNumber(), std::move(VariableDeclarations)));
67 }
68 
69 } // end of namespace Ice
70