2017-05-26 04:48:44 +08:00
|
|
|
/*
|
|
|
|
* Program.cs
|
|
|
|
*
|
|
|
|
* This source file is part of the FoundationDB open source project
|
|
|
|
*
|
|
|
|
* Copyright 2013-2018 Apple Inc. and the FoundationDB project authors
|
2018-02-22 02:25:11 +08:00
|
|
|
*
|
2017-05-26 04:48:44 +08:00
|
|
|
* 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
|
2018-02-22 02:25:11 +08:00
|
|
|
*
|
2017-05-26 04:48:44 +08:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2018-02-22 02:25:11 +08:00
|
|
|
*
|
2017-05-26 04:48:44 +08:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2019-06-10 01:32:28 +08:00
|
|
|
using System;
|
2017-05-26 04:48:44 +08:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Text;
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
namespace actorcompiler
|
|
|
|
{
|
|
|
|
class Program
|
|
|
|
{
|
|
|
|
public static int Main(string[] args)
|
|
|
|
{
|
2019-05-22 08:56:14 +08:00
|
|
|
bool generateProbes = false;
|
2017-05-26 04:48:44 +08:00
|
|
|
if (args.Length < 2)
|
|
|
|
{
|
|
|
|
Console.WriteLine("Usage:");
|
2019-08-10 04:43:02 +08:00
|
|
|
Console.WriteLine(" actorcompiler <input> <output> [--disable-diagnostics] [--generate-probes]");
|
2017-05-26 04:48:44 +08:00
|
|
|
return 100;
|
|
|
|
}
|
|
|
|
Console.WriteLine("actorcompiler {0}", string.Join(" ", args));
|
|
|
|
string input = args[0], output = args[1], outputtmp = args[1] + ".tmp";
|
2019-02-13 02:32:45 +08:00
|
|
|
ErrorMessagePolicy errorMessagePolicy = new ErrorMessagePolicy();
|
2019-06-10 01:32:28 +08:00
|
|
|
foreach (var arg in args) {
|
|
|
|
if (arg.StartsWith("--")) {
|
2019-08-10 04:43:02 +08:00
|
|
|
if (arg.Equals("--disable-diagnostics")) {
|
|
|
|
errorMessagePolicy.DisableDiagnostics = true;
|
2019-06-10 01:32:28 +08:00
|
|
|
} else if (arg.Equals("--generate-probes")) {
|
|
|
|
generateProbes = true;
|
|
|
|
}
|
|
|
|
}
|
2019-05-22 08:56:14 +08:00
|
|
|
}
|
2017-05-26 04:48:44 +08:00
|
|
|
try
|
|
|
|
{
|
|
|
|
var inputData = File.ReadAllText(input);
|
|
|
|
using (var outputStream = new StreamWriter(outputtmp))
|
2019-07-17 06:53:00 +08:00
|
|
|
new ActorParser(inputData, input.Replace('\\', '/'), errorMessagePolicy, generateProbes).Write(outputStream, output.Replace('\\', '/'));
|
2017-05-26 04:48:44 +08:00
|
|
|
if (File.Exists(output))
|
|
|
|
{
|
|
|
|
File.SetAttributes(output, FileAttributes.Normal);
|
|
|
|
File.Delete(output);
|
|
|
|
}
|
|
|
|
File.Move(outputtmp, output);
|
|
|
|
File.SetAttributes(output, FileAttributes.ReadOnly);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
catch (actorcompiler.Error e)
|
|
|
|
{
|
|
|
|
Console.Error.WriteLine("{0}({1}): error FAC1000: {2}", input, e.SourceLine, e.Message);
|
|
|
|
if (File.Exists(outputtmp))
|
|
|
|
File.Delete(outputtmp);
|
|
|
|
if (File.Exists(output))
|
|
|
|
{
|
|
|
|
File.SetAttributes(output, FileAttributes.Normal);
|
|
|
|
File.Delete(output);
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
Console.Error.WriteLine("{0}({1}): error FAC2000: Internal {2}", input, 1, e.ToString());
|
|
|
|
if (File.Exists(outputtmp))
|
|
|
|
File.Delete(outputtmp);
|
|
|
|
if (File.Exists(output))
|
|
|
|
{
|
|
|
|
File.SetAttributes(output, FileAttributes.Normal);
|
|
|
|
File.Delete(output);
|
|
|
|
}
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|