protected void CodeEmitWorksWithFixup(string source, FixupType type, int offset, params byte[] opCodes)
        {
            // --- Arrange
            var compiler = new Z80Assembler();

            // --- Act
            var output = compiler.Compile(source);

            // --- Assert
            output.ErrorCount.ShouldBe(0);
            output.Segments.Count.ShouldBe(1);
            var bytes = output.Segments[0].EmittedCode;

            bytes.Count.ShouldBe(opCodes.Length);
            for (var i = 0; i < opCodes.Length; i++)
            {
                bytes[i].ShouldBe(opCodes[i]);
            }
            output.Fixups.Count.ShouldBe(1);
            var fixup = output.Fixups[0];

            fixup.Type.ShouldBe(type);
            fixup.SegmentIndex.ShouldBe(0);
            fixup.Offset.ShouldBe(offset);
            fixup.Expression.ShouldNotBeNull();
        }
Exemple #2
0
        internal HtmlNodeFixup AddOrUpdateFixUp(FixupType type, HtmlNode node, string originalValue)
        {
            HtmlNodeFixup fixUp = null;

            foreach (HtmlNodeFixup probeFixUp in m_AllFixups)
            {
                if (probeFixUp.HtmlNode.Equals(node))
                {
                    fixUp = probeFixUp;

                    Debug.Assert(type == fixUp.Type);

                    if (type != fixUp.Type)
                    {
                        throw new InvalidOperationException("Cannot update object with different fix-up type.");
                    }

                    break;
                }
            }

            if (fixUp == null)
            {
                fixUp = new HtmlNodeFixup(type, node, originalValue);
                m_AllFixups.Add(fixUp);
            }
            else
            {
                Debug.Assert(fixUp.OriginalValue == originalValue);
                // Nothing to do, the value will be retrieved via the HtmlNode
            }

            return(fixUp);
        }
Exemple #3
0
 /// <summary>Initializes a new instance of the <see cref="T:System.Object" /> class.</summary>
 public FixupInfo(FixupType type, int segmentIndex, ushort offset, bool resolved, string expression)
 {
     Type         = type;
     SegmentIndex = segmentIndex;
     Offset       = offset;
     Resolved     = resolved;
     Expression   = expression;
 }
Exemple #4
0
 /// <summary>Initializes a new instance of the <see cref="T:System.Object" /> class.</summary>
 public FixupEntry(SourceLineBase sourceLine, FixupType type, int segmentIndex, int offset, ExpressionNode expression, string label = null)
 {
     SourceLine   = sourceLine;
     Type         = type;
     SegmentIndex = segmentIndex;
     Offset       = offset;
     Expression   = expression;
     Label        = label;
 }
Exemple #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:System.Object" /> class.
 /// </summary>
 public FixupEntry(IEvaluationContext parentContext, AssemblyModule module,
                   SourceLineBase sourceLine, FixupType type,
                   int segmentIndex, int offset, ExpressionNode expression, string label = null,
                   Dictionary <ushort, byte> structBytes = null)
 {
     ParentContext = parentContext;
     Module        = module;
     SourceLine    = sourceLine;
     Type          = type;
     SegmentIndex  = segmentIndex;
     Offset        = offset;
     Expression    = expression;
     Resolved      = false;
     Label         = label;
     StructBytes   = structBytes;
 }
        /// <summary>
        /// Records fixup information
        /// </summary>
        /// <param name="opLine">The operation line</param>
        /// <param name="type">Fixup type</param>
        /// <param name="expression">Fixup expression</param>
        /// <param name="label">Optional EQU label</param>
        /// <param name="structeBytes">Optional structure bytes</param>
        /// <param name="offset">Fixup offset, if not the current position</param>
        private void RecordFixup(SourceLineBase opLine, FixupType type, ExpressionNode expression,
                                 string label = null, Dictionary <ushort, byte> structeBytes = null, ushort?offset = null)
        {
            var fixupOffset = CurrentSegment.CurrentOffset;

            // --- Translate field invocation fixups so that field-related fixups will be
            // --- processed only after other fixups.
            if (IsInStructInvocation)
            {
                fixupOffset = _currentStructStartOffset + _currentStructOffset;
                if (type == FixupType.Bit8)
                {
                    type = FixupType.FieldBit8;
                }
                else if (type == FixupType.Bit16)
                {
                    type = FixupType.FieldBit16;
                }
            }

            // --- Create to fixup entry to resolve
            var fixup = new FixupEntry(this, CurrentModule, opLine, type, Output.Segments.Count - 1,
                                       offset ?? fixupOffset,
                                       expression, label, structeBytes);

            // --- Record fixups in every local scope up to the root
            foreach (var scope in CurrentModule.LocalScopes)
            {
                scope.Fixups.Add(fixup);
            }

            // --- Record fixup in every module up to the root
            var currentModule = CurrentModule;

            while (currentModule != null)
            {
                currentModule.Fixups.Add(fixup);
                currentModule = currentModule.ParentModule;
            }
        }
Exemple #7
0
        internal HtmlNodeFixup(FixupType type, HtmlNode node, string originalValue)
        {
            Type          = type;
            HtmlNode      = node;
            OriginalValue = originalValue;

            if (node is HtmlAttribute)
            {
                if (node.NodePosition.ValueStartPos < 0)
                {
                    ValueEnclosingCharacter = '\"';
                }
                else if (node.OwnerDocument.RawHtml.Length > node.NodePosition.ValueStartPos)
                {
                    ValueEnclosingCharacter = node.OwnerDocument.RawHtml[node.NodePosition.ValueStartPos - 1];
                    if ("'\"".IndexOf(ValueEnclosingCharacter) == -1)
                    {
                        ValueEnclosingCharacter = '\x0';
                    }
                }
            }
        }
Exemple #8
0
 /// <summary>
 /// Records fixup information
 /// </summary>
 /// <param name="opLine">The operation line</param>
 /// <param name="type">Fixup type</param>
 /// <param name="expression">Fixup expression</param>
 /// <param name="label">Optional EQU label</param>
 private void RecordFixup(SourceLineBase opLine, FixupType type, ExpressionNode expression, string label = null)
 {
     _output.Fixups.Add(new FixupEntry(opLine, type, _output.Segments.Count - 1,
                                       CurrentSegment.CurrentOffset, expression, label));
 }
Exemple #9
0
 public Fixup(FixupType type, int tag, int position)
 {
     Type     = type;
     Tag      = tag;
     Position = position;
 }