[DRAFT] Add debug information to litmus format#1006
[DRAFT] Add debug information to litmus format#1006hernanponcedeleon wants to merge 2 commits intodevelopmentfrom
Conversation
| // TODO: make this the default addChild implementation | ||
| public Event addChildWithMetadata(int fid, Event child, int ln) { | ||
| Event e = addChild(fid, child); | ||
| e.setMetadata(new LineNumber(ln)); | ||
| return e; | ||
| } |
There was a problem hiding this comment.
It should probably be named addChildWithSourceInfo/DebugInfo or even addChildWithLineNumber.
Of course, if you eventually decide that this is the default addChild implementation, then the name can be simplified again.
There was a problem hiding this comment.
Yes, as the PR description mentions, I will eventually merge both methods into a default addChild
| public static String getLitmusLocationString(Event ev, boolean showThread) { | ||
| final String prefix = showThread ? ev.getThread().getName() : ""; | ||
| return ev.hasMetadata(LineNumber.class) ? | ||
| String.format("%s#%s", prefix, ev.getMetadata(LineNumber.class).lineNumber()) : | ||
| "@unknown"; | ||
| } | ||
|
|
There was a problem hiding this comment.
I'm not conviced that the use-site should know what shape the source location comes in.
Maybe you should actually have SourceLocation as the root type, and then subtypes like LineNumber.
Maybe it is even better to have language-specific subtypes like LitmusSourceLoc and LLVMSourceLoc (or GenericSourceLoc for high-level languages?). You can define those even as nested types SourceLocation.Litmus and SourceLocation.LLVM/SourceLocation.Generic within SourceLocation.
The getSourceLocationString method can do the case distinction based on the type of the source location.
The caller might still need to do a case-distinction based on whether he wants the thread to be printed or not though (unless we simply ignore that parameter for LLVM source locations).
However, you should fix MetadataMap.contains to look for subclasses instead of strict class equality (oddly enough, MetadataMap.get is based on subclassing?!). Then just use MetadataMap.get(SourceLocation.class).
In fact, if you overwrite toString for both types of source location appropriately, you don't even need a case distinction at all: just use String.format("@%s%s", prefix, srcLoc) (I would still put "@" for litmus code!)
|
Btw. we should stay with the name |
|
I pushed a variant of what I have suggested. Feel free to revert or modify the changes if you don't like them. |
Signed-off-by: Hernan Ponce de Leon <hernanl.leon@huawei.com>
9488289 to
59e2775
Compare
|
The output is still the same and the code LGTM (thanks!). Maybe I would just change I'll change all the litmus visitors to make use of the new metadata. |
We could also have |
|
I thought about it, but then we could not simply use There are only two places where we use |
That's why I'm asking if we should unconditionally print the thread. Our events always have an IR-level location and optionally a source-level location, and currently we just print both of them (which is IMO fine).
Is it really worth it to avoid the repetition though? |
We currently provide no useful debug information to the user for litmus programs . For example
The same is also true for witnesses.
This PR adds line number debug information to litmus code. So far it only does so for a few instructions (thus the draft status), but once we agree on code and the format we want for the output/witness, I will move the code in
addChildWithMetadatatoaddChildand pass the LOC in all litmus visitors.Output format: once we have proper lines of code for every format, which we already have for spirv/llvm (unless they fail to provide debug info, but I have rarely seen this happen), I think the information about the events id becomes completely useless for the user (it is probably already useless unless they know how to use the printer). However, it might still be useful for developers, so I will keep it, but at the end of the output.
The output for the example above looks like this now
This is even more useful for litmus syntax where each thread is a column
For the witness, since the nodes already contain the thread, I only use the LOC.