public void Program(CParser.TranslationUnit Program) { Console.WriteLine("using System"); Console.WriteLine(""); Console.WriteLine("static public class Invoke"); Console.WriteLine("{"); Console.WriteLine("\tconst string DllName = \"mydll.dll\";"); Traverse(Program.Declarations); Console.WriteLine("}"); }
public void ConvertTranslationUnit(CCompiler CCompiler, CParser.TranslationUnit Program) { Console.WriteLine(Program.ToYaml()); }
/// <summary> /// /// </summary> /// <param name="CCompiler"></param> /// <param name="TranslationUnit"></param> void ICConverter.ConvertTranslationUnit(CCompiler CCompiler, CParser.TranslationUnit TranslationUnit) { this.CCompiler = CCompiler; Traverse(TranslationUnit); }
public void TranslationUnit(CParser.TranslationUnit TranslationUnit) { #if false try { #endif PutDebugLine(TranslationUnit); try { File.Delete(OutFolder + "\\" + OutputName); } catch { } var ClassName = Path.GetFileNameWithoutExtension(OutputName); this.AssemblyBuilder = SafeAssemblyUtils.CreateAssemblyBuilder(ClassName, OutFolder); this.ModuleBuilder = this.AssemblyBuilder.CreateModuleBuilder(OutputName); this.RootTypeBuilder = this.ModuleBuilder.DefineType(ClassName, TypeAttributes.Class | TypeAttributes.Public | TypeAttributes.Sealed | TypeAttributes.BeforeFieldInit); PendingTypesToCreate.Add(this.RootTypeBuilder); var InitializerBuilder = this.RootTypeBuilder.DefineTypeInitializer(); var CurrentStaticInitializerSafeILGenerator = new SafeILGenerator(InitializerBuilder.GetILGenerator(), CheckTypes: false, DoDebug: false, DoLog: false); Scopable.RefScope(ref this.StaticInitializerSafeILGenerator, CurrentStaticInitializerSafeILGenerator, () => { Scopable.RefScope(ref this.CurrentClass, this.RootTypeBuilder, () => { AScope <VariableReference> .NewScope(ref this.VariableScope, () => { Traverse(TranslationUnit.Declarations); this.StaticInitializerSafeILGenerator.Return(typeof(void)); //RootTypeBuilder.CreateType(); foreach (var FunctionReference in FunctionScope.GetAll()) { if (!FunctionReference.BodyFinalized && FunctionReference.HasStartedBody) { Console.WriteLine("Function {0} without body", FunctionReference.Name); var FakeSafeILGenerator = new SafeILGenerator((FunctionReference.MethodInfo as MethodBuilder).GetILGenerator(), CheckTypes: true, DoDebug: true, DoLog: false); FakeSafeILGenerator.Push(String.Format("Not implemented '{0}'", FunctionReference.Name)); FakeSafeILGenerator.NewObject(typeof(NotImplementedException).GetConstructor(new Type[] { typeof(string) })); FakeSafeILGenerator.Throw(); } } foreach (var TypeToCreate in PendingTypesToCreate) { TypeToCreate.CreateType(); } if (EntryPoint != null) { this.AssemblyBuilder.SetEntryPoint(EntryPoint); } if (SaveAssembly) { // Copy the runtime. var RuntimePath = typeof(CModuleAttribute).Assembly.Location; try { File.Copy(RuntimePath, OutFolder + "\\" + Path.GetFileName(RuntimePath), overwrite: true); } catch { } /* * if (EntryPoint != null) * { * OutputName = Path.GetFileNameWithoutExtension(OutputName) + ".exe"; * } * else * { * OutputName = Path.GetFileNameWithoutExtension(OutputName) + ".dll"; * } */ #if false Console.WriteLine("Writting to {0}", OutputName); #endif //this.AssemblyBuilder.Save(OutputName, PortableExecutableKinds.Required32Bit, ImageFileMachine.I386); this.AssemblyBuilder.Save(OutputName, PortableExecutableKinds.ILOnly, ImageFileMachine.I386); } }); }); }); #if false } catch (Exception Exception) { if (ThrowException) { throw (Exception); } while (Exception.InnerException != null) { Exception = Exception.InnerException; } Console.Error.WriteLine(""); Console.Error.WriteLine("LastPosition: {0}", LastPositionInfo); Console.Error.WriteLine("{0} : '{1}'", Exception.TargetSite, Exception.Message); if (Exception.StackTrace != null) { Console.Error.WriteLine("{0}", String.Join("\n", Exception.StackTrace.Split('\n').Take(4))); Console.Error.WriteLine(" ..."); } } #endif }