public void Convert() { var lexer = new CLexer(rdr); var parser = new CParser(parserState, lexer); var declarations = parser.Parse(); var symbolTable = new SymbolTable(platform) { NamedTypes = { { "off_t", new PrimitiveType_v1 { Domain = Domain.SignedInt, ByteSize = 4 } }, //$BUGBUG: arch-dependent! { "ssize_t", new PrimitiveType_v1 { Domain = Domain.SignedInt, ByteSize = 4 } }, //$BUGBUG: arch-dependent! { "size_t", new PrimitiveType_v1 { Domain = Domain.UnsignedInt, ByteSize = 4 } }, //$BUGBUG: arch-dependent! { "va_list", new PrimitiveType_v1 { Domain = Domain.Pointer, ByteSize = platform.PointerType.Size } } } }; foreach (var decl in declarations) { symbolTable.AddDeclaration(decl); } var lib = new SerializedLibrary { Types = symbolTable.Types.ToArray(), Procedures = symbolTable.Procedures.ToList(), }; var ser = SerializedLibrary.CreateSerializer(); ser.Serialize(writer, lib); }
public void ProcessDeclaration(Decl declaration, IPlatform platform, TypeLibraryDeserializer tldser, SymbolTable symbolTable) { var types = symbolTable.AddDeclaration(declaration); var type = types[0]; int? vectorOffset = GetVectorOffset(declaration); if (vectorOffset.HasValue) { var ntde = new NamedDataTypeExtractor(platform, declaration.decl_specs, symbolTable); foreach (var declarator in declaration.init_declarator_list) { var nt = ntde.GetNameAndType(declarator.Declarator); var ssig = (SerializedSignature)nt.DataType; if (ssig.ReturnValue != null) { ssig.ReturnValue.Kind = ntde.GetArgumentKindFromAttributes( "returns", declaration.attribute_list); } var sser = platform.CreateProcedureSerializer(tldser, platform.DefaultCallingConvention); var sig = sser.Deserialize(ssig, platform.Architecture.CreateFrame()); SystemServices.Add( vectorOffset.Value, new SystemService { Name = nt.Name, SyscallInfo = new SyscallInfo { Vector = vectorOffset.Value, }, Signature = sig, }); } } }
public override TypeLibrary Load(IPlatform platform, TypeLibrary dstLib) { var rdr = new StreamReader(new MemoryStream(bytes)); var lexer = new CLexer(rdr); var state = new ParserState(); var parser = new CParser(state, lexer); var symbolTable = new SymbolTable(platform); var declarations = parser.Parse(); var tldser = new TypeLibraryDeserializer(platform, true, dstLib); foreach (var decl in declarations) { ProcessDeclaration(decl, platform, tldser, symbolTable); } return dstLib; }
private bool TryParseSignature(string txtSignature, out Core.Serialization.Procedure_v1 sProc) { // save the user a keystroke. txtSignature = txtSignature + ";"; var lexer = new Core.CLanguage.CLexer(new StringReader(txtSignature)); var cstate = new Core.CLanguage.ParserState(); var cParser = new CParser(cstate, lexer); try { var decl = cParser.Parse_Decl(); sProc = null; if (decl == null) return false; var syms = new SymbolTable(); syms.AddDeclaration(decl); if (syms.Procedures.Count != 1) return false; sProc = (Core.Serialization.Procedure_v1) syms.Procedures[0]; return true; } catch { sProc = null; return false; } }
public void Setup() { symbolTable = new SymbolTable(); }
public UserSignatureBuilder(Program program) { this.program = program; this.symbolTable = new SymbolTable(); }
public void Setup() { this.arch = new FakeArchitecture(); this.platform = new DefaultPlatform(null, arch); symbolTable = new SymbolTable(platform); }
public NamedDataTypeExtractor(IPlatform platform, IEnumerable<DeclSpec> specs, SymbolTable converter) { if (platform == null) throw new ArgumentNullException("platform"); this.platform = platform; this.specs = specs; this.symbolTable = converter; this.callingConvention = CTokenType.None; this.eval = new CConstantEvaluator(platform, converter.Constants); this.basicType = CBasicType.None; foreach (var declspec in specs) { dt = declspec.Accept(this); } }