newCompilerContext returns a new compiler context ready for use, most importantly with a newly created LLVM context and module.
(moduleName string, machine llvm.TargetMachine, config *Config, dumpSSA bool)
| 97 | // newCompilerContext returns a new compiler context ready for use, most |
| 98 | // importantly with a newly created LLVM context and module. |
| 99 | func newCompilerContext(moduleName string, machine llvm.TargetMachine, config *Config, dumpSSA bool) *compilerContext { |
| 100 | c := &compilerContext{ |
| 101 | Config: config, |
| 102 | DumpSSA: dumpSSA, |
| 103 | difiles: make(map[string]llvm.Metadata), |
| 104 | ditypes: make(map[types.Type]llvm.Metadata), |
| 105 | machine: machine, |
| 106 | targetData: machine.CreateTargetData(), |
| 107 | functionInfos: map[*ssa.Function]functionInfo{}, |
| 108 | astComments: map[string]*ast.CommentGroup{}, |
| 109 | } |
| 110 | |
| 111 | c.ctx = llvm.NewContext() |
| 112 | c.builder = c.ctx.NewBuilder() |
| 113 | c.mod = c.ctx.NewModule(moduleName) |
| 114 | c.mod.SetTarget(config.Triple) |
| 115 | c.mod.SetDataLayout(c.targetData.String()) |
| 116 | if c.Debug { |
| 117 | c.dibuilder = llvm.NewDIBuilder(c.mod) |
| 118 | } |
| 119 | |
| 120 | c.uintptrType = c.ctx.IntType(c.targetData.PointerSize() * 8) |
| 121 | if c.targetData.PointerSize() <= 4 { |
| 122 | // 8, 16, 32 bits targets |
| 123 | c.intType = c.ctx.Int32Type() |
| 124 | } else if c.targetData.PointerSize() == 8 { |
| 125 | // 64 bits target |
| 126 | c.intType = c.ctx.Int64Type() |
| 127 | } else { |
| 128 | panic("unknown pointer size") |
| 129 | } |
| 130 | c.dataPtrType = llvm.PointerType(c.ctx.Int8Type(), 0) |
| 131 | |
| 132 | dummyFuncType := llvm.FunctionType(c.ctx.VoidType(), nil, false) |
| 133 | dummyFunc := llvm.AddFunction(c.mod, "tinygo.dummy", dummyFuncType) |
| 134 | c.funcPtrAddrSpace = dummyFunc.Type().PointerAddressSpace() |
| 135 | c.funcPtrType = dummyFunc.Type() |
| 136 | dummyFunc.EraseFromParentAsFunction() |
| 137 | |
| 138 | return c |
| 139 | } |
| 140 | |
| 141 | // Dispose everything related to the context, _except_ for the IR module (and |
| 142 | // the associated context). |
no test coverage detected