示例#1
0
        static void Main(string[] args)
        {
            LLVM.InitializeAllTargets();
            LLVM.InitializeAllTargetMCs();
            LLVM.InitializeAllTargetInfos();
            LLVM.InitializeAllAsmPrinters();

            ModuleRef mod = LLVM.ModuleCreateWithName("LLVMSharpIntro");

            TypeRef[]     param_types = { LLVM.Int32Type(), LLVM.Int32Type() };
            TypeRef       ret_type    = LLVM.FunctionType(LLVM.Int32Type(), param_types, false);
            ValueRef      sum         = LLVM.AddFunction(mod, "sum", ret_type);
            BasicBlockRef entry       = LLVM.AppendBasicBlock(sum, "entry");
            BuilderRef    builder     = LLVM.CreateBuilder();

            LLVM.PositionBuilderAtEnd(builder, entry);
            ValueRef tmp = LLVM.BuildAdd(builder, LLVM.GetParam(sum, 0), LLVM.GetParam(sum, 1), "tmp");

            LLVM.BuildRet(builder, tmp);
            MyString the_error = new MyString();

            LLVM.VerifyModule(mod, VerifierFailureAction.AbortProcessAction, the_error);
            //LLVM.DisposeMessage(error);
            ExecutionEngineRef   engine;
            MCJITCompilerOptions options = new MCJITCompilerOptions();
            var optionsSize = (4 * sizeof(int)) + IntPtr.Size; // LLVMMCJITCompilerOptions has 4 ints and a pointer

            LLVM.InitializeMCJITCompilerOptions(options, (uint)optionsSize);
            LLVM.CreateMCJITCompilerForModule(out engine, mod, options, (uint)optionsSize, the_error);
            var    ptr       = LLVM.GetPointerToGlobal(engine, sum);
            IntPtr p         = (IntPtr)ptr;
            Add    addMethod = (Add)Marshal.GetDelegateForFunctionPointer(p, typeof(Add));
            int    result    = addMethod(10, 10);

            Console.WriteLine("Result of sum is: " + result);
            if (LLVM.WriteBitcodeToFile(mod, "sum.bc") != 0)
            {
                Console.WriteLine("error writing bitcode to file, skipping");
            }
            LLVM.DumpModule(mod);
            LLVM.DisposeBuilder(builder);
            LLVM.DisposeExecutionEngine(engine);
        }
示例#2
0
文件: Program.cs 项目: oxugen/labs
        static void Main(string[] args)
        {
            MyString s1 = new MyString("abc, defgabc! ijk...");
            MyString s2 = new MyString("ab cdefgjhkkf kk");

            s1.SetOwner("abc", "Mike", "Example Corp.");
            s2.SetOwner("dgc", "Bob", "ABC Corp.");
            s1.SetDate(23, 6, 2001);
            s2.SetDate(26, 4, 1986);

            Console.WriteLine(s1 < s2);
            Console.WriteLine(s1 + 5);
            Console.WriteLine(--s2);
            Console.WriteLine(s2 * 'd');
            Console.WriteLine(s1[2]);


            MyString s3 = new MyString("abcd /efgh");

            Console.WriteLine($"{s1.ServiceCheck()}\n{s3.ServiceCheck()}");
            Console.WriteLine(s1.DeletePunctuation());
        }
示例#3
0
        public static MyString DeletePunctuation(this MyString str)
        {
            MyString       temp           = new MyString(str);
            HashSet <char> serviceSymbols = new HashSet <char>();

            serviceSymbols.Add('.');
            serviceSymbols.Add(',');
            serviceSymbols.Add(':');
            serviceSymbols.Add('?');
            serviceSymbols.Add('!');
            serviceSymbols.Add('-');
            string tempString = str.ToString();

            for (int i = 0; i < tempString.Length; i++)
            {
                if (serviceSymbols.Contains(tempString[i]))
                {
                    tempString = tempString.Remove(i, 1);
                }
            }
            temp.SetString(tempString);
            return(temp);
        }
示例#4
0
文件: MyString.cs 项目: oxugen/labs
 public MyString(MyString copy)
 {
     this.data  = copy.data;
     this.date  = copy.date;
     this.owner = copy.owner;
 }
示例#5
0
 public static int Count(this MyString str)
 {
     return(str.ToString().Length);
 }