All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sandius.rembulan.compiler.analysis.LivenessInfo Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2016 Miroslav Janíček
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package net.sandius.rembulan.compiler.analysis;

import net.sandius.rembulan.compiler.ir.AbstractVal;
import net.sandius.rembulan.compiler.ir.IRNode;
import net.sandius.rembulan.compiler.ir.Var;
import net.sandius.rembulan.util.Check;

import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;

public class LivenessInfo {

	private final Map entries;
	
	public LivenessInfo(Map entries) {
		this.entries = Check.notNull(entries);
	}

	public static class Entry {

		private final Set var_in;
		private final Set var_out;
		private final Set val_in;
		private final Set val_out;

		Entry(Set var_in, Set var_out, Set val_in, Set val_out) {
			this.var_in = Check.notNull(var_in);
			this.var_out = Check.notNull(var_out);
			this.val_in = Check.notNull(val_in);
			this.val_out = Check.notNull(val_out);
		}

		public Entry immutableCopy() {
			return new Entry(
					Collections.unmodifiableSet(new HashSet<>(var_in)),
					Collections.unmodifiableSet(new HashSet<>(var_out)),
					Collections.unmodifiableSet(new HashSet<>(val_in)),
					Collections.unmodifiableSet(new HashSet<>(val_out)));
		}

		public Set inVar() {
			return var_in;
		}

		public Set outVar() {
			return var_out;
		}

		public Set inVal() {
			return val_in;
		}

		public Set outVal() {
			return val_out;
		}

	}

	public Entry entry(IRNode node) {
		Check.notNull(node);
		Entry e = entries.get(node);
		if (e == null) {
			throw new NoSuchElementException("No liveness information for " + node);
		}
		else {
			return e;
		}
	}

	public Iterable liveInVars(IRNode node) {
		return entry(node).inVar();
	}

	public Iterable liveOutVars(IRNode node) {
		return entry(node).outVar();
	}

	public Iterable liveInVals(IRNode node) {
		return entry(node).inVal();
	}

	public Iterable liveOutVals(IRNode node) {
		return entry(node).outVal();
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy