public override bool Visit(RoutineDeclaration node) { declEnv.EnterNextContext(); Visit((CallableDeclaration)node); declEnv.EnterNextContext(); return(true); }
public override Value Visit(RoutineDeclaration node) { ProceduralType functype = node.Type; TypeRef llvmfrettype = (node.IsFunction ? GetLLVMType(functype.funcret) : TypeRef.CreateVoid()); var @params = [email protected](); var args = @params.Select(a => GetLLVMType(a.type)); Function func = new Function(module, node.name, llvmfrettype, args.ToArray()); func.SetLinkage(LLVMLinkage.ExternalLinkage); // If F conflicted, there was already something named 'Name'. If it has a // body, don't allow redefinition or reextern. if (func.IsDuplicate()) { // Delete the one we just made and get the existing one. func.Delete(); func = module.GetFunction(node.name); } // Set names for all arguments. uint i = 0; foreach (var param in @params) { Value val = func.GetParameter(i++); val.Name = param.name; // calls llvm } valuemap.AddValue(node, func); return(func); }
public SLangRoutineDefinition( UnitDefinition unit, RoutineDeclaration routine ) : base(unit, routine.Name, new SignatureReference(unit.Context, routine)) { AST = routine; }
/// <summary> /// From JSON IR routine declaration. /// </summary> /// <para>Extracts named parameters and the return type.</para> /// <param name="ctx"></param> /// <param name="routine"></param> public SignatureReference(Context ctx, RoutineDeclaration routine) : base( new UnitReference(ctx, routine.ReturnType), routine .Parameters .Select(param => new Parameter <UnitReference>( param.Name, new UnitReference(ctx, param.Type)))) { }
public virtual T Visit(RoutineDeclaration node) { return(Visit((CallableDeclaration)node)); }
public static string MainFunction(RoutineDeclaration routine, string name, List <ParameterDeclaration> param) { dict.Clear(); var listParam = ""; var typeparam = ""; for (var i = 0; i < param.Count; i++) { if (param[i].Type.PrimitiveType == PrimitiveType.Int) { typeparam = "int32"; } if (param[i].Type.PrimitiveType == PrimitiveType.Real) { typeparam = "float64"; } if (param[i].Type.PrimitiveType == PrimitiveType.Boolean) { typeparam = "bool"; } if (i + 1 == param.Count) { listParam += typeparam + " " + param[i].Identifier; } else { listParam += typeparam + " " + param[i].Identifier + ", "; } dict.Add(param[i].Identifier, 0); } var s = " .method public hidebysig static void " + name + "(" + listParam + ") " + "cil managed\n {\n"; if (name == "Main") { s += " .entrypoint\n .maxstack 2\n"; } else { s += " .maxstack 2\n"; } var sinit = " .locals init (\n"; var sbody = " nop\n"; var list = VariableList(routine.Body); index = 0; var cnt = 0; for (var i = 0; i < list.Count; i++) { if (i + 1 == list.Count) { sinit += " [" + i + "] " + list[i].Value + " " + list[i].Key + "\n"; } else { sinit += " [" + i + "] " + list[i].Value + " " + list[i].Key + ",\n"; } } sinit += " )\n"; sbody += BodyResult(routine.Body, "routine") + " ret\n"; s += sinit + sbody; s += " }\n\n"; return(s); }
public override bool Visit(RoutineDeclaration node) { Visit((CallableDeclaration)node); return(true); }
void CreateBuiltinFunction(RoutineDeclaration routine) { builtinDecls.Add(routine.name, routine); RegisterDeclaration(routine); }