Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
using System.Reflection;
using System.Runtime.CompilerServices;
[assembly: AssemblyVersion (Consts.MonoVersion)]
[assembly: AssemblyTitle ("Mono ILasm Compiler")]
[assembly: AssemblyDescription ("Mono ILasm Compiler")]
[assembly: AssemblyCopyright ("Sergey Chaban and Jackson Harper")]

409
mcs/ilasm/ChangeLog Normal file
View File

@@ -0,0 +1,409 @@
2009-01-09 Miguel de Icaza <miguel@novell.com>
* Add support for `strict' in .method declaration
2008-02-21 Ankit Jain <jankit@novell.com>
Fix bug #363587
* Driver.cs: Use Report.Message for emitting messages.
* Report.cs (AssembleFile): Honor 'quiet'.
Patch from Andrea Carlo Ornstein <andrea.ornstein@st.com>
2008-02-07 Gert Driesen <drieseng@users.sourceforge.net>
* Driver.cs: Removed crazy logic prevent debug symbol from being
created when /debug is set.
2008-02-06 Ankit Jain <jankit@novell.com>
Fix bug #358496.
* ExternMethodRef.cs (ResolveVararg): Fix the check for sentinel.
2007-12-31 Rodrigo Kumpera <rkumpera@novell.com>
* ilasm.exe.sources: added EmiteByteInst.cs.
2006-06-07 Ankit Jain <jankit@novell.com>
* Report.cs (Report.FilePath): New, static property.
(Report.Error): Remove overload with file_path param.
(Report.Warning): New.
* Driver.cs (DriverMain.Run): Set Report.FilePath .
(DriverMain.ProcessFile): Update use of Report.Error .
2006-05-26 Ankit Jain <jankit@novell.com>
* ilasm.exe.sources: Add Assembly.cs
* Driver.cs: Update to use the new Assembly class.
2006-05-26 Ankit Jain <jankit@novell.com>
* ilasm.exe.sources: Add PermissionMember.cs, PermissionSet.cs &
Permission.cs
2006-05-11 Ankit Jain <jankit@novell.com>
* Report.cs (Report.Error): Add 2 new overloads.
(ILAsmException.ctor): Add 2 new overloads, with location and file_path
params.
(ILAsmException.Location):
(ILAsmException.FilePath): New properties.
(ILAsmException.ToString): Return formatted error message.
* Driver.cs (DriverMain.ProcessFile): Improve error message display.
(DriverMain.Run): Use ILAsmException.ToString ().
2006-05-09 Sebastien Pouliot <sebastien@ximian.com>
* Driver.cs: Move up the loading of the strongname key pair to allow
embedding the public part into the assembly. Also don't try to sign
netmodules.
2006-04-24 Ankit Jain <jankit@novell.com>
* Driver.cs (DriverMain.Run): Update use of CodeGen.ctor .
2006-02-20 Ankit Jain <jankit@novell.com>
* Report.cs (Report): Make all methods,fields static.
(Report.Error): Update to throw ILAsmException.
(ILAsmException): New.
(InternalErrorException): New. Derive from ILAsmException.
* Driver.cs (Driver.Run): Catch ILAsmException and PEFileException and
print error messages instead of dumping the stack trace, and delete the
output file if CodeGen.Write() fails.
Move the check for entrypoint from CodeGen.Write to here.
2006-01-19 Ankit Jain <jankit@novell.com>
* ilasm.exe.sources: Add Module.cs to the build.
2006-01-13 Ankit Jain <jankit@novell.com>
* ilasm.exe.sources: Replace IMethodRef.cs with BaseMethodRef.cs
2006-01-09 Ankit Jain <jankit@novell.com>
* ilasm.exe.sources: Replace GenericTypeRef.cs with GenericParamRef.cs
2006-01-07 Ankit Jain <jankit@novell.com>
* ilasm.exe.sources: Add GenericParameters.cs to the build.
2006-01-06 Ankit Jain <jankit@novell.com>
* ilasm.exe.sources: Remove ExternTypeRefInst from build.
2005-12-21 Ankit Jain <jankit@novell.com>
* ilasm.exe.sources: Add GenericArguments.cs to the build.
2005-08-26 Kornél Pál <kornelpal@hotmail.com>
* AssemblyInfo.cs: Using Consts.MonoVersion instead of MonoVersion.cs.
* ilasm.exe.sources: Using Consts.MonoVersion instead of MonoVersion.cs.
2005-08-05 Ankit Jain <jankit@novell.com>
* ilasm.exe.sources: Add DeclSecurity.cs to the build.
2005-05-12 Ankit Jain <ankit@corewars.org>
* Makefile (LOCAL_MCS_FLAGS): Use the in-tree PEAPI.dll as its public
interface has changed a bit, so avoid clash with older installed
dll.
2005-04-21 Raja R Harinath <rharinath@novell.com>
* Makefile (PROGRAM): Make profile-specific.
2004-12-08 Sebastien Pouliot <sebastien@ximian.com>
* Driver.cs: Added support for /key option to strongname assemblies
produced by ilasm. Fix bug #69721.
* Makefile: Added dependency on Mono.Security.dll assembly to provide
strongnaming support.
2004-12-02 Miguel de Icaza <miguel@ximian.com>
* CodeGen.cs: Correctly compute the name of a nested class,
currently it was ignoring anything above level 1.
2004-07-27 Jackson Harper <jackson@ximian.com>
* Driver.cs: Make debug switch compatible with MS's add debug to
the usage.
2004-07-27 Martin Baulig <martin@ximian.com>
Added debugging support to ilasm :-)
* Makefile: Depend on Mono.CSharp.Debugger.dll (this is only
exposed in DebuggingInfo.cs, so we can easily change that).
* Driver.cs: Added --debug command line argument to create
debugging info; this'll create a .mdb symbol file.
2004-06-26 Jackson Harper <jackson@ximian.com>
* Report.cs: Fix quiet.
2004-06-24 Jackson Harper <jackson@ximian.com>
* Report.cs: Add new mehtod for displaying messages.
2004-06-23 Jackson Harper <jackson@ximian.com>
* Driver.cs: Use the same success message as MS.
2004-06-19 Jackson Harper <jackson@ximian.com>
* ilasm.exe.sources: Add MethodPointerTypeRef.cs to the build.
2004-06-14 Jackson Harper <jackson@ximian.com>
* ilasm.exe.sources: Add FileRef.cs
2004-06-10 Jackson Harper <jackson@ximian.com>
* Driver.cs: Handle tokenization errors with the correct error
message.
* Report.cs: Print error messages properly. Add an extra \n after
the assemble file message.
* ilasm.exe.sources: Add new exception, remove old one.
2004-06-04 Jackson Harper <jackson@ximian.com>
* Driver.cs: Do everything using the invariant culture.
2004-04-26 Jackson Harper <jackson@ximian.com>
* Makefile: Get libs from the default profile directory
2004-04-05 Jackson Harper <jackson@ximian.com>
* Driver.cs: Accept output option. Usage shows /output instead of
/out like MS.
2004-04-01 Jackson Harper <jackson@ximian.com>
* Driver.cs: The parser now needs to take a scanner object in its
constructor so it can set a flag when parsing byte arrays.
2004-02-18 Jackson Harper <jackson@ximian.com>
* ilasm.exe.sources: Add ExternTypeRefInst to the build.
2003-11-16 Jackson Harper <jackson@ximian.com>
* Driver.cs: Give the parser an instance of the stream reader so
it can get the streams encoding.
2003-11-16 Jackson Harper <jackson@ximian.com>
* Driver.cs: If an arg isn't a switch and starts with a / add it
as a file to be compiled. This fixes bug #51041.
2003-10-28 Jackson Harper <jackson@ximian.com>
* Driver.cs: Stub some command line args to maintain compatibility
with MS.
2003-10-01 Jackson Harper <jackson@latitudegeo.com>
* Driver.cs: Remove delete on error, add quiet option.
* Report.cs: Can be quiet
2003-09-21 Jackson Harper <jackson@latitudegeo.com>
* Driver.cs: Give codegen a report object
* Report.cs: Remove silly methods that wouldnt have worked. Errors
are just string messages.
2003-08-14 Jackson Harper <jackson@latitudegeo.com>
* Driver.cs: Report entry for each il file processed
* Report.cs: New file - All error/warning/progress reporting will
go through here.
* ilasm.exe.sources: Add report to build
2003-08-12 Jackson Harper <jackson@latitudegeo.com>
* AssemblyInfo.cs: Bump up the vizzity-version number.
2003-07-30 Jackson Harper <jackson@latitudegeo.com>
* Driver.cs: Throw compile errors for now
2003-07-30 Jackson Harper <jackson@latitudegeo.com>
* Driver.cs: Add some basic line number feedback when an error
occurs
2003-07-17 Jackson Harper <jackson@latitudegeo.com>
* ilasm.exe.sources: Add corlib/GenericTypeRef.cs to build
2003-07-15 Jackson Harper <jackson@latitudegeo.com>
* Driver.cs: Use WriteLine for 'compilation succeeded' message.
2003-07-16 Peter Williams <peter@newton.cx>
* Makefile (ILParser.cs): Move this from parser/ so we avoid
slash direction issues on the Windows build.
* .cvsignore: Add ILParser.cs here.
2003-07-14 Jackson Harper <jackson@latitudegeo.com>
* Makefile: Add the class/lib directory to the lib path so the
newest PEAPI is allways loaded.
2003-06-08 Jackson Harper <jackson@latitudegeo.com>
* AssemblyInfo.cs: Bump version number up (way up) lots of
features have been implemented since last version.
2003-05-19 Jackson Harper <jackson@latitudegeo.com>
* Driver.cs: Exit with 1 return code when no arguments are supplied.
2003-05-19 Jackson Harper <jackson@latitudegeo.com>
* Driver.cs: Add command switch to delete output files created if
there is an error.
2003-05-19 Jackson Harper <jackson@latitudegeo.com>
* Driver.cs: Print error exception when compilation fails.
2003-05-18 Jackson Harper <jackson@latitudegeo.com>
* Driver.cs: Return an error code if any errors occur during
compiling. Also print a success or error message.
2003-05-02 Jackson Harper <jackson@latitudegeo.com>
* AssemblyInfo.cs: Bump up version number
2003-04-30 Jackson Harper <jackson@latitudegeo.com>
* makefile: Add instructions to build
* makefile.gnu: Add instructions to build
2003-04-20 Jackson Harper <jackson@latitudegeo.com>
* makefile: Add DataDef to build
* makefile.gnu: Add DataDef to build
2003-04-17 Jackson Harper <jackson@latitudegeo.com>
* makefile: Add new types to build
* makefile.gnu: Add new types to build
2003-04-17 Jackson Harper <jackson@latitudegeo.com>
* AssemblyInfo.cs: Increase version number.
2003-04-17 Jackson Harper <jackson@latitudegeo.com>
* Driver.cs: Call new codegen methods.
* makefile: Add new types to build
* makefile.gnu: Add new types to build
2003-03-31 Jackson Harper <jackson@latitudegeo.com>
* Driver.cs: de-tabbify
2003-03-29 Jackson Harper <jackson@latitudegeo.com>
* Driver.cs: Add switch to display parser debugging information.
2003-03-16 Jackson Harper <jackson@latitudegeo.com>
* Driver.cs: Add switch to display method definitions and references.
2003-03-16 Jackson Harper <jackson@latitudegeo.com>
* Driver.cs: Add switch to display tokens as they are generated.
2003-03-15 Jackson Harper <jackson@latitudegeo.com>
* makefile, makefile.gnu: Add FieldTable to build
Fri Mar 14 10:06:49 CET 2003 Paolo Molaro <lupus@ximian.com>
* codegen/InstrTable.cs: fix break instruction name.
* codegen/Method.cs: use ArgumentNullException.
* parser/ILParser.jay: handle stdcall convention.
2003-03-08 Jackson Harper <jackson@latitudegeo.com>
* makefile, makefile.gnu: Add InstrTable to build
2003-03-08 Jackson Harper <jackson@latitudegeo.com>
* makefile, makefile.gnu: Add MethodTable and TypeRef to build.
2003-03-08 Jackson Harper <jackson@latitudegeo.com>
* makefile, makefile.gnu: Add ExternTable to build
2003-03-08 Jackson Harper <jackson@latitudegeo.com>
* Driver.cs: If a file does not exist print an error and exit.
2003-03-07 Alp Toker <alp@atoker.com>
* makefile, makefile.gnu: reference PEAPI.dll instead of including
PEAPI.cs
2003-03-06 Jackson Harper <jackson@latitudegeo.com>
* AssemblyInfo.cs: Bump up version number, this new version is a major
structural change, PEAPI is now being used for code emission.
* makefile, makefile.gnu: Add AssemblyInfo.cs to build
2003-03-06 Jackson Harper <jackson@latitudegeo.com>
* Driver.cs: Check that all types are defined before writing pe file
2003-03-06 Jackson Harper <jackson@latitudegeo.com>
* makefile, makefile.gnu: Include PEAPI.cs instead of linking to it, this fixes build but is not ideal.
2003-03-06 Jackson Harper <jackson@latitudegeo.com>
* Driver.cs: Change a few calls to match new CodeGen
* makefile: Build with PEAPI
* makefile.gnu: Build with PEAPI
2003-02-22 Jackson Harper <jackson@latitudegeo.com>
* Driver.cs: Add version option, fix bug that allowed -- switches to be invoked with /-
2003-02-21 Jackson Harper <jackson@latitudegeo.com>
* AssemblyInfo.cs: Add file
* makefile: Add AssemblyInfo to build
* makefile.gnu: Add AssemblyInfo to build
2003-02-08 Jackson Harper <jackson@latitudegeo.com>
* makefile: Add TypeManager.cs to build
* makefile.gnu: Add TypeManager.cs to build
2003-02-03 Jackson Harper <jackson@latitudegeo.com>
* Driver.cs: Remove some debugging info.
2003-02-02 Jackson Harper <jackson@latitudegeo.com>
* makefile.gnu: Use new Driver.cs instead of Main.cs
2003-02-02 Jackson Harper <jackson@latitudegeo.com>
* Driver.cs: Add new Driver
* tests: Add new tests directory
* makefile: Use new Driver.cs instead of Main.cs

371
mcs/ilasm/Driver.cs Normal file
View File

@@ -0,0 +1,371 @@
//
// Mono.ILASM.Driver
// Main Command line interface for Mono ILasm Compiler
//
// Author(s):
// Jackson Harper (Jackson@LatitudeGeo.com)
//
// (C) 2003 Jackson Harper, All rights reserved
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
//
using System;
using System.IO;
using System.Reflection;
using System.Collections;
using System.Security.Cryptography;
using Mono.Security;
namespace Mono.ILASM {
public class Driver {
enum Target {
Dll,
Exe
}
public static int Main (string[] args)
{
// Do everything in Invariant
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
DriverMain driver = new DriverMain (args);
if (!driver.Run ())
return 1;
Report.Message ("Operation completed successfully");
return 0;
}
private class DriverMain {
private ArrayList il_file_list;
private string output_file;
private Target target = Target.Exe;
private string target_string = "exe";
private bool show_tokens = false;
private bool show_method_def = false;
private bool show_method_ref = false;
private bool show_parser = false;
private bool scan_only = false;
private bool debugging_info = false;
private CodeGen codegen;
private bool keycontainer = false;
private string keyname;
private StrongName sn;
public DriverMain (string[] args)
{
il_file_list = new ArrayList ();
ParseArgs (args);
}
public bool Run ()
{
if (il_file_list.Count == 0)
Usage ();
if (output_file == null)
output_file = CreateOutputFilename ();
try {
codegen = new CodeGen (output_file, target == Target.Dll, debugging_info);
foreach (string file_path in il_file_list) {
Report.FilePath = file_path;
ProcessFile (file_path);
}
if (scan_only)
return true;
if (Report.ErrorCount > 0)
return false;
if (target != Target.Dll && !codegen.HasEntryPoint)
Report.Error ("No entry point found.");
// if we have a key and aren't assembling a netmodule
if ((keyname != null) && !codegen.IsThisAssembly (null)) {
LoadKey ();
// this overrides any attribute or .publickey directive in the source
codegen.ThisAssembly.SetPublicKey (sn.PublicKey);
}
try {
codegen.Write ();
} catch {
File.Delete (output_file);
throw;
}
} catch (ILAsmException e) {
Error (e.ToString ());
return false;
} catch (PEAPI.PEFileException pe) {
Error ("Error : " + pe.Message);
return false;
}
try {
if (sn != null) {
Report.Message ("Signing assembly with the specified strongname keypair");
return Sign (output_file);
}
} catch {
return false;
}
return true;
}
private void Error (string message)
{
Console.WriteLine (message + "\n");
Console.WriteLine ("***** FAILURE *****\n");
}
private void LoadKey ()
{
if (keycontainer) {
CspParameters csp = new CspParameters ();
csp.KeyContainerName = keyname;
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider (csp);
sn = new StrongName (rsa);
} else {
byte[] data = null;
using (FileStream fs = File.OpenRead (keyname)) {
data = new byte [fs.Length];
fs.Read (data, 0, data.Length);
fs.Close ();
}
sn = new StrongName (data);
}
}
private bool Sign (string filename)
{
// note: if the file cannot be signed (no public key in it) then
// we do not show an error, or a warning, if the key file doesn't
// exists
return sn.Sign (filename);
}
private void ProcessFile (string file_path)
{
if (!File.Exists (file_path)) {
Console.WriteLine ("File does not exist: {0}",
file_path);
Environment.Exit (2);
}
Report.AssembleFile (file_path, null,
target_string, output_file);
StreamReader reader = File.OpenText (file_path);
ILTokenizer scanner = new ILTokenizer (reader);
if (show_tokens)
scanner.NewTokenEvent += new NewTokenEvent (ShowToken);
//if (show_method_def)
// MethodTable.MethodDefinedEvent += new MethodDefinedEvent (ShowMethodDef);
//if (show_method_ref)
// MethodTable.MethodReferencedEvent += new MethodReferencedEvent (ShowMethodRef);
if (scan_only) {
ILToken tok;
while ((tok = scanner.NextToken) != ILToken.EOF) {
Console.WriteLine (tok);
}
return;
}
ILParser parser = new ILParser (codegen, scanner);
codegen.BeginSourceFile (file_path);
try {
if (show_parser)
parser.yyparse (new ScannerAdapter (scanner),
new yydebug.yyDebugSimple ());
else
parser.yyparse (new ScannerAdapter (scanner), null);
} catch (ILTokenizingException ilte) {
Report.Error (ilte.Location, "syntax error at token '" + ilte.Token + "'");
} catch (Mono.ILASM.yyParser.yyException ye) {
Report.Error (scanner.Reader.Location, ye.Message);
} catch (ILAsmException ie) {
ie.FilePath = file_path;
ie.Location = scanner.Reader.Location;
throw;
} catch (Exception e){
Console.Write ("{0} ({1}, {2}): ",file_path, scanner.Reader.Location.line, scanner.Reader.Location.column);
throw;
} finally {
codegen.EndSourceFile ();
}
}
public void ShowToken (object sender, NewTokenEventArgs args)
{
Console.WriteLine ("token: '{0}'", args.Token);
}
/*
public void ShowMethodDef (object sender, MethodDefinedEventArgs args)
{
Console.WriteLine ("***** Method defined *****");
Console.WriteLine ("-- signature: {0}", args.Signature);
Console.WriteLine ("-- name: {0}", args.Name);
Console.WriteLine ("-- return type: {0}", args.ReturnType);
Console.WriteLine ("-- is in table: {0}", args.IsInTable);
Console.WriteLine ("-- method atts: {0}", args.MethodAttributes);
Console.WriteLine ("-- impl atts: {0}", args.ImplAttributes);
Console.WriteLine ("-- call conv: {0}", args.CallConv);
}
public void ShowMethodRef (object sender, MethodReferencedEventArgs args)
{
Console.WriteLine ("***** Method referenced *****");
Console.WriteLine ("-- signature: {0}", args.Signature);
Console.WriteLine ("-- name: {0}", args.Name);
Console.WriteLine ("-- return type: {0}", args.ReturnType);
Console.WriteLine ("-- is in table: {0}", args.IsInTable);
}
*/
private void ParseArgs (string[] args)
{
string command_arg;
foreach (string str in args) {
if ((str[0] != '-') && (str[0] != '/')) {
il_file_list.Add (str);
continue;
}
switch (GetCommand (str, out command_arg)) {
case "out":
case "output":
output_file = command_arg;
break;
case "exe":
target = Target.Exe;
target_string = "exe";
break;
case "dll":
target = Target.Dll;
target_string = "dll";
break;
case "quiet":
Report.Quiet = true;
break;
case "debug":
case "deb":
debugging_info = true;
break;
// Stubs to stay commandline compatible with MS
case "listing":
case "nologo":
case "clock":
case "error":
case "subsystem":
case "flags":
case "alignment":
case "base":
case "resource":
break;
case "key":
if (command_arg.Length > 0)
keycontainer = (command_arg [0] == '@');
if (keycontainer)
keyname = command_arg.Substring (1);
else
keyname = command_arg;
break;
case "scan_only":
scan_only = true;
break;
case "show_tokens":
show_tokens = true;
break;
case "show_method_def":
show_method_def = true;
break;
case "show_method_ref":
show_method_ref = true;
break;
case "show_parser":
show_parser = true;
break;
case "-about":
if (str[0] != '-')
break;
About ();
break;
case "-version":
if (str[0] != '-')
break;
Version ();
break;
default:
if (str [0] == '-')
break;
il_file_list.Add (str);
break;
}
}
}
private string GetCommand (string str, out string command_arg)
{
int end_index = str.IndexOfAny (new char[] {':', '='}, 1);
string command = str.Substring (1,
end_index == -1 ? str.Length - 1 : end_index - 1);
if (end_index != -1) {
command_arg = str.Substring (end_index+1);
} else {
command_arg = null;
}
return command.ToLower ();
}
/// <summary>
/// Get the first file name and makes it into an output file name
/// </summary>
private string CreateOutputFilename ()
{
string file_name = (string)il_file_list[0];
int ext_index = file_name.LastIndexOf ('.');
if (ext_index == -1)
ext_index = file_name.Length;
return String.Format ("{0}.{1}", file_name.Substring (0, ext_index),
target_string);
}
private void Usage ()
{
Console.WriteLine ("Mono ILasm compiler\n" +
"ilasm [options] source-files\n" +
" --about About the Mono ILasm compiler\n" +
" --version Print the version number of the Mono ILasm compiler\n" +
" /output:file_name Specifies output file.\n" +
" /exe Compile to executable.\n" +
" /dll Compile to library.\n" +
" /debug Include debug information.\n" +
" /key:keyfile Strongname using the specified key file\n" +
" /key:@container Strongname using the specified key container\n" +
"Options can be of the form -option or /option\n");
Environment.Exit (1);
}
private void About ()
{
Console.WriteLine (
"For more information on Mono, visit the project Web site\n" +
" http://www.go-mono.com\n\n");
Environment.Exit (0);
}
private void Version ()
{
string version = System.Reflection.Assembly.GetExecutingAssembly ().GetName ().Version.ToString ();
Console.WriteLine ("Mono ILasm compiler version {0}", version);
Environment.Exit (0);
}
}
}
}

22
mcs/ilasm/Makefile Normal file
View File

@@ -0,0 +1,22 @@
thisdir = ilasm
SUBDIRS =
include ../build/rules.make
PROGRAM = ilasm.exe
BUILT_SOURCES = ILParser.cs
LOCAL_MCS_FLAGS = /lib:../class/lib/$(PROFILE) /r:../class/lib/$(PROFILE)/PEAPI.dll /r:Mono.CompilerServices.SymbolWriter.dll /r:Mono.Security.dll
CLEAN_FILES = parser/y.output
EXTRA_DISTFILES = \
parser/ILParser.jay \
parser/ChangeLog \
scanner/ChangeLog \
tests/ChangeLog \
$(wildcard tests/*.il)
ILParser.cs: parser/ILParser.jay $(topdir)/jay/skeleton.cs
$(topdir)/jay/jay -ct < $(topdir)/jay/skeleton.cs $(CURDIR)/$< >$@
include ../build/executable.make

158
mcs/ilasm/Report.cs Normal file
View File

@@ -0,0 +1,158 @@
//
// Mono.ILASM.Report
//
// Author(s):
// Jackson Harper (Jackson@LatitudeGeo.com)
//
// (C) 2003 Jackson Harper, All rights reserved
//
using System;
using System.IO;
namespace Mono.ILASM {
public abstract class Report {
private static int error_count;
private static int mark_count;
private static bool quiet;
/* Current file being processed */
private static string file_path;
static Report ()
{
error_count = 0;
quiet = false;
}
public static int ErrorCount {
get { return error_count; }
}
public static bool Quiet {
get { return quiet; }
set { quiet = value; }
}
public static string FilePath {
get { return file_path; }
set { file_path = value; }
}
public static void AssembleFile (string file, string listing,
string target, string output)
{
if (quiet)
return;
Console.WriteLine ("Assembling '{0}' , {1}, to {2} --> '{3}'", file,
GetListing (listing), target, output);
Console.WriteLine ();
}
public static void Error (string message)
{
Error (null, message);
}
public static void Error (Location location, string message)
{
error_count++;
throw new ILAsmException (file_path, location, message);
}
public static void Warning (string message)
{
Warning (null, message);
}
public static void Warning (Location location, string message)
{
string location_str = " : ";
if (location != null)
location_str = " (" + location.line + ", " + location.column + ") : ";
Console.Error.WriteLine (String.Format ("{0}{1}Warning -- {2}",
(file_path != null ? file_path : ""), location_str, message));
}
public static void Message (string message)
{
if (quiet)
return;
Console.WriteLine (message);
}
private static string GetListing (string listing)
{
if (listing == null)
return "no listing file";
return listing;
}
}
public class ILAsmException : Exception {
string message;
string file_path;
Location location;
public ILAsmException (string file_path, Location location, string message)
{
this.file_path = file_path;
this.location = location;
this.message = message;
}
public ILAsmException (Location location, string message)
: this (null, location, message)
{
}
public ILAsmException (string message)
: this (null, null, message)
{
}
public override string Message {
get { return message; }
}
public Location Location {
get { return location; }
set { location = value; }
}
public string FilePath {
get { return file_path; }
set { file_path = value; }
}
public override string ToString ()
{
string location_str = " : ";
if (location != null)
location_str = " (" + location.line + ", " + location.column + ") : ";
return String.Format ("{0}{1}Error : {2}",
(file_path != null ? file_path : ""), location_str, message);
}
}
public class InternalErrorException : Exception {
public InternalErrorException ()
: base ("Internal error")
{
}
public InternalErrorException (string message)
: base (message)
{
}
}
}

View File

@@ -0,0 +1,123 @@
//
// Mono.ILASM.Assembly
//
// Represents .assembly { }
//
// Author(s):
// Ankit Jain <JAnkit@novell.com>
//
// Copyright (C) 2006 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Collections;
namespace Mono.ILASM {
public class Assembly : IDeclSecurityTarget, ICustomAttrTarget
{
private DeclSecurity decl_sec;
private ArrayList customattr_list;
private string name;
private byte [] public_key;
private int major_version;
private int minor_version;
private int build_version;
private int revision_version;
private string locale;
private int hash_algorithm;
private PEAPI.AssemAttr attr;
public Assembly (string name)
{
this.name = name;
}
public string Name {
get { return name; }
}
public DeclSecurity DeclSecurity {
get {
if (decl_sec == null)
decl_sec = new DeclSecurity ();
return decl_sec;
}
}
public void SetVersion (int major, int minor, int build, int revision)
{
this.major_version = major;
this.minor_version = minor;
this.build_version = build;
this.revision_version = revision;
}
public void SetLocale (string locale)
{
this.locale = locale;
}
public void SetHashAlgorithm (int algorithm)
{
hash_algorithm = algorithm;
}
public void SetPublicKey (byte [] public_key)
{
this.public_key = public_key;
}
public void SetAssemblyAttr (PEAPI.AssemAttr attr)
{
this.attr = attr;
}
public void AddCustomAttribute (CustomAttr customattr)
{
if (customattr_list == null)
customattr_list = new ArrayList ();
customattr_list.Add (customattr);
}
public void Resolve (CodeGen code_gen, PEAPI.Assembly asm)
{
if (customattr_list != null)
foreach (CustomAttr customattr in customattr_list) {
customattr.AddTo (code_gen, asm);
}
if (decl_sec != null)
decl_sec.AddTo (code_gen, asm);
asm.AddAssemblyInfo(major_version,
minor_version, build_version,
revision_version, public_key,
(uint) hash_algorithm, locale);
asm.AddAssemblyAttr (attr);
}
}
}

View File

@@ -0,0 +1,69 @@
//
// Mono.ILASM.BaseClassRef
//
// Author(s):
// Ankit Jain <jankit@novell.com>
//
// Copyright 2006 Novell, Inc (http://www.novell.com)
//
using System;
using System.Collections;
namespace Mono.ILASM {
public abstract class BaseClassRef : BaseTypeRef {
protected Hashtable p_genericinst_table;
protected bool is_valuetype;
protected BaseClassRef (string full_name, bool is_valuetype)
: this (full_name, is_valuetype, null, null)
{
}
protected BaseClassRef (string full_name, bool is_valuetype, ArrayList conv_list, string sig_mod)
: base (full_name, conv_list, sig_mod)
{
this.is_valuetype = is_valuetype;
p_genericinst_table = null;
}
public PEAPI.Class PeapiClass {
get { return type as PEAPI.Class; }
}
public virtual void MakeValueClass ()
{
is_valuetype = true;
}
public virtual GenericTypeInst GetGenericTypeInst (GenericArguments gen_args)
{
return new GenericTypeInst (this, gen_args, is_valuetype);
}
public virtual PEAPI.Type ResolveInstance (CodeGen code_gen, GenericArguments gen_args)
{
PEAPI.GenericTypeInst gtri = null;
string sig = gen_args.ToString ();
if (p_genericinst_table == null)
p_genericinst_table = new Hashtable ();
else
gtri = p_genericinst_table [sig] as PEAPI.GenericTypeInst;
if (gtri == null) {
if (!IsResolved)
Resolve (code_gen);
gtri = new PEAPI.GenericTypeInst (PeapiType, gen_args.Resolve (code_gen));
p_genericinst_table [sig] = gtri;
}
return gtri;
}
}
}

View File

@@ -0,0 +1,42 @@
//
// Mono.ILASM.BaseGenericTypeRef
//
// Author(s):
// Ankit Jain <jankit@novell.com>
//
// Copyright 2006 Novell, Inc (http://www.novell.com)
//
using System;
using System.Collections;
namespace Mono.ILASM {
public abstract class BaseGenericTypeRef : BaseClassRef {
public BaseGenericTypeRef (string full_name, bool is_valuetype, ArrayList conv_list, string sig_mod)
: base (full_name, is_valuetype, conv_list, sig_mod)
{
}
/* Used to resolve any gen params in arguments, constraints etc */
public abstract void Resolve (GenericParameters type_gen_params, GenericParameters method_gen_params);
/* Only resolves, does not add it to the TypeSpec
table */
public abstract void ResolveNoTypeSpec (CodeGen code_gen);
public override GenericTypeInst GetGenericTypeInst (GenericArguments gen_args)
{
Report.Error ("Invalid attempt to create '" + FullName + "''" + gen_args.ToString () + "'");
return null;
}
public override PEAPI.Type ResolveInstance (CodeGen code_gen, GenericArguments gen_args)
{
Report.Error ("Invalid attempt to create '" + FullName + "''" + gen_args.ToString () + "'");
return null;
}
}
}

View File

@@ -0,0 +1,79 @@
//
// Mono.ILASM.BaseMethodRef
//
// Author(s):
// Ankit Jain <JAnkit@novell.com>
//
// Copyright 2006 Novell, Inc (http://www.novell.com)
//
using System;
using System.Collections;
namespace Mono.ILASM {
public abstract class BaseMethodRef {
protected BaseTypeRef owner;
protected PEAPI.CallConv call_conv;
protected BaseTypeRef ret_type;
protected string name;
protected BaseTypeRef[] param;
protected PEAPI.Method peapi_method;
protected bool is_resolved;
protected int gen_param_count;
protected Hashtable gen_method_table;
public BaseMethodRef (BaseTypeRef owner, PEAPI.CallConv call_conv,
BaseTypeRef ret_type, string name, BaseTypeRef[] param, int gen_param_count)
{
this.owner = owner;
this.call_conv = call_conv;
this.ret_type = ret_type;
this.name = name;
this.param = param;
this.gen_param_count = gen_param_count;
if (gen_param_count > 0)
CallConv |= PEAPI.CallConv.Generic;
is_resolved = false;
}
public virtual PEAPI.Method PeapiMethod {
get { return peapi_method; }
}
public virtual PEAPI.CallConv CallConv {
get { return call_conv; }
set { call_conv = value; }
}
public virtual BaseTypeRef Owner {
get { return owner; }
}
public abstract void Resolve (CodeGen code_gen);
public GenericMethodRef GetGenericMethodRef (GenericArguments gen_args)
{
GenericMethodRef methref = null;
if (gen_method_table == null)
gen_method_table = new Hashtable ();
else
methref = (GenericMethodRef) gen_method_table [gen_args.ToString ()];
if (methref == null) {
methref = new GenericMethodRef (this, GenericMethodSig.GetInstance (gen_args));
gen_method_table [gen_args.ToString ()] = methref;
}
return methref;
}
}
}

View File

@@ -0,0 +1,103 @@
//
// Mono.ILASM.BaseTypeRef
//
// Author(s):
// Ankit Jain <jankit@novell.com>
//
// Copyright 2006 Novell, Inc (http://www.novell.com)
//
using System;
using System.Collections;
namespace Mono.ILASM {
public abstract class BaseTypeRef : ModifiableType {
protected string full_name;
protected string sig_mod;
protected PEAPI.Type type;
protected bool is_resolved;
protected Hashtable method_table;
protected Hashtable field_table;
protected BaseTypeRef (string full_name)
: this (full_name, null, null)
{
}
protected BaseTypeRef (string full_name, ArrayList conv_list, string sig_mod)
{
this.full_name = full_name;
this.sig_mod = sig_mod;
is_resolved = false;
if (conv_list != null)
ConversionList = conv_list;
}
public virtual string FullName {
get { return full_name + sig_mod; }
}
public override string SigMod {
get { return sig_mod; }
set { sig_mod = value; }
}
public PEAPI.Type PeapiType {
get { return type; }
}
public bool IsResolved {
get { return is_resolved; }
}
public abstract void Resolve (CodeGen code_gen);
public abstract BaseTypeRef Clone ();
protected abstract BaseMethodRef CreateMethodRef (BaseTypeRef ret_type,
PEAPI.CallConv call_conv, string name, BaseTypeRef[] param, int gen_param_count);
public virtual BaseMethodRef GetMethodRef (BaseTypeRef ret_type,
PEAPI.CallConv call_conv, string name, BaseTypeRef[] param, int gen_param_count)
{
BaseMethodRef mr = null;
/* Note: FullName not reqd as this is cached per object */
string key = MethodDef.CreateSignature (ret_type, call_conv, name, param, gen_param_count, true);
if (method_table == null)
method_table = new Hashtable ();
else
mr = (BaseMethodRef) method_table [key];
if (mr == null) {
mr = CreateMethodRef (ret_type, call_conv, name, param, gen_param_count);
method_table [key] = mr;
}
return mr;
}
protected abstract IFieldRef CreateFieldRef (BaseTypeRef ret_type, string name);
public virtual IFieldRef GetFieldRef (BaseTypeRef ret_type, string name)
{
IFieldRef fr = null;
string key = ret_type.FullName + name;
if (field_table == null)
field_table = new Hashtable ();
else
fr = (IFieldRef) field_table [key];
if (fr == null) {
fr = CreateFieldRef (ret_type, name);
field_table [key] = fr;
}
return fr;
}
}
}

View File

@@ -0,0 +1,36 @@
//
// Mono.ILASM.BranchInstr
//
// Author(s):
// Jackson Harper (Jackson@LatitudeGeo.com)
//
// (C) 2003 Jackson Harper, All rights reserved
//
using System;
namespace Mono.ILASM {
public class BranchInstr : IInstr {
private PEAPI.BranchOp op;
private LabelInfo label;
public BranchInstr (PEAPI.BranchOp op, LabelInfo label, Location loc)
: base (loc)
{
this.op = op;
this.label = label;
}
public override void Emit (CodeGen code_gen, MethodDef meth,
PEAPI.CILInstructions cil)
{
cil.Branch (op, label.Label);
}
}
}

View File

@@ -0,0 +1,56 @@
//
// Mono.ILASM.CalliInstr
//
// Author(s):
// Jackson Harper (Jackson@LatitudeGeo.com)
//
// (C) 2003 Jackson Harper, All rights reserved
//
using System;
namespace Mono.ILASM {
public class CalliInstr : IInstr {
private PEAPI.CallConv call_conv;
private BaseTypeRef ret_type;
private BaseTypeRef[] param;
public CalliInstr (PEAPI.CallConv call_conv, BaseTypeRef ret_type,
BaseTypeRef[] param, Location loc)
: base (loc)
{
this.call_conv = call_conv;
this.ret_type = ret_type;
this.param = param;
}
public override void Emit (CodeGen code_gen, MethodDef meth,
PEAPI.CILInstructions cil)
{
PEAPI.Type[] param_array;
PEAPI.CalliSig callisig;
if (param != null) {
param_array = new PEAPI.Type[param.Length];
int count = 0;
foreach (BaseTypeRef typeref in param) {
typeref.Resolve (code_gen);
param_array[count++] = typeref.PeapiType;
}
} else {
param_array = new PEAPI.Type[0];
}
ret_type.Resolve (code_gen);
callisig = new PEAPI.CalliSig (call_conv,
ret_type.PeapiType, param_array);
cil.calli (callisig);
}
}
}

View File

@@ -0,0 +1,45 @@
//
// Mono.ILASM.CatchBlock
//
// Author(s):
// Jackson Harper (Jackson@LatitudeGeo.com)
//
// (C) 2003 Jackson Harper, All rights reserved
//
using System;
namespace Mono.ILASM {
public class CatchBlock : ISehClause {
private BaseTypeRef type_ref;
private HandlerBlock handler_block;
public CatchBlock (BaseTypeRef type_ref)
{
this.type_ref = type_ref;
}
public void SetHandlerBlock (HandlerBlock hb)
{
handler_block = hb;
}
public PEAPI.HandlerBlock Resolve (CodeGen code_gen, MethodDef method)
{
PEAPI.CILLabel from = handler_block.GetFromLabel (code_gen, method);
PEAPI.CILLabel to = handler_block.GetToLabel (code_gen, method);
PEAPI.Catch katch;
type_ref.Resolve (code_gen);
katch = new PEAPI.Catch (type_ref.PeapiType, from, to);
return katch;
}
}
}

1926
mcs/ilasm/codegen/ChangeLog Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,58 @@
//
// Mono.ILASM.CustomAttr
//
// Author(s):
// Jackson Harper (Jackson@LatitudeGeo.com)
//
// (C) 2003 Jackson Harper, All rights reserved
//
using System;
using System.Collections;
namespace Mono.ILASM {
public interface ICustomAttrTarget {
void AddCustomAttribute (CustomAttr customattr);
}
public class CustomAttr {
private BaseMethodRef method_ref;
private byte[] data;
public CustomAttr (BaseMethodRef method_ref, byte[] data)
{
this.method_ref = method_ref;
this.data = data;
}
public void AddTo (CodeGen code_gen, PEAPI.MetaDataElement elem)
{
method_ref.Resolve (code_gen);
code_gen.PEFile.AddCustomAttribute (method_ref.PeapiMethod, data, elem);
}
public bool IsSuppressUnmanaged (CodeGen codegen)
{
string asmname = "";
BaseTypeRef owner = method_ref.Owner;
if (owner == null)
return false;
ExternTypeRef etr = owner as ExternTypeRef;
if (etr != null) {
ExternAssembly ea = etr.ExternRef as ExternAssembly;
if (ea != null)
asmname = ea.Name;
}
return (owner.FullName == "System.Security.SuppressUnmanagedCodeSecurityAttribute"
&& (asmname == "mscorlib" || codegen.IsThisAssembly ("mscorlib")) );
}
}
}

View File

@@ -0,0 +1,40 @@
//
// Mono.ILASM.DataDef
//
// Author(s):
// Jackson Harper (Jackson@LatitudeGeo.com)
//
// (C) 2003 Jackson Harper, All rights reserved
//
using System;
namespace Mono.ILASM {
public class DataDef {
private string name;
private bool is_tls;
private PEAPI.Constant constant;
public DataDef (string name, bool is_tls)
{
this.name = name;
this.is_tls = is_tls;
}
public PEAPI.Constant PeapiConstant {
get { return constant; }
set { constant = value; }
}
public string Name {
get { return name; }
set { name = value; }
}
}
}

View File

@@ -0,0 +1,107 @@
//
// Mono.ILASM.DebuggingInfo.cs
//
// Author(s):
// Martin Baulig (martin@ximian.com)
//
// Copyright (C) 2004 Novell, Inc.
//
using PEAPI;
using System;
using System.IO;
using System.Collections;
using Mono.CompilerServices.SymbolWriter;
namespace Mono.ILASM {
public class SymbolWriter : MonoSymbolWriter
{
Mono.ILASM.SourceMethod current_method;
CompileUnitEntry current_source;
ArrayList methods;
public SymbolWriter (string filename)
: base (filename)
{
methods = new ArrayList ();
}
public Mono.ILASM.SourceMethod BeginMethod (MethodDef method, Location start)
{
current_method = new Mono.ILASM.SourceMethod (current_source, method, start);
methods.Add (current_method);
return current_method;
}
public void EndMethod (Location end)
{
current_method.EndLine = end.line;
current_method = null;
}
public void BeginSourceFile (string filename)
{
SourceFileEntry file = DefineDocument (filename, null, null);
current_source = DefineCompilationUnit (file);
}
public void EndSourceFile ()
{
current_source = null;
}
public void Write (Guid guid)
{
foreach (Mono.ILASM.SourceMethod method in methods)
method.Write (this);
WriteSymbolFile (guid);
}
}
public class SourceMethod : IMethodDef
{
CompileUnitEntry file;
MethodDef method;
ArrayList lines;
public int StartLine, EndLine;
public SourceMethod (CompileUnitEntry file, MethodDef method, Location start)
{
this.file = file;
this.method = method;
this.StartLine = start.line;
lines = new ArrayList ();
MarkLocation (start.line, 0);
}
public string Name {
get { return method.Name; }
}
public int Token {
get {
PEAPI.MethodDef pemethod = method.PeapiMethodDef;
return (int) (((uint) PEAPI.MDTable.Method << 24) | pemethod.Row);
}
}
public void MarkLocation (int line, uint offset)
{
lines.Add (new LineNumberEntry (0, line, (int) offset));
}
public void Write (MonoSymbolWriter writer)
{
LineNumberEntry[] the_lines = new LineNumberEntry [lines.Count];
lines.CopyTo (the_lines, 0);
LocalVariableEntry[] locals = method.GetLocalVars ();
MethodEntry entry = writer.SymbolFile.DefineMethod (
file, Token, null, locals, the_lines, null, null, 0, 0);
}
}
}

View File

@@ -0,0 +1,105 @@
//
// Mono.ILASM.DeclSecurity
//
// Author(s):
// Ankit Jain <JAnkit@novell.com>
//
// (C) 2005 Ankit Jain, All rights reserved
//
using System;
using System.Collections;
using System.Security;
using System.Security.Permissions;
using SSPermissionSet = System.Security.PermissionSet;
using MIPermissionSet = Mono.ILASM.PermissionSet;
namespace Mono.ILASM {
public interface IDeclSecurityTarget {
DeclSecurity DeclSecurity { get; }
}
public class DeclSecurity {
private Hashtable permissionset_table;
private Hashtable permissionset20_table;
public DeclSecurity ()
{
permissionset_table = new Hashtable ();
}
public void AddPermission (PEAPI.SecurityAction sec_action, IPermission perm)
{
SSPermissionSet ps = (SSPermissionSet) permissionset_table [sec_action];
if (ps == null) {
ps = new SSPermissionSet (PermissionState.None);
permissionset_table [sec_action] = ps;
}
ps.AddPermission (perm);
}
public void AddPermissionSet (PEAPI.SecurityAction sec_action, SSPermissionSet perm_set)
{
SSPermissionSet ps = (SSPermissionSet) permissionset_table [sec_action];
if (ps == null) {
permissionset_table [sec_action] = perm_set;
return;
}
foreach (IPermission iper in perm_set)
ps.AddPermission (iper);
}
//Not called by parser for profile != NET_2_0
public void AddPermissionSet (PEAPI.SecurityAction sec_action, MIPermissionSet perm_set)
{
PermissionSet ps = null;
if (permissionset20_table == null)
permissionset20_table = new Hashtable ();
else
ps = (MIPermissionSet) permissionset20_table [sec_action];
if (ps == null) {
permissionset20_table [sec_action] = perm_set;
return;
}
foreach (Permission perm in perm_set.Permissions)
ps.AddPermission (perm);
}
public void AddTo (CodeGen code_gen, PEAPI.MetaDataElement elem)
{
System.Text.UnicodeEncoding ue = new System.Text.UnicodeEncoding ();
foreach (DictionaryEntry entry in permissionset_table) {
PEAPI.SecurityAction sec_action = (PEAPI.SecurityAction) entry.Key;
SSPermissionSet ps = (SSPermissionSet) entry.Value;
code_gen.PEFile.AddDeclSecurity (sec_action,
ue.GetBytes (ps.ToXml ().ToString ()),
elem);
}
if (permissionset20_table == null)
return;
foreach (DictionaryEntry entry in permissionset20_table) {
PEAPI.SecurityAction sec_action = (PEAPI.SecurityAction) entry.Key;
MIPermissionSet ps = (MIPermissionSet) entry.Value;
code_gen.PEFile.AddDeclSecurity (sec_action,
ps.Resolve (code_gen),
elem);
}
}
}
}

View File

@@ -0,0 +1,34 @@
//
// Mono.ILASM.EmitByteIntr.cs
//
// Author(s):
// Rodrigo Kumpera (rkumpera@novell.com)
//
// (C) 2007 Novell, Inc (http://www.novell.com)
//
using System;
using System.Collections;
namespace Mono.ILASM {
public class EmitByteInstr : IInstr {
private int value;
public EmitByteInstr (int value, Location loc)
: base (loc)
{
this.value = value;
}
public override void Emit (CodeGen code_gen, MethodDef meth,
PEAPI.CILInstructions cil)
{
cil.emitbyte ((byte)value);
}
}
}

Some files were not shown because too many files have changed in this diff Show More