Skip to content

Commit

Permalink
Merge 052489a into b667254
Browse files Browse the repository at this point in the history
  • Loading branch information
dannypsnl committed Jan 14, 2020
2 parents b667254 + 052489a commit b3a4ab3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
3 changes: 3 additions & 0 deletions asm/asm_test.go
Expand Up @@ -341,6 +341,9 @@ func TestParseFile(t *testing.T) {
{path: "../testdata/llvm/test/Bitcode/callbr.ll"},
{path: "../testdata/llvm/test/Bitcode/disubrange.ll"},

// LLVM test/CodeGen.
{path: "../testdata/llvm/test/CodeGen/X86/extractps.ll"},

// LLVM test/DebugInfo/Generic.
{path: "../testdata/llvm/test/DebugInfo/Generic/constant-pointers.ll"},
{path: "../testdata/llvm/test/DebugInfo/Generic/debug-info-enum.ll"},
Expand Down
18 changes: 14 additions & 4 deletions asm/module.go
Expand Up @@ -15,6 +15,7 @@ import (

// indexTopLevelEntities indexes the AST top-level entities of the given module.
func (gen *generator) indexTopLevelEntities(old *ast.Module) error {
id := int64(0)
// 1. Index AST top-level entities.
for _, entity := range old.TopLevelEntities() {
switch entity := entity.(type) {
Expand Down Expand Up @@ -43,28 +44,28 @@ func (gen *generator) indexTopLevelEntities(old *ast.Module) error {
}
gen.old.comdatDefs[name] = entity
case *ast.GlobalDecl:
ident := globalIdent(entity.Name())
ident := giveUnnamedIdentID(globalIdent(entity.Name()), &id)
if prev, ok := gen.old.globals[ident]; ok {
return errors.Errorf("global identifier %q already present; prev `%s`, new `%s`", ident.Ident(), text(prev), text(entity))
}
gen.old.globals[ident] = entity
gen.old.globalOrder = append(gen.old.globalOrder, ident)
case *ast.IndirectSymbolDef:
ident := globalIdent(entity.Name())
ident := giveUnnamedIdentID(globalIdent(entity.Name()), &id)
if prev, ok := gen.old.globals[ident]; ok {
return errors.Errorf("global identifier %q already present; prev `%s`, new `%s`", ident.Ident(), text(prev), text(entity))
}
gen.old.globals[ident] = entity
gen.old.globalOrder = append(gen.old.globalOrder, ident)
case *ast.FuncDecl:
ident := globalIdent(entity.Header().Name())
ident := giveUnnamedIdentID(globalIdent(entity.Header().Name()), &id)
if prev, ok := gen.old.globals[ident]; ok {
return errors.Errorf("global identifier %q already present; prev `%s`, new `%s`", ident.Ident(), text(prev), text(entity))
}
gen.old.globals[ident] = entity
gen.old.globalOrder = append(gen.old.globalOrder, ident)
case *ast.FuncDef:
ident := globalIdent(entity.Header().Name())
ident := giveUnnamedIdentID(globalIdent(entity.Header().Name()), &id)
if prev, ok := gen.old.globals[ident]; ok {
return errors.Errorf("global identifier %q already present; prev `%s`, new `%s`", ident.Ident(), text(prev), text(entity))
}
Expand Down Expand Up @@ -98,6 +99,15 @@ func (gen *generator) indexTopLevelEntities(old *ast.Module) error {
return nil
}

// giveUnnamedIdentID give unnamed variable ID to ensure no conflict with others unnamed variables
func giveUnnamedIdentID(ident ir.GlobalIdent, id *int64) ir.GlobalIdent {
if ident.IsUnnamed() {
ident.SetID(*id)
*id++
}
return ident
}

// === [ Create and index IR ] =================================================

// createTopLevelEntities indexes IR top-level identifiers and creates
Expand Down

0 comments on commit b3a4ab3

Please sign in to comment.