MCPcopy Create free account
hub / github.com/google/gapid / NewModule

Function NewModule

core/codegen/module.go:46–117  ·  view source on GitHub ↗

NewModule returns a new module with the specified name.

(name string, target *device.ABI)

Source from the content-addressed store, hash-verified

44
45// NewModule returns a new module with the specified name.
46func NewModule(name string, target *device.ABI) *Module {
47 if target == nil {
48 panic("NewModule must be passed a non-nil target")
49 }
50 layout := target.MemoryLayout
51 intSize := 8 * int(layout.Integer.Size)
52 ptrSize := 8 * int(layout.Pointer.Size)
53 sizeSize := 8 * int(layout.Size.Size)
54
55 triple := TargetTriple(target)
56
57 ctx := llvm.NewContext()
58
59 module := ctx.NewModule(name)
60 module.SetTarget(triple.String())
61 if dl := DataLayout(target); dl != "" {
62 module.SetDataLayout(dl)
63 }
64
65 bt := func(name string, dtl *device.DataTypeLayout, llvm llvm.Type) basicType {
66 return basicType{name, 8 * int(dtl.Size), 8 * int(dtl.Alignment), llvm}
67 }
68
69 m := &Module{
70 Types: Types{
71 Void: basicType{"void", 0, 0, ctx.VoidType()},
72 Bool: Integer{false, basicType{"bool", 1, 8, ctx.Int1Type()}},
73 Int: Integer{true, bt("int", layout.Integer, ctx.IntType(intSize))},
74 Int8: Integer{true, bt("int8", layout.I8, ctx.Int8Type())},
75 Int16: Integer{true, bt("int16", layout.I16, ctx.Int16Type())},
76 Int32: Integer{true, bt("int32", layout.I32, ctx.Int32Type())},
77 Int64: Integer{true, bt("int64", layout.I64, ctx.Int64Type())},
78 Uint: Integer{false, bt("uint", layout.Integer, ctx.IntType(intSize))},
79 Uint8: Integer{false, bt("uint8", layout.I8, ctx.Int8Type())},
80 Uint16: Integer{false, bt("uint16", layout.I16, ctx.Int16Type())},
81 Uint32: Integer{false, bt("uint32", layout.I32, ctx.Int32Type())},
82 Uint64: Integer{false, bt("uint64", layout.I64, ctx.Int64Type())},
83 Uintptr: Integer{false, bt("uintptr", layout.Pointer, ctx.IntType(ptrSize))},
84 Size: Integer{false, bt("size", layout.Size, ctx.IntType(sizeSize))},
85 Float32: Float{bt("float32", layout.F32, ctx.FloatType())},
86 Float64: Float{bt("float64", layout.F64, ctx.DoubleType())},
87 pointers: map[Type]Pointer{},
88 arrays: map[typeInt]*Array{},
89 structs: map[string]*Struct{},
90 funcs: map[string]*FunctionType{},
91 enums: map[string]Enum{},
92 aliases: map[string]Alias{},
93 named: map[string]Type{},
94 },
95 llvm: module,
96 ctx: ctx,
97 target: target,
98 triple: triple,
99 name: name,
100 funcs: map[string]*Function{},
101 strings: map[string]llvm.Value{},
102 }
103 m.Types.emptyStructField = Field{"empty-struct", m.Types.Int8}

Callers

nothing calls this directly

Calls 10

FunctionMethod · 0.95
TargetTripleFunction · 0.85
DataLayoutFunction · 0.85
SetTargetMethod · 0.80
IntTypeMethod · 0.80
FloatTypeMethod · 0.80
DoubleTypeMethod · 0.80
StringMethod · 0.65
initMethod · 0.65
PointerMethod · 0.45

Tested by

no test coverage detected