Beispiel #1
0
        public Construct VisitValue(Value node)
        {
            // Create the value buffer.
            LlvmValue value;

            // Ensure value is identified as a literal.
            if (!Recognition.IsLiteral(node.Content))
            {
                throw new Exception("Content could not be identified as a valid literal");
            }
            // Integer literal.
            else if (Recognition.IsInteger(node.Content))
            {
                // Visit the kind.
                this.VisitKind(node.Kind);

                // Pop the resulting type off the stack.
                LlvmType type = this.typeStack.Pop();

                // Create the type and assign the value buffer.
                value = LlvmFactory.Int(type, int.Parse(node.Content));
            }
            // String literal.
            else if (Recognition.IsStringLiteral(node.Content))
            {
                value = LlvmFactory.String(node.Content);
            }
            // Unrecognized literal.
            else
            {
                throw new Exception($"Unrecognized literal: {node.Content}");
            }

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

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