driver: suggest the closest triple for an unknown --target=

Open
#188 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
85/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
c
Domain
compilers

Research direction

Read src/driver/main.c around the unknown-target error and src/sema/sema.c around edit_distance() to understand the existing suggestion logic. Share that helper for the driver, then update tests/golden/triple.sh to cover a one-letter typo and a distant target such as banana. Done when the typo suggests the closest built triple, the distant target gets no suggestion, and the listed checks pass.

Written by the indexing model from the issue text.

Description

enhancement good first issue

Context. A mistyped triple gets the whole list of targets EmbCC knows, with no hint about which one was meant:

$ ./embcc --target=thumbv7m-none-eab -c t.c
embcc: error: unknown target 'thumbv7m-none-eab'
embcc: the targets it emits for are:
embcc:   x86_64-elf
...

clang and GCC users expect did you mean 'thumbv7m-none-eabi'?.

Where.

  • src/driver/main.c, around line 7091: the unknown target error, which walks target_triple_count() / target_triple_name().
  • src/sema/sema.c, line 2108: edit_distance(), a bounded Levenshtein distance that already powers "did you mean" for undeclared names. It is static there. Move it somewhere the driver can share (for example src/driver/util.c and util.h), rather than copying it.
  • Tests: tests/golden/triple.sh already checks the unknown-target error.

Steps.

  1. Make edit_distance shareable, and keep sema's use of it unchanged.
  2. In the unknown-target branch, find the built triple (target_triple_built(t)) closest to what was typed. If it is within a few edits (sema uses max(2, len / 3)), print embcc: note: did you mean 'X'? before the list.
  3. Add cases to tests/golden/triple.sh: a one-letter typo gets the suggestion, and something far from every triple (--target=banana) gets none.

Done when --target=thumbv7m-none-eab suggests thumbv7m-none-eabi, a nonsense triple suggests nothing, the test covers both, and make check and sh tests/golden/triple.sh pass.

Before you start: the contributor's guide has the rules. A new test counts only after it has failed against the code before your change, and a commit subject reads area: summary. Questions are welcome in the comments or in Discussions.

Dominant language
C
Stars
1
Forks
2
Avg merge
20h 55m
Merged PRs (30d)
73

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from EmbLinkOs/EmbCC

All issues in EmbLinkOs/EmbCC

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.