Skip to content

Commit 6856849

Browse files
committed
improve parsing of globals and types
1 parent e97f48a commit 6856849

2 files changed

Lines changed: 25 additions & 4 deletions

File tree

src/intertyper.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,13 @@ function intertyper(data, sidePass, baseLineNums) {
6969

7070
if (mainPass && (line[0] == '%' || line[0] == '@')) {
7171
// If this isn't a type, it's a global variable, make a note of the information now, we will need it later
72-
var testType = /[@%\w\d\.\" $-]+ = type .*/.exec(line);
72+
var parts = line.split(' = ');
73+
assert(parts.length >= 2);
74+
var left = parts[0], right = parts.slice(1).join(' = ');
75+
var testType = /^type .*/.exec(right);
7376
if (!testType) {
74-
var global = /([@%\w\d\.\" $-]+) = .*/.exec(line);
75-
var globalIdent = toNiceIdent(global[1]);
76-
var testAlias = /[@%\w\d\.\" $-]+ = (hidden )?alias .*/.exec(line);
77+
var globalIdent = toNiceIdent(left);
78+
var testAlias = /^(hidden )?alias .*/.exec(right);
7779
Variables.globals[globalIdent] = {
7880
name: globalIdent,
7981
alias: !!testAlias,

tests/cases/typestr.ll

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
; ModuleID = 'tests/hello_world.bc'
2+
target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32-S128"
3+
target triple = "i386-pc-linux-gnu"
4+
5+
@.str = private unnamed_addr constant [15 x i8] c"hello, world!\0A\00", align 1 ; [#uses=1 type=[15 x i8]*]
6+
@.str1227 = private unnamed_addr constant [9 x i8] c" = type \00", align 1
7+
8+
; [#uses=0]
9+
define i32 @main() {
10+
entry:
11+
%retval = alloca i32, align 4 ; [#uses=1 type=i32*]
12+
store i32 0, i32* %retval
13+
%call0 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([9 x i8]* @.str1227, i32 0, i32 0)) ; [#uses=0 type=i32]
14+
%call = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([15 x i8]* @.str, i32 0, i32 0)) ; [#uses=0 type=i32]
15+
ret i32 1
16+
}
17+
18+
; [#uses=1]
19+
declare i32 @printf(i8*, ...)

0 commit comments

Comments
 (0)