ssm-lang / sslang

A language built atop the Sparse Synchronous Model
BSD 3-Clause "New" or "Revised" License
18 stars 0 forks source link

Add name mangling pass to make VarIds globally unique #120

Closed j-hui closed 1 year ago

j-hui commented 2 years ago

This pass adds a name mangling pass that ensures all variable identifiers are globally unique, while also making sure that identifier names are actually valid C identifiers.

My mangling strategy is conservative; when picking a new identifier, it appends ascending numbers until it finds a name that hasn't already been defined. Though this is somewhat inefficient when there are consistent clashes, it produces much more readable mangled names.

This pass also introduces a global identifiers map in the Program record that maps those global identifiers to their original names. This can be used for nicer pretty-printing, or to ensure that newly generated names do not clash with any other identifiers.

Still left to do:

j-hui commented 2 years ago

The lambda lift pass is still broken with respect to #111 . To fix it, I need to add type information to the varNames map, which will allow me to simplify the lambda lifting pass to not have to manage local scope anymore.