Sorry about this, yeah, it's harder than I remembered.

Overall the AST is the same as Uglify1. I don't actually see docs for it
right now, although I thought there were some.

But making this more complicated is that while the AST is Uglify1, the code
must also be asm.js. That is what you are hitting here, as asm.js must have
var and param declarations first. In other words, you can't put your new
call as the first element in the function, it must be after the vars and
params,

function f(x) {
  // not ok to add new code here
  x = x | 0;
  var y = 0;
  call(); // this is the first place you can add code
  ...
}

I believe you can call normalizeAsm() to remove those initial var and param
declarations, then it is ok to add the call as the first. Then you call
denormalizeAsm() to restore things. There are examples of those functions
in the other passes.


On Mon, Oct 31, 2016 at 8:50 AM, caiiiycuk <[email protected]> wrote:

> I want to implement PGO on js-optimizer step. But it hard to understand
> format of AST, is there are some docs about it? Currently I try to simply
> call PGO_INVOKE(1) in beginning of each function:
> function pgo(ast) {
>   var PATCHED_FUNCS = set();
>   traverseGeneratedFunctions(ast, function(func) {
>     var sig = func[1];
>     if (sig in PATCHED_FUNCS) return null;
>     var children = func[3];
>     children.unshift(['call', ['name', 'PGO_INVOKE'], [['num', 1]]]);
>     PATCHED_FUNCS[sig] = 1;
>   });
> }
>
> But after pgo step, I see an error:
> bad, seeing a var in need of fixing
> bad, seeing a var in need of fixing: ["defun", "__ZNSt3__26vectorI5VideoNS_
> 9allocatorIS1_EEE21__push_back_slow_pathIRKS1_EEvOT_", ["$0", "$1"],
> [["call", ["name", "PGO_INVOKE"], [["num", 1]]], ["stat", ["assign", true,
> ["name", "$0"], ["binary", "|", ["name", "$0"], ["num", 0]]]], ["stat",
> bad, seeing a var in need of fixing["assign": , ["defuntrue, ", "__
> ZN9Texture2D11imageLoadedEPviib", ["name", "[$1""]$0", , [""$1"binary",
> ", "$2", "$3|"", , "["name$4""], ", [$1"][, "call["", num"[", 0name",
> "PGO_INVOKE"], [[]"num]"]], , 1[]]], ["stat", ["assign"", true...
>
> Can you give me some advice?
>
> --
> You received this message because you are subscribed to the Google Groups
> "emscripten-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to