Extending dart2js

68 views
Skip to first unread message

p4j...@gmail.com

unread,
Nov 26, 2014, 3:46:06 AM11/26/14
to compil...@dartlang.org
Is it actually possible to extend the dart2js compiler without forking it?

For example I would like to extend it so that I can set a flag and let dart2js compile doubles to single precision by inserting Math.fround() on any operation with a double in it.


cheers
Peter

Florian Loitsch

unread,
Nov 26, 2014, 9:23:18 AM11/26/14
to Peter Jakobs, Dart Compiler Developers
Adding Math.fround everywhere is a significant change and would probably can't be done without lots of changes in different parts of the compiler. As such, I would suggest forking the compiler.

Wrt your project: you will need to pay attention to (at least) the following places (the files have been moved recently, so you might need to look in other places if you don't have the exact same revision as me):
- pkg/compiler/lib/src/ssa/codegen.dart: visitAdd,...
  This produces the JS binary operations. We also use the operator + for string concatenation, so you will need to look at the left-operator's type before you add a `Math.fround` there.
- sdk/lib/_internal/compiler/js_lib/js_number.dart: operator+, ...

In theory you also need to adapt the compile-time constant operations:
- pkg/compiler/lib/src/js_backend/constant_system_javascript.dart

There might be other places that I forgot, but it should be a good start.

If I were you I would start temporarily with an environment flag to toggle the rounding:
  `const FORCE_SINGLE_PRECISION = const bool.fromEnvironment("force-single-precision");`
which you can then enable as follows:
DART_VM_OPTIONS='-Dforce-single-precision=true' sdk/lib/bin/dart2js ...

Hope that helps.

To unsubscribe from this group and stop receiving emails from it, send an email to compiler-dev...@dartlang.org.



--
Give a man a fire and he's warm for the whole day,
but set fire to him and he's warm for the rest of his life. - Terry Pratchett
Reply all
Reply to author
Forward
0 new messages