public List <Opcode> BuildProgram(bool interpreted) { CodePart program = new CodePart(); foreach (CodePart part in _parts) { if (interpreted) { program.MainCode.AddRange(part.InitializationCode); } else { program.InitializationCode.AddRange(part.InitializationCode); } program.FunctionsCode.AddRange(part.FunctionsCode); program.MainCode.AddRange(part.MainCode); } AddJumpToEntryPoint(program); AddEndOfProgram(program, interpreted); List <Opcode> mergedProgram = program.MergeSections(); ReplaceLabels(mergedProgram); return(mergedProgram); }
private void AddJumpToEntryPoint(CodePart program) { if (program.MainCode.Count > 0) { OpcodeBranchJump jumpOpcode = new OpcodeBranchJump(); jumpOpcode.DestinationLabel = program.MainCode[0].Label; program.FunctionsCode.Insert(0, jumpOpcode); } }
private void AddEndOfProgram(CodePart program, bool interpreted) { if (interpreted) { program.MainCode.Add(new OpcodeEOF()); } else { program.MainCode.Add(new OpcodeEOP()); } }
public void Add(CodePart part) { _parts.Add(part); }