Beispiel #1
0
        public void innerViewBuildtest1()
        {
            InnerViewBuilder innerViewBuilder = new InnerViewBuilder("sub main\ncall main");
            InnerView        innerView        = innerViewBuilder.Build();
            bool             actual           = innerView.Functions.ContainsKey("main");

            Assert.AreEqual(true, actual);
            CallInst inst = (CallInst)innerView.Functions["main"][0];

            Assert.AreEqual("CALL", inst.Type.ToString());
        }
Beispiel #2
0
        public Construct VisitCallInst(CallInst node)
        {
            // Create an argument buffer list.
            List <LlvmValue> arguments = new List <LlvmValue>();

            // Emit the call arguments.
            foreach (Constructs.Construct argument in node.Arguments)
            {
                // Continue if the argument is null.
                if (argument == null)
                {
                    continue;
                }

                // Visit the argument.
                this.Visit(argument);

                // Pop the argument off the value stack.
                LlvmValue argumentValue = this.valueStack.Pop();

                // Append argument value to the argument buffer list.
                arguments.Add(argumentValue);
            }

            // Retrieve the callee function.
            LlvmFunction callee = node.Callee;

            // Ensure argument count is correct (with continuous arguments).
            if (callee.HasInfiniteArguments && arguments.Count < callee.ArgumentCount - 1)
            {
                throw new Exception($"Target function requires at least {callee.ArgumentCount - 1} argument(s)");
            }
            // Otherwise, expect the argument count to be exact.
            else if (arguments.Count != callee.ArgumentCount)
            {
                throw new Exception($"Argument amount mismatch, target function requires exactly {callee.ArgumentCount} argument(s)");
            }

            // Create the function call.
            LlvmValue call = this.builder.CreateCall(callee, node.ResultIdentifier, arguments.ToArray());

            // Append the value onto the stack.
            this.valueStack.Push(call);

            // Return the node.
            return(node);
        }