dcbaker / meson-plus-plus

An experimental and incomplete implementation of Meson in C++, for solving Meson's bootstrapping issue.
Apache License 2.0
50 stars 7 forks source link

constant propogation #15

Closed dcbaker closed 2 years ago

dcbaker commented 3 years ago

We need a constant propagation and folding transformation pass to handle non-trivial programs.

we need to be able to take Meson DSL like:


srcs = files('a.cpp', 'b.cpp')
if host_machine.system() == 'windows'
    srcs += files('windows.cpp')
else
   srcs += files('posix.cpp')
endif

executable(
   exe,
  srcs,
)```

Since we can first resolve the if statement using passes that already exist:
```meson
srcs = files('a.cpp', 'b.cpp')
srcs += files('posix.cpp')

executable(
   exe,
  srcs,
)```

Then we can do constant folding:
```meson
srcs = files('a.cpp', 'b.cpp', 'posix.cpp')

executable(
   exe,
  srcs,
)```

then finally propogation:
```meson
executable(
   exe,
   files('a.cpp', 'b.cpp', 'posix.cpp'),
)```