Skip to content

Commit

Permalink
Sync changes from FE to SDK (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
jimspr authored Jul 20, 2023
1 parent 1407a0a commit a4b9418
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 57 deletions.
3 changes: 1 addition & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ include(FetchContent)

FetchContent_Declare(GSL
GIT_REPOSITORY "https://github.com/microsoft/GSL"
GIT_TAG "v3.1.0"
GIT_TAG "v4.0.0"
)
FetchContent_MakeAvailable(GSL)

if (MSVC)
add_compile_options(
/permissive- # Turn on strict language conformance
/EHsc # Turn on exception handling semantics
)
endif()
Expand Down
18 changes: 11 additions & 7 deletions include/ifc/abstract-sgraph.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,8 @@ namespace Module {
struct SourceLocation {
LineIndex line = { };
ColumnNumber column = { };

bool operator==(const SourceLocation&) const = default;
};

// Conceptually, this is a token; but we have too many token type and it would be confusing to call this Token.
Expand Down Expand Up @@ -2032,7 +2034,7 @@ namespace Module {

template<typename T>
struct Identity {
T name; // The name of the entity (either 'NameIndex' or 'TextOffset')
T name{}; // The name of the entity (either 'NameIndex' or 'TextOffset')
SourceLocation locus; // Source location of this entity
};

Expand Down Expand Up @@ -2098,11 +2100,11 @@ namespace Module {
Identity<TextOffset> identity; // The name and location of this function parameter
TypeIndex type; // Sort and index of this decl's type. Null means no type.
ExprIndex type_constraint; // Optional type-constraint on the parameter type.
DefaultIndex initializer; // Default argument. Null means none was provided.
uint32_t level; // The nesting depth of this parameter (template or function).
uint32_t position; // The 1-based position of this parameter.
ParameterSort sort; // The kind of parameter.
ReachableProperties properties; // The set of semantic properties reaching to outside importers.
DefaultIndex initializer{}; // Default argument. Null means none was provided.
uint32_t level{}; // The nesting depth of this parameter (template or function).
uint32_t position{}; // The 1-based position of this parameter.
ParameterSort sort{}; // The kind of parameter.
ReachableProperties properties{}; // The set of semantic properties reaching to outside importers.
};

// A variable declaration, including static data members.
Expand Down Expand Up @@ -2871,7 +2873,9 @@ namespace Module {
uint32_t exec_charset : 8; // value of #pragma execution_character_set
uint32_t vtor_disp : 8; // value of #pragma vtordisp
uint32_t std_for_scope : 1; // value of #pragma conform(forScope)
uint32_t pure_cil : 1; // value of #pragma managed
uint32_t unused : 1; // unused bit - was previously pure_cil, which was meant to be the captured
// state of #pragma managed(off/on). This is not actually required as we
// don't support module export for /clr, and it's always the case for native code.
uint32_t strict_gs_check : 1; // value of #pragma strict_gs_check
};

Expand Down
97 changes: 53 additions & 44 deletions include/ifc/file.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ namespace Module {
cursor = span.begin();
}

const auto contents() const
auto contents() const
{
return span;
}
Expand Down Expand Up @@ -392,50 +392,8 @@ namespace Module {
}

template <UnitSort Kind, typename T>
bool validate(const Module::Pathname& path, Architecture arch, const T& ifc_designator, IfcOptions options)
bool designator_matches_ifc_unit_sort(const Header* header, const T& ifc_designator, IfcOptions options)
{
if (!has_signature(*this, Module::InterfaceSignature))
return false;

if (implies(options, IfcOptions::IntegrityCheck))
{
validate_content_integrity(*this);
}

auto header = hdr = read<Header>();
if (header == nullptr)
return false;

if (header->version > CurrentFormatVersion
|| (header->version < MinimumFormatVersion && header->version != EDGFormatVersion))
throw UnsupportedFormatVersion{ header->version };

// If the user requested an unknown architecture, we do not perform architecture check.
if (arch != Architecture::Unknown and not compatible_architectures(header->arch, arch))
{
if constexpr (Kind != UnitSort::Partition)
{
throw IfcArchMismatch{ ifc_designator, path };
}
else
{
throw IfcArchMismatch{ ifc_designator.partition, path };
}
}

position(header->toc);
toc = read<PartitionSummaryData>();

if (!zero(header->string_table_bytes))
{
if (!position(header->string_table_bytes))
return false;
auto bytes = tell();
auto nbytes = to_underlying(header->string_table_size);
IFCASSERT(has_room_left_for(EntitySize{ nbytes }));
str_tab = { &bytes[0], static_cast<StringTable::size_type>(nbytes) };
}

if constexpr (Kind == UnitSort::Primary || Kind == UnitSort::ExportedTU)
{
// If we are reading module to merge then the final module name (which can be provided on the command-line) may not
Expand Down Expand Up @@ -505,6 +463,57 @@ namespace Module {
}
}

return true;
}

template <UnitSort Kind, typename T>
bool validate(const Module::Pathname& path, Architecture arch, const T& ifc_designator, IfcOptions options)
{
if (!has_signature(*this, Module::InterfaceSignature))
return false;

if (implies(options, IfcOptions::IntegrityCheck))
{
validate_content_integrity(*this);
}

auto header = hdr = read<Header>();
if (header == nullptr)
return false;

if (header->version > CurrentFormatVersion
|| (header->version < MinimumFormatVersion && header->version != EDGFormatVersion))
throw UnsupportedFormatVersion{ header->version };

// If the user requested an unknown architecture, we do not perform architecture check.
if (arch != Architecture::Unknown and not compatible_architectures(header->arch, arch))
{
if constexpr (Kind != UnitSort::Partition)
{
throw IfcArchMismatch{ ifc_designator, path };
}
else
{
throw IfcArchMismatch{ ifc_designator.partition, path };
}
}

position(header->toc);
toc = read<PartitionSummaryData>();

if (!zero(header->string_table_bytes))
{
if (!position(header->string_table_bytes))
return false;
auto bytes = tell();
auto nbytes = to_underlying(header->string_table_size);
IFCASSERT(has_room_left_for(EntitySize{ nbytes }));
str_tab = { &bytes[0], static_cast<StringTable::size_type>(nbytes) };
}

if (not designator_matches_ifc_unit_sort<Kind>(header, ifc_designator, options))
return false;

if (!position(ByteOffset(sizeof InterfaceSignature)))
throw IfcReadFailure { path };
return true;
Expand Down
2 changes: 2 additions & 0 deletions include/ifc/operators.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ namespace Module {
MsvcConfusedVtorDisplacement, // The compiler generated expression representing an offset amount to a virtual base pointer address during initialization.
MsvcConfusedDependentExpression, // At times the old YACC parser will 'give up' parsing a dependent expression and simply return a constant with a dummy bit set.
// This operator attempts to catch these offending dependent expression values.
MsvcConfusedSubstitution, // Represents a template parameter substitution 'P -> expr' where 'expr' could be a type or a non-type argument replacement.

Last
};
Expand Down Expand Up @@ -231,6 +232,7 @@ namespace Module {
MsvcBuiltinIsCorrespondingMember, // __builtin_is_corresponding_member(x, y)
MsvcIntrinsic, // -- abstract machine, misc intrinsic with no regular function declaration
MsvcSaturatedArithmetic, // An MSVC intrinsic for an abstract machine saturated arithemtic operation.
MsvcBuiltinAllocationAnnotation, // An MSVC intrinsic used to propagate debugging information to the runtime. __allocation_annotation(x, T)

Last
};
Expand Down
10 changes: 8 additions & 2 deletions include/ifc/pathname.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ namespace Module {
using Base::value_type;
using Base::iterator;
using Base::const_iterator;
using Base::reserve;

Pathname()
{
Expand Down Expand Up @@ -109,7 +110,12 @@ namespace Module {
return begin()[length() - 1];
}

void push_back(value_type c)
void prepend(value_type c)
{
Base::insert(begin(), c);
}

void append(value_type c)
{
Base::insert(end(), c);
}
Expand Down Expand Up @@ -137,7 +143,7 @@ namespace Module {

Pathname& extend_with_type(const value_type* ext)
{
push_back(u8'.');
append(u8'.');
append(ext);
return minted();
}
Expand Down
2 changes: 1 addition & 1 deletion src/hash_win.cxx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Windows Implementation of SHA256

#include <windows.h>
#include <gsl/gsl_util>
#include <gsl/util>
#include <ifc/file.hxx>
#include <vector>
#include <ifc/assertions.hxx>
Expand Down
2 changes: 1 addition & 1 deletion src/sgraph.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ namespace Module {
struct entry
{
std::string_view name;
S sort;
S sort{};
};

explicit constexpr FieldOffsetTable(const SortNameMapEntry<S>(&seq)[N]) noexcept
Expand Down

0 comments on commit a4b9418

Please sign in to comment.