示例#1
0
        /// <summary>
        /// Constructs a Program object with the given options and name. The name determines
        /// the module name and thus should be valid as per module name rules. The isExecutable
        /// flag specifies whether the program is directly executable and thus is an EXE file
        /// or is a library and thus is a DLL.
        /// </summary>
        /// <param name="opts">A set of options</param>
        /// <param name="name">String containing the program name</param>
        /// <param name="isExecutable">Specifies whether or not the program is directly executable</param>
        public Program(Options opts, string name, bool isExecutable)
        {
            if (opts == null) {
                throw new ArgumentNullException("opts");
            }
            if (name == null) {
                throw new ArgumentNullException("name");
            }

            _opts = opts;
            _isExecutable = isExecutable;

            _ad = AppDomain.CurrentDomain;
            _an = new AssemblyName();

            // For .NET conventions, make the initial letter of the name
            // uppercase.
            name = name.CapitaliseString();

            _an.Name = name;
            _an.Version = new Version(_opts.VersionString);

            bool isSaveable = !string.IsNullOrEmpty(opts.OutputFile);
            AssemblyBuilderAccess access = isSaveable ? AssemblyBuilderAccess.RunAndSave : AssemblyBuilderAccess.Run;
            _ab = _ad.DefineDynamicAssembly(_an, access);

            // Make this assembly debuggable if the debug option was specified.
            if (_opts.GenerateDebug) {
                AddDebuggable(_ab);
            }

            // Don't make the main class abstract if the program is being run from
            // memory as otherwise the caller will be unable to create an instance.
            TypeAttributes typeAttributes = TypeAttributes.Public;
            if (isSaveable) {
                _mb = _ab.DefineDynamicModule(name, OutputFilename, true);
                typeAttributes |= TypeAttributes.Abstract | TypeAttributes.Sealed;
            } else {
                _mb = _ab.DefineDynamicModule(name, true);
            }

            // Create an implicit namespace using the output file name if
            // one is specified.
            string className = string.Empty;
            if (!string.IsNullOrEmpty(opts.OutputFile)) {
                className = String.Concat(opts.OutputFile.CapitaliseString(), ".");
            }
            className = String.Concat(className, name);
            _tb = _mb.DefineType(className, typeAttributes);
        }
示例#2
0
 /// <summary>
 /// Constructs a language neutral code generator object.
 /// </summary>
 /// <param name="opts">Compiler options</param>
 public CodeGenerator(Options opts)
 {
     _opts = opts;
     _lineno = -1;
 }