public CompilerOutput Compile(string solcPath, string derivedFilePath) { if (!File.Exists(solcPath)) { throw new SystemException($"Cannot find solidity compiler at {solcPath}"); } derivedFilePath = derivedFilePath.Replace("\\", "/" /*, StringComparison.CurrentCulture*/); Console.WriteLine(solcPath); string jsonString = RunSolc(solcPath, derivedFilePath); List <string> errors = new List <string>(); var settings = new JsonSerializerSettings { Error = (sender, errorArgs) => { errors.Add(errorArgs.ErrorContext.Error.Message); errorArgs.ErrorContext.Handled = true; }, }; CompilerOutput compilerOutput = JsonConvert.DeserializeObject <CompilerOutput>(jsonString); if (errors.Count != 0) { throw new SystemException($"Deserialization of Solidity compiler output failed with errors: {JsonConvert.SerializeObject(errors)}"); } return(compilerOutput); }
// Legacy entry point for testing private static void LegacyMain(string[] args) { DirectoryInfo debugDirectoryInfo = Directory.GetParent(Directory.GetCurrentDirectory()); string workingDirectory = debugDirectoryInfo.Parent.Parent.Parent.Parent.FullName; string filename = "AssertTrue.sol"; string solcPath = workingDirectory + "\\Tool\\solc.exe"; string filePath = workingDirectory + "\\Test\\regression\\" + filename; SolidityCompiler compiler = new SolidityCompiler(); CompilerOutput compilerOutput = compiler.Compile(solcPath, filePath); AST ast = new AST(compilerOutput); Console.WriteLine(ast.GetSourceUnits()); Console.ReadLine(); }
public bool Execute(string filename) { string filePath = testDirectory + "\\" + filename; // read the program text string programText = File.ReadAllText(filePath); // get the text of AST traversal SolidityCompiler compiler = new SolidityCompiler(); CompilerOutput compilerOutput = compiler.Compile(solcPath, filePath); AST ast = new AST(compilerOutput); ASTNode sourceUnits = ast.GetSourceUnits(); return(TextCompare(programText, sourceUnits.ToString())); }