001package org.clafer.alloy.solve; 002 003import java.io.BufferedReader; 004import java.io.File; 005import java.io.InputStreamReader; 006import java.nio.charset.StandardCharsets; 007import java.util.List; 008import org.clafer.frontend.ModelFiles; 009import org.clafer.frontend.ToIr; 010import org.clafer.ig.Repl; 011 012/** 013 * The solution loop of a temporal model with the Alloy backend, as 014 * {@code claferIG FILE} runs it. 015 */ 016public final class Main { 017 018 private Main() { 019 } 020 021 /** 022 * Reads the model with the Java frontend. 023 * 024 * @throws IllegalArgumentException with the errors of the model 025 */ 026 public static ToIr.Result read(String path, List<String> imports) { 027 ToIr.Result r = ToIr.toIr(ModelFiles.read(path, imports)); 028 if (!r.messages().isEmpty()) { 029 throw new IllegalArgumentException(String.join("\n", r.messages())); 030 } 031 return r; 032 } 033 034 public static void main(String[] args) throws Exception { 035 String path = args[0]; 036 AlloyBackend backend = new AlloyBackend(() -> read(path, List.of()), new File(path).getName(), 037 AlloyBackend.Options.Default); 038 new Repl(backend, new Repl.Io(new BufferedReader(new InputStreamReader(System.in, StandardCharsets.UTF_8)), 039 System.out, System.err), false).run(); 040 } 041}