public CodeGenerator(DynamicRuntimeState globalState, TargetMachine machine, bool disableOptimization = false) : base(null) { globalState.ValidateNotNull(nameof(globalState)); machine.ValidateNotNull(nameof(machine)); if (globalState.LanguageLevel > LanguageLevel.MutableVariables) { throw new ArgumentException("Language features not supported by this generator", nameof(globalState)); } RuntimeState = globalState; Context = new Context( ); TargetMachine = machine; DisableOptimizations = disableOptimization; InstructionBuilder = new InstructionBuilder(Context); Module = Context.CreateBitcodeModule( ); Module.TargetTriple = machine.Triple; Module.Layout = TargetMachine.TargetData; FunctionPassManager = new FunctionPassManager(Module); FunctionPassManager.AddPromoteMemoryToRegisterPass( ); if (!DisableOptimizations) { FunctionPassManager.AddInstructionCombiningPass( ) .AddReassociatePass( ) .AddGVNPass( ) .AddCFGSimplificationPass( ); } FunctionPassManager.Initialize( ); }
/// <summary>Initializes a new instance of the <see cref="Parser"/> class.</summary> /// <param name="globalState"><see cref="DynamicRuntimeState"/> for the parse</param> /// <param name="diagnostics">Diagnostic representations to generate when parsing</param> /// <param name="lexErrorListener">Error listener for Lexer errors</param> /// <param name="parseErrorListener">Error listener for parer errors</param> public Parser(DynamicRuntimeState globalState , DiagnosticRepresentations diagnostics , IAntlrErrorListener <int> lexErrorListener , IAntlrErrorListener <IToken> parseErrorListener ) { GlobalState = globalState.ValidateNotNull(nameof(globalState)); Diagnostics = diagnostics; LexErrorListener = lexErrorListener; ParseErrorListener = parseErrorListener; ErrorStrategy = new ReplErrorStrategy( ); }
public CodeGenerator(DynamicRuntimeState globalState) : base(null) { if (globalState.LanguageLevel > LanguageLevel.SimpleExpressions) { throw new ArgumentException("Language features not supported by this generator", nameof(globalState)); } RuntimeState = globalState; Context = new Context( ); Module = Context.CreateBitcodeModule("Kaleidoscope"); InstructionBuilder = new InstructionBuilder(Context); }
public CodeGenerator(DynamicRuntimeState globalState, bool disableOptimization = false) : base(null) { if (globalState.LanguageLevel > LanguageLevel.MutableVariables) { throw new ArgumentException("Language features not supported by this generator", nameof(globalState)); } RuntimeState = globalState; Context = new Context( ); DisableOptimizations = disableOptimization; InitializeModuleAndPassManager( ); InstructionBuilder = new InstructionBuilder(Context); }
public CodeGenerator(DynamicRuntimeState globalState, bool disableOptimization = false, TextWriter?outputWriter = null) : base(null) { JIT.OutputWriter = outputWriter ?? Console.Out; globalState.ValidateNotNull(nameof(globalState)); if (globalState.LanguageLevel > LanguageLevel.SimpleExpressions) { throw new ArgumentException("Language features not supported by this generator", nameof(globalState)); } RuntimeState = globalState; Context = new Context( ); DisableOptimizations = disableOptimization; InitializeModuleAndPassManager( ); InstructionBuilder = new InstructionBuilder(Context); }
public CodeGenerator(DynamicRuntimeState globalState, TargetMachine machine, string sourcePath, bool disableOptimization = false) : base(null) { globalState.ValidateNotNull(nameof(globalState)); machine.ValidateNotNull(nameof(machine)); if (globalState.LanguageLevel > LanguageLevel.MutableVariables) { throw new ArgumentException("Language features not supported by this generator", nameof(globalState)); } RuntimeState = globalState; Context = new Context( ); TargetMachine = machine; DisableOptimizations = disableOptimization; InstructionBuilder = new InstructionBuilder(Context); #region InitializeModuleAndPassManager Module = Context.CreateBitcodeModule(Path.GetFileName(sourcePath), SourceLanguage.C, sourcePath, "Kaleidoscope Compiler"); Debug.Assert(Module.DICompileUnit != null, "Expected non null compile unit"); Debug.Assert(Module.DICompileUnit.File != null, "Expected non-null file for compile unit"); Module.TargetTriple = machine.Triple; Module.Layout = TargetMachine.TargetData; DoubleType = new DebugBasicType(Context.DoubleType, Module, "double", DiTypeKind.Float); FunctionPassManager = new FunctionPassManager(Module); FunctionPassManager.AddPromoteMemoryToRegisterPass( ); if (!DisableOptimizations) { FunctionPassManager.AddInstructionCombiningPass( ) .AddReassociatePass( ) .AddGVNPass( ) .AddCFGSimplificationPass( ); } FunctionPassManager.Initialize( ); #endregion }
public KaleidoscopeParser(ITokenStream tokenStream, DynamicRuntimeState globalState, IParseErrorListener?errorListener, bool useDiagnosticListener = false) : this( tokenStream ) { globalState.ValidateNotNull(nameof(globalState)); GlobalState = globalState; if (errorListener != null) { RemoveErrorListeners( ); AddErrorListener(new ParseErrorListenerAdapter(errorListener)); } if (globalState.LanguageLevel >= LanguageLevel.UserDefinedOperators) { AddParseListener(new KaleidoscopeUserOperatorListener(GlobalState)); } if (useDiagnosticListener) { AddParseListener(new DebugTraceListener(this)); } ErrorHandler = new FailedPredicateErrorStrategy( ); }
public KaleidoscopeUserOperatorListener(DynamicRuntimeState state) { RuntimeState = state; }
public override IKaleidoscopeCodeGenerator <Value> CreateGenerator(DynamicRuntimeState state) { return(new CodeGenerator(state)); }
public override IKaleidoscopeCodeGenerator<IAstNode> CreateGenerator( DynamicRuntimeState state ) { return new CodeGenerator( ); }
public AstBuilder(DynamicRuntimeState globalState) { RuntimeState = globalState; }
public abstract IKaleidoscopeCodeGenerator <T> CreateGenerator(DynamicRuntimeState state);