tree-sitter / tree-sitter-c

C grammar for tree-sitter
MIT License
226 stars 100 forks source link

`Unknown register name 'x10' in asm` - inserting RISC-V assembly #157

Closed JL102 closed 1 year ago

JL102 commented 1 year ago

Hi,

I'm writing some C code which includes custom instructions for a RISC-V processor. I'm using a header file which includes macros for those custom instructions.

Here's an example of one of my functions after the macros have been evaluated:

static inline unsigned long qGetAny() {
  unsigned long result;
  {
  register uint64_t rd_ asm("x"
                            "10");
  asm volatile(".word "
               "0b0001011 | (10 << (7)) | (0 << (7+5)) | (0 << (7+5+1)) | (1 "
               "<< (7+5+2)) | (0 << (7+5+3)) | (0 << (7+5+3+5)) | ((((~(~0 << "
               "7) << 0) & (0b0000000 | 0b0000010)) >> 0) << (7+5+3+5+5))"
               "\n\t"
               : "=r"(rd_));
  result = rd_;
  };
  return result;
}

The clang LSP gives this error when it notices this code:

clang: Unknown register name 'x10' in asm [asm_unknown_register_name]

Is there some way to bypass this error, like for example to "inform" Clang that the register 'x10' exists?

amaanq commented 1 year ago

this is not related to tree-sitter at all

amaanq commented 1 year ago

That being said, this code does fail to parse

amaanq commented 1 year ago

I've fixed the parse bug - for the LSP you will need to generate a compile_commands.json file so the LSP can pick up on how it should compile the code - you likely need some sort of flag to pass in the proper arch/setup. you can output the file with -MJ iirc, just going off my memory.

JL102 commented 1 year ago

I've fixed the parse bug - for the LSP you will need to generate a compile_commands.json file so the LSP can pick up on how it should compile the code - you likely need some sort of flag to pass in the proper arch/setup. you can output the file with -MJ iirc, just going off my memory.

Thanks for the info! I don't entirely understand the terms you're using though; how do I pass those flags into the LSP?