parent
509d3c00ed
commit
1e27fe165c
|
@ -0,0 +1,40 @@
|
|||
//===--- TargetInfo.cpp - Information about Target machine ----------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file was developed by Chris Lattner and is distributed under
|
||||
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file implements the TargetInfo and TargetInfoImpl interfaces.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "clang/Basic/TargetInfo.h"
|
||||
#include "clang/Basic/Diagnostic.h"
|
||||
using namespace llvm;
|
||||
using namespace clang;
|
||||
|
||||
/// DiagnoseNonPortability - When a use of a non-portable target feature is
|
||||
/// used, this method emits the diagnostic and marks the translation unit as
|
||||
/// non-portable.
|
||||
void TargetInfo::DiagnoseNonPortability(SourceLocation Loc, unsigned DiagKind) {
|
||||
NonPortable = true;
|
||||
if (Diag) Diag->Report(Loc, DiagKind);
|
||||
}
|
||||
|
||||
|
||||
/// ComputeWCharWidth - Determine the width of the wchar_t type for the primary
|
||||
/// target, diagnosing whether this is non-portable across the secondary
|
||||
/// targets.
|
||||
void TargetInfo::ComputeWCharWidth(SourceLocation Loc) {
|
||||
WCharWidth = PrimaryTarget->getWCharWidth();
|
||||
|
||||
// Check whether this is portable across the secondary targets if the T-U is
|
||||
// portable so far.
|
||||
for (unsigned i = 0, e = SecondaryTargets.size(); i != e; ++i)
|
||||
if (SecondaryTargets[i]->getWCharWidth() != WCharWidth)
|
||||
return DiagnoseNonPortability(Loc, diag::port_wchar_t);
|
||||
}
|
||||
|
|
@ -22,6 +22,7 @@
|
|||
DE0FCB340A9C21F100248FD5 /* Expr.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DE0FCB330A9C21F100248FD5 /* Expr.cpp */; };
|
||||
DE1F22030A7D852A00FBF588 /* Parser.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DE1F22020A7D852A00FBF588 /* Parser.h */; };
|
||||
DE1F24820A7DCD3800FBF588 /* Declarations.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DE1F24810A7DCD3800FBF588 /* Declarations.h */; };
|
||||
DE46BF280AE0A82D00CC047C /* TargetInfo.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DE46BF270AE0A82D00CC047C /* TargetInfo.h */; };
|
||||
DE5932D10AD60FF400BC794C /* clang.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DE5932CD0AD60FF400BC794C /* clang.cpp */; };
|
||||
DE5932D20AD60FF400BC794C /* clang.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DE5932CE0AD60FF400BC794C /* clang.h */; };
|
||||
DE5932D30AD60FF400BC794C /* PrintParserCallbacks.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DE5932CF0AD60FF400BC794C /* PrintParserCallbacks.cpp */; };
|
||||
|
@ -33,6 +34,7 @@
|
|||
DEC8D9B60A9434FA00353FCA /* Builder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DEC8D9B50A9434FA00353FCA /* Builder.cpp */; };
|
||||
DEC8DAAD0A94400300353FCA /* ASTStreamer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DEC8DAAC0A94400300353FCA /* ASTStreamer.cpp */; };
|
||||
DEC8DAC00A94402500353FCA /* ASTStreamer.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DEC8DABF0A94402500353FCA /* ASTStreamer.h */; };
|
||||
DED626C90AE0C065001E80A4 /* TargetInfo.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DED626C80AE0C065001E80A4 /* TargetInfo.cpp */; };
|
||||
DED7D7410A524295003AD0FB /* Diagnostic.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DED7D7310A524295003AD0FB /* Diagnostic.h */; };
|
||||
DED7D7420A524295003AD0FB /* DiagnosticKinds.def in CopyFiles */ = {isa = PBXBuildFile; fileRef = DED7D7320A524295003AD0FB /* DiagnosticKinds.def */; };
|
||||
DED7D7430A524295003AD0FB /* FileManager.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DED7D7330A524295003AD0FB /* FileManager.h */; };
|
||||
|
@ -101,13 +103,14 @@
|
|||
DEC8DAC00A94402500353FCA /* ASTStreamer.h in CopyFiles */,
|
||||
DE0FCA630A95859D00248FD5 /* Expr.h in CopyFiles */,
|
||||
DE5932D20AD60FF400BC794C /* clang.h in CopyFiles */,
|
||||
DE46BF280AE0A82D00CC047C /* TargetInfo.h in CopyFiles */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 1;
|
||||
};
|
||||
/* End PBXCopyFilesBuildPhase section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
8DD76F6C0486A84900D96B5E /* clang */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = clang; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
8DD76F6C0486A84900D96B5E /* clang */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = "compiled.mach-o.executable"; path = clang; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
DE06B73D0A8307640050E87E /* LangOptions.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = LangOptions.h; sourceTree = "<group>"; };
|
||||
DE06BEC80A854E390050E87E /* Scope.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = Scope.cpp; path = Parse/Scope.cpp; sourceTree = "<group>"; };
|
||||
DE06BECA0A854E4B0050E87E /* Scope.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = Scope.h; path = clang/Parse/Scope.h; sourceTree = "<group>"; };
|
||||
|
@ -123,6 +126,7 @@
|
|||
DE0FCB330A9C21F100248FD5 /* Expr.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = Expr.cpp; path = AST/Expr.cpp; sourceTree = "<group>"; };
|
||||
DE1F22020A7D852A00FBF588 /* Parser.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = Parser.h; path = clang/Parse/Parser.h; sourceTree = "<group>"; };
|
||||
DE1F24810A7DCD3800FBF588 /* Declarations.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = Declarations.h; path = clang/Parse/Declarations.h; sourceTree = "<group>"; };
|
||||
DE46BF270AE0A82D00CC047C /* TargetInfo.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = TargetInfo.h; sourceTree = "<group>"; };
|
||||
DE5932CD0AD60FF400BC794C /* clang.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = clang.cpp; path = Driver/clang.cpp; sourceTree = "<group>"; };
|
||||
DE5932CE0AD60FF400BC794C /* clang.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = clang.h; path = Driver/clang.h; sourceTree = "<group>"; };
|
||||
DE5932CF0AD60FF400BC794C /* PrintParserCallbacks.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = PrintParserCallbacks.cpp; path = Driver/PrintParserCallbacks.cpp; sourceTree = "<group>"; };
|
||||
|
@ -134,6 +138,7 @@
|
|||
DEC8D9B50A9434FA00353FCA /* Builder.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = Builder.cpp; path = AST/Builder.cpp; sourceTree = "<group>"; };
|
||||
DEC8DAAC0A94400300353FCA /* ASTStreamer.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = ASTStreamer.cpp; path = AST/ASTStreamer.cpp; sourceTree = "<group>"; };
|
||||
DEC8DABF0A94402500353FCA /* ASTStreamer.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = ASTStreamer.h; path = clang/AST/ASTStreamer.h; sourceTree = "<group>"; };
|
||||
DED626C80AE0C065001E80A4 /* TargetInfo.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = TargetInfo.cpp; sourceTree = "<group>"; };
|
||||
DED7D7310A524295003AD0FB /* Diagnostic.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = Diagnostic.h; sourceTree = "<group>"; };
|
||||
DED7D7320A524295003AD0FB /* DiagnosticKinds.def */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; path = DiagnosticKinds.def; sourceTree = "<group>"; };
|
||||
DED7D7330A524295003AD0FB /* FileManager.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = FileManager.h; sourceTree = "<group>"; };
|
||||
|
@ -296,6 +301,7 @@
|
|||
DED7D7340A524295003AD0FB /* SourceBuffer.h */,
|
||||
DED7D7350A524295003AD0FB /* SourceLocation.h */,
|
||||
DED7D7360A524295003AD0FB /* SourceManager.h */,
|
||||
DE46BF270AE0A82D00CC047C /* TargetInfo.h */,
|
||||
DED7D7370A524295003AD0FB /* TokenKinds.def */,
|
||||
DED7D7380A524295003AD0FB /* TokenKinds.h */,
|
||||
);
|
||||
|
@ -328,6 +334,7 @@
|
|||
DED7D76C0A5242C7003AD0FB /* SourceBuffer.cpp */,
|
||||
DED7D76D0A5242C7003AD0FB /* SourceManager.cpp */,
|
||||
DED7D76E0A5242C7003AD0FB /* TokenKinds.cpp */,
|
||||
DED626C80AE0C065001E80A4 /* TargetInfo.cpp */,
|
||||
);
|
||||
path = Basic;
|
||||
sourceTree = "<group>";
|
||||
|
@ -415,6 +422,7 @@
|
|||
DE5932D10AD60FF400BC794C /* clang.cpp in Sources */,
|
||||
DE5932D30AD60FF400BC794C /* PrintParserCallbacks.cpp in Sources */,
|
||||
DE5932D40AD60FF400BC794C /* PrintPreprocessedOutput.cpp in Sources */,
|
||||
DED626C90AE0C065001E80A4 /* TargetInfo.cpp in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
|
|
@ -20,6 +20,12 @@
|
|||
// ERROR - Error, compilation will stop after parsing completes.
|
||||
// FATAL - Fatal error: parsing must stop.
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Portability
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
DIAG(port_wchar_t, NOTE,
|
||||
"sizeof(wchar_t) varies between targets")
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Lexer Diagnostics
|
||||
|
|
|
@ -0,0 +1,121 @@
|
|||
//===--- TargetInfo.h - Expose information about the target -----*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file was developed by Chris Lattner and is distributed under
|
||||
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file defines the TargetInfo and TargetInfoImpl interfaces.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_CLANG_BASIC_TARGETINFO_H
|
||||
#define LLVM_CLANG_BASIC_TARGETINFO_H
|
||||
|
||||
#include "clang/Basic/SourceLocation.h"
|
||||
#include <vector>
|
||||
|
||||
namespace llvm {
|
||||
namespace clang {
|
||||
|
||||
class TargetInfoImpl;
|
||||
class Diagnostic;
|
||||
|
||||
/// TargetInfo - This class exposes information about the current target set.
|
||||
/// A target set consists of a primary target and zero or more secondary targets
|
||||
/// which are each represented by a TargetInfoImpl object. TargetInfo responds
|
||||
/// to various queries as though it were the primary target, but keeps track of,
|
||||
/// and warns about, the first query made of it that are contradictary among the
|
||||
/// targets it tracks. For example, if it contains a "PPC32" and "PPC64"
|
||||
/// target, it will warn the first time the size of the 'long' datatype is
|
||||
/// queried.
|
||||
///
|
||||
/// Note that TargetInfo does not take ownership of the various targets, but
|
||||
/// does expect them to be alive for as long as it is.
|
||||
///
|
||||
class TargetInfo {
|
||||
/// Primary - This tracks the primary target in the target set.
|
||||
///
|
||||
TargetInfoImpl *PrimaryTarget;
|
||||
|
||||
/// SecondaryTargets - This tracks the set of secondary targets.
|
||||
///
|
||||
std::vector<TargetInfoImpl*> SecondaryTargets;
|
||||
|
||||
/// Diag - If non-null, this object is used to report the first use of
|
||||
/// non-portable functionality in the translation unit.
|
||||
///
|
||||
Diagnostic *Diag;
|
||||
|
||||
/// NonPortable - This instance variable keeps track of whether or not the
|
||||
/// current translation unit is portable across the set of targets tracked.
|
||||
bool NonPortable;
|
||||
|
||||
/// These are all caches for target values.
|
||||
unsigned WCharWidth;
|
||||
|
||||
public:
|
||||
TargetInfo(TargetInfoImpl *Primary, Diagnostic *D = 0) {
|
||||
PrimaryTarget = Primary;
|
||||
Diag = D;
|
||||
NonPortable = false;
|
||||
|
||||
// Initialize Cache values to uncomputed.
|
||||
WCharWidth = 0;
|
||||
}
|
||||
|
||||
/// isNonPortable - Return true if the current translation unit has used a
|
||||
/// target property that is non-portable across the secondary targets.
|
||||
bool isNonPortable() const {
|
||||
return NonPortable;
|
||||
}
|
||||
|
||||
/// isPortable - Return true if this translation unit is portable across the
|
||||
/// secondary targets so far.
|
||||
bool isPortable() const {
|
||||
return !NonPortable;
|
||||
}
|
||||
|
||||
/// AddSecondaryTarget - Add a secondary target to the target set.
|
||||
void AddSecondaryTarget(TargetInfoImpl *Secondary) {
|
||||
SecondaryTargets.push_back(Secondary);
|
||||
}
|
||||
|
||||
///===---- Target property query methods --------------------------------===//
|
||||
|
||||
/// getWCharWidth - Return the size of wchar_t in bytes.
|
||||
///
|
||||
unsigned getWCharWidth(SourceLocation Loc) {
|
||||
if (!WCharWidth) ComputeWCharWidth(Loc);
|
||||
return WCharWidth;
|
||||
}
|
||||
private:
|
||||
void DiagnoseNonPortability(SourceLocation Loc, unsigned DiagKind);
|
||||
void ComputeWCharWidth(SourceLocation Loc);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
/// TargetInfoImpl - This class is implemented for specific targets and is used
|
||||
/// by the TargetInfo class. Target implementations should initialize instance
|
||||
/// variables and implement various virtual methods if the default values are
|
||||
/// not appropriate for the target.
|
||||
class TargetInfoImpl {
|
||||
protected:
|
||||
unsigned WCharWidth; /// sizeof(wchar_t) in bytes. Default value is 4.
|
||||
public:
|
||||
TargetInfoImpl() : WCharWidth(4) {}
|
||||
|
||||
/// getWCharWidth - Return the size of wchar_t in bytes.
|
||||
///
|
||||
unsigned getWCharWidth() const { return WCharWidth; }
|
||||
|
||||
};
|
||||
|
||||
} // end namespace clang
|
||||
} // end namespace llvm
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue