@@ -2962,38 +2962,34 @@ SlangResult OptionsParser::_parse(int argc, char const* const* argv)
2962
2962
// Coerce Slang to load from the given file, without letting it automatically
2963
2963
// choose .slang-module files over .slang files.
2964
2964
// First try to load as source string, and fall back to loading as an IR Blob.
2965
- // Avoid guessing based on filename or inspect the file contents.
2966
- FILE* file;
2967
- fopen_s (&file, fileName.value .getBuffer (), " rb" );
2968
- if (!file)
2965
+ // Avoid guessing based on filename or inspecting the file contents.
2966
+ FileStream file;
2967
+ if (SLANG_FAILED (file.init (fileName.value , FileMode::Open, FileAccess::Read, FileShare::None)))
2969
2968
{
2970
2969
m_sink->diagnose (arg.loc , Diagnostics::cannotOpenFile, fileName.value );
2971
2970
return SLANG_FAIL;
2972
2971
}
2973
- fseek (file, 0 , SEEK_END);
2974
- size_t size = ftell (file);
2975
- fseek (file, 0 , SEEK_SET);
2976
- std::vector<char > buffer (size + 1 );
2977
- size_t result = fread (buffer.data (), 1 , size, file);
2978
- if (result != size)
2979
- {
2980
- m_sink->diagnoseRaw (Severity::Error, " Failed to read file" );
2981
- return SLANG_FAIL;
2982
- }
2983
- buffer[size] = 0 ;
2984
- fclose (file);
2985
2972
2973
+ List<uint8_t > buffer;
2974
+ file.seek (SeekOrigin::End, 0 );
2975
+ const Int64 size = file.getPosition ();
2976
+ buffer.setCount (size + 1 );
2977
+ file.seek (SeekOrigin::Start, 0 );
2978
+ SLANG_RETURN_ON_FAIL (file.readExactly (buffer.getBuffer (), (size_t )size));
2979
+ buffer[size] = 0 ;
2980
+ file.close ();
2981
+
2986
2982
ComPtr<slang::IModule> module;
2987
2983
module = session->loadModuleFromSourceString (
2988
2984
" module" ,
2989
2985
" path" ,
2990
- buffer.data (),
2986
+ ( const char *) buffer.getBuffer (),
2991
2987
diagnostics.writeRef ());
2992
2988
if (!module)
2993
2989
{
2994
2990
// Load buffer as an IR blob
2995
2991
ComPtr<slang::IBlob> blob;
2996
- blob = RawBlob::create (buffer.data (), size);
2992
+ blob = RawBlob::create (buffer.getBuffer (), size);
2997
2993
2998
2994
module = session->loadModuleFromIRBlob (
2999
2995
" module" ,
@@ -3012,6 +3008,7 @@ SlangResult OptionsParser::_parse(int argc, char const* const* argv)
3012
3008
}
3013
3009
else
3014
3010
{
3011
+ // success, print out the disassembly in a way that slang-test can read
3015
3012
m_sink->diagnoseRaw (
3016
3013
Severity::Note,
3017
3014
(const char *)disassemblyBlob->getBufferPointer ());
0 commit comments