This is an archive of the discontinued LLVM Phabricator instance.

[yaml2obj] Add new command line option `-docnum`
ClosedPublic

Authored by atanasyan on May 23 2014, 1:31 PM.

Details

Reviewers
silvas
Summary

Input YAML file might contain multiple object file definitions. New option -docnum allows to specify an ordinal number (starting from 1) of definition used for an object file generation.

Diff Detail

Event Timeline

atanasyan updated this revision to Diff 9776.May 23 2014, 1:31 PM
atanasyan retitled this revision from to [yaml2obj] Add new command line option `-docnum`.
atanasyan updated this object.
atanasyan edited the test plan for this revision. (Show Details)
atanasyan added a reviewer: silvas.
atanasyan added a subscriber: Unknown Object (MLST).
silvas requested changes to this revision.May 25 2014, 12:26 PM
silvas edited edge metadata.
silvas added inline comments.
lib/Support/YAMLTraits.cpp
93–95

This seems like it should be a separately tested bug fix for YAMLIO

tools/yaml2obj/yaml2elf.cpp
498–508

Can we pull this loop up into yaml2obj.cpp and share it between yaml2coff and yaml2elf? I would prefer if all uses of the DocNum cl::opt are kept in the same file (and for there to be just one use).

The current way you are doing this also injects a false dependency on the document type (ELFYAML::Object or COFFYAML::Object) into the loop. It should be possible to skip documents without knowing their type (think Postel's Law). Essentially I'm imagining something like this Python code:

yaml2which = ... # yaml2coff or yaml2elf
for i, doc in enumerate(documents, 1):
    if i == docnum:
        yaml2which(doc)
        break
else:
    errs() << ...
This revision now requires changes to proceed.May 25 2014, 12:26 PM

Good point. I am going to send a new patch which moves the loop to the yaml2obj.cpp soon.

lib/Support/YAMLTraits.cpp
93–95

It is not a bug fix. Function Input::nextDocument() just incremented the DocIterator. We checked the end of documents stream in the Input::setCurrentDocument(). Now the Input::nextDocument() increments the iterator and return its "status".

atanasyan updated this revision to Diff 9925.May 29 2014, 12:07 PM
atanasyan updated this object.
atanasyan edited edge metadata.

Move the code which iterates YAML documents to the yaml2obj.cpp.

silvas accepted this revision.May 30 2014, 1:32 PM
silvas edited edge metadata.

LGTM with the tiny naming nit above about convertYaml/convertYAML.

I'm slightly worried that using indices could end up being brittle as test files are changed, but I can't think of a better way to select a document without introducing a lot of complexity. We can always change it later if it turns out to be a source of bugs.

tools/yaml2obj/yaml2obj.cpp
65

Tiny nit: typically when we use the acronym "yaml" in camel case, we spell it with all caps, so this function should be "convertYAML".

There are good arguments for doing it the way you have here (My favorite: HTTPSend/HTTPSEnd vs HttpSend/HttpsEnd), but I'd rather stick to convention.

This revision is now accepted and ready to land.May 30 2014, 1:32 PM
atanasyan closed this revision.May 30 2014, 10:01 PM

Thanks for review.

Initially I planed to implement something like -docname option. But I could not figure out how to name YAML documents. We can use tags for that but it is a good idea to reserve the tags for output file format specification (ELF | COFF). Maybe solution is to support some sort of "complex" tag format like !ELF|<doc label>.

Closed by commit rL209967.