Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mu-impl-ref2
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
5
Issues
5
List
Board
Labels
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mu
mu-impl-ref2
Commits
5cc0978b
Commit
5cc0978b
authored
Jul 13, 2016
by
Kunshan Wang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed writeIDNameMap
parent
85e4a1bb
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
44 additions
and
33 deletions
+44
-33
BundleSerializer.scala
src/main/scala/uvm/ir/textoutput/BundleSerializer.scala
+35
-22
MicroVM.scala
src/main/scala/uvm/refimpl/MicroVM.scala
+1
-1
BootImageBuilder.scala
src/main/scala/uvm/refimpl/bootimg/BootImageBuilder.scala
+6
-8
DumpLoadTimer.scala
src/test/scala/junks/DumpLoadTimer.scala
+1
-1
BundleSerializerSmokeTest.scala
...t/scala/uvm/ir/textoutput/BundleSerializerSmokeTest.scala
+1
-1
No files found.
src/main/scala/uvm/ir/textoutput/BundleSerializer.scala
View file @
5cc0978b
...
...
@@ -10,7 +10,7 @@ import uvm.ssavariables._
import
java.time.temporal.IsoFields.Unit
import
uvm.ssavariables.NewStackAction
object
Unnamed
EntityUtils
{
object
EntityUtils
{
def
getName
(
obj
:
Identified
)
:
String
=
{
obj
.
name
.
getOrElse
(
"@uvm.unnamed"
+
obj
.
id
.
toString
())
}
...
...
@@ -18,29 +18,22 @@ object UnnamedEntityUtils {
def
getNames
(
objs
:
Seq
[
Identified
])
:
String
=
{
objs
.
map
(
getName
).
mkString
(
" "
)
}
}
class
BundleSerializer
(
val
bundle
:
GlobalBundle
,
val
writeList
:
Option
[
Set
[
Int
]])
{
import
UnnamedEntityUtils._
import
BundleSerializer._
def
isMetaEntity
(
id
:
Int
)
:
Boolean
=
{
id
<
65536
}
def
filter
(
id
:
Int
)
:
Boolean
=
{
if
(
isMetaEntity
(
id
))
{
false
}
else
{
writeList
match
{
case
None
=>
true
case
Some
(
s
)
=>
s
.
contains
(
id
)
}
}
def
isMetaEntity
(
obj
:
Identified
)
:
Boolean
=
{
isMetaEntity
(
obj
.
id
)
}
}
class
BundleSerializer
(
val
bundle
:
GlobalBundle
,
val
whiteList
:
Set
[
TopLevel
])
{
import
EntityUtils._
import
BundleSerializer._
def
filter
(
obj
:
Identified
)
:
Boolean
=
{
filter
(
obj
.
id
)
def
filter
(
obj
:
TopLevel
)
:
Boolean
=
{
!
isMetaEntity
(
obj
)
&&
whiteList
.
contains
(
obj
)
}
def
writeIDNameMap
(
output
:
Writer
)
:
Unit
=
{
...
...
@@ -51,11 +44,31 @@ class BundleSerializer(val bundle: GlobalBundle, val writeList: Option[Set[Int]]
}
def
writeIDNameMap
(
output
:
StringBuilder
)
:
Unit
=
{
for
(
obj
<-
bundle
.
allNs
.
all
if
filter
(
obj
))
{
val
name
=
getName
(
obj
)
output
.
append
(
"%s %d\n"
.
format
(
name
,
obj
.
id
))
for
(
obj
<-
whiteList
if
!
isMetaEntity
(
obj
))
{
writeIDNamePair
(
obj
,
output
)
obj
match
{
case
func
:
Function
=>
{
bundle
.
funcToVers
(
func
).
headOption
match
{
case
Some
(
fv
)
=>
{
fv
.
bbs
foreach
{
bb
=>
writeIDNamePair
(
bb
,
output
)
bb
.
localVarNs
.
all
foreach
{
lv
=>
writeIDNamePair
(
lv
,
output
)
}
bb
.
insts
foreach
{
inst
=>
writeIDNamePair
(
inst
,
output
)
}
}
}
case
None
=>
// ignore
}
}
case
_
=>
// ignore
}
}
}
private
def
writeIDNamePair
(
obj
:
Identified
,
output
:
StringBuilder
)
:
Unit
=
{
val
id
=
obj
.
id
val
name
=
getName
(
obj
)
output
.
append
(
"%d,%s\n"
.
format
(
id
,
name
))
}
def
writeUIR
(
output
:
Writer
)
:
Unit
=
{
val
sb
=
new
StringBuilder
()
...
...
@@ -212,7 +225,7 @@ class BundleSerializer(val bundle: GlobalBundle, val writeList: Option[Set[Int]]
}
object
BundleSerializer
{
import
Unnamed
EntityUtils._
import
EntityUtils._
def
destToString
(
dest
:
DestClause
)
:
String
=
{
s
"${dest.bb.n}(${dest.args.ns})"
...
...
src/main/scala/uvm/refimpl/MicroVM.scala
View file @
5cc0978b
...
...
@@ -163,7 +163,7 @@ class MicroVM(vmConf: VMConf) {
*
*/
def
debugPrintGlobalBundle
(
w
:
Writer
)
:
Unit
=
{
val
bs
=
new
BundleSerializer
(
globalBundle
,
None
)
val
bs
=
new
BundleSerializer
(
globalBundle
,
globalBundle
.
allTopLevels
().
toSet
)
bs
.
writeUIR
(
w
)
}
...
...
src/main/scala/uvm/refimpl/bootimg/BootImageBuilder.scala
View file @
5cc0978b
...
...
@@ -20,7 +20,7 @@ import uvm.refimpl.nat.NativeSupport
import
uvm.refimpl.nat.PlatformConstants.Word
import
uvm.types._
import
uvm.utils.WithUtils.tryWithResource
import
uvm.ir.textoutput.
Unnamed
EntityUtils
import
uvm.ir.textoutput.EntityUtils
import
uvm.ir.textoutput.BundleSerializer
class
BootImageBuilder
(
implicit
microVM
:
MicroVM
)
{
...
...
@@ -91,6 +91,8 @@ object BootImageWriter {
class
BootImageWriter
(
tcb
:
TransitiveClosureBuilder
,
outputFile
:
String
)(
implicit
microVM
:
MicroVM
)
{
import
BootImageWriter._
val
bundleSerializer
=
new
BundleSerializer
(
microVM
.
globalBundle
,
tcb
.
tls
.
set
)
val
tempDir
=
Files
.
createTempDirectory
(
"mu-bootimg"
)
logger
.
info
(
"Writing bootimg files to temp dir: %s"
.
format
(
tempDir
.
toAbsolutePath
().
toString
()))
...
...
@@ -121,7 +123,6 @@ class BootImageWriter(tcb: TransitiveClosureBuilder, outputFile: String)(implici
writeAllocRecs
(
heapGroup
)
writeIDNameMap
()
writeUIRBundle
()
}
...
...
@@ -155,23 +156,20 @@ class BootImageWriter(tcb: TransitiveClosureBuilder, outputFile: String)(implici
private
def
writeAllocRecs
(
group
:
FileGroup
)
:
Unit
=
{
tryWithResource
(
Files
.
newBufferedWriter
(
group
.
allocFile
,
StandardCharsets
.
UTF_8
))
{
writer
=>
for
(
ar
<-
group
.
allocRecs
)
{
writer
.
write
(
"%d,%d,%d,%d,%s\n"
.
format
(
ar
.
num
,
ar
.
fileOffset
,
ar
.
ty
.
id
,
ar
.
varLen
,
Unnamed
EntityUtils
.
getName
(
ar
.
ty
)))
writer
.
write
(
"%d,%d,%d,%d,%s\n"
.
format
(
ar
.
num
,
ar
.
fileOffset
,
ar
.
ty
.
id
,
ar
.
varLen
,
EntityUtils
.
getName
(
ar
.
ty
)))
}
}
}
private
def
writeIDNameMap
()
:
Unit
=
{
tryWithResource
(
Files
.
newBufferedWriter
(
idNameMapPath
,
StandardCharsets
.
UTF_8
))
{
writer
=>
for
(
obj
<-
tcb
.
tls
.
set
)
{
writer
.
write
(
"%d,%s\n"
.
format
(
obj
.
id
,
UnnamedEntityUtils
.
getName
(
obj
)))
}
bundleSerializer
.
writeIDNameMap
(
writer
)
}
}
private
def
writeUIRBundle
()
:
Unit
=
{
val
bs
=
new
BundleSerializer
(
microVM
.
globalBundle
,
Some
(
tcb
.
tls
.
set
.
map
(
_
.
id
)))
tryWithResource
(
Files
.
newBufferedWriter
(
uirBundlePath
,
StandardCharsets
.
UTF_8
))
{
writer
=>
b
s
.
writeUIR
(
writer
)
b
undleSerializer
.
writeUIR
(
writer
)
}
}
}
...
...
src/test/scala/junks/DumpLoadTimer.scala
View file @
5cc0978b
...
...
@@ -44,7 +44,7 @@ object DumpLoadTimer extends App {
logger
.
info
(
"Dumping loaded bundle..."
)
val
sw
=
new
StringWriter
()
val
bs
=
new
BundleSerializer
(
gb
,
None
)
val
bs
=
new
BundleSerializer
(
gb
,
gb
.
allTopLevels
().
toSet
)
bs
.
writeUIR
(
sw
)
val
bTxt
=
sw
.
toString
()
...
...
src/test/scala/uvm/ir/textoutput/BundleSerializerSmokeTest.scala
View file @
5cc0978b
...
...
@@ -39,7 +39,7 @@ class BundleSerializerSmokeTest extends UvmTestBase with TestingBundlesValidator
logger
.
info
(
"Dumping loaded bundle..."
)
val
sw
=
new
StringWriter
()
val
bs
=
new
BundleSerializer
(
gb
,
None
)
val
bs
=
new
BundleSerializer
(
gb
,
gb
.
allTopLevels
().
toSet
)
bs
.
writeUIR
(
sw
)
val
bTxt
=
sw
.
toString
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment