Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds an unimplemented exception and exception catching in drivers #555

Merged
merged 2 commits into from
May 3, 2017

Conversation

cc10512
Copy link
Contributor

@cc10512 cc10512 commented May 2, 2017

Adds a new type of P4Exception: CompilerUnimplemented to replace
instances where we use BUG/BUG_CHECK as a placeholder for features
that we have not yet implemented.

Also adds exception catching in the compiler drivers, such that the
compiler exits cleanly.

@cc10512 cc10512 requested a review from jnfoster May 2, 2017 22:58
lib/exceptions.h Outdated
@@ -48,13 +48,31 @@ class CompilerBug final : public P4CExceptionBase {
template <typename... T>
CompilerBug(const char* format, T... args)
: P4CExceptionBase(format, args...)
{ message = "COMPILER BUG:\n" + message; }
// \e[31m prints the text in red
{ message = "\e[31mCOMPILER BUG\e[0m:\n" + message; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No "\e[5m"? Kidding. Should we remove the all-caps?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure "\e5m" will convey the right message: can it blink slow enough to wait for someone to fix the bug? :)

Yeah, camel case will make it less threatening.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this portable, or will it look terrible in non-xterm terminals?
I usually have my shell in emacs.

Copy link
Contributor

@jnfoster jnfoster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great.

Adds a new type of P4Exception: CompilerUnimplemented to replace
instances where we use BUG/BUG_CHECK as a placeholder for features
that we have not yet implemented.

Also adds exception catching in the compiler drivers, such that the
compiler exits cleanly.
P4::FrontEnd frontend;
frontend.addDebugHook(hook);
program = frontend.run(options, program);
} catch (const Util::P4CExceptionBase &bug) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a benefit for not catching exceptions: makes debugging easier.
Otherwise you have to set breakpoints manually in all these places.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory for debugging purposes you could use catch throw in gdb. I haven't ever actually tried that, though, so I'm not sure how well it works in practice.

lib/exceptions.h Outdated
@@ -48,13 +48,31 @@ class CompilerBug final : public P4CExceptionBase {
template <typename... T>
CompilerBug(const char* format, T... args)
: P4CExceptionBase(format, args...)
{ message = "COMPILER BUG:\n" + message; }
// \e[31m prints the text in red
{ message = "\e[31mCOMPILER BUG\e[0m:\n" + message; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this portable, or will it look terrible in non-xterm terminals?
I usually have my shell in emacs.

lib/exceptions.h Outdated
};

// This class indicates an unimplemented feature in the compiler
class CompilerUnimplemented final : public P4CExceptionBase {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably want a JavaDoc comment.
Also, this is not yet used anywhere, perhaps you want at least one use case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will start using it during code reviews. In particular, we are working on the bmv2 backend and there are a few places there. Coming ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is definitely portable. Works even on mobile phones. Emacs shell as well:
screen shot 2017-05-02 at 17 53 44

And address reviewer's comments + prettify.
@cc10512 cc10512 merged commit 0bfc94e into p4lang:master May 3, 2017
cc10512 pushed a commit to cc10512/p4c that referenced this pull request May 3, 2017
…lang#555)

* adds an unimplemented exception and exception catching in drivers

Adds a new type of P4Exception: CompilerUnimplemented to replace
instances where we use BUG/BUG_CHECK as a placeholder for features
that we have not yet implemented.

Also adds exception catching in the compiler drivers, such that the
compiler exits cleanly.

* fix unit test to account for escape sequences

And address reviewer's comments + prettify.
@cc10512 cc10512 deleted the cc/unimpl branch May 4, 2017 22:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants