[patch][rfc] Add pwrite to raw_stream

Rafael EspĂ­ndola rafael.espindola at gmail.com
Wed Apr 8 20:57:56 PDT 2015


> I'm surprised by this, FWIW.
>
> Whether it really makes sense or not, most of the raw_ostream interface is
> around formatting output in textual ways. Is the interface that you want
> really related to that at all?
>
> I feel like the object writer should be using a much simpler abstraction...

The problem is that it needs to at least have a common base class. We
pass a stream to LLVMTargetMachine::addPassesToEmitFile which then
gets used for asm or obj.

Note that different streams have different extra features.
formatted_raw_ostream is the one that keep tracks of columns.
raw_fd_stream already has seek.

Short of the need to support writing to a pipe, raw_fd_stream would
fit just fine.

>> * Thing has pwrite and/or seek.
>> * The object writer/streamer takes a thing instead of a plain raw_ostream.
>> * The thing can directly write to disk or hold data in a buffer and
>> dump it in the end.
>>
>> Would it work for you to have thing be raw_pwrite_streamer and
>
>
> I think its not a "streamer" and probably shouldn't try to follow the
> std::ostream interface patterns (including name).
>
>>
>>
>> raw_pwrite_streamer inherits from raw_ostream.
>
>
> If being able to pass this thing to raw_ostream-accepting interfaces is
> actually critical, sure.

LLVMTargetMachine::addPassesToEmitFile, see above.

>>
>> raw_fd_stream inherits from raw_pwrite_streamer
>> raw_svector_stream inherits from raw_pwrite_streamer
>> the object writer/streamer takes a raw_pwrite_streamer
>
>
> Related to the above, I suspect that most of the consumers of raw_fd_stream
> and raw_svector_stream have remarkably different constraints from the object
> writer. It seems weird to try to serve both of their needs via the same
> interface.

Not sure I understand.

For what it is worth, I have attached the two followup patches I have locally.

The first one avoids wrapping a stream in a formatted_raw_ostream when
writing an object file from llc or llvm-mc.

The second one builds on that to make sure the streamer passed to the
object writer supports pwrite and simplify the elf writer.

Cheers,
Rafael
-------------- next part --------------
A non-text attachment was scrubbed...
Name: t1.patch
Type: text/x-patch
Size: 5328 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150408/357f0c03/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: t2.patch
Type: text/x-patch
Size: 10599 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150408/357f0c03/attachment-0001.bin>


More information about the llvm-commits mailing list