Generator can produce link names
This commit is contained in:
parent
88bc83f277
commit
a9ff511496
@ -117,10 +117,11 @@ func (this *Tree) ensure () {
|
||||
this.Functions = make(map[string] *entity.Function)
|
||||
|
||||
for name, ty := range builtinTypes {
|
||||
access := entity.AccessPublic
|
||||
this.Types[name] = &entity.Typedef {
|
||||
Public: true,
|
||||
Name: name,
|
||||
Type: ty,
|
||||
Acc: &access,
|
||||
Name: name,
|
||||
Type: ty,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ type TopLevel interface {
|
||||
|
||||
// Access determines the external access rule for a top-level entity.
|
||||
type Access int; const (
|
||||
AccessPrivate = iota
|
||||
AccessPrivate Access = iota
|
||||
AccessRestricted
|
||||
AccessPublic
|
||||
)
|
||||
|
@ -20,7 +20,12 @@ func (this *generator) generateFunction (
|
||||
params[index] = llvm.NewParameter(argument.Name, paramType)
|
||||
}
|
||||
|
||||
irFunc := this.module.NewFunction(function.Signature.Name, ret, params...)
|
||||
var name string; if function.LinkName == "" {
|
||||
name = function.Signature.Name
|
||||
} else {
|
||||
name = function.LinkName
|
||||
}
|
||||
irFunc := this.module.NewFunction(name, ret, params...)
|
||||
|
||||
if function.Body != nil {
|
||||
this.blockManager = this.pushBlockManager(irFunc)
|
||||
@ -36,6 +41,8 @@ func (this *generator) generateFunction (
|
||||
this.blockManager.NewRet(body)
|
||||
}
|
||||
}
|
||||
|
||||
this.functions[function.Signature.Name] = irFunc
|
||||
return irFunc, nil
|
||||
}
|
||||
|
||||
@ -57,9 +64,12 @@ func (this *generator) generateMethod (
|
||||
}
|
||||
params[0] = llvm.NewParameter("this", new(llvm.TypePointer))
|
||||
|
||||
irFunc := this.module.NewFunction (
|
||||
method.TypeName + "." + method.Signature.Name,
|
||||
ret, params...)
|
||||
var name string; if method.LinkName == "" {
|
||||
name = method.TypeName + "." + method.Signature.Name
|
||||
} else {
|
||||
name = method.LinkName
|
||||
}
|
||||
irFunc := this.module.NewFunction(name, ret, params...)
|
||||
|
||||
if method.Body != nil {
|
||||
this.blockManager = this.pushBlockManager(irFunc)
|
||||
@ -75,5 +85,7 @@ func (this *generator) generateMethod (
|
||||
this.blockManager.NewRet(body)
|
||||
}
|
||||
}
|
||||
|
||||
this.functions[method.TypeName + "." + method.Signature.Name] = irFunc
|
||||
return irFunc, nil
|
||||
}
|
||||
|
@ -22,6 +22,8 @@ type generator struct {
|
||||
tree analyzer.Tree
|
||||
module *llvm.Module
|
||||
|
||||
functions map[string] *llvm.Function
|
||||
|
||||
managerStack []*blockManager
|
||||
blockManager *blockManager
|
||||
}
|
||||
@ -31,9 +33,10 @@ type generator struct {
|
||||
// the semantic tree that prevents the code generation process from occurring.
|
||||
func (this Target) Generate (tree analyzer.Tree) (*llvm.Module, error) {
|
||||
return (&generator {
|
||||
module: new(llvm.Module),
|
||||
target: this,
|
||||
tree: tree,
|
||||
module: new(llvm.Module),
|
||||
target: this,
|
||||
tree: tree,
|
||||
functions: make(map[string] *llvm.Function),
|
||||
}).generate()
|
||||
}
|
||||
|
||||
@ -73,34 +76,28 @@ func (this *generator) typedef (typeName string) (llvm.Type, error) {
|
||||
}
|
||||
|
||||
func (this *generator) method (typeName string, name string) (*llvm.Function, error) {
|
||||
for _, function := range this.module.Functions {
|
||||
if function.Name() == typeName + "." + name {
|
||||
return function, nil
|
||||
}
|
||||
}
|
||||
|
||||
method, exists := this.functions[typeName + "." + name]
|
||||
if exists { return method, nil }
|
||||
|
||||
ty, exists := this.tree.Types[typeName]
|
||||
if !exists {
|
||||
return nil, errNotFound
|
||||
}
|
||||
method, exists := ty.Methods[name]
|
||||
if !exists {
|
||||
return nil, errNotFound
|
||||
|
||||
if method, exists := ty.Methods[name]; exists {
|
||||
return this.generateMethod(method)
|
||||
}
|
||||
return this.generateMethod(method)
|
||||
return nil, errNotFound
|
||||
}
|
||||
|
||||
func (this *generator) function (name string) (*llvm.Function, error) {
|
||||
for _, function := range this.module.Functions {
|
||||
if function.Name() == name {
|
||||
return function, nil
|
||||
}
|
||||
function, exists := this.functions[name]
|
||||
if exists { return function, nil }
|
||||
|
||||
if function, exists := this.tree.Functions[name]; exists {
|
||||
return this.generateFunction(function)
|
||||
}
|
||||
function, exists := this.tree.Functions[name]
|
||||
if !exists {
|
||||
return nil, errNotFound
|
||||
}
|
||||
return this.generateFunction(function)
|
||||
return nil, errNotFound
|
||||
}
|
||||
|
||||
func sortMapKeys[T any] (unsorted map[string] T) []string {
|
||||
|
Loading…
Reference in New Issue
Block a user