[PATCH] D53842: [WebAssembly] Parsing missing directives to produce valid .o

Wouter van Oortmerssen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 1 09:28:04 PDT 2018


aardappel added inline comments.


================
Comment at: lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp:282
+                                            Triple::wasm64);
+          // TODO: do we ideally want more generic handling like this code
+          // below instead of checkKnownSymbol?
----------------
sbc100 wrote:
> aardappel wrote:
> > dschuff wrote:
> > > aardappel wrote:
> > > > I could remove the code below, left in for code review purposes.
> > > In general, I think making the assembler dumb is not a bad thing. Also you could argue that conventions for symbol names are compiler/ABI conventions and should not be automatically assumed by the assembler. So I guess if we thought of it that way it would mean that we'd have something like this generic code here, and the compiler would be required to output a directive declaring the type of `__stack_pointer` as a global, right? I think that is actually better than making the assembler smart about the compiler's ABI. Even the factoring of the Assembler/MC code reflects this idea; it's why there's no good place to put that code if it were shared.
> > Ok, so I could make the InstPrinter print out this info, but really the only information that should be in the .S output is wether it is global (which is already in there, and I can recover using the commented code below), and the type of the var, which I can also infer in the assembler. So really I don't need to share the function, the only reason to do was that a) it happens the same in both places, and b) that if someone decides to refactor this code they'll be forced to look at both.
> > 
> > I could make the assembler dumber if the InstPrinter also outputs the type. This could be in a directive like `.global __stack_pointer i32` but there is no obvious prelude/post output in InstPrinter (on the wasm side). Or we could pack it all in the symbol reference somehow, like `__stack_pointer at GLOBAL:I32` (would maybe require changes from the general parser) or `__stack_pointer at GLOBAL_I32` (polute with wasm specific symbol types).
> Seem like either `.global __stack_pointer` or `__stack_pointer at GLOBAL_I32` would be preferable to checkKnownSymbol.   For one thing, it would be nice if authors of .S files could declare (or at least use)  globals.
> 
> Also, `.global` is probably a bad directive name because `.globl` already exists for symbol binding.
> 
> 
Talked with @sunfish also and he seemed to prefer a directive.

What name should we use instead? .wasm_global? That's a bit odd as none of the other directives have wasm_ in them. Maybe .globaltype __stack_pointer i32 makes sense.


================
Comment at: lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp:396
+        return Error("Cannot parse .size expression: ", Lexer.getTok());
+      LastFunction->setSize(Exp);
     } else if (DirectiveID.getString() == ".param" ||
----------------
sbc100 wrote:
> Isn't `.size` already handled by the ELFAsmParser, e.g. `ELFAsmParser::ParseDirectiveSize`?  Or do we not use the ELFAsmParser at all anymore?
Without me parsing this, the binary writer would complain the size wasn't set. I'll look into it.


Repository:
  rL LLVM

https://reviews.llvm.org/D53842





More information about the llvm-commits mailing list