Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 1 | //===- subzero/src/IceTranslator.h - 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 | // This file declares the general driver class for translating ICE to |
| 11 | // machine code. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #ifndef SUBZERO_SRC_ICETRANSLATOR_H |
| 16 | #define SUBZERO_SRC_ICETRANSLATOR_H |
| 17 | |
Karl Schimpf | 5ee234a | 2014-09-12 10:41:40 -0700 | [diff] [blame] | 18 | namespace llvm { |
| 19 | class Module; |
| 20 | } |
| 21 | |
Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 22 | namespace Ice { |
| 23 | |
| 24 | class ClFlags; |
| 25 | class Cfg; |
Karl Schimpf | 9d98d79 | 2014-10-13 15:01:08 -0700 | [diff] [blame] | 26 | class VariableDeclaration; |
Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 27 | class GlobalContext; |
| 28 | |
Karl Schimpf | 9d98d79 | 2014-10-13 15:01:08 -0700 | [diff] [blame] | 29 | // Base class for translating ICE to machine code. Derived classes convert |
| 30 | // other intermediate representations down to ICE, and then call the appropriate |
| 31 | // (inherited) methods to convert ICE into machine instructions. |
Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 32 | class Translator { |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 33 | Translator(const Translator &) = delete; |
| 34 | Translator &operator=(const Translator &) = delete; |
| 35 | |
Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 36 | public: |
Jim Stichnoth | bbca754 | 2015-02-11 16:08:31 -0800 | [diff] [blame^] | 37 | Translator(GlobalContext *Ctx); |
Jan Voung | 72984d8 | 2015-01-29 14:42:38 -0800 | [diff] [blame] | 38 | |
Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 39 | ~Translator(); |
Jim Stichnoth | fa4efea | 2015-01-27 05:06:03 -0800 | [diff] [blame] | 40 | const ErrorCode &getErrorStatus() const { return ErrorStatus; } |
Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 41 | |
Karl Schimpf | d6064a1 | 2014-08-27 15:34:58 -0700 | [diff] [blame] | 42 | GlobalContext *getContext() const { return Ctx; } |
| 43 | |
Jim Stichnoth | bbca754 | 2015-02-11 16:08:31 -0800 | [diff] [blame^] | 44 | const ClFlags &getFlags() const { return Ctx->getFlags(); } |
Karl Schimpf | d6064a1 | 2014-08-27 15:34:58 -0700 | [diff] [blame] | 45 | |
| 46 | /// Translates the constructed ICE function Fcn to machine code. |
Jim Stichnoth | fa4efea | 2015-01-27 05:06:03 -0800 | [diff] [blame] | 47 | /// Takes ownership of Func. |
Jim Stichnoth | 8e92838 | 2015-02-02 17:03:08 -0800 | [diff] [blame] | 48 | void translateFcn(std::unique_ptr<Cfg> Func); |
Karl Schimpf | d6064a1 | 2014-08-27 15:34:58 -0700 | [diff] [blame] | 49 | |
| 50 | /// Emits the constant pool. |
| 51 | void emitConstants(); |
| 52 | |
Jim Stichnoth | fa4efea | 2015-01-27 05:06:03 -0800 | [diff] [blame] | 53 | /// If there was an error during bitcode reading/parsing, copy the |
| 54 | /// error code into the GlobalContext. |
| 55 | void transferErrorCode() const; |
| 56 | |
Karl Schimpf | 9d98d79 | 2014-10-13 15:01:08 -0700 | [diff] [blame] | 57 | /// Lowers the given list of global addresses to target. Generates |
| 58 | /// list of corresponding variable declarations. |
Jim Stichnoth | bbca754 | 2015-02-11 16:08:31 -0800 | [diff] [blame^] | 59 | void |
| 60 | lowerGlobals(std::unique_ptr<VariableDeclarationList> VariableDeclarations); |
Karl Schimpf | e3f64d0 | 2014-10-07 10:38:22 -0700 | [diff] [blame] | 61 | |
| 62 | /// Creates a name using the given prefix and corresponding index. |
| 63 | std::string createUnnamedName(const IceString &Prefix, SizeT Index); |
| 64 | |
| 65 | /// Reports if there is a (potential) conflict between Name, and using |
| 66 | /// Prefix to name unnamed names. Errors are put on Ostream. |
| 67 | /// Returns true if there isn't a potential conflict. |
| 68 | bool checkIfUnnamedNameSafe(const IceString &Name, const char *Kind, |
Jim Stichnoth | e4a8f40 | 2015-01-20 12:52:51 -0800 | [diff] [blame] | 69 | const IceString &Prefix); |
Karl Schimpf | e3f64d0 | 2014-10-07 10:38:22 -0700 | [diff] [blame] | 70 | |
Jim Stichnoth | bbca754 | 2015-02-11 16:08:31 -0800 | [diff] [blame^] | 71 | uint32_t getNextSequenceNumber() { return NextSequenceNumber++; } |
| 72 | |
Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 73 | protected: |
| 74 | GlobalContext *Ctx; |
Jim Stichnoth | bbca754 | 2015-02-11 16:08:31 -0800 | [diff] [blame^] | 75 | uint32_t NextSequenceNumber; |
Jim Stichnoth | fa4efea | 2015-01-27 05:06:03 -0800 | [diff] [blame] | 76 | // Exit status of the translation. False is successful. True otherwise. |
| 77 | ErrorCode ErrorStatus; |
Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 78 | }; |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 79 | |
| 80 | } // end of namespace Ice |
Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 81 | |
| 82 | #endif // SUBZERO_SRC_ICETRANSLATOR_H |