Uh oh!
There was an error while loading. Please reload this page.
Implement emit-h - #7111
Conversation
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
pixelherodev
commented
Nov 14, 2020
I'll review this tonight or tomorrow before getting back to work on the CBE :) |
pixelherodev
commented
Nov 15, 2020
Alright, reviewing now! :) @tetsuo-cpp Are you on IRC? |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| decl.analysis = .dependency_failure; | ||
| }, | ||
| else => { | ||
| try module.failed_decls.ensureCapacity(module.gpa, module.failed_decls.items().len + 1); |
There was a problem hiding this comment.
I think this makes sense. If emit-h is desired and fails, it should be treated as a failed compilation.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
pixelherodev
commented
Nov 15, 2020
@tetsuo-cpp Do you want to fix this up, or do you want me to? I'm happy either way :) |
pixelherodev
commented
Nov 15, 2020
Ah, right, one other thing: you need to add tests. However, there's no test harness for headers yet. I was planning on working on tests today anyways, I can add the harness and tests in a separate PR if you want to do the rest of the work and leave the tests to me. Alternately, if you want, I can (as mentioned earlier) take over this PR and do the tests myself, or I can help you with the full PR + tests and leave the work to you on this one. This is entirely up to you, just let me know how you want to proceed. I'm going to work on unrelated CBE test integration (running the tests with |
tetsuo-cpp
commented
Nov 15, 2020
Thanks for taking a look @pixelherodev.
I don't use IRC at the moment. I can get set up if it's helpful.
I'm happy to continue working on this until it's mergeable. Most of these comments look straightforward so I'll address them shortly.
Sure, let's do that. Once you've written the harness, I'm happy to help with writing tests if you'd like. |
tetsuo-cpp
commented
Nov 16, 2020
I've addressed your comments and marked the ones that aren't relevant anymore as "resolved". Since we decided to continue returning The main sticking point this time was reverting back to using the Another alternative would be to rip Since Sorry if this isn't what you meant, I'm still finding my feet here. |
pixelherodev
commented
Nov 16, 2020
I think this is good, just needs the testing work - I'll try to have that ready for you tonight :) |
b126510 to
2a12c56Comparepixelherodev
commented
Nov 18, 2020
Mind if I open a PR against your branch splitting this into multiple commits? |
tetsuo-cpp
commented
Nov 18, 2020
Sure, no problem. |
pixelherodev
commented
Nov 19, 2020
Okay, I think I should have a PR for header tests shortly :) |
pixelherodev
commented
Nov 19, 2020
pixelherodev
commented
Nov 19, 2020
Last problem: emit-h in compilation and c_header shouldn't coexist, and should be merged. |
pixelherodev
commented
Nov 19, 2020
Actually, this is also missing emit_h enablement in |
tetsuo-cpp
commented
Nov 19, 2020
Done. I added an
Done. Thanks, I missed that. Am I understanding correctly that if we do Thanks for doing that. It looks good to me. How do we want to do this? I'm thinking that I should merge that PR into my branch now and then I'll push a follow up commit adding some unit tests for the header generation. Do you agree with that? |
pixelherodev
commented
Nov 19, 2020
Nope!
Yep! Once that's done, we can bump this up to the core team for further review and merging :) |
tetsuo-cpp
commented
Nov 20, 2020
The changes that I uncommented in
Sounds good! I'll prepare some tests over the weekend. |
pixelherodev
commented
Nov 20, 2020
Ah, I see. I'd say either leave it as is and change the docs ( |
9b0184c to
cce3138Comparetetsuo-cpp
commented
Nov 23, 2020
@pixelherodev The only other changes since last time are that I've disabled header generation unless |
| } | ||
| } | ||
| // If we've chosen to emit a C header, flush the header the disk. |
There was a problem hiding this comment.
| // If we've chosen to emit a C header, flush the header the disk. | |
| // If we've chosen to emit a C header, flush the header to the disk. |
pixelherodev
commented
Nov 24, 2020
via email
Okay,if you merge the suggested fix for the comment, I think this has my
approval :) |
tetsuo-cpp
commented
Nov 25, 2020
Awesome. Done! |
8884f1f to
98a533bComparephifty
commented
Dec 17, 2020
Are there any news on this? |
tetsuo-cpp
commented
Dec 17, 2020
This patch is ready to go from my point of view. Just pending a review + merge from the team. |
phifty
commented
Dec 17, 2020
Ok thanks! I'm looking forward to this. It's preventing me to update my zig version. |
| if (expected_output.len != out.len) { | ||
| std.debug.print("\nTransformed header length differs:\n================\nExpected:\n================\n{}\n================\nFound:\n================\n{}\n================\nTest failed.\n", .{ expected_output, out }); | ||
| std.process.exit(1); | ||
| } | ||
| for (expected_output) |e, i| { | ||
| if (out[i] != e) { | ||
| std.debug.print("\nTransformed header differs:\n================\nExpected:\n================\n{}\n================\nFound:\n================\n{}\n================\nTest failed.\n", .{ expected_output, out }); | ||
| std.process.exit(1); | ||
| } | ||
| } |
There was a problem hiding this comment.
These should use std.testing.expectEqualStrings.
There was a problem hiding this comment.
As @pixelherodev mentioned, it's done like this elsewhere in test.zig. I'm planning to follow up with a PR after this to make this change across the file.
| man.hash.add(comp.bin_file.options.is_test); | ||
| man.hash.add(comp.bin_file.options.emit != null); | ||
| man.hash.addOptionalEmitLoc(comp.emit_h); | ||
| man.hash.add(comp.c_header != null); |
There was a problem hiding this comment.
There should be a addOptionalEmitLoc(header.emit_loc.?) here if c_header != null.
| .call => try genCall(&ctx, inst.castTag(.call).?), | ||
| .add => try genBinOp(&ctx, inst.cast(Inst.BinOp).?, "+"), | ||
| .sub => try genBinOp(&ctx, inst.cast(Inst.BinOp).?, "-"), | ||
| .assembly => try genAsm(&ctx, file, inst.castTag(.assembly).?), |
There was a problem hiding this comment.
Why remove file from the context if you're just going to pass it to nearly everything anyways?
There was a problem hiding this comment.
The file contains everything needed to output C source when the CBE is selected (buffers for main, constants, etc). That doesn't apply when we're generating a header and we may not even have one since we could be using a different backend in combination with emit-h.
Therefore, I've removed it from the context and passed it as a separate argument in the non-header code paths. Another idea could be to make it optional within the context but that seemed more error-prone to me.
pixelherodev
commented
Dec 17, 2020
via email
File should stay in the context.
Re testing expect vs print and exit, I think I copied that style from the
surrounding code - might be better to leave it alone here and do a full
cleanup in a follow up PR. |
tetsuo-cpp
commented
Dec 22, 2020
@Vexu |
Closes#6533.