blob: 11899513e415337d0b1b01a53747dfa9668093e3 [file] [log] [blame]
Karl Schimpf8d7abae2014-07-07 14:50:30 -07001//===- 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
18#include "llvm/ADT/OwningPtr.h"
19
20namespace Ice {
21
22class ClFlags;
23class Cfg;
24class GlobalContext;
25
26// Base class for translating ICE to machine code.
27// Derived classes convert other intermediate representations down to ICE,
28// and then call the appropriate (inherited) methods to convert ICE into
29// machine instructions.
30class Translator {
31public:
32 Translator(GlobalContext *Ctx, ClFlags &Flags)
Karl Schimpfb164d202014-07-11 10:26:34 -070033 : Ctx(Ctx), Flags(Flags), ErrorStatus(0) {}
Karl Schimpf8d7abae2014-07-07 14:50:30 -070034
35 ~Translator();
Karl Schimpfb164d202014-07-11 10:26:34 -070036 bool getErrorStatus() const { return ErrorStatus; }
Karl Schimpf8d7abae2014-07-07 14:50:30 -070037
38protected:
39 GlobalContext *Ctx;
40 ClFlags &Flags;
Karl Schimpfb164d202014-07-11 10:26:34 -070041 // The exit status of the translation. False is successful. True
Karl Schimpf8d7abae2014-07-07 14:50:30 -070042 // otherwise.
Karl Schimpfb164d202014-07-11 10:26:34 -070043 bool ErrorStatus;
Karl Schimpf8d7abae2014-07-07 14:50:30 -070044 // Ideally, Func would be inside the methods that converts IR to
45 // functions. However, emitting the constant pool requires a valid
46 // Cfg object, so we need to defer deleting the last non-empty Cfg
47 // object to emit the constant pool (via emitConstants). TODO:
48 // Since all constants are globally pooled in the GlobalContext
49 // object, change all Constant related functions to use
50 // GlobalContext instead of Cfg, and then make emitConstantPool use
51 // that.
52 llvm::OwningPtr<Cfg> Func;
53
54 /// Translates the constructed ICE function Fcn to machine code.
55 /// Note: As a side effect, Field Func is set to Fcn.
56 void translateFcn(Cfg *Fcn);
57
58 /// Emits the constant pool.
59 void emitConstants();
60
61private:
62 Translator(const Translator &) LLVM_DELETED_FUNCTION;
63 Translator &operator=(const Translator &) LLVM_DELETED_FUNCTION;
64};
65}
66
67#endif // SUBZERO_SRC_ICETRANSLATOR_H