コード例 #1
0
ファイル: Assembly.cs プロジェクト: sharpos/SharpOS
		/// <summary>
		/// Encodes the specified engine.
		/// </summary>
		/// <param name="engine">The engine.</param>
		/// <param name="target">The target.</param>
		/// <returns></returns>
		public bool Encode (Engine engine, string target)
		{
			this.symbols = new List<SharpOS.AOT.COFF.Symbol> ();
			this.data = new Assembly ();
			this.bss = new Assembly ();
			this.engine = engine;

			this.engine.Dump.Section (DumpSection.Encoding);

#if PE
			this.AddPEHeader ();
#else
			this.AddMultibootHeader ();
#endif

			this.ALIGN (ALIGNMENT);
			this.LABEL (START_CODE);

			this.AddEntryPoint ();

			this.engine.Dump.Section (DumpSection.MethodEncode);

			foreach (Class _class in engine) {
				// interfaces don't have method bodies
				if (_class.IsInterface)
					continue;

				if (_class.IsGenericType)
					continue;

				GenerateIMTHelpers(_class);

				if (_class.IsInternal)
					continue;

				foreach (Method method in _class.Methods) {
					if (method.IsGenericType)
						continue;

					this.engine.Dump.MethodEncode (method);

					engine.SetStatusInformation (_class.ClassDefinition.Module.Assembly,
						_class.ClassDefinition.Module, _class.ClassDefinition,
						method.MethodDefinition);

					new AssemblyMethod (this, method).GetAssemblyCode ();

					engine.ClearStatusInformation ();
				}
			}

			this.engine.Dump.PopElement ();

			this.AddHelperFunctions ();

			this.ALIGN (ALIGNMENT);
			this.LABEL (END_CODE);

			this.AddData ();
			this.AddSymbols ();
			this.AddBSS ();

			this.ALIGN (ALIGNMENT);
			this.LABEL (THE_END);

			this.Save (target);

			return true;
		}