Generalize simpleBuilder, add tests for genTopLevelFunc*